Skip to content

Commit

Permalink
api updates
Browse files Browse the repository at this point in the history
patient and encounter apis updated to show the medications and encounters that are associated with the patient or healthcare encounter

Ref carnival-data/carnival#123
  • Loading branch information
hjwilli committed Aug 1, 2024
1 parent 6eaa859 commit 6800277
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
34 changes: 33 additions & 1 deletion docs/ResearchAnswersApi.raml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
34 changes: 31 additions & 3 deletions src/main/groovy/example/carnival/micronaut/web/AppWS.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ Total Number of Survey Question Responses: ${numSurveyResponses}
String url = ""
String first_name = ""
String last_name = ""
List<String> encounter_ids = []
List<String> encounter_urls = []

Map diagnosed_with = [:]
Map perscribed = [:]
}
class PatientResponse {
List<Patient> patients = []
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6800277

Please sign in to comment.