Skip to content

Commit

Permalink
OZ-812: Make order type UUIDs configurable (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishSiddharth authored Jan 30, 2025
1 parent 2ca128b commit 20b5220
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@

import org.apache.camel.LoggingLevel;
import org.openmrs.eip.fhir.FhirResource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import lombok.Setter;

@Component
@Setter
public class MedicationRequestRouter extends BaseFhirResourceRouter {

@Value("${eip.drug.order.concept.uuid:" + DRUG_ORDER_TYPE_UUID + "}")
private String drugOrderTypeUuid;

MedicationRequestRouter() {
super(FhirResource.MEDICATIONREQUEST);
}
Expand All @@ -20,7 +27,7 @@ public void configure() throws Exception {
from(FhirResource.MEDICATIONREQUEST.incomingUrl()).routeId("fhir-medicationrequest-router").filter(
isSupportedTable()).toD(
"sql:SELECT ot.uuid as uuid from order_type ot join orders o on o.order_type_id = ot.order_type_id where o.uuid = '${exchangeProperty.event.identifier}'?dataSource=#openmrsDataSource")
.filter(simple("${body[0]['uuid']} == '" + DRUG_ORDER_TYPE_UUID + "'"))
.filter(simple("${body[0]['uuid']} == '" + drugOrderTypeUuid + "'"))
.log(LoggingLevel.INFO, "Processing ${exchangeProperty.event.tableName} message")
.toD(
"sql:SELECT voided, order_action, previous_order_id FROM orders WHERE uuid = '${exchangeProperty.event.identifier}'?dataSource=#openmrsDataSource")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class ProcedureRouter extends BaseFhirResourceRouter {
@Value("${openmrs.baseUrl}")
private String openmrsBaseUrl;

@Value("${eip.procedure.order.concept.uuid:" + PROCEDURE_ORDER_TYPE_UUID + "}")
private String procedureOrderTypeUuid;

@Autowired
private OpenmrsRestConfiguration openmrsRestConfiguration;

Expand All @@ -43,7 +46,7 @@ public void configure() throws Exception {

from(FhirResource.PROCEDURE.incomingUrl()).routeId("fhir-procedure-router").filter(isSupportedTable()).toD(
"sql:SELECT ot.uuid as uuid from order_type ot join orders o on o.order_type_id = ot.order_type_id where o.uuid ='${exchangeProperty.event.identifier}'?dataSource=#openmrsDataSource")
.filter(simple("${body[0]['uuid']} == '" + PROCEDURE_ORDER_TYPE_UUID + "'"))
.filter(simple("${body[0]['uuid']} == '" + procedureOrderTypeUuid + "'"))
.log(LoggingLevel.INFO, "Processing ProcedureRouter ${exchangeProperty.event.tableName}")
.toD(
"sql:SELECT voided, order_action, previous_order_id FROM orders WHERE uuid = '${exchangeProperty.event.identifier}'?dataSource=#openmrsDataSource")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@

import org.apache.camel.LoggingLevel;
import org.openmrs.eip.fhir.FhirResource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import lombok.Setter;

@Component
@Setter
public class ServiceRequestRouter extends BaseFhirResourceRouter {

@Value("${eip.test.order.concept.uuid:" + TEST_ORDER_TYPE_UUID + "}")
private String testOrderTypeUuid;

@Value("${eip.imaging.order.concept.uuid:" + IMAGING_ORDER_TYPE_UUID + "}")
private String imagingOrderTypeUuid;

ServiceRequestRouter() {
super(FhirResource.SERVICEREQUEST);
}
Expand All @@ -20,8 +30,8 @@ public class ServiceRequestRouter extends BaseFhirResourceRouter {
public void configure() throws Exception {
from(FhirResource.SERVICEREQUEST.incomingUrl()).routeId("fhir-servicerequest-router").filter(isSupportedTable()).toD(
"sql:SELECT ot.uuid as uuid from order_type ot join orders o on o.order_type_id = ot.order_type_id where o.uuid ='${exchangeProperty.event.identifier}'?dataSource=#openmrsDataSource")
.filter(simple("${body[0]['uuid']} == '" + TEST_ORDER_TYPE_UUID + "' || ${body[0]['uuid']} == '"
+ IMAGING_ORDER_TYPE_UUID + "'"))
.filter(simple("${body[0]['uuid']} == '" + testOrderTypeUuid + "' || ${body[0]['uuid']} == '"
+ imagingOrderTypeUuid + "'"))
.log(LoggingLevel.INFO, "Processing ${exchangeProperty.event.tableName} message")
.toD(
"sql:SELECT voided, order_action, previous_order_id FROM orders WHERE uuid = '${exchangeProperty.event.identifier}'?dataSource=#openmrsDataSource")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.camel.model.dataformat.JsonLibrary;
import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.ServiceRequest;
import org.hl7.fhir.r4.model.SupplyRequest;
import org.openmrs.eip.fhir.FhirResource;
import org.openmrs.eip.fhir.routes.resources.dto.Order;
Expand All @@ -30,6 +29,9 @@ public class SupplyRequestRouter extends BaseFhirResourceRouter {
@Value("${openmrs.baseUrl}")
private String openmrsBaseUrl;

@Value("${eip.supplyrequest.order.concept.uuid:" + SUPPLY_REQUEST_ORDER_TYPE_UUID + "}")
private String supplyRequestOrderTypeUuid;

@Autowired
private OpenmrsRestConfiguration openmrsRestConfiguration;

Expand All @@ -44,7 +46,7 @@ public void configure() throws Exception {

from(FhirResource.SUPPLYREQUEST.incomingUrl()).routeId("fhir-supplyrequest-router").filter(isSupportedTable()).toD(
"sql:SELECT ot.uuid as uuid from order_type ot join orders o on o.order_type_id = ot.order_type_id where o.uuid ='${exchangeProperty.event.identifier}'?dataSource=#openmrsDataSource")
.filter(simple("${body[0]['uuid']} == '" + SUPPLY_REQUEST_ORDER_TYPE_UUID + "'"))
.filter(simple("${body[0]['uuid']} == '" + supplyRequestOrderTypeUuid + "'"))
.log(LoggingLevel.INFO, "Processing SupplyRequestRouter ${exchangeProperty.event.tableName}")
.toD(
"sql:SELECT voided, order_action, previous_order_id FROM orders WHERE uuid = '${exchangeProperty.event.identifier}'?dataSource=#openmrsDataSource")
Expand Down
8 changes: 8 additions & 0 deletions camel-openmrs-fhir/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@
openmrs.baseUrl=${openmrs.baseUrl}
openmrs.username=${eip.fhir.username}
openmrs.password=${eip.fhir.password}
# ----------------------------------------------------------------------------------------------------------------------

# *********************** EIP Configuration ********************************************************************
eip.test.order.concept.uuid=${eip.test.order.concept.uuid}
eip.imaging.order.concept.uuid=${eip.imaging.order.concept.uuid}
eip.procedure.order.concept.uuid=${eip.procedure.order.concept.uuid}
eip.supplyrequest.order.concept.uuid=${eip.supplyrequest.order.concept.uuid}
eip.drug.order.concept.uuid=${eip.drug.order.concept.uuid}
# ----------------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.AdviceWith;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
import org.apache.camel.test.spring.junit5.UseAdviceWith;
Expand All @@ -43,9 +42,10 @@ protected AbstractApplicationContext createApplicationContext() {

@Override
protected RoutesBuilder createRouteBuilder() {
RouteBuilder rb = new MedicationRequestRouter();
rb.from(FhirResource.MEDICATIONREQUEST.outgoingUrl()).to("mock:result");
return rb;
MedicationRequestRouter medicationRequestRouter = new MedicationRequestRouter();
medicationRequestRouter.setDrugOrderTypeUuid(DRUG_ORDER_TYPE_UUID);
medicationRequestRouter.from(FhirResource.MEDICATIONREQUEST.outgoingUrl()).to("mock:result");
return medicationRequestRouter;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected RoutesBuilder createRouteBuilder() {
ProcedureRouter procedureRouter = new ProcedureRouter();
procedureRouter.setOpenmrsRestConfiguration(new OpenmrsRestConfiguration());
procedureRouter.setOpenmrsBaseUrl("http://openmrs:8080/openmrs");
procedureRouter.setProcedureOrderTypeUuid(PROCEDURE_ORDER_TYPE_UUID);
procedureRouter.from(FhirResource.PROCEDURE.outgoingUrl()).to("mock:result");
return procedureRouter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.openmrs.eip.fhir.Constants.DRUG_ORDER_TYPE_UUID;
import static org.openmrs.eip.fhir.Constants.HEADER_FHIR_EVENT_TYPE;
import static org.openmrs.eip.fhir.Constants.IMAGING_ORDER_TYPE_UUID;
import static org.openmrs.eip.fhir.Constants.TEST_ORDER_TYPE_UUID;

import java.util.Collections;
Expand All @@ -18,7 +19,6 @@
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.AdviceWith;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
import org.apache.camel.test.spring.junit5.UseAdviceWith;
Expand All @@ -41,9 +41,11 @@ protected AbstractApplicationContext createApplicationContext() {

@Override
protected RoutesBuilder createRouteBuilder() {
RouteBuilder rb = new ServiceRequestRouter();
rb.from(FhirResource.SERVICEREQUEST.outgoingUrl()).to("mock:result");
return rb;
ServiceRequestRouter serviceRequestRouter = new ServiceRequestRouter();
serviceRequestRouter.setTestOrderTypeUuid(TEST_ORDER_TYPE_UUID);
serviceRequestRouter.setImagingOrderTypeUuid(IMAGING_ORDER_TYPE_UUID);
serviceRequestRouter.from(FhirResource.SERVICEREQUEST.outgoingUrl()).to("mock:result");
return serviceRequestRouter;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.AdviceWith;
import org.apache.camel.builder.AdviceWithRouteBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
import org.apache.camel.test.spring.junit5.UseAdviceWith;
import org.hl7.fhir.r4.model.ServiceRequest;
import org.hl7.fhir.r4.model.SupplyRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openmrs.eip.fhir.FhirResource;
import org.openmrs.eip.fhir.spring.OpenmrsRestConfiguration;
Expand All @@ -47,6 +44,7 @@ protected RoutesBuilder createRouteBuilder() {
SupplyRequestRouter supplyRequestRouter = new SupplyRequestRouter();
supplyRequestRouter.setOpenmrsRestConfiguration(new OpenmrsRestConfiguration());
supplyRequestRouter.setOpenmrsBaseUrl("http://openmrs:8080/openmrs");
supplyRequestRouter.setSupplyRequestOrderTypeUuid(SUPPLY_REQUEST_ORDER_TYPE_UUID);
supplyRequestRouter.from(FhirResource.SUPPLYREQUEST.outgoingUrl()).to("mock:result");
return supplyRequestRouter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;

Expand All @@ -27,10 +28,7 @@
*/
@SpringBootTest
@ContextConfiguration(classes = OpenmrsFhirConfiguration.class)
@TestPropertySource(properties = { "eip.fhir.resources=Encounter", "openmrs.eip.log.level=DEBUG",
"eip.fhir.serverUrl=http://localhost:8080/openmrs/ws/fhir2/R4", "eip.fhir.username=admin",
"eip.fhir.password=password", "openmrs.baseUrl=http://localhost:8080/openmrs", "openmrs.username=admin",
"openmrs.password=password" })
@ActiveProfiles("test")
public class OpenmrsFhirConfigurationTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.env.Environment;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;

@SpringBootTest
@ContextConfiguration(classes = OpenmrsRestConfiguration.class)
@TestPropertySource(properties = { "eip.fhir.resources=Encounter", "openmrs.eip.log.level=DEBUG",
"eip.fhir.serverUrl=http://localhost:8080/openmrs/ws/fhir2/R4", "eip.fhir.username=admin",
"eip.fhir.password=password", "openmrs.baseUrl=http://localhost:8080/openmrs", "openmrs.username=admin",
"openmrs.password=password" })
@ActiveProfiles("test")
public class OpenmrsRestConfigurationTest {

@Autowired
Expand Down
20 changes: 17 additions & 3 deletions camel-openmrs-fhir/src/test/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# *********************** OpenMRS EIP Configuration ********************************************************************
openmrs.baseUrl=http://openmrs:8080/openmrs
openmrs.baseUrl=http://localhost:8080/openmrs
openmrs.username=admin
openmrs.password=Admin123
# ----------------------------------------------------------------------------------------------------------------------
openmrs.password=password

eip.fhir.resources=Encounter
openmrs.eip.log.level=DEBUG
eip.fhir.serverUrl=http://localhost:8080/openmrs/ws/fhir2/R4
eip.fhir.username=admin
eip.fhir.password=password
# ----------------------------------------------------------------------------------------------------------------------

# *********************** EIP Configuration ********************************************************************
eip.test.order.concept.uuid=52a447d3-a64a-11e3-9aeb-50e549534c5e
eip.imaging.order.concept.uuid=8d2aff07-55e6-4a4a-8878-72b9eb36a3b8
eip.procedure.order.concept.uuid=67a92e56-0f88-11ea-8d71-362b9e155667
eip.supplyrequest.order.concept.uuid=67a92bd6-0f88-11ea-8d71-362b9e155667
eip.drug.order.concept.uuid=131168f4-15f5-102d-96e4-000c29c2a5d7
# ----------------------------------------------------------------------------------------------------------------------

0 comments on commit 20b5220

Please sign in to comment.