Skip to content

Commit

Permalink
BAH-3375 | Add. Rest Client Implementation for Create Lab Test, Lab P…
Browse files Browse the repository at this point in the history
…anel 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 <[email protected]>

* 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 9ebfe34.

---------

Co-authored-by: Rahul Ramesh <[email protected]>
Co-authored-by: deeptirawat1510 <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 6e5ef32 commit 6bb11a7
Show file tree
Hide file tree
Showing 24 changed files with 691 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ public class OpenMRSLabPanelEvent extends OpenMRSLabOrderTypeEvent<OpenMRSLabPan
@Override
protected List<Parameter> buildParameters(Event event, OpenMRSLabPanel openMRSLabOrderTypeEvent) {
List<Parameter> 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<Parameter> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ public class OpenMRSLabTestEvent extends OpenMRSLabOrderTypeEvent<OpenMRSLabTest
@Override
protected List<Parameter> buildParameters(Event event, OpenMRSLabTest openMRSLabOrderTypeEvent) {
List<Parameter> 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<Parameter> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ public class OpenMRSRadiologyTestEvent extends OpenMRSLabOrderTypeEvent<OpenMRSR
@Override
protected List<Parameter> buildParameters(Event event, OpenMRSRadiologyTest openMRSLabOrderTypeEvent) {
List<Parameter> 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<Parameter> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<String, OpenMRSLabOrderTypeEvent> 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) {

}
}
Original file line number Diff line number Diff line change
@@ -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<String, OpenMRSLabOrderTypeEvent> 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) {

}
}
Loading

0 comments on commit 6bb11a7

Please sign in to comment.