From 513bdcbb67aebc9aed28b1bf0d55adb052c4c8dc Mon Sep 17 00:00:00 2001 From: "aime.rolandi" Date: Tue, 28 Oct 2025 09:43:28 -0300 Subject: [PATCH] Seleccionar idstudy segun identifierfield para redirect --- lib/api_web/controllers/redirect.ex | 39 +++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/api_web/controllers/redirect.ex b/lib/api_web/controllers/redirect.ex index 014c883..d885c5b 100644 --- a/lib/api_web/controllers/redirect.ex +++ b/lib/api_web/controllers/redirect.ex @@ -12,13 +12,6 @@ defmodule ApiWeb.Redirect do viewer_uid = Envar.get("imViewer4_uid") gethash = Envar.get("imViewer4_gethash") idsite = Envar.get("IDSITE") - studyidentifier_ed = Envar.get("acceso_ed") - - accession = studyidentifier = if studyidentifier_ed == "IDSTUDY" do - String.to_integer(accession) - else - accession - end Logger.info("parametros: #{inspect(accession)}") @@ -79,7 +72,37 @@ defmodule ApiWeb.Redirect do defp open_imviewer4(v, accession, expiration) do url = v.gethash <> v.client_uuid - case Req.post(url, json: %{"accessionnumber" => accession, "expiration" => expiration}) do + studyidentifier = Envar.get("IDENTIFIERFIELD") || "IDSTUDY" + + query = + if studyidentifier == "IDSTUDY" do + from s in "study", + join: p in "patient", + on: p.idpatient == s.idpatient, + where: s.accessionnumber == ^accessionnumber, + select: %{ + idstudy: s.idstudy + } + else + from s in "study", + join: p in "patient", + on: p.idpatient == s.idpatient, + where: s.accessionnumber == ^accessionnumber, + select: %{ + idstudy: s.idstudy + } + end + + idstudy = case Repo.one(query) do + nil -> + "nil" + res -> + res.idstudy + end + + idstudy_str = to_string(idstudy) + + case Req.post(url, json: %{"idstudy" => idstudy_str, "expiration" => expiration}) do {:ok, %Req.Response{status: 200, body: %{"hash" => hash}}} -> {:ok, hash}