From 75198c597c7491d91cd54482e58a2fab4066a1d7 Mon Sep 17 00:00:00 2001 From: Parvathy Babu <102500787+parvathy00@users.noreply.github.com> Date: Wed, 15 May 2024 17:18:03 +0530 Subject: [PATCH] BAH-3745 | Fix. Handle Syncing Of Quantity For Revised Drug Orders (#108) * Parvathy | BAH-3745 | Fix. Handle Syncing Of Quantity For Same Drug Orders * Parvathy | BAH-3745 | Refactor. Move removeDuplicateOrders Function to MapERPOrders Class * Parvathy | BAH-3745 | Fix. Add Previous Order Of Revised Order To OpenERPOrders * Parvathy | BAH-3745 | Add. Test Cases * Parvathy | BAH-3745 | Refactor. Rename drugOrderUri Property * Parvathy | BAH-3745 | Fix. Failing Tests --- .../openerp/OpenERPAtomFeedProperties.java | 9 + .../openerp/client/FeedClientFactory.java | 2 +- .../domain/encounter/MapERPOrders.java | 91 ++++++- .../domain/encounter/OpenERPOrders.java | 26 +- .../domain/encounter/OpenMRSDrugOrder.java | 39 +++ .../worker/OpenERPSaleOrderEventWorker.java | 9 +- .../feed/openerp/worker/WorkerFactory.java | 5 +- .../main/resources/erp-atomfeed.properties | 1 + .../openerp/client/OpenERPCustomerFeedIT.java | 3 +- .../domain/encounter/MapERPOrdersTest.java | 222 ++++++++++++++- .../domain/encounter/OpenERPOrdersTest.java | 42 --- .../worker/OpenERPSaleOrderEventWorkerIT.java | 5 +- .../src/test/resources/bahmniDrugOrder.json | 126 +++++++++ .../resources/encounterResourceForOrders.json | 257 ++++++++++++++++++ .../encounterResourceForRevisedDrugOrder.json | 94 +++++++ .../erp-atomfeed.properties.template | 1 + 16 files changed, 842 insertions(+), 90 deletions(-) delete mode 100644 openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrdersTest.java create mode 100644 openerp-atomfeed-service/src/test/resources/bahmniDrugOrder.json create mode 100644 openerp-atomfeed-service/src/test/resources/encounterResourceForOrders.json create mode 100644 openerp-atomfeed-service/src/test/resources/encounterResourceForRevisedDrugOrder.json diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenERPAtomFeedProperties.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenERPAtomFeedProperties.java index 7a3c0cf0..7099b06c 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenERPAtomFeedProperties.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/OpenERPAtomFeedProperties.java @@ -58,6 +58,9 @@ public String getFeedUri(String feedname) { @Value("${saleable.feed.generator.uri}") private String saleableFeedUri; + @Value("${drugorder.uri}") + private String drugOrderUri; + public String getFeedUriForJob(Jobs feedJob) { switch (feedJob){ case CUSTOMER_FEED: return customFeedUri; @@ -88,6 +91,11 @@ public String getOdooRESTUrlEndPoint(Jobs feedJob) { default: throw new RuntimeException("Can not identify endpoint URI for requested Job."); } } + + public String getDrugOrderUri() { + return drugOrderUri; + } + @Value("${openerp.host}") private String openErpHost; @@ -224,6 +232,7 @@ private HashMap getInfo() { values.put("drug.feed.generator.uri",drugFeedUri ); values.put("lab.feed.generator.uri",labFeedUri ); values.put("saleorder.feed.generator.uri", saleOrderFeedUri); + values.put("drugorder.uri", drugOrderUri); values.put("openerp.host",openErpHost ); values.put("openerp.port",openErpPort ); values.put("openerp.database",openErpDatabase ); diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/FeedClientFactory.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/FeedClientFactory.java index 5fa447cd..b5759938 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/FeedClientFactory.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/FeedClientFactory.java @@ -46,7 +46,7 @@ public AtomFeedClient getFeedClient(OpenERPAtomFeedProperties openERPAtomFeedPro } try { String urlPrefix = getURLPrefix(jobName,openERPAtomFeedProperties); - EventWorker eventWorker = workerFactory.getWorker(jobName, feedUri, odooURL, openERPContext, urlPrefix); + EventWorker eventWorker = workerFactory.getWorker(jobName, feedUri, odooURL, openERPContext, urlPrefix, openERPAtomFeedProperties, isRestEnabled); return new AtomFeedClient(allFeeds, allMarkers, allFailedEvents, atomFeedProperties(openERPAtomFeedProperties), transactionManager, new URI(feedUri), eventWorker) ; } catch (URISyntaxException e) { throw new RuntimeException("error for uri:" + feedUri, e); diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrders.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrders.java index 11ab77d3..8732917b 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrders.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrders.java @@ -1,24 +1,38 @@ package org.bahmni.feed.openerp.domain.encounter; +import com.fasterxml.jackson.databind.ObjectMapper; import org.bahmni.feed.openerp.ObjectMapperRepository; +import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; +import org.bahmni.feed.openerp.client.OpenMRSWebClient; import org.bahmni.feed.openerp.domain.visit.OpenMRSVisit; import org.bahmni.feed.openerp.domain.visit.VisitAttributes; import org.bahmni.openerp.web.request.builder.Parameter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; +import java.net.URI; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class MapERPOrders extends OpenMRSEncounterEvent { + private final Boolean isOdoo16; private OpenMRSEncounter openMRSEncounter; private OpenMRSVisit openMRSVisit; + private OpenMRSWebClient openMRSWebClient; + private OpenERPAtomFeedProperties openERPAtomFeedProperties; + private static Logger logger = LoggerFactory.getLogger(MapERPOrders.class); - public MapERPOrders(OpenMRSEncounter openMRSEncounter, OpenMRSVisit openMRSVisit) { + public MapERPOrders(OpenMRSEncounter openMRSEncounter, OpenMRSVisit openMRSVisit, OpenMRSWebClient openMRSWebClient, OpenERPAtomFeedProperties openERPAtomFeedProperties, Boolean isOdoo16) { this.openMRSEncounter = openMRSEncounter; this.openMRSVisit = openMRSVisit; - + this.openMRSWebClient = openMRSWebClient; + this.openERPAtomFeedProperties = openERPAtomFeedProperties; + this.isOdoo16 = isOdoo16; } public List getParameters(String eventId, String feedURIForLastReadEntry, String feedURI) throws IOException { @@ -74,10 +88,12 @@ private String mapOpenERPOrders() throws IOException { openERPOrder.setConceptName(drugOrder.getConceptName()); openERPOrders.add(openERPOrder); + if(isOdoo16) { + addPreviousDrugOrder(openERPOrder, openERPOrders); + } } - - + Map latestOrders = new LinkedHashMap<>(); for (OpenMRSOrder order : openMRSEncounter.getOrders()) { OpenERPOrder openERPOrder = new OpenERPOrder(); openERPOrder.setVisitId(openMRSEncounter.getVisitUuid()); @@ -95,12 +111,73 @@ private String mapOpenERPOrders() throws IOException { openERPOrder.setType(order.getOrderType()); openERPOrder.setVisitType(getVisitType()); openERPOrder.setProviderName(providerName); - openERPOrders.add(openERPOrder); - } + latestOrders = findLatestOrder(openERPOrder, latestOrders); + } + for (OpenERPOrder latestOrder : latestOrders.values()) { + openERPOrders.add(latestOrder); + } return ObjectMapperRepository.objectMapper.writeValueAsString(openERPOrders); } + private void addPreviousDrugOrder(OpenERPOrder openERPOrder, OpenERPOrders openERPOrders) { + if ("REVISE".equals(openERPOrder.getAction()) && !isPreviousOrderFound(openERPOrder, openERPOrders)) { + OpenERPOrder previousOrder = fetchPreviousDrugOrder(openERPOrder.getPreviousOrderId()); + if (previousOrder != null) { + openERPOrders.add(previousOrder); + } + } + } + + private boolean isPreviousOrderFound(OpenERPOrder openERPOrder, OpenERPOrders openERPOrders) { + List existingOrders = openERPOrders.getOpenERPOrders(); + for (OpenERPOrder existingOrder : existingOrders) { + if (existingOrder.getOrderId().equals(openERPOrder.getPreviousOrderId())) { + return true; + } + } + return false; + } + + private OpenERPOrder fetchPreviousDrugOrder(String previousOrderId) { + String apiUrl = openERPAtomFeedProperties.getDrugOrderUri() + "/" + previousOrderId; + final ObjectMapper mapper = new ObjectMapper(); + try { + String response = openMRSWebClient.get(URI.create(apiUrl)); + OpenMRSDrugOrder previousOrder = mapper.readValue(response, OpenMRSDrugOrder.class); + OpenERPOrder order = new OpenERPOrder(); + order.setOrderId(previousOrder.getUuid()); + order.setPreviousOrderId(previousOrder.getUuid()); + order.setEncounterId(previousOrder.getEncounterUuid()); + order.setProductId(previousOrder.getDrugUuid()); + order.setProductName(previousOrder.getDrugName()); + order.setQuantity(previousOrder.getQuantity()); + order.setQuantityUnits(previousOrder.getQuantityUnits()); + order.setAction(previousOrder.getAction()); + order.setVisitId(previousOrder.getVisitUuid()); + order.setVisitType(getVisitType()); + order.setType(previousOrder.getOrderType()); + order.setVoided(previousOrder.isVoided()); + order.setProviderName(previousOrder.getProviderName()); + order.setDispensed("false"); + order.setConceptName(previousOrder.getConceptName()); + order.setDateCreated(previousOrder.getDateActivated()); + return order; + } catch (Exception e) { + logger.error("Error occurred while fetching previous drug order: " + e.getMessage()); + throw new RuntimeException("Failed to fetch previous drug order", e); + } + } + + //Filters orders to keep only the latest action for each product. This is necessary for ensuring consistent and accurate quotation generation, particularly when order objects may not be in chronological order. + private Map findLatestOrder(OpenERPOrder openERPOrder, Map latestOrders) { + String productId = openERPOrder.getProductId(); + if (!latestOrders.containsKey(productId) || latestOrders.get(productId).getDateCreated().before(openERPOrder.getDateCreated())) { + latestOrders.put(productId, openERPOrder); + } + return latestOrders; + } + private String getVisitType() { for (VisitAttributes visitAttribute : openMRSVisit.getAttributes()) { if (visitAttribute.getAttributeType().getDisplay().equals("Visit Status")) { @@ -109,6 +186,4 @@ private String getVisitType() { } return null; } - - } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java index c8af6e1a..fac554fe 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java @@ -11,31 +11,11 @@ public OpenERPOrders(String id){ this.openERPOrders = new ArrayList(); } - public List getOpenERPOrders() { - return removeDuplicateOrders(openERPOrders); + public OpenERPOrders(){ } - //Filters orders to keep only the latest action for each product. This is necessary for ensuring consistent and accurate quotation generation, particularly when order objects may not be in chronological order. - public List removeDuplicateOrders(List orders) { - Map latestOrders = new LinkedHashMap<>(); - for (OpenERPOrder order : orders) { - if("Drug Order".equals(order.getType())) { - String productId = order.getProductId(); - if (latestOrders.containsKey(productId)) { - OpenERPOrder existingOrder = latestOrders.get(productId); - double updatedQuantity = "NEW".equals(order.getAction()) ? existingOrder.getQuantity() + order.getQuantity() : existingOrder.getQuantity() - order.getQuantity(); - existingOrder.setQuantity(updatedQuantity); - latestOrders.put(productId, existingOrder); - } else { - latestOrders.put(productId, order); - } - } else { - latestOrders.merge(order.getProductId(), order, (existingOrder, newOrder) -> - (existingOrder.getDateCreated().before(newOrder.getDateCreated())) ? newOrder : existingOrder - ); - } - } - return new ArrayList<>(latestOrders.values()); + public List getOpenERPOrders() { + return openERPOrders; } public void add(OpenERPOrder order) { diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSDrugOrder.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSDrugOrder.java index d9317885..bf38bdb3 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSDrugOrder.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSDrugOrder.java @@ -17,6 +17,9 @@ public class OpenMRSDrugOrder { private String orderType; private Date dateActivated; private boolean voided; + private String encounterUuid; + private OpenMRSVisit visit; + private Provider provider; public OpenMRSConcept getConcept() { return concept; @@ -74,6 +77,18 @@ public String getQuantityUnits() { return getDosingInstructions() != null ? getDosingInstructions().getQuantityUnits() : null; } + public String getEncounterUuid() { + return encounterUuid; + } + + public String getVisitUuid() { + return getVisit().getUuid(); + } + + public OpenMRSVisit getVisit() { + return visit; + } + public boolean isVoided() { return voided; } @@ -82,6 +97,14 @@ public String getOrderType() { return orderType; } + public String getProviderName() { + return getProvider().getName(); + } + + public Provider getProvider() { + return provider; + } + @JsonIgnoreProperties(ignoreUnknown = true) public class OpenMRSDrug { private String uuid; @@ -114,4 +137,20 @@ public String getQuantityUnits() { return quantityUnits; } } + + @JsonIgnoreProperties(ignoreUnknown = true) + public class OpenMRSVisit { + private String uuid; + public String getUuid() { + return uuid; + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public class Provider { + private String name; + public String getName() { + return name; + } + } } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorker.java index 490d129e..f9d8d516 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorker.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorker.java @@ -1,5 +1,6 @@ package org.bahmni.feed.openerp.worker; +import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.bahmni.feed.openerp.ObjectMapperRepository; @@ -17,21 +18,25 @@ import java.net.URI; public class OpenERPSaleOrderEventWorker implements EventWorker { + private final Boolean isOdoo16; OpenERPContext openERPContext; private final String feedUrl; private final String odooURL; private final OpenMRSWebClient webClient; private final String urlPrefix; + private final OpenERPAtomFeedProperties openERPAtomFeedProperties; private static Logger logger = LoggerFactory.getLogger(OpenERPSaleOrderEventWorker.class); - public OpenERPSaleOrderEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient webClient, String urlPrefix) { + public OpenERPSaleOrderEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient webClient, String urlPrefix, OpenERPAtomFeedProperties openERPAtomFeedProperties, Boolean isOdoo16) { this.feedUrl = feedUrl; this.odooURL = odooURL; this.openERPContext = openERPContext; this.webClient = webClient; this.urlPrefix = urlPrefix; + this.openERPAtomFeedProperties = openERPAtomFeedProperties; + this.isOdoo16 = isOdoo16; } @Override @@ -63,7 +68,7 @@ private OpenERPRequest mapRequest(Event event) throws IOException { String visitContent = webClient.get(URI.create(urlPrefix + visitURL)); OpenMRSVisit openMRSVisit = ObjectMapperRepository.objectMapper.readValue(visitContent, OpenMRSVisit.class); - MapERPOrders mapERPOrders = new MapERPOrders(openMRSEncounter, openMRSVisit); + MapERPOrders mapERPOrders = new MapERPOrders(openMRSEncounter, openMRSVisit, webClient, openERPAtomFeedProperties, isOdoo16); OpenERPRequest erpRequest = new OpenERPRequest("atom.event.worker", "process_event", mapERPOrders.getParameters(event.getId(), event.getFeedUri(), feedUrl)); if (event.getFeedUri() == null) diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/WorkerFactory.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/WorkerFactory.java index 80bc48b3..96480bc1 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/WorkerFactory.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/WorkerFactory.java @@ -1,5 +1,6 @@ package org.bahmni.feed.openerp.worker; +import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; import org.bahmni.feed.openerp.job.Jobs; import org.bahmni.feed.openerp.client.WebClientProvider; import org.bahmni.openerp.web.client.strategy.OpenERPContext; @@ -14,10 +15,10 @@ public WorkerFactory(WebClientProvider webClientProvider) { } - public EventWorker getWorker(Jobs jobName, String feedUrl, String odooURL, OpenERPContext openERPContext, String urlPrefix) { + public EventWorker getWorker(Jobs jobName, String feedUrl, String odooURL, OpenERPContext openERPContext, String urlPrefix, OpenERPAtomFeedProperties openERPAtomFeedProperties, Boolean isOdoo16) { switch (jobName){ case CUSTOMER_FEED: return new OpenERPCustomerServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); - case SALEORDER_FEED: return new OpenERPSaleOrderEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + case SALEORDER_FEED: return new OpenERPSaleOrderEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix, openERPAtomFeedProperties, isOdoo16); case OPENELIS_SALEORDER_FEED: return new OpenElisSaleOrderEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.openElisWebClient(), urlPrefix); case DRUG_FEED: return new OpenERPDrugServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); case LAB_TEST_FEED: return new OpenERPLabTestServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); diff --git a/openerp-atomfeed-service/src/main/resources/erp-atomfeed.properties b/openerp-atomfeed-service/src/main/resources/erp-atomfeed.properties index 13ba37ca..58ac4be6 100644 --- a/openerp-atomfeed-service/src/main/resources/erp-atomfeed.properties +++ b/openerp-atomfeed-service/src/main/resources/erp-atomfeed.properties @@ -28,6 +28,7 @@ openelis.saleorder.feed.generator.uri=http://localhost:8052/openelis/ws/feed/pat drug.feed.generator.uri=http://localhost:8050/openmrs/ws/atomfeed/drug/recent lab.feed.generator.uri=http://localhost:8050/openmrs/ws/atomfeed/lab/recent saleable.feed.generator.uri=http://localhost:8050/openmrs/ws/atomfeed/saleable/recent +drugorder.uri=http://localhost:8050/openmrs/ws/rest/v1/bahmnicore/drugOrders chunking.strategy=number diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/client/OpenERPCustomerFeedIT.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/client/OpenERPCustomerFeedIT.java index 1c81d409..4b411f68 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/client/OpenERPCustomerFeedIT.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/client/OpenERPCustomerFeedIT.java @@ -98,6 +98,7 @@ public class OpenERPCustomerFeedIT { @Autowired private AtomFeedSpringTransactionSupport transactionSupport; + private Boolean isOdoo16; @Before public void setUp() throws URISyntaxException { @@ -191,7 +192,7 @@ public void shouldCreateCustomerInOpenERP() throws URISyntaxException, FeedExcep when(openMRSAuthenticator.authenticate("mrsuser", "mrspwd", ObjectMapperRepository.objectMapper)).thenReturn(authenticationResponse); when(webClientProvider.getWebClient(any(Jobs.class))).thenReturn(webClient); - when(workerFactory.getWorker(Jobs.CUSTOMER_FEED, feedUrl, odooURL, openERPContext, "http://mrs.auth.uri")).thenReturn(openERPCustomerServiceEventWorker); + when(workerFactory.getWorker(Jobs.CUSTOMER_FEED, feedUrl, odooURL, openERPContext, "http://mrs.auth.uri", atomFeedProperties, isOdoo16)).thenReturn(openERPCustomerServiceEventWorker); AtomFeedClientHelper clientHelper = mock(AtomFeedClientHelper.class); AtomFeedClient atomFeedClient = new AtomFeedClient(allFeedsMock, allMarkersJdbc, allFailedEvents, FeedClientFactory.atomFeedProperties(atomFeedProperties), diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrdersTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrdersTest.java index 3fa8d4a4..9fa73dbd 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrdersTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrdersTest.java @@ -1,9 +1,13 @@ package org.bahmni.feed.openerp.domain.encounter; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import org.bahmni.feed.openerp.ObjectMapperRepository; -import org.bahmni.feed.openerp.domain.encounter.MapERPOrders; -import org.bahmni.feed.openerp.domain.encounter.OpenMRSEncounter; +import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; +import org.bahmni.feed.openerp.client.OpenMRSWebClient; import org.bahmni.feed.openerp.domain.visit.OpenMRSVisit; +import org.bahmni.feed.openerp.domain.visit.VisitAttributeType; +import org.bahmni.feed.openerp.domain.visit.VisitAttributes; import org.bahmni.feed.openerp.testhelper.FileConverter; import org.bahmni.openerp.web.request.builder.Parameter; import org.junit.Assert; @@ -14,9 +18,10 @@ import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; -import java.util.List; +import java.net.URI; +import java.util.*; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) public class MapERPOrdersTest { @@ -29,9 +34,23 @@ public class MapERPOrdersTest { @Mock private OpenMRSVisit openMRSVisit; + @Mock + private OpenMRSWebClient openMRSWebClient; + + @Mock + private OpenERPAtomFeedProperties openERPAtomFeedProperties; + + @Mock + private VisitAttributes visitAttribute; + + @Mock + private VisitAttributeType visitAttributeType; + + private Boolean isOdoo16 = true; + @Before public void setUp() { - mapERPOrders = new MapERPOrders(openMRSEncounter, openMRSVisit); + mapERPOrders = new MapERPOrders(openMRSEncounter, openMRSVisit, openMRSWebClient, openERPAtomFeedProperties, isOdoo16); } @Test @@ -52,7 +71,7 @@ public void shouldMapOpenERPOrders() throws IOException { public void shouldMapEncountersWithObsCodedUnRelatedToOrders() throws Exception { String orderEncounter = FileConverter.convertToString("orderWithEncObsWithCodedConceptUnRelatedToOrder.json"); OpenMRSEncounter encounter = ObjectMapperRepository.objectMapper.readValue(orderEncounter, OpenMRSEncounter.class); - MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit); + MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit, openMRSWebClient, openERPAtomFeedProperties, isOdoo16); List parameters = mapERPOrders.getParameters("102", "something", "somethingelse"); Assert.assertEquals(8, parameters.size()); } @@ -61,7 +80,7 @@ public void shouldMapEncountersWithObsCodedUnRelatedToOrders() throws Exception public void shouldMapEncountersWithObsNumericUnRelatedToOrders() throws Exception { String orderEncounter = FileConverter.convertToString("orderWithEncObsOfNumericUnRelatedOrder.json"); OpenMRSEncounter encounter = ObjectMapperRepository.objectMapper.readValue(orderEncounter, OpenMRSEncounter.class); - MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit); + MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit, openMRSWebClient, openERPAtomFeedProperties, isOdoo16); List parameters = mapERPOrders.getParameters("102", "something", "somethingelse"); Assert.assertEquals(8, parameters.size()); } @@ -70,12 +89,197 @@ public void shouldMapEncountersWithObsNumericUnRelatedToOrders() throws Exceptio public void shouldMapEncountersWithObsDispensedRelatedToOrders() throws Exception { String orderEncounter = FileConverter.convertToString("orderWithEncObsCodedWithDispensedRelatedToOrder.json"); OpenMRSEncounter encounter = ObjectMapperRepository.objectMapper.readValue(orderEncounter, OpenMRSEncounter.class); - MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit); + MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit, openMRSWebClient, openERPAtomFeedProperties, isOdoo16); + List parameters = mapERPOrders.getParameters("102", "something", "somethingelse"); + Assert.assertEquals(8, parameters.size()); + } + + @Test + public void shouldAddOnlyOrdersWithLatestAction() throws Exception { + String orderEncounter = FileConverter.convertToString("encounterResourceForOrders.json"); + OpenMRSEncounter encounter = ObjectMapperRepository.objectMapper.readValue(orderEncounter, OpenMRSEncounter.class); + String openERPOrders = "{"+ + "\"id\":\"ca4ef1ba-5258-4853-81c6-7c72d86bd615\","+ + "\"openERPOrders\":["+ + "{"+ + "\"orderId\":\"27b361c5-93fe-4273-8b7d-a725fe7237c6\","+ + "\"previousOrderId\":null,"+ + "\"encounterId\":\"ca4ef1ba-5258-4853-81c6-7c72d86bd615\","+ + "\"productId\":\"d9c230a5-89d8-4e4d-b08b-2af3b1234c80\","+ + "\"productName\":\"Paracetamol 500mg\","+ + "\"quantity\":12.0,"+ + "\"quantityUnits\":\"Tablet(s)\","+ + "\"action\":\"NEW\","+ + "\"visitId\":\"4d25c6ed-f069-4bce-b696-a45a9bd96f53\","+ + "\"visitType\":\"OPD\","+ + "\"type\":\"Drug Order\","+ + "\"description\":null,"+ + "\"voided\":false,"+ + "\"locationName\":null,"+ + "\"providerName\":\"Super Man\","+ + "\"dispensed\":\"false\","+ + "\"conceptName\":\"Paracetamol 500mg\","+ + "\"dateCreated\":1714474203000"+ + "},"+ + "{"+ + "\"orderId\":\"540e979b-ff9a-41ac-a638-9abc6e3ca5c4\","+ + "\"previousOrderId\":\"27b361c5-93fe-4273-8b7d-a725fe7237c6\","+ + "\"encounterId\":\"ca4ef1ba-5258-4853-81c6-7c72d86bd615\","+ + "\"productId\":\"d9c230a5-89d8-4e4d-b08b-2af3b1234c80\","+ + "\"productName\":\"Paracetamol 500mg\","+ + "\"quantity\":18.0,"+ + "\"quantityUnits\":\"Tablet(s)\","+ + "\"action\":\"REVISE\","+ + "\"visitId\":\"4d25c6ed-f069-4bce-b696-a45a9bd96f53\","+ + "\"visitType\":\"OPD\","+ + "\"type\":\"Drug Order\","+ + "\"description\":null,"+ + "\"voided\":false,"+ + "\"locationName\":null,"+ + "\"providerName\":\"Super Man\","+ + "\"dispensed\":\"false\","+ + "\"conceptName\":\"Paracetamol 500mg\","+ + "\"dateCreated\":1714474203000"+ + "},"+ + "{"+ + "\"orderId\":\"03de97ab-0816-4b51-b317-5680c32a44f9\","+ + "\"previousOrderId\":null,"+ + "\"encounterId\":\"ca4ef1ba-5258-4853-81c6-7c72d86bd615\","+ + "\"productId\":\"33cb5232-172e-4769-ad2d-49fadaafc318\","+ + "\"productName\":\"CD4 Test\","+ + "\"quantity\":1.0,"+ + "\"quantityUnits\":\"Unit(s)\","+ + "\"action\":\"NEW\","+ + "\"visitId\":\"4d25c6ed-f069-4bce-b696-a45a9bd96f53\","+ + "\"visitType\":\"OPD\","+ + "\"type\":\"Lab Order\","+ + "\"description\":null,"+ + "\"voided\":false,"+ + "\"locationName\":null,"+ + "\"providerName\":\"Super Man\","+ + "\"dispensed\":\"false\","+ + "\"conceptName\":null,"+ + "\"dateCreated\":1714474115000"+ + "},"+ + "{"+ + "\"orderId\":\"47695984-bfd9-45a9-9196-060ab6ee6ab7\","+ + "\"previousOrderId\":\"7282556e-fefe-45b6-be43-1cdb507ae3b4\","+ + "\"encounterId\":\"ca4ef1ba-5258-4853-81c6-7c72d86bd615\","+ + "\"productId\":\"c424eed0-3f10-11e4-adec-0800271c1b75\","+ + "\"productName\":\"CHEST Lateral\","+ + "\"quantity\":1.0,"+ + "\"quantityUnits\":\"Unit(s)\","+ + "\"action\":\"DISCONTINUE\","+ + "\"visitId\":\"4d25c6ed-f069-4bce-b696-a45a9bd96f53\","+ + "\"visitType\":\"OPD\","+ + "\"type\":\"Radiology Order\","+ + "\"description\":null,"+ + "\"voided\":false,"+ + "\"locationName\":null,"+ + "\"providerName\":\"Super Man\","+ + "\"dispensed\":\"false\","+ + "\"conceptName\":null,"+ + "\"dateCreated\":1714474203000"+ + "}"+ + "]}"; +// ObjectMapper objectMapper = ObjectMapperRepository.objectMapper.enable(SerializationFeature.INDENT_OUTPUT); +// Object jsonObject = objectMapper.readValue(openERPOrdersJson, Object.class); +// OpenERPOrders openERPOrders = ObjectMapperRepository.objectMapper.writeValueAsString(openERPOrdersJson, OpenERPOrders.class); + + when(visitAttribute.getValue()).thenReturn("OPD"); + when(visitAttribute.getAttributeType()).thenReturn(visitAttributeType); + when(visitAttributeType.getDisplay()).thenReturn("Visit Status"); + + List visitAttributesList = new ArrayList<>(); + visitAttributesList.add(visitAttribute); + when(openMRSVisit.getAttributes()).thenReturn(visitAttributesList); + + MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit, openMRSWebClient, openERPAtomFeedProperties, isOdoo16); List parameters = mapERPOrders.getParameters("102", "something", "somethingelse"); +// OpenERPOrders openERPOrdersParameters = ObjectMapperRepository.objectMapper.readValue(parameters.get(6).getValue(), OpenERPOrders.class); Assert.assertEquals(8, parameters.size()); + Assert.assertEquals(openERPOrders, parameters.get(6).getValue()); } + @Test + public void shouldFetchPreviousOrderForRevisedOrderInDifferentEncounter() throws Exception{ + String orderEncounter = FileConverter.convertToString("encounterResourceForRevisedDrugOrder.json"); + OpenMRSEncounter encounter = ObjectMapperRepository.objectMapper.readValue(orderEncounter, OpenMRSEncounter.class); + String previousOrder = FileConverter.convertToString("bahmniDrugOrder.json"); + String response = "{" + + "\"id\":\"ca4ef1ba-5258-4853-81c6-7c72d86bd615\"," + + "\"openERPOrders\":[" + + "{" + + "\"orderId\":\"540e979b-ff9a-41ac-a638-9abc6e3ca5c4\"," + + "\"previousOrderId\":\"27b361c5-93fe-4273-8b7d-a725fe7237c6\"," + + "\"encounterId\":\"ca4ef1ba-5258-4853-81c6-7c72d86bd615\"," + + "\"productId\":\"d9c230a5-89d8-4e4d-b08b-2af3b1234c80\"," + + "\"productName\":\"Paracetamol 500mg\"," + + "\"quantity\":18.0," + + "\"quantityUnits\":\"Tablet(s)\"," + + "\"action\":\"REVISE\"," + + "\"visitId\":\"4d25c6ed-f069-4bce-b696-a45a9bd96f53\"," + + "\"visitType\":\"OPD\"," + + "\"type\":\"Drug Order\"," + + "\"description\":null," + + "\"voided\":false," + + "\"locationName\":null," + + "\"providerName\":\"Super Man\"," + + "\"dispensed\":\"false\"," + + "\"conceptName\":\"Paracetamol 500mg\"," + + "\"dateCreated\":1714474203000" + + "}," + + "{" + + "\"orderId\":\"27b361c5-93fe-4273-8b7d-a725fe7237c6\"," + + "\"previousOrderId\":\"27b361c5-93fe-4273-8b7d-a725fe7237c6\"," + + "\"encounterId\":\"f4aed26e-1d1d-4602-a02e-b1fb9e79f649\"," + + "\"productId\":\"d9c230a5-89d8-4e4d-b08b-2af3b1234c80\"," + + "\"productName\":\"Paracetamol 500mg\"," + + "\"quantity\":12.0," + + "\"quantityUnits\":\"Tablet(s)\"," + + "\"action\":\"NEW\"," + + "\"visitId\":\"4d25c6ed-f069-4bce-b696-a45a9bd96f53\"," + + "\"visitType\":\"OPD\"," + + "\"type\":\"Drug Order\"," + + "\"description\":null," + + "\"voided\":false," + + "\"locationName\":null," + + "\"providerName\":\"docthree docthree\"," + + "\"dispensed\":\"false\"," + + "\"conceptName\":\"Paracetamol 500mg\"," + + "\"dateCreated\":1714636983000" + + "}" + + "]}"; +// ObjectMapper objectMapper = ObjectMapperRepository.objectMapper.enable(SerializationFeature.INDENT_OUTPUT); +// Object jsonObject = objectMapper.readValue(response, Object.class); +// response = objectMapper.writeValueAsString(jsonObject); + when(openERPAtomFeedProperties.getDrugOrderUri()).thenReturn("http://example.com/drugOrders"); + String apiUrl = "http://example.com/drugOrders/27b361c5-93fe-4273-8b7d-a725fe7237c6"; + when(openMRSWebClient.get(URI.create(apiUrl))).thenReturn(previousOrder); + when(visitAttribute.getValue()).thenReturn("OPD"); + when(visitAttribute.getAttributeType()).thenReturn(visitAttributeType); + when(visitAttributeType.getDisplay()).thenReturn("Visit Status"); + List visitAttributesList = new ArrayList<>(); + visitAttributesList.add(visitAttribute); + when(openMRSVisit.getAttributes()).thenReturn(visitAttributesList); + MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit, openMRSWebClient, openERPAtomFeedProperties, isOdoo16); + List parameters = mapERPOrders.getParameters("102", "something", "somethingelse"); + Assert.assertEquals(8, parameters.size()); + Assert.assertEquals(response, parameters.get(6).getValue()); + } + + @Test + public void shouldNotAddPreviousOrderIfRevisedOrderInSameEncounter() throws Exception{ + String orderEncounter = FileConverter.convertToString("encounterResourceForOrders.json"); + OpenMRSEncounter encounter = ObjectMapperRepository.objectMapper.readValue(orderEncounter, OpenMRSEncounter.class); + + MapERPOrders mapERPOrders = new MapERPOrders(encounter, openMRSVisit, openMRSWebClient, openERPAtomFeedProperties, isOdoo16); + List parameters = mapERPOrders.getParameters("102", "something", "somethingelse"); + Assert.assertEquals(8, parameters.size()); + OpenERPOrders finalOrders = ObjectMapperRepository.objectMapper.readValue(parameters.get(6).getValue(), OpenERPOrders.class); + Assert.assertEquals(4, finalOrders.getOpenERPOrders().size()); + } -} \ No newline at end of file +} diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrdersTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrdersTest.java deleted file mode 100644 index 4a4ae8d0..00000000 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrdersTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.bahmni.feed.openerp.domain.encounter; - -import org.junit.Test; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import static org.junit.Assert.assertEquals; - -public class OpenERPOrdersTest { - - @Test - public void shouldRemoveDuplicateOrders() { - OpenERPOrder order1 = new OpenERPOrder(); - order1.setProductId("1"); - order1.setDateCreated(new Date(1704718128000L)); - - OpenERPOrder order2 = new OpenERPOrder(); - order2.setProductId("2"); - order2.setDateCreated(new Date(17047181283000L)); - - OpenERPOrder order3 = new OpenERPOrder(); - order3.setProductId("1"); - order3.setDateCreated(new Date(1704718125000L)); - - OpenERPOrder order4 = new OpenERPOrder(); - order4.setProductId("3"); - order4.setDateCreated(new Date(1704718131000L)); - - OpenERPOrders openerpOrders = new OpenERPOrders("123"); - openerpOrders.add(order1); - openerpOrders.add(order2); - openerpOrders.add(order3); - openerpOrders.add(order4); - - List result = openerpOrders.removeDuplicateOrders(openerpOrders.getOpenERPOrders()); - - List expected = Arrays.asList(order1, order2, order4); - - assertEquals(expected, result); - } -} - diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorkerIT.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorkerIT.java index 2d500b17..8a21b8aa 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorkerIT.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPSaleOrderEventWorkerIT.java @@ -45,6 +45,7 @@ public class OpenERPSaleOrderEventWorkerIT { @Autowired private AtomFeedSpringTransactionSupport transactionSupport; + private Boolean isOdoo16; @Before public void setUp() throws URISyntaxException { @@ -87,7 +88,7 @@ public void create_SaleOrder_In_ERP_For_Lab_Order(){ String feedUrl = "http://xxxx/encounter/feed/2"; String odooURL = "http://odooURL"; - OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl,odooURL,openERPContext,webClient,"http://mrs.auth.uri"); + OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl,odooURL,openERPContext,webClient,"http://mrs.auth.uri", atomFeedProperties, isOdoo16); Event event = new Event("Test",feedUrl); eventWorker.process(event); } @@ -119,7 +120,7 @@ public void create_SaleOrder_For_Bed_In_ERP_When_Bed_Is_Assigned() { String odooURL = "http://odooURL"; Event event = new Event("Test", feedUrl); - OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl, odooURL, openERPContext, webClient,"http://mrs.auth.uri"); + OpenERPSaleOrderEventWorker eventWorker = new OpenERPSaleOrderEventWorker(feedUrl, odooURL, openERPContext, webClient,"http://mrs.auth.uri", atomFeedProperties, isOdoo16); eventWorker.process(event); } diff --git a/openerp-atomfeed-service/src/test/resources/bahmniDrugOrder.json b/openerp-atomfeed-service/src/test/resources/bahmniDrugOrder.json new file mode 100644 index 00000000..09a63333 --- /dev/null +++ b/openerp-atomfeed-service/src/test/resources/bahmniDrugOrder.json @@ -0,0 +1,126 @@ +{ + "visit": { + "uuid": "4d25c6ed-f069-4bce-b696-a45a9bd96f53", + "startDateTime": 1714473839000 + }, + "drugOrder": { + "concept": { + "uuid": "62b91692-0641-45b1-9233-3c9609c6b6a8", + "name": "Paracetamol 500mg", + "dataType": "N/A", + "shortName": "Paracetamol 500mg", + "units": null, + "conceptClass": "Misc", + "hiNormal": null, + "lowNormal": null, + "set": false, + "mappings": [] + }, + "instructions": null, + "uuid": "27b361c5-93fe-4273-8b7d-a725fe7237c6", + "orderType": "Drug Order", + "accessionNumber": null, + "orderGroup": null, + "dateCreated": null, + "dateChanged": null, + "dateStopped": null, + "orderNumber": "ORD-524", + "careSetting": "OUTPATIENT", + "action": "NEW", + "commentToFulfiller": null, + "autoExpireDate": 1715279399000, + "urgency": null, + "previousOrderUuid": "27b361c5-93fe-4273-8b7d-a725fe7237c6", + "drug": { + "name": "Paracetamol 500mg", + "uuid": "d9c230a5-89d8-4e4d-b08b-2af3b1234c80", + "form": "Tablet", + "strength": null + }, + "drugNonCoded": null, + "dosingInstructionType": "org.openmrs.module.bahmniemrapi.drugorder.dosinginstructions.FlexibleDosingInstructions", + "dosingInstructions": { + "dose": 2.0, + "doseUnits": "Tablet(s)", + "route": "Oral", + "frequency": "Thrice a day", + "asNeeded": false, + "administrationInstructions": "{\"instructions\":\"As directed\"}", + "quantity": 12.0, + "quantityUnits": "Tablet(s)", + "numberOfRefills": null + }, + "dateActivated": 1714474203000, + "scheduledDate": 1715106600000, + "effectiveStartDate": 1715106600000, + "effectiveStopDate": 1715279399000, + "orderReasonText": null, + "duration": 2, + "durationUnits": "Day(s)", + "voided": false, + "voidReason": null, + "orderReasonConcept": null, + "sortWeight": null, + "conceptUuid": "62b91692-0641-45b1-9233-3c9609c6b6a8" + }, + "provider": { + "uuid": "c195a58f-f873-4a2f-b5e0-d7d575e13015", + "name": "docthree docthree", + "encounterRoleUuid": null + }, + "orderAttributes": null, + "retired": false, + "encounterUuid": "f4aed26e-1d1d-4602-a02e-b1fb9e79f649", + "creatorName": "docthree docthree", + "orderReasonConcept": null, + "orderReasonText": null, + "dosingInstructionType": "org.openmrs.module.bahmniemrapi.drugorder.dosinginstructions.FlexibleDosingInstructions", + "previousOrderUuid": "27b361c5-93fe-4273-8b7d-a725fe7237c6", + "concept": { + "uuid": "62b91692-0641-45b1-9233-3c9609c6b6a8", + "name": "Paracetamol 500mg", + "dataType": "N/A", + "shortName": "Paracetamol 500mg", + "units": null, + "conceptClass": "Misc", + "hiNormal": null, + "lowNormal": null, + "set": false, + "mappings": [] + }, + "uuid": "27b361c5-93fe-4273-8b7d-a725fe7237c6", + "careSetting": "OUTPATIENT", + "orderType": "Drug Order", + "autoExpireDate": 1714982177000, + "scheduledDate": 1714809378000, + "dateStopped": null, + "instructions": null, + "dateActivated": 1714636983000, + "commentToFulfiller": null, + "orderNumber": "ORD-524", + "effectiveStartDate": 1714809378000, + "effectiveStopDate": 1714982177000, + "sortWeight": null, + "orderGroup": null, + "drugNonCoded": null, + "drug": { + "name": "Paracetamol 500mg", + "uuid": "d9c230a5-89d8-4e4d-b08b-2af3b1234c80", + "form": "Tablet", + "strength": null + }, + "dosingInstructions": { + "dose": 2.0, + "doseUnits": "Tablet(s)", + "route": "Oral", + "frequency": "Thrice a day", + "asNeeded": false, + "administrationInstructions": "{\"instructions\":\"As directed\"}", + "quantity": 12.0, + "quantityUnits": "Tablet(s)", + "numberOfRefills": null + }, + "durationUnits": "Day(s)", + "duration": 2, + "action": "NEW" +} \ No newline at end of file diff --git a/openerp-atomfeed-service/src/test/resources/encounterResourceForOrders.json b/openerp-atomfeed-service/src/test/resources/encounterResourceForOrders.json new file mode 100644 index 00000000..a171139e --- /dev/null +++ b/openerp-atomfeed-service/src/test/resources/encounterResourceForOrders.json @@ -0,0 +1,257 @@ +{ + "bahmniDiagnoses": [], + "observations": [], + "accessionNotes": [], + "encounterType": "Consultation", + "visitType": "null", + "patientId": "GAN203025", + "reason": null, + "patientUuid": "ea589c0c-da76-4bd8-8332-7475f48fa330", + "visitUuid": "4d25c6ed-f069-4bce-b696-a45a9bd96f53", + "drugOrders": [ + { + "concept": { + "uuid": "62b91692-0641-45b1-9233-3c9609c6b6a8", + "name": "Paracetamol 500mg", + "dataType": "N/A", + "shortName": "Paracetamol 500mg", + "units": null, + "conceptClass": "Misc", + "hiNormal": null, + "lowNormal": null, + "set": false, + "mappings": [] + }, + "instructions": null, + "uuid": "27b361c5-93fe-4273-8b7d-a725fe7237c6", + "orderType": "Drug Order", + "accessionNumber": null, + "orderGroup": null, + "dateCreated": null, + "dateChanged": null, + "dateStopped": null, + "orderNumber": "ORD-524", + "careSetting": "OUTPATIENT", + "action": "NEW", + "commentToFulfiller": null, + "autoExpireDate": 1715279399000, + "urgency": null, + "previousOrderUuid": null, + "drug": { + "name": "Paracetamol 500mg", + "uuid": "d9c230a5-89d8-4e4d-b08b-2af3b1234c80", + "form": "Tablet", + "strength": null + }, + "drugNonCoded": null, + "dosingInstructionType": "org.openmrs.module.bahmniemrapi.drugorder.dosinginstructions.FlexibleDosingInstructions", + "dosingInstructions": { + "dose": 2, + "doseUnits": "Tablet(s)", + "route": "Oral", + "frequency": "Thrice a day", + "asNeeded": false, + "administrationInstructions": "{\"instructions\":\"As directed\"}", + "quantity": 12, + "quantityUnits": "Tablet(s)", + "numberOfRefills": null + }, + "dateActivated": 1714474203000, + "scheduledDate": 1715106600000, + "effectiveStartDate": 1715106600000, + "effectiveStopDate": 1715279399000, + "orderReasonText": null, + "duration": 2, + "durationUnits": "Day(s)", + "voided": false, + "voidReason": null, + "orderReasonConcept": null, + "sortWeight": null, + "conceptUuid": "62b91692-0641-45b1-9233-3c9609c6b6a8" + }, + { + "concept": { + "uuid": "62b91692-0641-45b1-9233-3c9609c6b6a8", + "name": "Paracetamol 500mg", + "dataType": "N/A", + "shortName": "Paracetamol 500mg", + "units": null, + "conceptClass": "Misc", + "hiNormal": null, + "lowNormal": null, + "set": false, + "mappings": [] + }, + "instructions": null, + "uuid": "540e979b-ff9a-41ac-a638-9abc6e3ca5c4", + "orderType": "Drug Order", + "accessionNumber": null, + "orderGroup": null, + "dateCreated": null, + "dateChanged": null, + "dateStopped": null, + "orderNumber": "ORD-524", + "careSetting": "OUTPATIENT", + "action": "REVISE", + "commentToFulfiller": null, + "autoExpireDate": 1715279399000, + "urgency": null, + "previousOrderUuid": "27b361c5-93fe-4273-8b7d-a725fe7237c6", + "drug": { + "name": "Paracetamol 500mg", + "uuid": "d9c230a5-89d8-4e4d-b08b-2af3b1234c80", + "form": "Tablet", + "strength": null + }, + "drugNonCoded": null, + "dosingInstructionType": "org.openmrs.module.bahmniemrapi.drugorder.dosinginstructions.FlexibleDosingInstructions", + "dosingInstructions": { + "dose": 3, + "doseUnits": "Tablet(s)", + "route": "Oral", + "frequency": "Thrice a day", + "asNeeded": false, + "administrationInstructions": "{\"instructions\":\"As directed\"}", + "quantity": 18, + "quantityUnits": "Tablet(s)", + "numberOfRefills": null + }, + "dateActivated": 1714474203000, + "scheduledDate": 1715106600000, + "effectiveStartDate": 1715106600000, + "effectiveStopDate": 1715279399000, + "orderReasonText": null, + "duration": 2, + "durationUnits": "Day(s)", + "voided": false, + "voidReason": null, + "orderReasonConcept": null, + "sortWeight": null, + "conceptUuid": "62b91692-0641-45b1-9233-3c9609c6b6a8" + } + ], + "encounterTypeUuid": "81852aee-3f10-11e4-adec-0800271c1b75", + "locationUuid": "baf7bd38-d225-11e4-9c67-080027b662ec", + "encounterDateTime": 1714473839000, + "disposition": null, + "encounterUuid": "ca4ef1ba-5258-4853-81c6-7c72d86bd615", + "visitTypeUuid": "c22a5000-3f10-11e4-adec-0800271c1b75", + "associatedToPatientProgram": false, + "patientProgramUuid": null, + "locationName": "General Ward", + "orders": [ + { + "concept": { + "uuid": "33cb5232-172e-4769-ad2d-49fadaafc318", + "name": "CD4 Test", + "dataType": "Text", + "shortName": "CD4 Test", + "units": null, + "conceptClass": "LabTest", + "hiNormal": null, + "lowNormal": null, + "set": false, + "mappings": [] + }, + "instructions": null, + "uuid": "03de97ab-0816-4b51-b317-5680c32a44f9", + "orderType": "Lab Order", + "accessionNumber": null, + "orderGroup": null, + "dateCreated": 1714474115000, + "dateChanged": null, + "dateStopped": null, + "orderNumber": "ORD-521", + "careSetting": null, + "action": "NEW", + "commentToFulfiller": null, + "autoExpireDate": null, + "urgency": "ROUTINE", + "previousOrderUuid": null, + "conceptUuid": "33cb5232-172e-4769-ad2d-49fadaafc318" + }, + { + "concept": { + "uuid": "c424eed0-3f10-11e4-adec-0800271c1b75", + "name": "CHEST Lateral", + "dataType": "Text", + "shortName": "chest lateral", + "units": null, + "conceptClass": "Radiology", + "hiNormal": null, + "lowNormal": null, + "set": true, + "mappings": [ + { + "code": "1234", + "name": "chest ap", + "source": "PACS Procedure Code" + } + ] + }, + "instructions": null, + "uuid": "47695984-bfd9-45a9-9196-060ab6ee6ab7", + "orderType": "Radiology Order", + "accessionNumber": null, + "orderGroup": null, + "dateCreated": 1714474203000, + "dateChanged": null, + "dateStopped": null, + "orderNumber": "ORD-525", + "careSetting": null, + "action": "DISCONTINUE", + "commentToFulfiller": null, + "autoExpireDate": null, + "urgency": "ROUTINE", + "previousOrderUuid": "7282556e-fefe-45b6-be43-1cdb507ae3b4", + "conceptUuid": "c424eed0-3f10-11e4-adec-0800271c1b75" + }, + { + "concept": { + "uuid": "c424eed0-3f10-11e4-adec-0800271c1b75", + "name": "CHEST Lateral", + "dataType": "Text", + "shortName": "chest lateral", + "units": null, + "conceptClass": "Radiology", + "hiNormal": null, + "lowNormal": null, + "set": true, + "mappings": [ + { + "code": "1234", + "name": "chest ap", + "source": "PACS Procedure Code" + } + ] + }, + "instructions": null, + "uuid": "7282556e-fefe-45b6-be43-1cdb507ae3b4", + "orderType": "Radiology Order", + "accessionNumber": null, + "orderGroup": null, + "dateCreated": 1714474115000, + "dateChanged": null, + "dateStopped": 1714474202000, + "orderNumber": "ORD-523", + "careSetting": null, + "action": "NEW", + "commentToFulfiller": null, + "autoExpireDate": null, + "urgency": "ROUTINE", + "previousOrderUuid": null, + "conceptUuid": "c424eed0-3f10-11e4-adec-0800271c1b75" + } + ], + "providers": [ + { + "uuid": "c1c26908-3f10-11e4-adec-0800271c1b75", + "name": "Super Man", + "encounterRoleUuid": "a0b03050-c99b-11e0-9572-0800200c9a66" + } + ], + "context": {}, + "extensions": { + "mdrtbSpecimen": [] + } +} \ No newline at end of file diff --git a/openerp-atomfeed-service/src/test/resources/encounterResourceForRevisedDrugOrder.json b/openerp-atomfeed-service/src/test/resources/encounterResourceForRevisedDrugOrder.json new file mode 100644 index 00000000..38fa761f --- /dev/null +++ b/openerp-atomfeed-service/src/test/resources/encounterResourceForRevisedDrugOrder.json @@ -0,0 +1,94 @@ +{ + "bahmniDiagnoses": [], + "observations": [], + "accessionNotes": [], + "encounterType": "Consultation", + "visitType": "null", + "patientId": "GAN203025", + "reason": null, + "patientUuid": "ea589c0c-da76-4bd8-8332-7475f48fa330", + "visitUuid": "4d25c6ed-f069-4bce-b696-a45a9bd96f53", + "drugOrders": [ + { + "concept": { + "uuid": "62b91692-0641-45b1-9233-3c9609c6b6a8", + "name": "Paracetamol 500mg", + "dataType": "N/A", + "shortName": "Paracetamol 500mg", + "units": null, + "conceptClass": "Misc", + "hiNormal": null, + "lowNormal": null, + "set": false, + "mappings": [] + }, + "instructions": null, + "uuid": "540e979b-ff9a-41ac-a638-9abc6e3ca5c4", + "orderType": "Drug Order", + "accessionNumber": null, + "orderGroup": null, + "dateCreated": null, + "dateChanged": null, + "dateStopped": null, + "orderNumber": "ORD-524", + "careSetting": "OUTPATIENT", + "action": "REVISE", + "commentToFulfiller": null, + "autoExpireDate": 1715279399000, + "urgency": null, + "previousOrderUuid": "27b361c5-93fe-4273-8b7d-a725fe7237c6", + "drug": { + "name": "Paracetamol 500mg", + "uuid": "d9c230a5-89d8-4e4d-b08b-2af3b1234c80", + "form": "Tablet", + "strength": null + }, + "drugNonCoded": null, + "dosingInstructionType": "org.openmrs.module.bahmniemrapi.drugorder.dosinginstructions.FlexibleDosingInstructions", + "dosingInstructions": { + "dose": 3, + "doseUnits": "Tablet(s)", + "route": "Oral", + "frequency": "Thrice a day", + "asNeeded": false, + "administrationInstructions": "{\"instructions\":\"As directed\"}", + "quantity": 18, + "quantityUnits": "Tablet(s)", + "numberOfRefills": null + }, + "dateActivated": 1714474203000, + "scheduledDate": 1715106600000, + "effectiveStartDate": 1715106600000, + "effectiveStopDate": 1715279399000, + "orderReasonText": null, + "duration": 2, + "durationUnits": "Day(s)", + "voided": false, + "voidReason": null, + "orderReasonConcept": null, + "sortWeight": null, + "conceptUuid": "62b91692-0641-45b1-9233-3c9609c6b6a8" + } + ], + "encounterTypeUuid": "81852aee-3f10-11e4-adec-0800271c1b75", + "locationUuid": "baf7bd38-d225-11e4-9c67-080027b662ec", + "encounterDateTime": 1714473839000, + "disposition": null, + "encounterUuid": "ca4ef1ba-5258-4853-81c6-7c72d86bd615", + "visitTypeUuid": "c22a5000-3f10-11e4-adec-0800271c1b75", + "associatedToPatientProgram": false, + "patientProgramUuid": null, + "locationName": "General Ward", + "orders": [], + "providers": [ + { + "uuid": "c1c26908-3f10-11e4-adec-0800271c1b75", + "name": "Super Man", + "encounterRoleUuid": "a0b03050-c99b-11e0-9572-0800200c9a66" + } + ], + "context": {}, + "extensions": { + "mdrtbSpecimen": [] + } +} \ No newline at end of file diff --git a/package/docker/templates/erp-atomfeed.properties.template b/package/docker/templates/erp-atomfeed.properties.template index 1873c2a2..81dd5780 100644 --- a/package/docker/templates/erp-atomfeed.properties.template +++ b/package/docker/templates/erp-atomfeed.properties.template @@ -27,6 +27,7 @@ openelis.saleorder.feed.generator.uri=http://${OPENELIS_HOST}:${OPENELIS_PORT}/o drug.feed.generator.uri=http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs/ws/atomfeed/drug/recent lab.feed.generator.uri=http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs/ws/atomfeed/lab/recent saleable.feed.generator.uri=http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs/ws/atomfeed/saleable/recent +drugorder.uri=http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs/ws/rest/v1/bahmnicore/drugOrders chunking.strategy=number