From 6bb11a7bee4244287d2b196a61971a326d12aabc Mon Sep 17 00:00:00 2001 From: Parvathy Babu <102500787+parvathy00@users.noreply.github.com> Date: Tue, 12 Dec 2023 13:16:24 +0530 Subject: [PATCH] BAH-3375 | Add. Rest Client Implementation for Create Lab Test, Lab Panel and Radiology Test (#87) * BAH-3375 | Deepti, Parvathy | Add. Rest Client Implementation for Create Lab Test, Lab Panel and Radiology Test * BAH-3375 | Deepti, Parvathy | Refactor. Tests for lab order types * [Parvathy, Rahul] | BAH-3375 | Refactor. Split getOdooURIForJob Method Based on Client Strategy Co-authored-by: Parvathy Babu * Parvathy|BAH-3375|Refactor. Normal and Failed Event Sequencing * Parvathy|BAH-3375|Refactor. Normal and Failed Event Sequencing * BAH-3375|Deepti,Parvathy|Add. null check to rest template and Lab test, panel and radiology event * BAH-3375|Deepti,Parvathy|Add. LoggerFactory to lab test and lab panel event worker. * Revert "BAH-3375|Deepti,Parvathy|Add. LoggerFactory to lab test and lab panel event worker." This reverts commit 9ebfe34c9bc2e14904440e81be1e2986627c4ab0. --------- Co-authored-by: Rahul Ramesh Co-authored-by: deeptirawat1510 --- .../openerp/OpenERPAtomFeedProperties.java | 31 +-- .../openerp/client/FeedClientFactory.java | 6 +- .../openerp/client/WebClientProvider.java | 4 +- .../labOrderType/OpenMRSLabPanelEvent.java | 14 +- .../labOrderType/OpenMRSLabTestEvent.java | 14 +- .../OpenMRSRadiologyTestEvent.java | 14 +- .../org/bahmni/feed/openerp/job/Jobs.java | 4 +- .../feed/openerp/job/OpenERPLabFeedJob.java | 24 --- .../openerp/job/OpenERPLabPanelFeedJob.java | 22 +++ .../openerp/job/OpenERPLabTestFeedJob.java | 24 +++ .../job/OpenERPRadiologyTestFeedJob.java | 23 +++ .../OpenERPLabPanelServiceEventWorker.java | 59 ++++++ .../OpenERPLabTestServiceEventWorker.java | 59 ++++++ ...enERPRadiologyTestServiceEventWorker.java} | 11 +- .../feed/openerp/worker/WorkerFactory.java | 4 +- .../src/main/resources/jobs-context.xml | 95 +++++++-- .../job/OpenERPLabPanelFeedJobTest.java | 37 ++++ ...st.java => OpenERPLabTestFeedJobTest.java} | 20 +- .../job/OpenERPRadiologyTestFeedJobTest.java | 37 ++++ ...ERPLabOrderTypeServiceEventWorkerTest.java | 181 ------------------ ...OpenERPLabPanelServiceEventWorkerTest.java | 94 +++++++++ .../OpenERPLabTestServiceEventWorkerTest.java | 99 ++++++++++ ...RPRadiologyTestServiceEventWorkerTest.java | 86 +++++++++ .../request/template/rest_template.ftl | 10 +- 24 files changed, 691 insertions(+), 281 deletions(-) delete mode 100644 openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJob.java create mode 100644 openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabPanelFeedJob.java create mode 100644 openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabTestFeedJob.java create mode 100644 openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPRadiologyTestFeedJob.java create mode 100644 openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabPanelServiceEventWorker.java create mode 100644 openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabTestServiceEventWorker.java rename openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/{OpenERPLabOrderTypeServiceEventWorker.java => OpenERPRadiologyTestServiceEventWorker.java} (77%) create mode 100644 openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabPanelFeedJobTest.java rename openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/{OpenERPLabFeedJobTest.java => OpenERPLabTestFeedJobTest.java} (51%) create mode 100644 openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPRadiologyTestFeedJobTest.java delete mode 100644 openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorkerTest.java create mode 100644 openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabPanelServiceEventWorkerTest.java create mode 100644 openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabTestServiceEventWorkerTest.java create mode 100644 openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPRadiologyTestServiceEventWorkerTest.java 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 8a3c7ef2..a1bec144 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 @@ -61,25 +61,28 @@ public String getFeedUriForJob(Jobs feedJob) { case SALEORDER_FEED: return saleOrderFeedUri; case OPENELIS_SALEORDER_FEED: return elisSaleOrderFeedUri; case DRUG_FEED: return drugFeedUri; - case LAB_FEED: return labFeedUri; + case LAB_TEST_FEED: return labFeedUri; + case LAB_PANEL_FEED: return labFeedUri; + case RADIOLOGY_TEST_FEED: return labFeedUri; case SALEABLE_FEED: return saleableFeedUri; } throw new RuntimeException("Can not identify feed URI for requested Job."); } - public String getOdooURIForJob(Jobs feedJob, boolean isRestEnabled) { - if (isRestEnabled) { - switch (feedJob) { - case SALEORDER_FEED: - case LAB_FEED: - case SALEABLE_FEED: return ""; - case CUSTOMER_FEED: return "/api/bahmni-customer"; - case DRUG_FEED: return "/api/bahmni-drug"; - default: throw new RuntimeException("Can not identify endpoint URI for requested Job."); - } - } - else { - return "/xmlrpc/object"; + public String getOdooXMLUrlEndpoint() { + return "xmlrpc/object"; + } + + public String getOdooRESTUrlEndPoint(Jobs feedJob) { + switch (feedJob) { + case SALEORDER_FEED: + case SALEABLE_FEED: return ""; + case CUSTOMER_FEED: return "/api/bahmni-customer"; + case LAB_TEST_FEED: return "/api/bahmni-lab-test"; + case LAB_PANEL_FEED: return "/api/bahmni-lab-panel"; + case RADIOLOGY_TEST_FEED: return "/api/bahmni-radiology-test"; + case DRUG_FEED: return "/api/bahmni-drug"; + default: throw new RuntimeException("Can not identify endpoint URI for requested Job."); } } @Value("${openerp.host}") 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 70574ff2..41ae9353 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 @@ -33,7 +33,7 @@ public FeedClientFactory(WorkerFactory workerFactory) { public AtomFeedClient getFeedClient(OpenERPAtomFeedProperties openERPAtomFeedProperties, AtomFeedSpringTransactionSupport transactionManager, OpenERPContext openERPContext, AllFeeds allFeeds, AllMarkers allMarkers, AllFailedEvents allFailedEvents, Jobs jobName, Boolean isRestEnabled) { String feedUri = openERPAtomFeedProperties.getFeedUriForJob(jobName); - String odooURL = openERPAtomFeedProperties.getOdooURIForJob(jobName, isRestEnabled); + String odooURL = isRestEnabled ? openERPAtomFeedProperties.getOdooRESTUrlEndPoint(jobName) : openERPAtomFeedProperties.getOdooXMLUrlEndpoint(); if (StringUtils.isBlank(feedUri)) { String message = String.format("No feed-uri defined for Job [%s][%s]", jobName, jobName.getFeedUriRef()); logger.warn(message); @@ -71,7 +71,9 @@ private static String getURIForJob(Jobs jobName,OpenERPAtomFeedProperties atomFe case SALEORDER_FEED: case SALEABLE_FEED: case DRUG_FEED: - case LAB_FEED: + case LAB_TEST_FEED: + case LAB_PANEL_FEED: + case RADIOLOGY_TEST_FEED: return atomFeedProperties.getAuthenticationURI(); case REFERENCE_DATA_FEED: return atomFeedProperties.getReferenceDataEndpointURI(); case OPENELIS_SALEORDER_FEED: return atomFeedProperties.getOpenElisURI(); diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/WebClientProvider.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/WebClientProvider.java index 273dfa61..7ea155e4 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/WebClientProvider.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/client/WebClientProvider.java @@ -42,7 +42,9 @@ public AbstractWebClient getWebClient(Jobs jobName){ switch (jobName){ case CUSTOMER_FEED: return getOpenMRSWebClient() ; case DRUG_FEED: return getOpenMRSWebClient() ; - case LAB_FEED: return getOpenMRSWebClient() ; + case LAB_TEST_FEED: return getOpenMRSWebClient() ; + case LAB_PANEL_FEED: return getOpenMRSWebClient() ; + case RADIOLOGY_TEST_FEED: return getOpenMRSWebClient() ; case SALEORDER_FEED: return getOpenMRSWebClient() ; case SALEABLE_FEED: return getOpenMRSWebClient(); case REFERENCE_DATA_FEED: return referenceDataWebClient() ; diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSLabPanelEvent.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSLabPanelEvent.java index 5c5a8bd0..df88f9a1 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSLabPanelEvent.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSLabPanelEvent.java @@ -14,13 +14,17 @@ public class OpenMRSLabPanelEvent extends OpenMRSLabOrderTypeEvent buildParameters(Event event, OpenMRSLabPanel openMRSLabOrderTypeEvent) { List parameters = new ArrayList<>(); - parameters.add(new Parameter("name", openMRSLabOrderTypeEvent.getName())); - parameters.add(new Parameter("uuid", openMRSLabOrderTypeEvent.getUuid())); - parameters.add(new Parameter("is_active", openMRSLabOrderTypeEvent.getActive(), "boolean")); - parameters.add(new Parameter("category", "create.lab.panel")); + addToParametersIfNotEmpty(parameters, "name", openMRSLabOrderTypeEvent.getName(),"string"); + addToParametersIfNotEmpty(parameters, "uuid", openMRSLabOrderTypeEvent.getUuid(),"string"); + addToParametersIfNotEmpty(parameters, "is_active", openMRSLabOrderTypeEvent.getActive(),"boolean"); + addToParametersIfNotEmpty(parameters, "category", "create.lab.panel","string"); return parameters; } - + private void addToParametersIfNotEmpty(List parameters, String name, String value, String type) { + if (value != null && !value.isEmpty()) { + parameters.add(new Parameter(name, value, type)); + } + } @Override protected OpenMRSLabPanel readLabOrderTypeEvent(String openMRSLabOrderTypeEventJson) throws IOException { return ObjectMapperRepository.objectMapper.readValue(openMRSLabOrderTypeEventJson, OpenMRSLabPanel.class); diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSLabTestEvent.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSLabTestEvent.java index 4c67a62a..645f9e75 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSLabTestEvent.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSLabTestEvent.java @@ -14,13 +14,17 @@ public class OpenMRSLabTestEvent extends OpenMRSLabOrderTypeEvent buildParameters(Event event, OpenMRSLabTest openMRSLabOrderTypeEvent) { List parameters = new ArrayList<>(); - parameters.add(new Parameter("name", openMRSLabOrderTypeEvent.getName())); - parameters.add(new Parameter("uuid", openMRSLabOrderTypeEvent.getUuid())); - parameters.add(new Parameter("is_active", openMRSLabOrderTypeEvent.getActive(), "boolean")); - parameters.add(new Parameter("category", "create.lab.test")); + addToParametersIfNotEmpty(parameters, "name", openMRSLabOrderTypeEvent.getName(), "string"); + addToParametersIfNotEmpty(parameters, "uuid", openMRSLabOrderTypeEvent.getUuid(), "string"); + addToParametersIfNotEmpty(parameters, "is_active", openMRSLabOrderTypeEvent.getActive(), "boolean"); + addToParametersIfNotEmpty(parameters, "category", "create.lab.test", "string"); return parameters; } - + private void addToParametersIfNotEmpty(List parameters, String name, String value, String type) { + if (value != null && !value.isEmpty()) { + parameters.add(new Parameter(name, value, type)); + } + } @Override protected OpenMRSLabTest readLabOrderTypeEvent(String openMRSLabOrderTypeEventJson) throws IOException { return ObjectMapperRepository.objectMapper.readValue(openMRSLabOrderTypeEventJson, OpenMRSLabTest.class); diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSRadiologyTestEvent.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSRadiologyTestEvent.java index d54df93e..057b0124 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSRadiologyTestEvent.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/labOrderType/OpenMRSRadiologyTestEvent.java @@ -14,13 +14,17 @@ public class OpenMRSRadiologyTestEvent extends OpenMRSLabOrderTypeEvent buildParameters(Event event, OpenMRSRadiologyTest openMRSLabOrderTypeEvent) { List parameters = new ArrayList<>(); - parameters.add(new Parameter("name", openMRSLabOrderTypeEvent.getName())); - parameters.add(new Parameter("uuid", openMRSLabOrderTypeEvent.getUuid())); - parameters.add(new Parameter("is_active", openMRSLabOrderTypeEvent.getActive(), "boolean")); - parameters.add(new Parameter("category", "create.radiology.test")); + addToParametersIfNotEmpty(parameters,"name",openMRSLabOrderTypeEvent.getName(), "string"); + addToParametersIfNotEmpty(parameters,"uuid",openMRSLabOrderTypeEvent.getUuid(), "string"); + addToParametersIfNotEmpty(parameters,"is_active",openMRSLabOrderTypeEvent.getActive(), "boolean"); + addToParametersIfNotEmpty(parameters,"category","create.radiology.test", "string"); return parameters; } - + private void addToParametersIfNotEmpty(List parameters, String name, String value, String type) { + if (value != null && !value.isEmpty()) { + parameters.add(new Parameter(name, value, type)); + } + } @Override protected OpenMRSRadiologyTest readLabOrderTypeEvent(String openMRSLabOrderTypeEventJson) throws IOException { return ObjectMapperRepository.objectMapper.readValue(openMRSLabOrderTypeEventJson, OpenMRSRadiologyTest.class); diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/Jobs.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/Jobs.java index a0497811..e5707dc9 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/Jobs.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/Jobs.java @@ -7,7 +7,9 @@ public enum Jobs { REFERENCE_DATA_FEED("referencedata.feed.generator.uri"), OPENELIS_SALEORDER_FEED("openelis.saleorder.feed.generator.uri"), DRUG_FEED("drug.feed.generator.uri"), - LAB_FEED("lab.feed.generator.uri"), + LAB_TEST_FEED("lab.feed.generator.uri"), + LAB_PANEL_FEED("lab.feed.generator.uri"), + RADIOLOGY_TEST_FEED("lab.feed.generator.uri"), SALEABLE_FEED("saleable.feed.generator.uri"); private final String feedUriRef; diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJob.java deleted file mode 100644 index f6658e58..00000000 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJob.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.bahmni.feed.openerp.job; - -import com.sun.syndication.io.FeedException; - -public class OpenERPLabFeedJob { - - private SimpleFeedJob openMRSFeedJob; - - public OpenERPLabFeedJob() { - } - - public OpenERPLabFeedJob(SimpleFeedJob openMRSFeedJob) throws FeedException { - this.openMRSFeedJob = openMRSFeedJob; - } - - public void processFeed() { - openMRSFeedJob.processFeed(Jobs.LAB_FEED); - } - - public void processFailedEvents() { - openMRSFeedJob.processFailedEvents(Jobs.LAB_FEED); - } - -} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabPanelFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabPanelFeedJob.java new file mode 100644 index 00000000..96f3407f --- /dev/null +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabPanelFeedJob.java @@ -0,0 +1,22 @@ +package org.bahmni.feed.openerp.job; + +import com.sun.syndication.io.FeedException; + +public class OpenERPLabPanelFeedJob { + private SimpleFeedJob openMRSFeedJob; + + public OpenERPLabPanelFeedJob() { + } + + public OpenERPLabPanelFeedJob(SimpleFeedJob openMRSFeedJob) throws FeedException { + this.openMRSFeedJob = openMRSFeedJob; + } + + public void processFeed() { + openMRSFeedJob.processFeed(Jobs.LAB_PANEL_FEED); + } + + public void processFailedEvents() { + openMRSFeedJob.processFailedEvents(Jobs.LAB_PANEL_FEED); + } +} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabTestFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabTestFeedJob.java new file mode 100644 index 00000000..d00033a6 --- /dev/null +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPLabTestFeedJob.java @@ -0,0 +1,24 @@ +package org.bahmni.feed.openerp.job; + +import com.sun.syndication.io.FeedException; + +public class OpenERPLabTestFeedJob { + + private SimpleFeedJob openMRSFeedJob; + + public OpenERPLabTestFeedJob() { + } + + public OpenERPLabTestFeedJob(SimpleFeedJob openMRSFeedJob) throws FeedException { + this.openMRSFeedJob = openMRSFeedJob; + } + + public void processFeed() { + openMRSFeedJob.processFeed(Jobs.LAB_TEST_FEED); + } + + public void processFailedEvents() { + openMRSFeedJob.processFailedEvents(Jobs.LAB_TEST_FEED); + } + +} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPRadiologyTestFeedJob.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPRadiologyTestFeedJob.java new file mode 100644 index 00000000..fd037da0 --- /dev/null +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/job/OpenERPRadiologyTestFeedJob.java @@ -0,0 +1,23 @@ +package org.bahmni.feed.openerp.job; + +import com.sun.syndication.io.FeedException; + +public class OpenERPRadiologyTestFeedJob { + private SimpleFeedJob openMRSFeedJob; + + public OpenERPRadiologyTestFeedJob() { + } + + public OpenERPRadiologyTestFeedJob(SimpleFeedJob openMRSFeedJob) throws FeedException { + this.openMRSFeedJob = openMRSFeedJob; + } + + public void processFeed() { + openMRSFeedJob.processFeed(Jobs.RADIOLOGY_TEST_FEED); + } + + public void processFailedEvents() { + openMRSFeedJob.processFailedEvents(Jobs.RADIOLOGY_TEST_FEED); + } + +} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabPanelServiceEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabPanelServiceEventWorker.java new file mode 100644 index 00000000..d993117b --- /dev/null +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabPanelServiceEventWorker.java @@ -0,0 +1,59 @@ +package org.bahmni.feed.openerp.worker; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bahmni.feed.openerp.client.OpenMRSWebClient; +import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabOrderTypeEvent; +import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabPanelEvent; +import org.bahmni.openerp.web.client.strategy.OpenERPContext; +import org.bahmni.openerp.web.request.OpenERPRequest; +import org.ict4h.atomfeed.client.domain.Event; +import org.ict4h.atomfeed.client.service.EventWorker; + +import java.io.IOException; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +public class OpenERPLabPanelServiceEventWorker implements EventWorker { + + private static final Logger logger = LogManager.getLogger(OpenERPLabPanelServiceEventWorker.class); + private final OpenERPContext openERPContext; + private final String feedUrl; + private final String odooURL; + private final OpenMRSWebClient webClient; + private final String urlPrefix; + private Map labOrderTypeEventMap = new HashMap<>(); + + + //This event worker takes care of only lab panel master data. All the lab panel orders are handled by sale order event worker. + public OpenERPLabPanelServiceEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { + this.openERPContext = openERPContext; + this.feedUrl = feedUrl; + this.odooURL = odooURL; + this.webClient = openMRSWebClient; + this.urlPrefix = urlPrefix; + labOrderTypeEventMap.put(OpenMRSLabPanelEvent.LAB_PANEL_EVENT_NAME, new OpenMRSLabPanelEvent()); + } + + @Override + public void process(Event event) { + logger.debug("Processing the event [{}]", event.getContent()); + try { + OpenMRSLabOrderTypeEvent openMRSLabOrderTypeEvent = labOrderTypeEventMap.get(event.getTitle()); + if(openMRSLabOrderTypeEvent == null) return ; + openERPContext.execute(mapRequest(event, openMRSLabOrderTypeEvent), odooURL); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private OpenERPRequest mapRequest(Event event, OpenMRSLabOrderTypeEvent openMRSLabOrderTypeEvent) throws IOException { + String labOrderTypeJson = webClient.get(URI.create(urlPrefix + event.getContent())); + return openMRSLabOrderTypeEvent.mapEventToOpenERPRequest(event, labOrderTypeJson, feedUrl); + } + @Override + public void cleanUp(Event event) { + + } +} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabTestServiceEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabTestServiceEventWorker.java new file mode 100644 index 00000000..b1335f6e --- /dev/null +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabTestServiceEventWorker.java @@ -0,0 +1,59 @@ +package org.bahmni.feed.openerp.worker; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bahmni.feed.openerp.client.OpenMRSWebClient; +import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabOrderTypeEvent; +import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabTestEvent; +import org.bahmni.openerp.web.client.strategy.OpenERPContext; +import org.bahmni.openerp.web.request.OpenERPRequest; +import org.ict4h.atomfeed.client.domain.Event; +import org.ict4h.atomfeed.client.service.EventWorker; + +import java.io.IOException; +import java.net.URI; +import java.util.HashMap; +import java.util.Map; + +public class OpenERPLabTestServiceEventWorker implements EventWorker { + + private static final Logger logger = LogManager.getLogger(OpenERPLabTestServiceEventWorker.class); + private final OpenERPContext openERPContext; + private final String feedUrl; + private final String odooURL; + private final OpenMRSWebClient webClient; + private final String urlPrefix; + private Map labOrderTypeEventMap = new HashMap<>(); + + + //This event worker takes care of only lab test master data. All the lab test orders are handled by sale order event worker. + public OpenERPLabTestServiceEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { + this.openERPContext = openERPContext; + this.feedUrl = feedUrl; + this.odooURL = odooURL; + this.webClient = openMRSWebClient; + this.urlPrefix = urlPrefix; + labOrderTypeEventMap.put(OpenMRSLabTestEvent.LAB_TEST_EVENT_NAME, new OpenMRSLabTestEvent()); + } + + @Override + public void process(Event event) { + logger.debug("Processing the event [{}]", event.getContent()); + try { + OpenMRSLabOrderTypeEvent openMRSLabOrderTypeEvent = labOrderTypeEventMap.get(event.getTitle()); + if(openMRSLabOrderTypeEvent == null) return ; + openERPContext.execute(mapRequest(event, openMRSLabOrderTypeEvent), odooURL); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private OpenERPRequest mapRequest(Event event, OpenMRSLabOrderTypeEvent openMRSLabOrderTypeEvent) throws IOException { + String labOrderTypeJson = webClient.get(URI.create(urlPrefix + event.getContent())); + return openMRSLabOrderTypeEvent.mapEventToOpenERPRequest(event, labOrderTypeJson, feedUrl); + } + @Override + public void cleanUp(Event event) { + + } +} diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorker.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPRadiologyTestServiceEventWorker.java similarity index 77% rename from openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorker.java rename to openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPRadiologyTestServiceEventWorker.java index 6c9f77c2..2219dbac 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorker.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/worker/OpenERPRadiologyTestServiceEventWorker.java @@ -4,8 +4,6 @@ import org.apache.logging.log4j.Logger; import org.bahmni.feed.openerp.client.OpenMRSWebClient; import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabOrderTypeEvent; -import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabPanelEvent; -import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabTestEvent; import org.bahmni.feed.openerp.domain.labOrderType.OpenMRSRadiologyTestEvent; import org.bahmni.openerp.web.client.strategy.OpenERPContext; import org.bahmni.openerp.web.request.OpenERPRequest; @@ -17,9 +15,9 @@ import java.util.HashMap; import java.util.Map; -public class OpenERPLabOrderTypeServiceEventWorker implements EventWorker { +public class OpenERPRadiologyTestServiceEventWorker implements EventWorker { - private static final Logger logger = LogManager.getLogger(OpenERPLabOrderTypeServiceEventWorker.class); + private static final Logger logger = LogManager.getLogger(OpenERPRadiologyTestServiceEventWorker.class); private final OpenERPContext openERPContext; private final String feedUrl; private final String odooURL; @@ -28,15 +26,14 @@ public class OpenERPLabOrderTypeServiceEventWorker implements EventWorker { private Map labOrderTypeEventMap = new HashMap<>(); - public OpenERPLabOrderTypeServiceEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { + //This event worker takes care of only radiology test master data. All the radiology test orders are handled by sale order event worker. + public OpenERPRadiologyTestServiceEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) { this.openERPContext = openERPContext; this.feedUrl = feedUrl; this.odooURL = odooURL; this.webClient = openMRSWebClient; this.urlPrefix = urlPrefix; labOrderTypeEventMap.put(OpenMRSRadiologyTestEvent.RADIOLOGY_TEST_EVENT_NAME, new OpenMRSRadiologyTestEvent()); - labOrderTypeEventMap.put(OpenMRSLabTestEvent.LAB_TEST_EVENT_NAME, new OpenMRSLabTestEvent()); - labOrderTypeEventMap.put(OpenMRSLabPanelEvent.LAB_PANEL_EVENT_NAME, new OpenMRSLabPanelEvent()); } @Override 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 901fea3c..8ad19446 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 @@ -20,7 +20,9 @@ public EventWorker getWorker(Jobs jobName, String feedUrl, String odooURL, OpenE case SALEORDER_FEED: return new OpenERPSaleOrderEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); 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_FEED: return new OpenERPLabOrderTypeServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + case LAB_TEST_FEED: return new OpenERPLabTestServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + case LAB_PANEL_FEED: return new OpenERPLabPanelServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); + case RADIOLOGY_TEST_FEED: return new OpenERPRadiologyTestServiceEventWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); case SALEABLE_FEED: return new OpenERPSaleableResourceWorker(feedUrl, odooURL, openERPContext, webClientProvider.getOpenMRSWebClient(), urlPrefix); } throw new RuntimeException(String.format("No worker for %s", jobName)); diff --git a/openerp-atomfeed-service/src/main/resources/jobs-context.xml b/openerp-atomfeed-service/src/main/resources/jobs-context.xml index 2eb0d195..49369583 100644 --- a/openerp-atomfeed-service/src/main/resources/jobs-context.xml +++ b/openerp-atomfeed-service/src/main/resources/jobs-context.xml @@ -17,7 +17,6 @@ - @@ -29,7 +28,6 @@ - @@ -41,7 +39,6 @@ - @@ -53,7 +50,6 @@ - @@ -65,19 +61,42 @@ + - - + + + + + + + + - - + + + + + + + + + + + + + + + + + + @@ -87,14 +106,12 @@ - - @@ -108,6 +125,7 @@ + @@ -148,15 +166,41 @@ - - + - - + + + + + + + + + + + + + + + + + + + + + + + @@ -180,7 +224,6 @@ - @@ -200,8 +243,12 @@ - - + + + + + + @@ -210,7 +257,6 @@ - @@ -225,7 +271,15 @@ - + + + + + + + + + @@ -237,7 +291,6 @@ - @@ -261,4 +314,4 @@ - + \ No newline at end of file diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabPanelFeedJobTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabPanelFeedJobTest.java new file mode 100644 index 00000000..7bd91121 --- /dev/null +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabPanelFeedJobTest.java @@ -0,0 +1,37 @@ +package org.bahmni.feed.openerp.job; + +import com.sun.syndication.io.FeedException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.bahmni.feed.openerp.job.Jobs.LAB_PANEL_FEED; +import static org.mockito.Mockito.verify; + +public class OpenERPLabPanelFeedJobTest { + + OpenERPLabPanelFeedJob labPanelFeedJob; + + @Mock + SimpleFeedJob openMRSFeedJob; + + @Before + public void setUp(){ + MockitoAnnotations.initMocks(this); + } + + @Test + public void testProcessFeed() throws FeedException { + labPanelFeedJob = new OpenERPLabPanelFeedJob(openMRSFeedJob); + labPanelFeedJob.processFeed(); + verify(openMRSFeedJob).processFeed(LAB_PANEL_FEED); + } + + @Test + public void testProcessFailedEvents() throws FeedException { + labPanelFeedJob = new OpenERPLabPanelFeedJob(openMRSFeedJob); + labPanelFeedJob.processFailedEvents(); + verify(openMRSFeedJob).processFailedEvents(LAB_PANEL_FEED); + } +} \ No newline at end of file diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJobTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabTestFeedJobTest.java similarity index 51% rename from openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJobTest.java rename to openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabTestFeedJobTest.java index 58edfe02..379e0eef 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabFeedJobTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPLabTestFeedJobTest.java @@ -6,12 +6,12 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import static org.bahmni.feed.openerp.job.Jobs.LAB_FEED; +import static org.bahmni.feed.openerp.job.Jobs.LAB_TEST_FEED; import static org.mockito.Mockito.verify; -public class OpenERPLabFeedJobTest { +public class OpenERPLabTestFeedJobTest { - OpenERPLabFeedJob labFeedJob; + OpenERPLabTestFeedJob labTestFeedJob; @Mock SimpleFeedJob openMRSFeedJob; @@ -23,15 +23,15 @@ public void setUp(){ @Test public void testProcessFeed() throws FeedException { - labFeedJob = new OpenERPLabFeedJob(openMRSFeedJob); - labFeedJob.processFeed(); - verify(openMRSFeedJob).processFeed(LAB_FEED); + labTestFeedJob = new OpenERPLabTestFeedJob(openMRSFeedJob); + labTestFeedJob.processFeed(); + verify(openMRSFeedJob).processFeed(LAB_TEST_FEED); } @Test public void testProcessFailedEvents() throws FeedException { - labFeedJob = new OpenERPLabFeedJob(openMRSFeedJob); - labFeedJob.processFailedEvents(); - verify(openMRSFeedJob).processFailedEvents(LAB_FEED); + labTestFeedJob = new OpenERPLabTestFeedJob(openMRSFeedJob); + labTestFeedJob.processFailedEvents(); + verify(openMRSFeedJob).processFailedEvents(LAB_TEST_FEED); } -} +} \ No newline at end of file diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPRadiologyTestFeedJobTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPRadiologyTestFeedJobTest.java new file mode 100644 index 00000000..546ce7fd --- /dev/null +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/job/OpenERPRadiologyTestFeedJobTest.java @@ -0,0 +1,37 @@ +package org.bahmni.feed.openerp.job; + +import com.sun.syndication.io.FeedException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.bahmni.feed.openerp.job.Jobs.RADIOLOGY_TEST_FEED; +import static org.mockito.Mockito.verify; + +public class OpenERPRadiologyTestFeedJobTest { + + OpenERPRadiologyTestFeedJob radiologyTestFeedJob; + + @Mock + SimpleFeedJob openMRSFeedJob; + + @Before + public void setUp(){ + MockitoAnnotations.initMocks(this); + } + + @Test + public void testProcessFeed() throws FeedException { + radiologyTestFeedJob = new OpenERPRadiologyTestFeedJob(openMRSFeedJob); + radiologyTestFeedJob.processFeed(); + verify(openMRSFeedJob).processFeed(RADIOLOGY_TEST_FEED); + } + + @Test + public void testProcessFailedEvents() throws FeedException { + radiologyTestFeedJob = new OpenERPRadiologyTestFeedJob(openMRSFeedJob); + radiologyTestFeedJob.processFailedEvents(); + verify(openMRSFeedJob).processFailedEvents(RADIOLOGY_TEST_FEED); + } +} \ No newline at end of file diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorkerTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorkerTest.java deleted file mode 100644 index 0882f68f..00000000 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabOrderTypeServiceEventWorkerTest.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.bahmni.feed.openerp.worker; - -import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; -import org.bahmni.feed.openerp.client.OpenMRSWebClient; -import org.bahmni.openerp.web.client.strategy.OpenERPContext; -import org.bahmni.openerp.web.request.OpenERPRequest; -import org.bahmni.openerp.web.request.builder.Parameter; -import org.ict4h.atomfeed.client.domain.Event; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.io.IOException; -import java.net.URI; -import java.util.Date; -import java.util.List; - -import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabPanelEvent.LAB_PANEL_EVENT_NAME; -import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabTestEvent.LAB_TEST_EVENT_NAME; -import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSRadiologyTestEvent.RADIOLOGY_TEST_EVENT_NAME; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class OpenERPLabOrderTypeServiceEventWorkerTest { - - @Mock - private OpenERPAtomFeedProperties atomFeedProperties; - @Mock - private OpenERPContext openERPContext; - @Mock - private OpenMRSWebClient webClient; - - private final String feedUri = "http://feeduri"; - private final String odooURL = "http://odooURL"; - private OpenERPLabOrderTypeServiceEventWorker worker; - - @Before - public void setUp() { - String radiologyTestJson = "{\n" + - " \"isActive\": true,\n" + - " \"dateCreated\": \"2015-09-07T12:14:24.000+0530\",\n" + - " \"lastUpdated\": \"2015-09-07T14:18:15.000+0530\",\n" + - " \"name\": \"Chest X RAY\",\n" + - " \"id\": \"f59dd85b-fb13-4f3a-ae01-e6fd57eea6fe\"\n" + - "}"; - - String labTestJson = "{\n" + - " \"resultType\": \"Coded\",\n" + - " \"testUnitOfMeasure\": null,\n" + - " \"sortOrder\": 999,\n" + - " \"codedTestAnswer\": [\n" + - " {\n" + - " \"uuid\": \"f4838e40-321d-4bf7-b0d5-873dd47cfb68\",\n" + - " \"name\": \"Diabetes, Patient on Enalapril\"\n" + - " },\n" + - " {\n" + - " \"uuid\": \"148b3e66-9eb5-4437-8f96-06c7feb95d5c\",\n" + - " \"name\": \"COPD, Still Smoking\"\n" + - " }\n" + - " ],\n" + - " \"description\": \"newtest1\",\n" + - " \"isActive\": true,\n" + - " \"dateCreated\": \"2015-09-08T11:59:34.000+0530\",\n" + - " \"lastUpdated\": \"2015-09-08T12:04:46.000+0530\",\n" + - " \"name\": \"RBC\",\n" + - " \"id\": \"5cf81237-e888-46e8-b09a-2f190492c2d7\"\n" + - "}"; - String labPanelJson = "{\n" + - " \"sortOrder\": 999,\n" + - " \"tests\": [\n" + - " {\n" + - " \"uuid\": \"e20fd44e-1516-4a85-bc1e-ba50556ea10d\",\n" + - " \"name\": \"Smear Test (Slit Skin)\"\n" + - " }\n" + - " ],\n" + - " \"description\": \"newpanell\",\n" + - " \"dateCreated\": \"2015-09-08T14:53:02.000+0530\",\n" + - " \"lastUpdated\": \"2015-09-08T14:53:02.000+0530\",\n" + - " \"isActive\": true,\n" + - " \"name\": \"Smear Test\",\n" + - " \"id\": \"2dc3855a-263f-48df-8071-8ff974a11972\"\n" + - "}"; - - MockitoAnnotations.initMocks(this); - worker = new OpenERPLabOrderTypeServiceEventWorker(feedUri, odooURL, openERPContext, webClient, "http://prefix/"); - when(webClient.get(URI.create("http://prefix/radiology"))).thenReturn(radiologyTestJson); - when(webClient.get(URI.create("http://prefix/test"))).thenReturn(labTestJson); - when(webClient.get(URI.create("http://prefix/panel"))).thenReturn(labPanelJson); - - } - - @Test - public void shouldProcessRadiologyTestEvent() throws IOException { - Event event = new Event("1", RADIOLOGY_TEST_EVENT_NAME, RADIOLOGY_TEST_EVENT_NAME, feedUri, new Date()); - - worker.process(event); - ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); - - OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); - List parameters = openERPRequest.getParameters(); - - Assert.assertTrue(parameters.contains(new Parameter("last_read_entry_id", "1"))); - Assert.assertTrue(parameters.contains(new Parameter("category", "create.radiology.test"))); - Assert.assertTrue(parameters.contains(new Parameter("feed_uri_for_last_read_entry", feedUri))); - Assert.assertFalse(parameters.contains(new Parameter("is_failed_event", "1", "boolean"))); - Assert.assertTrue(parameters.contains(new Parameter("name", "Chest X RAY"))); - Assert.assertTrue(parameters.contains(new Parameter("uuid", "f59dd85b-fb13-4f3a-ae01-e6fd57eea6fe"))); - } - - - @Test - public void shouldProcessLabTestEvent() throws IOException { - Event event = new Event("2", LAB_TEST_EVENT_NAME, LAB_TEST_EVENT_NAME, feedUri, new Date()); - - worker.process(event); - ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); - - OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); - List parameters = openERPRequest.getParameters(); - - Assert.assertTrue(parameters.contains(new Parameter("last_read_entry_id", "2"))); - Assert.assertTrue(parameters.contains(new Parameter("category", "create.lab.test"))); - Assert.assertTrue(parameters.contains(new Parameter("feed_uri_for_last_read_entry", feedUri))); - Assert.assertFalse(parameters.contains(new Parameter("is_failed_event", "1", "boolean"))); - Assert.assertTrue(parameters.contains(new Parameter("name", "RBC"))); - Assert.assertTrue(parameters.contains(new Parameter("uuid", "5cf81237-e888-46e8-b09a-2f190492c2d7"))); - } - - @Test - public void shouldProcessLabPanelEvent() throws Exception { - Event event = new Event("6", LAB_PANEL_EVENT_NAME, LAB_PANEL_EVENT_NAME, feedUri, new Date()); - - worker.process(event); - ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); - - OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); - List parameters = openERPRequest.getParameters(); - - Assert.assertTrue(parameters.contains(new Parameter("last_read_entry_id","6"))); - Assert.assertTrue(parameters.contains(new Parameter("category","create.lab.panel"))); - Assert.assertTrue(parameters.contains(new Parameter("feed_uri_for_last_read_entry", feedUri))); - Assert.assertFalse(parameters.contains(new Parameter("is_failed_event","1","boolean"))); - Assert.assertTrue(parameters.contains(new Parameter("name","Smear Test"))); - Assert.assertTrue(parameters.contains(new Parameter("uuid", "2dc3855a-263f-48df-8071-8ff974a11972"))); - } - - @Test - public void testRadiologyFailedEvent() throws IOException { - Event event = new Event("3", RADIOLOGY_TEST_EVENT_NAME, RADIOLOGY_TEST_EVENT_NAME, null, new Date()); - - worker.process(event); - ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); - - OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); - List actualParameters = openERPRequest.getParameters(); - Assert.assertTrue(actualParameters.contains(new Parameter("is_failed_event", "1", "boolean"))); - - } - - @Test - public void testTestFailedEvent() throws IOException { - Event event = new Event("4", LAB_TEST_EVENT_NAME, LAB_TEST_EVENT_NAME, null, new Date()); - - worker.process(event); - ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); - verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); - - OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); - List actualParameters = openERPRequest.getParameters(); - Assert.assertTrue(actualParameters.contains(new Parameter("is_failed_event", "1", "boolean"))); - - } -} diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabPanelServiceEventWorkerTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabPanelServiceEventWorkerTest.java new file mode 100644 index 00000000..00e7da3d --- /dev/null +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabPanelServiceEventWorkerTest.java @@ -0,0 +1,94 @@ +package org.bahmni.feed.openerp.worker; + +import org.bahmni.feed.openerp.client.OpenMRSWebClient; +import org.bahmni.openerp.web.client.strategy.OpenERPContext; +import org.bahmni.openerp.web.request.OpenERPRequest; +import org.bahmni.openerp.web.request.builder.Parameter; +import org.ict4h.atomfeed.client.domain.Event; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.io.IOException; +import java.net.URI; +import java.util.Date; +import java.util.List; + +import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabPanelEvent.LAB_PANEL_EVENT_NAME; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class OpenERPLabPanelServiceEventWorkerTest { + @Mock + private OpenERPContext openERPContext; + @Mock + private OpenMRSWebClient webClient; + + private final String feedUri = "http://feeduri"; + private final String odooURL = "http://odooURL"; + private OpenERPLabPanelServiceEventWorker worker; + + @Before + public void setUp() { + + String labPanelJson = "{\n" + + " \"sortOrder\": 999,\n" + + " \"tests\": [\n" + + " {\n" + + " \"uuid\": \"e20fd44e-1516-4a85-bc1e-ba50556ea10d\",\n" + + " \"name\": \"Smear Test (Slit Skin)\"\n" + + " }\n" + + " ],\n" + + " \"description\": \"newpanell\",\n" + + " \"dateCreated\": \"2015-09-08T14:53:02.000+0530\",\n" + + " \"lastUpdated\": \"2015-09-08T14:53:02.000+0530\",\n" + + " \"isActive\": true,\n" + + " \"name\": \"Smear Test\",\n" + + " \"id\": \"2dc3855a-263f-48df-8071-8ff974a11972\"\n" + + "}"; + + MockitoAnnotations.initMocks(this); + worker = new OpenERPLabPanelServiceEventWorker(feedUri, odooURL, openERPContext, webClient, "http://prefix/"); + when(webClient.get(URI.create("http://prefix/panel"))).thenReturn(labPanelJson); + + } + + @Test + public void shouldProcessLabPanelEvent() throws Exception { + Event event = new Event("6", LAB_PANEL_EVENT_NAME, LAB_PANEL_EVENT_NAME, feedUri, new Date()); + + worker.process(event); + ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); + verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + + OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); + List parameters = openERPRequest.getParameters(); + + Assert.assertTrue(parameters.contains(new Parameter("last_read_entry_id","6"))); + Assert.assertTrue(parameters.contains(new Parameter("category","create.lab.panel"))); + Assert.assertTrue(parameters.contains(new Parameter("feed_uri_for_last_read_entry", feedUri))); + Assert.assertFalse(parameters.contains(new Parameter("is_failed_event","1","boolean"))); + Assert.assertTrue(parameters.contains(new Parameter("name","Smear Test"))); + Assert.assertTrue(parameters.contains(new Parameter("uuid", "2dc3855a-263f-48df-8071-8ff974a11972"))); + } + + @Test + public void testPanelFailedEvent() throws IOException { + Event event = new Event("4", LAB_PANEL_EVENT_NAME, LAB_PANEL_EVENT_NAME, null, new Date()); + + worker.process(event); + ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); + verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + + OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); + List actualParameters = openERPRequest.getParameters(); + Assert.assertTrue(actualParameters.contains(new Parameter("is_failed_event", "1", "boolean"))); + + } + + +} \ No newline at end of file diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabTestServiceEventWorkerTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabTestServiceEventWorkerTest.java new file mode 100644 index 00000000..98f9805f --- /dev/null +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPLabTestServiceEventWorkerTest.java @@ -0,0 +1,99 @@ +package org.bahmni.feed.openerp.worker; + +import org.bahmni.feed.openerp.client.OpenMRSWebClient; +import org.bahmni.openerp.web.client.strategy.OpenERPContext; +import org.bahmni.openerp.web.request.OpenERPRequest; +import org.bahmni.openerp.web.request.builder.Parameter; +import org.ict4h.atomfeed.client.domain.Event; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.io.IOException; +import java.net.URI; +import java.util.Date; +import java.util.List; + +import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSLabTestEvent.LAB_TEST_EVENT_NAME; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class OpenERPLabTestServiceEventWorkerTest { + + @Mock + private OpenERPContext openERPContext; + @Mock + private OpenMRSWebClient webClient; + + private final String feedUri = "http://feeduri"; + private final String odooURL = "http://odooURL"; + private OpenERPLabTestServiceEventWorker worker; + + @Before + public void setUp() { + String labTestJson = "{\n" + + " \"resultType\": \"Coded\",\n" + + " \"testUnitOfMeasure\": null,\n" + + " \"sortOrder\": 999,\n" + + " \"codedTestAnswer\": [\n" + + " {\n" + + " \"uuid\": \"f4838e40-321d-4bf7-b0d5-873dd47cfb68\",\n" + + " \"name\": \"Diabetes, Patient on Enalapril\"\n" + + " },\n" + + " {\n" + + " \"uuid\": \"148b3e66-9eb5-4437-8f96-06c7feb95d5c\",\n" + + " \"name\": \"COPD, Still Smoking\"\n" + + " }\n" + + " ],\n" + + " \"description\": \"newtest1\",\n" + + " \"isActive\": true,\n" + + " \"dateCreated\": \"2015-09-08T11:59:34.000+0530\",\n" + + " \"lastUpdated\": \"2015-09-08T12:04:46.000+0530\",\n" + + " \"name\": \"RBC\",\n" + + " \"id\": \"5cf81237-e888-46e8-b09a-2f190492c2d7\"\n" + + "}"; + + MockitoAnnotations.initMocks(this); + worker = new OpenERPLabTestServiceEventWorker(feedUri, odooURL, openERPContext, webClient, "http://prefix/"); + when(webClient.get(URI.create("http://prefix/test"))).thenReturn(labTestJson); + + } + + @Test + public void shouldProcessLabTestEvent() throws IOException { + Event event = new Event("2", LAB_TEST_EVENT_NAME, LAB_TEST_EVENT_NAME, feedUri, new Date()); + + worker.process(event); + ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); + verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + + OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); + List parameters = openERPRequest.getParameters(); + + Assert.assertTrue(parameters.contains(new Parameter("last_read_entry_id", "2"))); + Assert.assertTrue(parameters.contains(new Parameter("category", "create.lab.test"))); + Assert.assertTrue(parameters.contains(new Parameter("feed_uri_for_last_read_entry", feedUri))); + Assert.assertFalse(parameters.contains(new Parameter("is_failed_event", "1", "boolean"))); + Assert.assertTrue(parameters.contains(new Parameter("name", "RBC"))); + Assert.assertTrue(parameters.contains(new Parameter("uuid", "5cf81237-e888-46e8-b09a-2f190492c2d7"))); + } + + @Test + public void testTestFailedEvent() throws IOException { + Event event = new Event("4", LAB_TEST_EVENT_NAME, LAB_TEST_EVENT_NAME, null, new Date()); + + worker.process(event); + ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); + verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + + OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); + List actualParameters = openERPRequest.getParameters(); + Assert.assertTrue(actualParameters.contains(new Parameter("is_failed_event", "1", "boolean"))); + + } + +} \ No newline at end of file diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPRadiologyTestServiceEventWorkerTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPRadiologyTestServiceEventWorkerTest.java new file mode 100644 index 00000000..c3928cc4 --- /dev/null +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/worker/OpenERPRadiologyTestServiceEventWorkerTest.java @@ -0,0 +1,86 @@ +package org.bahmni.feed.openerp.worker; + +import org.bahmni.feed.openerp.OpenERPAtomFeedProperties; +import org.bahmni.feed.openerp.client.OpenMRSWebClient; +import org.bahmni.openerp.web.client.strategy.OpenERPContext; +import org.bahmni.openerp.web.request.OpenERPRequest; +import org.bahmni.openerp.web.request.builder.Parameter; +import org.ict4h.atomfeed.client.domain.Event; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.io.IOException; +import java.net.URI; +import java.util.Date; +import java.util.List; + +import static org.bahmni.feed.openerp.domain.labOrderType.OpenMRSRadiologyTestEvent.RADIOLOGY_TEST_EVENT_NAME; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class OpenERPRadiologyTestServiceEventWorkerTest { + + @Mock + private OpenERPContext openERPContext; + @Mock + private OpenMRSWebClient webClient; + + private final String feedUri = "http://feeduri"; + private final String odooURL = "http://odooURL"; + private OpenERPRadiologyTestServiceEventWorker worker; + + @Before + public void setUp() { + String radiologyTestJson = "{\n" + + " \"isActive\": true,\n" + + " \"dateCreated\": \"2015-09-07T12:14:24.000+0530\",\n" + + " \"lastUpdated\": \"2015-09-07T14:18:15.000+0530\",\n" + + " \"name\": \"Chest X RAY\",\n" + + " \"id\": \"f59dd85b-fb13-4f3a-ae01-e6fd57eea6fe\"\n" + + "}"; + + MockitoAnnotations.initMocks(this); + worker = new OpenERPRadiologyTestServiceEventWorker(feedUri, odooURL, openERPContext, webClient, "http://prefix/"); + when(webClient.get(URI.create("http://prefix/radiology"))).thenReturn(radiologyTestJson); + + } + + @Test + public void shouldProcessRadiologyTestEvent() throws IOException { + Event event = new Event("1", RADIOLOGY_TEST_EVENT_NAME, RADIOLOGY_TEST_EVENT_NAME, feedUri, new Date()); + + worker.process(event); + ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); + verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + + OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); + List parameters = openERPRequest.getParameters(); + + Assert.assertTrue(parameters.contains(new Parameter("last_read_entry_id", "1"))); + Assert.assertTrue(parameters.contains(new Parameter("category", "create.radiology.test"))); + Assert.assertTrue(parameters.contains(new Parameter("feed_uri_for_last_read_entry", feedUri))); + Assert.assertFalse(parameters.contains(new Parameter("is_failed_event", "1", "boolean"))); + Assert.assertTrue(parameters.contains(new Parameter("name", "Chest X RAY"))); + Assert.assertTrue(parameters.contains(new Parameter("uuid", "f59dd85b-fb13-4f3a-ae01-e6fd57eea6fe"))); + } + + @Test + public void testRadiologyFailedEvent() throws IOException { + Event event = new Event("3", RADIOLOGY_TEST_EVENT_NAME, RADIOLOGY_TEST_EVENT_NAME, null, new Date()); + + worker.process(event); + ArgumentCaptor erpRequestCatcher = ArgumentCaptor.forClass(OpenERPRequest.class); + verify(openERPContext).execute(erpRequestCatcher.capture(), eq(odooURL)); + + OpenERPRequest openERPRequest = erpRequestCatcher.getValue(); + List actualParameters = openERPRequest.getParameters(); + Assert.assertTrue(actualParameters.contains(new Parameter("is_failed_event", "1", "boolean"))); + + } + +} \ No newline at end of file diff --git a/openerp-client/src/main/resources/request/template/rest_template.ftl b/openerp-client/src/main/resources/request/template/rest_template.ftl index cc9d2493..4a9bc738 100644 --- a/openerp-client/src/main/resources/request/template/rest_template.ftl +++ b/openerp-client/src/main/resources/request/template/rest_template.ftl @@ -3,10 +3,12 @@ "params": { "data": { <#list parametersList as param> - <#if param.value?starts_with("{") && param.value?ends_with("}")> - "${param.name}": "${(param.value?js_string)!}"<#if param_has_next>, - <#else> - "${param.name}": "${param.value!}"<#if param_has_next>, + <#if param.value??> + <#if param.value?starts_with("{") && param.value?ends_with("}")> + "${param.name}": "${(param.value?js_string)!}"<#if param_has_next>, + <#else> + "${param.name}": "${param.value!}"<#if param_has_next>, + }