From 6800277941cbaa9421b1af4258f7011c5a54127e Mon Sep 17 00:00:00 2001 From: hjwilli Date: Thu, 1 Aug 2024 13:50:34 -0400 Subject: [PATCH] api updates patient and encounter apis updated to show the medications and encounters that are associated with the patient or healthcare encounter Ref https://github.com/carnival-data/carnival/issues/123 --- docs/ResearchAnswersApi.raml | 34 ++++++++++++++++++- .../carnival/micronaut/web/AppWS.groovy | 34 +++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/docs/ResearchAnswersApi.raml b/docs/ResearchAnswersApi.raml index 36bde1e..a7f9cc0 100644 --- a/docs/ResearchAnswersApi.raml +++ b/docs/ResearchAnswersApi.raml @@ -12,6 +12,12 @@ types: url: string first_name: string last_name: string + encounter_urls: string[] + diagnosed_with: + condition_codes: string[] + perscribed: + medication_codes: string[] + encounter: type: object properties: @@ -20,6 +26,10 @@ types: patient_url: string start: string end: string + diagnosed_at: + condition_codes: string[] + perscribed_at: + medication_codes: string[] /patient/{id}: get: @@ -35,7 +45,29 @@ types: "id":"821c1a88-ebfa-9ee9-a629-4e9eb546df6b", "url": "http://localhost:5858/patient/821c1a88-ebfa-9ee9-a629-4e9eb546df6b" "first_name":"Fernando603", - "last_name":"Reyes140" + "last_name":"Reyes140", + "encounter_urls": [ + "http://localhost:5858/encounter/5f608e6b-82c4-a02a-7833-d2ac1e9b84b5", + "http://localhost:5858/encounter/8412af74-ab45-db05-2990-b27142f69f22", + "http://localhost:5858/encounter/d1433764-19cf-88c5-9d53-e7c73281b51d", + "http://localhost:5858/encounter/e59f7314-416a-83b2-0a10-13f1c112a378" + ], + "diagnosed_with": { + "condition_codes": [ + "160903007", + "361055000", + "422650009" + ] + }, + "perscribed": { + "medication_codes": [ + "308136", + "310798", + "314076", + "849574", + "313782" + ] + } } 404: body: diff --git a/src/main/groovy/example/carnival/micronaut/web/AppWS.groovy b/src/main/groovy/example/carnival/micronaut/web/AppWS.groovy index cd1d0c2..f1b6d37 100644 --- a/src/main/groovy/example/carnival/micronaut/web/AppWS.groovy +++ b/src/main/groovy/example/carnival/micronaut/web/AppWS.groovy @@ -122,7 +122,10 @@ Total Number of Survey Question Responses: ${numSurveyResponses} String url = "" String first_name = "" String last_name = "" - List encounter_ids = [] + List encounter_urls = [] + + Map diagnosed_with = [:] + Map perscribed = [:] } class PatientResponse { List patients = [] @@ -142,6 +145,9 @@ Total Number of Survey Question Responses: ${numSurveyResponses} String reason_code = "" String reason_description = "" + + Map diagnosed_at = [:] + Map perscribed_at = [:] } private Encounter parseEncounterFromVertex(TinkerVertex eVtx) { @@ -160,8 +166,19 @@ Total Number of Survey Question Responses: ${numSurveyResponses} e.reason_description = GraphModel.PX_ENCOUNTER.REASON_DESCRIPTION.valueOf(eVtx) carnivalGraph.carnival.withTraversal { Graph graph, GraphTraversalSource g -> - e.patient_url = g.V(eVtx).in(GraphModel.EX.HAS).isa(GraphModel.VX.PATIENT) + e.patient_url = baseUrl + "/patient/" + + g.V(eVtx).in(GraphModel.EX.HAS).isa(GraphModel.VX.PATIENT) .values(GraphModel.PX.ID.getLabel()).toList().first() + + e.diagnosed_at["condition_codes"] = g.V(eVtx).out(GraphModel.EX.DIAGNOSED_AT) + .values(GraphModel.PX.CODE.getLabel()) + .dedup() + .toList() + + e.perscribed_at["medication_codes"] = g.V(eVtx).out(GraphModel.EX.PRESCRIBED_AT) + .values(GraphModel.PX.CODE.getLabel()) + .dedup() + .toList() } return e @@ -178,10 +195,21 @@ Total Number of Survey Question Responses: ${numSurveyResponses} p.last_name = GraphModel.PX_PATIENT.LAST_NAME.valueOf(pVtx) carnivalGraph.carnival.withTraversal { Graph graph, GraphTraversalSource g -> - p.encounter_ids = g.V(pVtx).out(GraphModel.EX.HAS).isa(GraphModel.VX.ENCOUNTER) + p.encounter_urls = g.V(pVtx).out(GraphModel.EX.HAS).isa(GraphModel.VX.ENCOUNTER) .values(GraphModel.PX.ID.getLabel()) .dedup() .toList() + .collect{ baseUrl + "/encounter/$it" } + + p.diagnosed_with["condition_codes"] = g.V(pVtx).out(GraphModel.EX.DIAGNOSED_WITH) + .values(GraphModel.PX.CODE.getLabel()) + .dedup() + .toList() + + p.perscribed["medication_codes"] = g.V(pVtx).out(GraphModel.EX.PRESCRIBED) + .values(GraphModel.PX.CODE.getLabel()) + .dedup() + .toList() } return p