Skip to content

Commit

Permalink
OZ-524: Enable syncing patient weight to Odoo quotation (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaishSiddharth authored Nov 27, 2024
1 parent a200abc commit 95d911f
Show file tree
Hide file tree
Showing 34 changed files with 2,800 additions and 86 deletions.
45 changes: 39 additions & 6 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,53 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<wiremock.version>3.9.1</wiremock.version>
<jakarta.activation.api.version>2.1.3</jakarta.activation.api.version>
<jackson.core.version>2.16.1</jackson.core.version>
<jakarta.xml.bind.api.version>4.0.2</jakarta.xml.bind.api.version>
<jaxb.impl.version>4.0.0</jaxb.impl.version>
</properties>

<dependencies>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>${jakarta.activation.api.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.core.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${jakarta.xml.bind.api.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb.impl.version}</version>
</dependency>
<dependency>
<groupId>com.ozonehis</groupId>
<artifactId>eip-odoo-openmrs</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.ozonehis.camel</groupId>
Expand All @@ -46,12 +85,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.16.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@
*/
package com.ozonehis.eip.odoo.openmrs;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static java.util.Arrays.asList;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.ozonehis.camel.test.infra.odoo.services.OdooService;
import com.ozonehis.camel.test.infra.odoo.services.OdooServiceFactory;
import com.ozonehis.eip.odoo.openmrs.client.OdooClient;
import com.ozonehis.eip.odoo.openmrs.client.OdooUtils;
import com.ozonehis.eip.odoo.openmrs.component.OdooComponent;
import com.ozonehis.eip.odoo.openmrs.handlers.CountryHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.CountryStateHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.ObservationHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.PartnerHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.ProductHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.SaleOrderHandler;
Expand All @@ -31,6 +43,7 @@
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
Expand All @@ -42,7 +55,9 @@
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.hl7.fhir.r4.model.Resource;
import org.junit.jupiter.api.extension.RegisterExtension;
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;

@Getter
Expand All @@ -51,6 +66,9 @@
@SpringBootTest(classes = {TestSpringConfiguration.class})
public abstract class BaseRouteIntegrationTest {

@Autowired
private Environment environment;

private OdooClient odooClient;

private static final String ODOO_SERVER_URL = "http://localhost:8069";
Expand All @@ -61,6 +79,23 @@ public abstract class BaseRouteIntegrationTest {

private static final String ODOO_PASSWORD = "admin";

private static final String odooCustomerWeightField = "x_customer_weight";

protected static final List<String> orderDefaultAttributes =
asList("id", "client_order_ref", "partner_id", "state", "order_line", odooCustomerWeightField);

protected WireMockServer wireMockServer = new WireMockServer(8080);

protected void mockOpenmrsFhirServer() {
// Mock OpenMRS FHIR API metadata endpoint
wireMockServer.start();
configureFor("localhost", 8080);
stubFor(get(urlMatching("/openmrs/ws/fhir2/R4/metadata"))
.willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody(readJSON("metadata.json"))));
}

@RegisterExtension
protected static CamelContextExtension contextExtension = new DefaultCamelContextExtension();

Expand All @@ -69,7 +104,9 @@ public abstract class BaseRouteIntegrationTest {

@ContextFixture
public void configureContext(CamelContext context) {
context.getComponent("odoo", OdooComponent.class).setOdooClient(getOdooClient());
OdooComponent odooComponent = context.getComponent("odoo", OdooComponent.class);
odooComponent.setOdooUtils(getOdooUtils());
odooComponent.setOdooClient(getOdooClient());
}

protected static OdooClient createOdooClient() {
Expand All @@ -83,7 +120,15 @@ public OdooClient getOdooClient() {
return odooClient;
}

public OdooUtils getOdooUtils() {
OdooUtils odooUtils = new OdooUtils();
odooUtils.setEnvironment(environment);
return odooUtils;
}

protected @Nonnull CamelContext getContextWithRouting(CamelContext context) throws Exception {
OdooUtils odooUtils = getOdooUtils();

CountryHandler countryHandler = new CountryHandler();
countryHandler.setOdooClient(getOdooClient());

Expand All @@ -94,9 +139,11 @@ public OdooClient getOdooClient() {

UomHandler uomHandler = new UomHandler();
uomHandler.setOdooClient(getOdooClient());
uomHandler.setOdooUtils(odooUtils);

ProductHandler productHandler = new ProductHandler();
productHandler.setOdooClient(getOdooClient());
productHandler.setOdooUtils(odooUtils);

SaleOrderMapper saleOrderMapper = new SaleOrderMapper();

Expand All @@ -105,6 +152,7 @@ public OdooClient getOdooClient() {
saleOrderLineHandler.setProductHandler(productHandler);
saleOrderLineHandler.setUomHandler(uomHandler);
saleOrderLineHandler.setSaleOrderLineMapper(saleOrderLineMapper);
saleOrderLineHandler.setOdooUtils(odooUtils);

PartnerMapper partnerMapper = new PartnerMapper();
partnerMapper.setCountryHandler(countryHandler);
Expand All @@ -113,12 +161,31 @@ public OdooClient getOdooClient() {
PartnerHandler partnerHandler = new PartnerHandler();
partnerHandler.setOdooClient(getOdooClient());
partnerHandler.setPartnerMapper(partnerMapper);
partnerHandler.setOdooUtils(odooUtils);

// Setup IGenericClient
FhirContext fhirContext = FhirContext.forR4();
String serverBase = "http://localhost:8080/openmrs/ws/fhir2/R4";
IGenericClient client = fhirContext.newRestfulGenericClient(serverBase);

String username = "admin";
String password = "Admin123";
BasicAuthInterceptor authInterceptor = new BasicAuthInterceptor(username, password);
client.registerInterceptor(authInterceptor);

ObservationHandler observationHandler = new ObservationHandler();
observationHandler.setOpenmrsFhirClient(client);

SaleOrderHandler saleOrderHandler = new SaleOrderHandler();
saleOrderHandler.setOdooClient(getOdooClient());
saleOrderHandler.setSaleOrderLineHandler(saleOrderLineHandler);
saleOrderHandler.setSaleOrderMapper(saleOrderMapper);
saleOrderHandler.setProductHandler(productHandler);
saleOrderHandler.setObservationHandler(observationHandler);
saleOrderHandler.setWeightConcept("5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
saleOrderHandler.setOdooCustomerWeightField(odooCustomerWeightField);
saleOrderHandler.setOrderDefaultAttributes(orderDefaultAttributes);
saleOrderHandler.setOdooUtils(odooUtils);

PatientProcessor patientProcessor = new PatientProcessor();
patientProcessor.setPartnerHandler(partnerHandler);
Expand Down
Loading

0 comments on commit 95d911f

Please sign in to comment.