Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

BAH-3375 | Add. Rest Client Implementation for Create Lab Test, Lab Panel and Radiology Test #87

Merged
merged 10 commits into from
Dec 12, 2023
Merged
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 @@ -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,58 @@
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<>();


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());
gsluthra marked this conversation as resolved.
Show resolved Hide resolved
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 {
gsluthra marked this conversation as resolved.
Show resolved Hide resolved
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,58 @@
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<>();


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) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -28,15 +26,13 @@ public class OpenERPLabOrderTypeServiceEventWorker implements EventWorker {
private Map<String, OpenMRSLabOrderTypeEvent> labOrderTypeEventMap = new HashMap<>();


public OpenERPLabOrderTypeServiceEventWorker(String feedUrl, String odooURL, OpenERPContext openERPContext, OpenMRSWebClient openMRSWebClient, String urlPrefix) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading
Loading