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

OZ-545: Refactor code to use camel-openmrs-fhir and rewrite routes with Java DSL #22

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
#
# Copyright © 2021, Ozone HIS <[email protected]>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

FROM gitpod/workspace-java-17:2024-05-15-13-36-34
8 changes: 8 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#
# Copyright © 2021, Ozone HIS <[email protected]>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

# The .gitpod.yml file is used to configure your Gitpod workspace.
image:
file: .gitpod.Dockerfile
8 changes: 8 additions & 0 deletions .ocd3.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#
# Copyright © 2021, Ozone HIS <[email protected]>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

version: 1
build:
# Unable to run tests because of no Docker agent available in OCD3 yet. https://mekomsolutions.atlassian.net/browse/INFRA-318
Expand Down
8 changes: 8 additions & 0 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#
# Copyright © 2021, Ozone HIS <[email protected]>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

version: '3'
services:
eip-client:
Expand Down
121 changes: 121 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright © 2021, Ozone HIS <[email protected]>

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ozonehis</groupId>
<artifactId>eip-odoo-openmrs-parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>odoo-openmrs-integration-tests</artifactId>
<name>Integration Tests</name>
<description>Integration tests for FHIR to Odoo</description>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.ozonehis</groupId>
<artifactId>eip-odoo-openmrs</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ozonehis.camel</groupId>
<artifactId>test-infra-odoo</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-infra-core</artifactId>
<version>${camel.version}</version>
<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>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<includes>
<include>**/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>resource-dependencies</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>process-test-resources</phase>
<configuration>
<includeArtifactIds>test-infra-odoo</includeArtifactIds>
<includes>**/*</includes>
<outputDirectory>${project.build.directory}/test-classes/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>process-test-classes</id>
<goals>
<goal>run</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<target>
<chmod perm="755">
<fileset dir="target/test-classes/distro/data/postgresql">
<include name="**/*.sh"/>
</fileset>
</chmod>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/*
* Copyright © 2021, Ozone HIS <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.ozonehis.eip.odoo.openmrs;

import ca.uhn.fhir.context.FhirContext;
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.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.PartnerHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.ProductHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.SaleOrderHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.SaleOrderLineHandler;
import com.ozonehis.eip.odoo.openmrs.handlers.UomHandler;
import com.ozonehis.eip.odoo.openmrs.mapper.odoo.PartnerMapper;
import com.ozonehis.eip.odoo.openmrs.mapper.odoo.SaleOrderLineMapper;
import com.ozonehis.eip.odoo.openmrs.mapper.odoo.SaleOrderMapper;
import com.ozonehis.eip.odoo.openmrs.processors.MedicationRequestProcessor;
import com.ozonehis.eip.odoo.openmrs.processors.PatientProcessor;
import com.ozonehis.eip.odoo.openmrs.processors.ServiceRequestProcessor;
import com.ozonehis.eip.odoo.openmrs.routes.MedicationRequestRouting;
import com.ozonehis.eip.odoo.openmrs.routes.PatientRouting;
import com.ozonehis.eip.odoo.openmrs.routes.ServiceRequestRouting;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import lombok.Getter;
import org.apache.camel.CamelContext;
import org.apache.camel.test.infra.core.CamelContextExtension;
import org.apache.camel.test.infra.core.DefaultCamelContextExtension;
import org.apache.camel.test.infra.core.annotations.ContextFixture;
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.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@Getter
@ActiveProfiles("test")
@CamelSpringBootTest
@SpringBootTest(classes = {TestSpringConfiguration.class})
public abstract class BaseRouteIntegrationTest {

private OdooClient odooClient;

private static final String ODOO_SERVER_URL = "http://localhost:8069";

private static final String ODOO_DATABASE = "odoo";

private static final String ODOO_USERNAME = "admin";

private static final String ODOO_PASSWORD = "admin";

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

@RegisterExtension
protected static final OdooService odooService = OdooServiceFactory.createSingletonService();

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

protected static OdooClient createOdooClient() {
return new OdooClient(ODOO_SERVER_URL, ODOO_DATABASE, ODOO_USERNAME, ODOO_PASSWORD);
}

public OdooClient getOdooClient() {
if (odooClient == null) {
odooClient = createOdooClient();
}
return odooClient;
}

protected @Nonnull CamelContext getContextWithRouting(CamelContext context) throws Exception {
CountryHandler countryHandler = new CountryHandler();
countryHandler.setOdooClient(getOdooClient());

CountryStateHandler countryStateHandler = new CountryStateHandler();
countryStateHandler.setOdooClient(getOdooClient());

SaleOrderLineMapper<Resource> saleOrderLineMapper = new SaleOrderLineMapper<>();

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

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

SaleOrderMapper saleOrderMapper = new SaleOrderMapper();

SaleOrderLineHandler saleOrderLineHandler = new SaleOrderLineHandler();
saleOrderLineHandler.setOdooClient(getOdooClient());
saleOrderLineHandler.setProductHandler(productHandler);
saleOrderLineHandler.setUomHandler(uomHandler);
saleOrderLineHandler.setSaleOrderLineMapper(saleOrderLineMapper);

PartnerMapper partnerMapper = new PartnerMapper();
partnerMapper.setCountryHandler(countryHandler);
partnerMapper.setCountryStateHandler(countryStateHandler);

PartnerHandler partnerHandler = new PartnerHandler();
partnerHandler.setOdooClient(getOdooClient());
partnerHandler.setPartnerMapper(partnerMapper);

SaleOrderHandler saleOrderHandler = new SaleOrderHandler();
saleOrderHandler.setOdooClient(getOdooClient());
saleOrderHandler.setSaleOrderLineHandler(saleOrderLineHandler);
saleOrderHandler.setSaleOrderMapper(saleOrderMapper);
saleOrderHandler.setProductHandler(productHandler);

PatientProcessor patientProcessor = new PatientProcessor();
patientProcessor.setPartnerHandler(partnerHandler);
patientProcessor.setMapper(partnerMapper);

PatientRouting patientRouting = new PatientRouting();
patientRouting.setPatientProcessor(patientProcessor);
patientRouting.setPatientSyncEnabled(true);

MedicationRequestProcessor medicationRequestProcessor = new MedicationRequestProcessor();
medicationRequestProcessor.setSaleOrderHandler(saleOrderHandler);
medicationRequestProcessor.setPartnerHandler(partnerHandler);

MedicationRequestRouting medicationRequestRouting = new MedicationRequestRouting();
medicationRequestRouting.setMedicationRequestProcessor(medicationRequestProcessor);

ServiceRequestProcessor serviceRequestProcessor = new ServiceRequestProcessor();
serviceRequestProcessor.setSaleOrderHandler(saleOrderHandler);
serviceRequestProcessor.setPartnerHandler(partnerHandler);

ServiceRequestRouting serviceRequestRouting = new ServiceRequestRouting();
serviceRequestRouting.setServiceRequestProcessor(serviceRequestProcessor);

context.addRoutes(patientRouting);
context.addRoutes(medicationRequestRouting);
context.addRoutes(serviceRequestRouting);

return context;
}

protected boolean hasRoute(CamelContext context, String routeId) {
return context.getRoute(routeId) != null;
}

/**
* Send a body and headers to an endpoint.
*
* @param endpoint the endpoint to send the body to.
* @param body the body to send.
* @param headers the headers to send.
*/
protected void sendBodyAndHeaders(String endpoint, Object body, Map<String, Object> headers) {
contextExtension
.getProducerTemplate()
.sendBodyAndHeaders(contextExtension.getContext().getEndpoint(endpoint), body, headers);
}

/**
* Load resource from a file path.
*
* @param filePath the file path of the resource to load.
* @param resource resource object
* @param <T> The type of the resource to load e.g., Patient, Encounter, etc.
* @return resource object
*/
@SuppressWarnings("unchecked")
protected <T extends Resource> T loadResource(String filePath, T resource) {
FhirContext ctx = FhirContext.forR4();
return (T) ctx.newJsonParser().parseResource(resource.getClass(), readJSON(filePath));
}

/**
* Read JSON file from the classpath.
*
* @param filePath the file path of the JSON file to read.
* @return JSON content as a string
*/
protected String readJSON(String filePath) {
InputStream is = getClass().getClassLoader().getResourceAsStream(filePath);
if (is == null) {
throw new IllegalArgumentException("File not found! " + filePath);
} else {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
}
}
}
Loading