From c7975f8bfeaf37fe5563647e485f3af03174c7fd Mon Sep 17 00:00:00 2001 From: makombe Date: Wed, 30 Oct 2024 13:26:34 +0300 Subject: [PATCH] Add hei outcome encounter endpoint --- .../KenyaemrCoreRestController.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java b/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java index 4bb289d3f..59649e7e0 100644 --- a/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java +++ b/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java @@ -574,6 +574,28 @@ public Object getFacilityName(@RequestParam("facilityCode") String facilityCode) locationResponseObj.put("name", facility.getName()); return locationResponseObj; } + /** + * Gets last hei outcome encounter + * @return + */ + @RequestMapping(method = RequestMethod.GET, value = "/heiOutcomeEncounter") + @ResponseBody + public Object getHeiOutcomeEncounter(@RequestParam("patientUuid") String patientUuid) { + SimpleObject heiOutcomeResponseObj = new SimpleObject(); + PatientIdentifierType heiNumber = MetadataUtils.existing(PatientIdentifierType.class, MchMetadata._PatientIdentifierType.HEI_ID_NUMBER); + Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); + PatientIdentifier pi = heiNumber != null && patient != null ? patient.getPatientIdentifier(heiNumber) : null; + EncounterType heiOutcomeEncType = MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHCS_HEI_COMPLETION); + Form heiOutcomeForm = MetadataUtils.existing(Form.class, MchMetadata._Form.MCHCS_HEI_COMPLETION); + Encounter lastHeiOutcomeEnc = EmrUtils.lastEncounter(patient, heiOutcomeEncType, heiOutcomeForm); + if(pi.getIdentifier() != null) { + heiOutcomeResponseObj.put("heiNumber", pi.getIdentifier()); + } + if(lastHeiOutcomeEnc != null) { + heiOutcomeResponseObj.put("heiOutcomeEncounterUuid", lastHeiOutcomeEnc.getUuid()); + } + return heiOutcomeResponseObj; + } /** * Get a list of programs a patient is eligible for