Skip to content

Commit

Permalink
Update patient api to list encounters
Browse files Browse the repository at this point in the history
Update patient api to return associated encounter_ids

Ref carnival-data/carnival#123
  • Loading branch information
hjwilli committed Aug 1, 2024
1 parent 098f8e5 commit 5a346ce
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/main/groovy/example/carnival/micronaut/web/AppWS.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.P
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerVertex

import org.apache.tinkerpop.gremlin.structure.Vertex
import org.apache.tinkerpop.gremlin.structure.Edge
Expand Down Expand Up @@ -119,11 +120,28 @@ Total Number of Survey Question Responses: ${numSurveyResponses}
String id = ""
String first_name = ""
String last_name = ""
List<String> encounter_ids = []
}
class PatientResponse {
List<Patient> patients = []
}

private Patient parsePatientFromVertex(TinkerVertex pVtx) {
Patient p = new Patient()
p.id = GraphModel.PX.ID.valueOf(pVtx)
p.first_name = GraphModel.PX_PATIENT.FIRST_NAME.valueOf(pVtx)
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)
.values(GraphModel.PX.ID.getLabel())
.dedup()
.toList()
}

return p
}

@Get("/case_patients")
@Produces(MediaType.APPLICATION_JSON)
PatientResponse casePatients() {
Expand All @@ -135,12 +153,7 @@ Total Number of Survey Question Responses: ${numSurveyResponses}
.isa(GraphModel.VX.PATIENT).as('p')
.select('p')
.each { m ->

Patient p = new Patient()
p.id = GraphModel.PX.ID.valueOf(m)
p.first_name = GraphModel.PX_PATIENT.FIRST_NAME.valueOf(m)
p.last_name = GraphModel.PX_PATIENT.LAST_NAME.valueOf(m)

Patient p = parsePatientFromVertex(m)
response.patients << p
//response += "\n ${p.id}"
}
Expand All @@ -161,11 +174,7 @@ Total Number of Survey Question Responses: ${numSurveyResponses}
.select('p')
.each { m ->

Patient p = new Patient()
p.id = GraphModel.PX.ID.valueOf(m)
p.first_name = GraphModel.PX_PATIENT.FIRST_NAME.valueOf(m)
p.last_name = GraphModel.PX_PATIENT.LAST_NAME.valueOf(m)

Patient p = parsePatientFromVertex(m)
response.patients << p
//response += "\n ${p.id}"
}
Expand Down

0 comments on commit 5a346ce

Please sign in to comment.