Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add. Accession number for lab test performed in OpenElis to orders table #238

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ private Obs createObsWith(String textValue, Concept concept, Date obsDateTime) {

protected Set<Encounter> associateTestResultsToOrder(OpenElisAccession openElisAccession) throws ParseException {
Encounter orderEncounter = encounterService.getEncounterByUuid(openElisAccession.getAccessionUuid());

if (!orderEncounter.getOrders().isEmpty()) {
for (OpenElisTestDetail testDetail : openElisAccession.getTestDetails()) {
if (testDetail == null && testDetail.getStatus() == null) {
angshu marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
for (Order order : orderEncounter.getOrders()) {
if (testDetail.getTestUuid().equals(order.getConcept().getUuid())) {
if ("Canceled".equals(testDetail.getStatus())) {
angshu marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
order.setAccessionNumber(openElisAccession.getAccessionUuid());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are setting the access uuid? we have the column name as access number.

}
}
}
}

final EncounterType labResultEncounterType = getLabResultEncounterType();
final Set<OpenElisTestDetail> allTests = openElisAccession.getTestDetails();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.bahmni.module.elisatomfeedclient.api.worker;

import java.util.HashMap;
import java.util.Map;
import org.bahmni.module.elisatomfeedclient.api.Constants;
import org.bahmni.module.elisatomfeedclient.api.ElisAtomFeedProperties;
import org.bahmni.module.elisatomfeedclient.api.builder.OpenElisAccessionBuilder;
Expand Down Expand Up @@ -35,8 +33,13 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -143,6 +146,38 @@ public void shouldUpdateEncounterWhenAccessionHasNewOrder() throws Exception {
verify(bahmniVisitAttributeSaveCommand).save(previousEncounter);
}

@Test
public void shouldUpdateEncounterWithAccessionNumberWhenItsGenerated() throws Exception {
Encounter orderEncounter = getEncounterWithTests("test1", "test2", "test3");
final Visit visit = new Visit();
visit.setId(1);
orderEncounter.setVisit(visit);
visit.setEncounters(new HashSet<>(Arrays.asList(orderEncounter)));
OpenElisTestDetail test1 = new OpenElisTestDetailBuilder().withTestUuid("test1").build();
OpenElisTestDetail test2 = new OpenElisTestDetailBuilder().withTestUuid("test2").build();
OpenElisTestDetail test3 = new OpenElisTestDetailBuilder().withTestUuid("test3").build();
test1.setStatus("Not started");
test2.setStatus("Canceled");
test3.setStatus("Not started");
OpenElisAccession openElisAccession = new OpenElisAccessionBuilder().withTestDetails(new HashSet<>(Arrays.asList(test1, test2, test3))).build();

stubAccession(openElisAccession);
when(encounterService.getEncounterByUuid(openElisAccession.getAccessionUuid())).thenReturn(orderEncounter);
when(accessionMapper.findOrInitializeVisit(any(Patient.class), any(Date.class), any(String.class))).thenReturn(visit);
when(encounterService.saveEncounter(orderEncounter)).thenReturn(orderEncounter);
accessionEventWorker.associateTestResultsToOrder(openElisAccession);

List<String> orderAccessionNumbers = orderEncounter.getOrders().stream()
.map(Order::getAccessionNumber)
.collect(Collectors.toList());

verify(encounterService, times(1)).getEncounterByUuid(openElisAccession.getAccessionUuid());

assertEquals("1234", orderAccessionNumbers.get(0));
assertNotEquals("1234", orderAccessionNumbers.get(1));
assertEquals("1234", orderAccessionNumbers.get(2));
}

@Test
public void shouldUpdateEncounterWhenAccessionHasRemovedOrderFromPreviousEncounter() throws Exception {
Encounter previousEncounter = getEncounterWithTests("test1", "test2", "test3");
Expand Down Expand Up @@ -228,8 +263,10 @@ private Encounter getEncounterWithTests(String... testUuids) {
for (String testUuid : testUuids) {
Order order = new Order();
Concept concept = new Concept();
concept.setId(123);
concept.setUuid(testUuid);
order.setConcept(concept);
order.setAccessionNumber(null);
encounter.addOrder(order);
encounter.setEncounterType(new EncounterType());
Patient patient = new Patient();
Expand Down
Loading