diff --git a/api/src/main/java/org/openmrs/module/emrapi/visit/VisitWithDiagnosesService.java b/api/src/main/java/org/openmrs/module/emrapi/visit/VisitWithDiagnosesService.java index 0742872d..07bd2917 100644 --- a/api/src/main/java/org/openmrs/module/emrapi/visit/VisitWithDiagnosesService.java +++ b/api/src/main/java/org/openmrs/module/emrapi/visit/VisitWithDiagnosesService.java @@ -4,10 +4,10 @@ public interface VisitWithDiagnosesService { /** - * Fetches visits of a patient by patient ID. + * Fetches visits with note encounters and diagnoses of a patient by patient ID. * * @param patientUuid the UUID of the patient - * @return a list of visits + * @return a list of visits that has note encounters and diagnoses */ List getVisitsByPatientId(String patientUuid, int startIndex, int limit); } diff --git a/omod/src/main/java/org/openmrs/module/emrapi/web/controller/VisitController.java b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/VisitController.java index c3f1a04c..2772c01a 100644 --- a/omod/src/main/java/org/openmrs/module/emrapi/web/controller/VisitController.java +++ b/omod/src/main/java/org/openmrs/module/emrapi/web/controller/VisitController.java @@ -38,15 +38,17 @@ public ResponseEntity getVisitsByPatientId( List visits; visits = visitWithDiagnosesService.getVisitsByPatientId(patientUuid, context.getStartIndex(), context.getLimit()); + // Convert the visits and diagnoses to SimpleObjects List convertedVisits = new ArrayList<>(); - for (VisitWithDiagnoses visit : visits) { SimpleObject visitObject = (SimpleObject) ConversionUtil.convertToRepresentation(visit, context.getRepresentation()); List convertedDiagnoses = new ArrayList<>(); + for (Diagnosis diagnosis : visit.getDiagnoses()) { convertedDiagnoses.add((SimpleObject) ConversionUtil.convertToRepresentation(diagnosis, context.getRepresentation())); } visitObject.put("diagnoses", convertedDiagnoses); + convertedVisits.add(visitObject); } diff --git a/omod/src/test/java/org/openmrs/module/emrapi/web/controller/VisitControllerTest.java b/omod/src/test/java/org/openmrs/module/emrapi/web/controller/VisitControllerTest.java index 546a0917..63780f2a 100644 --- a/omod/src/test/java/org/openmrs/module/emrapi/web/controller/VisitControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/emrapi/web/controller/VisitControllerTest.java @@ -46,8 +46,6 @@ public void shouldGetVisitsByPatientId() throws Exception { String firstVisitUuid = "1esd5218-6b78-11e0-93c3-18a905e044dc"; String secondVisitUuid = "1c72e1ac-9b18-11e0-93c3-18a905e044dc"; - // extract the response from the mockMvc - MvcResult response = mockMvc.perform(get("/rest/v1/emrapi/patient/" + patientUuid + "/visit") .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk())