diff --git a/bahmni-emr-api/src/main/java/org/openmrs/module/bahmniemrapi/laborder/service/LabOrderResultsServiceImpl.java b/bahmni-emr-api/src/main/java/org/openmrs/module/bahmniemrapi/laborder/service/LabOrderResultsServiceImpl.java index 6017956bb3..af1545a2bf 100644 --- a/bahmni-emr-api/src/main/java/org/openmrs/module/bahmniemrapi/laborder/service/LabOrderResultsServiceImpl.java +++ b/bahmni-emr-api/src/main/java/org/openmrs/module/bahmniemrapi/laborder/service/LabOrderResultsServiceImpl.java @@ -64,20 +64,18 @@ public LabOrderResults getAll(Patient patient, List visits, int numberOfA int currentAccession = 0; for (int count = totalEncounters - 1; count >= 0; count--) { Encounter encounter = encounters.get(count); - if (currentAccession >= numberOfAccessions) { - break; - } - EncounterTransaction encounterTransaction = encounterTransactionMapper.map(encounter, false); - List existingTestOrders = filterTestOrders(encounterTransaction, encounter, encounterTestOrderUuidMap, null, null, null); - testOrders.addAll(existingTestOrders); + if (currentAccession < numberOfAccessions) { + List existingTestOrders = filterTestOrders(encounterTransaction, encounter, encounterTestOrderUuidMap, null, null, null); + testOrders.addAll(existingTestOrders); + if (existingTestOrders.size() > 0) { + currentAccession++; + } + } List nonVoidedObservations = filterObservations(encounterTransaction.getObservations(), null, null); observations.addAll(nonVoidedObservations); createAccessionNotesByEncounter(encounterToAccessionNotesMap, encounters, encounter); - mapObservationsWithEncounter(nonVoidedObservations, encounter, encounterObservationMap); - if (existingTestOrders.size() > 0) { - currentAccession++; - } + mapObservationsWithEncounter(nonVoidedObservations, encounter, encounterObservationMap); } List labOrderResults = mapOrdersWithObs(testOrders, observations, encounterTestOrderUuidMap, encounterObservationMap, encounterToAccessionNotesMap);