Skip to content

Commit

Permalink
Added REST call to get latest Obs for patient
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickWaweru committed May 31, 2024
1 parent 88cfd54 commit f8cdd5c
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3089,4 +3089,39 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu

return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body(ret);
}

/**
* Returns the latest patient Obs value coded concept ID and UUID given the patient UUID and Concept UUID
* @param patientUuid
* @return value coded concept id and uuid
*/
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS})
@RequestMapping(method = RequestMethod.GET, value = "/latestobs")
@ResponseBody
public Object getLatestObs(@RequestParam("patientUuid") String patientUuid, @RequestParam("concept") String conceptIdentifier) {
SimpleObject ret = SimpleObject.create("conceptId", 0, "conceptUuid", "");
if (StringUtils.isBlank(patientUuid)) {
return new ResponseEntity<Object>("You must specify a patientUuid in the request!",
new HttpHeaders(), HttpStatus.BAD_REQUEST);
}

if (StringUtils.isBlank(conceptIdentifier)) {
return new ResponseEntity<Object>("You must specify a concept in the request!",
new HttpHeaders(), HttpStatus.BAD_REQUEST);
}

Patient patient = Context.getPatientService().getPatientByUuid(patientUuid);

Concept concept = Dictionary.getConcept(conceptIdentifier);
List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, concept);
if (obsList.size() > 0) {
// these are in reverse chronological order
Obs currentObs = obsList.get(0);
ret.put("conceptId", currentObs.getValueCoded().getId());
ret.put("conceptUuid", currentObs.getValueCoded().getUuid());
}

return ret;

}
}

0 comments on commit f8cdd5c

Please sign in to comment.