Se crea el parser para customfilter. Agregamos variables de entorno para manejar url de adjuntos con o sin clave de encriptacion.
This commit is contained in:
		@ -9,7 +9,6 @@ defmodule Api.Study do
 | 
			
		||||
 | 
			
		||||
    idsite = Envar.get("IDSITE") |> String.to_integer
 | 
			
		||||
    domain = Envar.get("CHECK_ORIGIN")
 | 
			
		||||
    escaneados = Envar.get("ESCANEADOS")
 | 
			
		||||
 | 
			
		||||
    id_study = if Envar.get("IDENTIFIERFIELD") == "ACCESSIONNUMBER" do
 | 
			
		||||
      query =
 | 
			
		||||
@ -25,15 +24,6 @@ defmodule Api.Study do
 | 
			
		||||
 | 
			
		||||
    id_study = if is_integer(id_study), do: id_study, else: String.to_integer(id_study)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # accession_fragment =
 | 
			
		||||
    #   if Envar.get("IDENTIFIERFIELD") == "ACCESSIONNUMBER" do
 | 
			
		||||
    #     fragment("?::text", ^accession)
 | 
			
		||||
    #   else
 | 
			
		||||
    #     fragment("?::integer", ^id_study)
 | 
			
		||||
    #   end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    Logger.info("id_study -------> #{inspect(id_study)}")
 | 
			
		||||
 | 
			
		||||
    # Las siguientes consultas obtienen la información completa
 | 
			
		||||
@ -70,56 +60,109 @@ defmodule Api.Study do
 | 
			
		||||
        }
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # escaneados
 | 
			
		||||
    subquery2 = subquery(
 | 
			
		||||
      from s in "study",
 | 
			
		||||
        join: ss in "studyscans", on: ss.idstudy == s.idstudy,
 | 
			
		||||
        join: sc in "scanclasses", on: sc.idscanclass == ss.idscanclass,
 | 
			
		||||
        join: p in "patient", on: s.idpatient == p.idpatient,
 | 
			
		||||
        where: s.idstudy == ^id_study,
 | 
			
		||||
        select: %{
 | 
			
		||||
          idsite: type(^idsite, :integer),
 | 
			
		||||
    escaneados_clave = Envar.get("ESCANEADOS_CLAVE")
 | 
			
		||||
    base_escaneados = Envar.get("ESCANEADOS")
 | 
			
		||||
 | 
			
		||||
    escaneados_expr =
 | 
			
		||||
      if escaneados_clave do
 | 
			
		||||
        dynamic([_, ss, _, _],
 | 
			
		||||
          fragment(
 | 
			
		||||
            "concat(?::text, substring(encrypt(?::text::bytea, ?, 'aes')::text from 3))",
 | 
			
		||||
            ^base_escaneados,
 | 
			
		||||
            ss.idstudyscan,
 | 
			
		||||
            ^escaneados_clave
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
      else
 | 
			
		||||
        dynamic([_, ss, _, _],
 | 
			
		||||
          fragment(
 | 
			
		||||
            "concat(?::text, ?::text)",
 | 
			
		||||
            ^base_escaneados,
 | 
			
		||||
            ss.idstudyscan
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
    select_expr_es =
 | 
			
		||||
      dynamic([s, ss, sc, p], %{
 | 
			
		||||
        idsite: type(^idsite, :integer),
 | 
			
		||||
          iddocument: fragment("substring(encrypt(?::text::bytea, '1nf0rm3', 'aes')::text from 3)", ss.idstudyscan),
 | 
			
		||||
          document_name: sc.scanclass,
 | 
			
		||||
          document_type: "url",
 | 
			
		||||
          url: fragment(
 | 
			
		||||
            "concat(?::text, substring(encrypt(?::text::bytea, '1nf0rm3', 'aes')::text from 3))",
 | 
			
		||||
            ^escaneados,
 | 
			
		||||
            ss.idstudyscan
 | 
			
		||||
          ),
 | 
			
		||||
          url: ^escaneados_expr,
 | 
			
		||||
          patientname: p.patientname,
 | 
			
		||||
          proceduredescription: s.studydescription,
 | 
			
		||||
          studydate: fragment("TO_CHAR(?, 'YYYY-MM-DD')", s.studydate),
 | 
			
		||||
          studytime: fragment("TO_CHAR(?, 'HH24:MI:SS')", s.studytime),
 | 
			
		||||
          accessionnumber: s.idstudy,
 | 
			
		||||
          patientid: p.patientid
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
    subquery2 = subquery(
 | 
			
		||||
      from s in "study",
 | 
			
		||||
        join: ss in "studyscans", on: ss.idstudy == s.idstudy,
 | 
			
		||||
        join: sc in "scanclasses", on: sc.idscanclass == ss.idscanclass,
 | 
			
		||||
        join: p in "patient", on: s.idpatient == p.idpatient,
 | 
			
		||||
        where: s.idstudy == ^id_study,
 | 
			
		||||
        select: ^select_expr_es
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    # adjuntos
 | 
			
		||||
    subquery3 =
 | 
			
		||||
    adjuntos_clave = Envar.get("ADJUNTOS_CLAVE")
 | 
			
		||||
    base_adjuntos = Envar.get("ADJUNTOS")
 | 
			
		||||
 | 
			
		||||
    adjuntos_expr =
 | 
			
		||||
      if adjuntos_clave do
 | 
			
		||||
        dynamic([_, sa, _],
 | 
			
		||||
          fragment(
 | 
			
		||||
            "concat(?::text, substring(encrypt(?::text::bytea, ?, 'aes')::text from 3))",
 | 
			
		||||
            ^base_adjuntos,
 | 
			
		||||
            sa.idstudyattachment,
 | 
			
		||||
            ^adjuntos_clave
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
      else
 | 
			
		||||
        dynamic([_, sa, _],
 | 
			
		||||
          fragment(
 | 
			
		||||
            "concat(?::text, ?::text)",
 | 
			
		||||
            ^base_adjuntos,
 | 
			
		||||
            sa.idstudyattachment
 | 
			
		||||
          )
 | 
			
		||||
        )
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
    select_expr_ad =
 | 
			
		||||
      dynamic([s, sa, p], %{
 | 
			
		||||
        idsite: type(^idsite, :integer),
 | 
			
		||||
        iddocument:
 | 
			
		||||
          fragment(
 | 
			
		||||
            "substring(encrypt(?::text::bytea, '1nf0rm3', 'aes')::text from 3)",
 | 
			
		||||
            sa.idstudyattachment
 | 
			
		||||
          ),
 | 
			
		||||
        document_name: sa.name,
 | 
			
		||||
        document_type:
 | 
			
		||||
          fragment(
 | 
			
		||||
            "CASE WHEN ? NOT IN ('jpg', 'jpeg', 'png') THEN 'attachment' ELSE 'url' END",
 | 
			
		||||
            sa.format
 | 
			
		||||
          ),
 | 
			
		||||
        url: ^adjuntos_expr,
 | 
			
		||||
        patientname: p.patientname,
 | 
			
		||||
        proceduredescription: s.studydescription,
 | 
			
		||||
        studydate: fragment("TO_CHAR(?, 'YYYY-MM-DD')", s.studydate),
 | 
			
		||||
        studytime: fragment("TO_CHAR(?, 'HH24:MI:SS')", s.studytime),
 | 
			
		||||
        accessionnumber: s.idstudy,
 | 
			
		||||
        patientid: ""
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
    subquery3 = subquery(
 | 
			
		||||
      from s in "study",
 | 
			
		||||
        join: sa in "studyattachments", on: sa.idstudy == s.idstudy,
 | 
			
		||||
        join: p in "patient", on: p.idpatient == s.idpatient,
 | 
			
		||||
        where: s.idstudy == ^id_study,
 | 
			
		||||
        select: %{
 | 
			
		||||
          idsite: type(^idsite, :integer),
 | 
			
		||||
          iddocument: fragment("substring(encrypt(?::text::bytea, '1nf0rm3', 'aes')::text from 3)", sa.idstudyattachment),
 | 
			
		||||
          document_name: sa.name,
 | 
			
		||||
          document_type: fragment("CASE WHEN ? NOT IN ('jpg', 'jpeg', 'png') THEN 'attachment' ELSE 'url' END", sa.format),
 | 
			
		||||
          url: fragment(
 | 
			
		||||
            "concat(?::text, ?::text, substring(encrypt(?::text::bytea, '1nf0rm3', 'aes')::text from 3))",
 | 
			
		||||
            ^domain,
 | 
			
		||||
            "/api/attachment/",
 | 
			
		||||
            sa.idstudyattachment
 | 
			
		||||
          ),
 | 
			
		||||
          patientname: p.patientname,
 | 
			
		||||
          proceduredescription: s.studydescription,
 | 
			
		||||
          studydate: fragment("TO_CHAR(?, 'YYYY-MM-DD')", s.studydate),
 | 
			
		||||
          studytime: fragment("TO_CHAR(?, 'HH24:MI:SS')", s.studytime),
 | 
			
		||||
          accessionnumber: s.idstudy,
 | 
			
		||||
          patientid: ""
 | 
			
		||||
        }
 | 
			
		||||
        select: ^select_expr_ad
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    # Si no encontró informes, ni adjuntos, ni nada
 | 
			
		||||
    # se traen sólo los datos básicos del estudio
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user