diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index ef644920..740f4888 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -1 +1,9 @@ +# +# Copyright © 2021, Ozone HIS +# +# 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 diff --git a/.gitpod.yml b/.gitpod.yml index 4dfe9bb0..337d3708 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,3 +1,11 @@ +# +# Copyright © 2021, Ozone HIS +# +# 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 diff --git a/.ocd3.yml b/.ocd3.yml index cfb4a7fb..970c6a95 100644 --- a/.ocd3.yml +++ b/.ocd3.yml @@ -1,3 +1,11 @@ +# +# Copyright © 2021, Ozone HIS +# +# 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 diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml index 50d97bc3..3e35786f 100644 --- a/dev/docker-compose.yml +++ b/dev/docker-compose.yml @@ -1,3 +1,11 @@ +# +# Copyright © 2021, Ozone HIS +# +# 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: diff --git a/odoo-openmrs/pom.xml b/odoo-openmrs/pom.xml new file mode 100644 index 00000000..cbcafea0 --- /dev/null +++ b/odoo-openmrs/pom.xml @@ -0,0 +1,135 @@ + + + + 4.0.0 + + com.ozonehis + eip-odoo-openmrs-parent + 2.0.0-SNAPSHOT + + + eip-odoo-openmrs + jar + EIP Odoo OpenMRS + EIP Odoo OpenMRS + + + 17 + 17 + UTF-8 + 4.0.1 + 4.1.0-SNAPSHOT + + + dependencies + + + + + org.openmrs.eip + camel-openmrs-fhir + ${camel.openmrs.fhir.version} + + + org.apache.xmlrpc + xmlrpc-client + ${xmlRpcClientVersion} + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + + shade + + package + + + + org.openmrs.eip:* + org.apache.xmlrpc:xmlrpc-client + org.liquibase:* + com.ozonehis:* + org.apache.camel:camel-fhir + org.apache.camel:camel-fhir-api + org.apache.commons:* + commons-io:commons-io + ca.uhn.hapi.fhir:* + com.fasterxml.jackson.core:jackson-databind + org.apache.httpcomponents:* + com.google.guava:* + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + META-INF/MANIFEST.MF + META-INF/okio.kotlin_module + META-INF.versions.9.module-info + + + + + + + + + net.mekomsolutions.maven.plugin + dependency-tracker-maven-plugin + 1.0.0-alpha + + + Compile dependency report + + track + + compile + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.5.0 + + + Attach the dependency report + + attach-artifact + + package + + + + ${project.build.directory}/${project.artifactId}-${project.version}-dependencies.txt + txt + ${dependencyReportClassifier} + + + + + + + + + + diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/Constants.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/Constants.java new file mode 100644 index 00000000..2ffc0ed0 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/Constants.java @@ -0,0 +1,54 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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 static java.util.Arrays.asList; + +import java.util.List; + +public class Constants { + public static final String PARTNER_MODEL = "res.partner"; + + public static final String SALE_ORDER_MODEL = "sale.order"; + + public static final String SALE_ORDER_LINE_MODEL = "sale.order.line"; + + public static final String COUNTRY_STATE_MODEL = "res.country.state"; + + public static final String COUNTRY_MODEL = "res.country"; + + public static final String UOM_MODEL = "uom.uom"; + + public static final String PRODUCT_MODEL = "product.product"; + + public static final String IR_MODEL = "ir.model.data"; + + public static final String CREATE_METHOD = "create"; + + public static final String SEARCH_READ_METHOD = "search_read"; + + public static final String SEARCH_METHOD = "search"; + + public static final String WRITE_METHOD = "write"; + + public static final String UNLINK_METHOD = "unlink"; + + public static final String HEADER_ODOO_ID_ATTRIBUTE_VALUE = "odoo.attribute.value"; + + public static final String EXCHANGE_PROPERTY_SKIP_ENCOUNTER = "skip.encounter"; + + public static final String FHIR_RESOURCE_TYPE = "fhir.resource.type"; + + public static final String HEADER_ENABLE_PATIENT_SYNC = "enable.patient.sync"; + + public static final List orderDefaultAttributes = + asList("id", "client_order_ref", "partner_id", "state", "order_line"); + + public static final List partnerDefaultAttributes = + asList("id", "name", "ref", "street", "street2", "city", "zip", "active", "comment"); +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/client/OdooClient.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/client/OdooClient.java new file mode 100644 index 00000000..05344668 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/client/OdooClient.java @@ -0,0 +1,170 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.client; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptyMap; +import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Slf4j +@Getter +@NoArgsConstructor +@Component +public class OdooClient { + + @Value("${odoo.baseUrl}") + private String url; + + @Value("${odoo.database}") + private String database; + + @Value("${odoo.username}") + private String username; + + @Value("${odoo.password}") + private String password; + + private Integer uid; + + private XmlRpcClientConfigImpl xmlRpcClientConfig; + + private XmlRpcClient client; + + private static final String SERVER_OBJECT_URL = "%s/xmlrpc/2/object"; + + private static final String SERVER_COMMON_URL = "%s/xmlrpc/2/common"; + + public OdooClient(String url, String database, String username, String password) { + this.url = url; + this.database = database; + this.username = username; + this.password = password; + } + + public void init() { + if (xmlRpcClientConfig == null) { + try { + xmlRpcClientConfig = new XmlRpcClientConfigImpl(); + xmlRpcClientConfig.setEnabledForExtensions(true); + xmlRpcClientConfig.setServerURL(new URL(String.format(SERVER_OBJECT_URL, getUrl()))); + } catch (MalformedURLException e) { + throw new RuntimeException( + String.format( + "Error occurred while building odoo server url %s error %s", getUrl(), e.getMessage()), + e); + } + } + if (client == null) { + client = new XmlRpcClient(); + client.setConfig(xmlRpcClientConfig); + } + // authenticate + if (uid == null) { + try { + XmlRpcClientConfigImpl xmlRpcClientCommonConfig = new XmlRpcClientConfigImpl(); + xmlRpcClientCommonConfig.setServerURL(new URL(String.format(SERVER_COMMON_URL, getUrl()))); + uid = (Integer) client.execute( + xmlRpcClientCommonConfig, + "authenticate", + asList(getDatabase(), getUsername(), getPassword(), emptyMap())); + } catch (XmlRpcException | MalformedURLException e) { + throw new RuntimeException("Cannot authenticate to Odoo server", e); + } + } + } + + public Integer create(String model, List> dataParams) { + init(); + + try { + return (Integer) client.execute( + "execute_kw", + asList(getDatabase(), uid, getPassword(), model, Constants.CREATE_METHOD, dataParams)); + } catch (XmlRpcException e) { + throw new RuntimeException("Error occurred while creating in odoo server error", e); + } + } + + public Boolean write(String model, List dataParams) { + init(); + + try { + return (Boolean) client.execute( + "execute_kw", asList(getDatabase(), uid, getPassword(), model, Constants.WRITE_METHOD, dataParams)); + } catch (XmlRpcException e) { + throw new RuntimeException("Error occurred while writing to odoo server error", e); + } + } + + public Boolean delete(String model, List dataParams) { + init(); + + try { + return (Boolean) client.execute( + "execute_kw", + asList(getDatabase(), uid, getPassword(), model, Constants.UNLINK_METHOD, dataParams)); + } catch (XmlRpcException e) { + throw new RuntimeException("Error occurred while deleting from odoo server error", e); + } + } + + public Object[] searchAndRead(String model, List criteria, List fields) { + init(); + + try { + List params = new ArrayList<>(); + params.add(getDatabase()); + params.add(uid); + params.add(getPassword()); + params.add(model); + params.add(Constants.SEARCH_READ_METHOD); + params.add(singletonList(criteria)); + if (fields != null) { + params.add(singletonMap("fields", fields)); + } + + return (Object[]) client.execute("execute_kw", params); + } catch (XmlRpcException e) { + throw new RuntimeException("Error occurred while searchAndRead from odoo server error", e); + } + } + + public Object[] search(String model, List criteria) { + init(); + + try { + return (Object[]) client.execute( + "execute_kw", + asList( + getDatabase(), + uid, + getPassword(), + model, + Constants.SEARCH_METHOD, + singletonList(singletonList(criteria)))); + } catch (XmlRpcException e) { + throw new RuntimeException("Error occurred while searching from odoo server error", e); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/client/OdooUtils.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/client/OdooUtils.java new file mode 100644 index 00000000..3ddebaa8 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/client/OdooUtils.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.client; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class OdooUtils { + + public static T convertToObject(Map data, Class objectClass) { + ObjectMapper mapper = new ObjectMapper(); + log.debug("OdooUtils: Converting map {} to object {}", data, objectClass.getName()); + try { + T obj = mapper.convertValue(data, objectClass); + log.debug("OdooUtils: Converted map {} to object {}", data, obj); + return obj; + } catch (Exception e) { + throw new RuntimeException(String.format("Error converting map %s to object: %s", data, e.getMessage())); + } + } + + public static Map convertObjectToMap(Object object) throws Exception { + Map map = new HashMap<>(); + Field[] fields = object.getClass().getDeclaredFields(); + log.debug("OdooUtils: Converting object {} to map", object.getClass().getName()); + + for (Field field : fields) { + field.setAccessible(true); + if (field.isAnnotationPresent(JsonProperty.class)) { + JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class); + String key = jsonProperty.value(); + Object value = field.get(object); + map.put(key, value); + } + } + log.debug("OdooUtils: Converted object {} to map {}", object.getClass().getName(), map); + return map; + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooComponent.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooComponent.java new file mode 100644 index 00000000..37483b54 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooComponent.java @@ -0,0 +1,36 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.component; + +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import java.util.Map; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.camel.Endpoint; +import org.apache.camel.spi.annotations.Component; +import org.apache.camel.support.DefaultComponent; +import org.springframework.beans.factory.annotation.Autowired; + +@Slf4j +@Setter +@Component("odoo") +public class OdooComponent extends DefaultComponent { + + @Autowired + private OdooClient odooClient; + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map parameters) { + log.info("Creating odoo endpoint with uri: {} remaining: {} parameters: {} ", uri, remaining, parameters); + String[] parts = remaining.split("/", 2); + if (parts.length != 2) { + throw new IllegalArgumentException("Invalid URI format. The expected format is 'odoo:method/model'"); + } + return new OdooEndpoint(uri, this, parts[0], parts[1], odooClient); + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooEndpoint.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooEndpoint.java new file mode 100644 index 00000000..465fa3d8 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooEndpoint.java @@ -0,0 +1,67 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.component; + +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriPath; +import org.apache.camel.support.DefaultEndpoint; + +/** + * Odoo component to integrate with Odoo XML RPC. + */ +@Slf4j +@UriEndpoint(firstVersion = "1.0.0", scheme = "odoo", title = "Odoo", syntax = "odoo:method/model", producerOnly = true) +public class OdooEndpoint extends DefaultEndpoint { + + @Getter + @Setter + @UriPath(description = "Odoo method name Eg. write, create") + @Metadata(required = true) + private String method; + + @Setter + @Getter + @UriPath(description = "Odoo model name Eg. res.partner, sale.order") + @Metadata(required = true) + private String model; + + private final OdooClient odooClient; + + public OdooEndpoint(String endpointUri, Component component, String method, String model, OdooClient odooClient) { + super(endpointUri, component); + this.method = method; + this.model = model; + this.odooClient = odooClient; + } + + @Override + public String getEndpointBaseUri() { + return super.getEndpointBaseUri(); + } + + @Override + public Producer createProducer() { + log.info("Creating odoo producer"); + return new OdooProducer(this, odooClient); + } + + @Override + public Consumer createConsumer(Processor processor) { + log.error("Odoo camel component consumer not supported"); + throw new UnsupportedOperationException(); + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooProducer.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooProducer.java new file mode 100644 index 00000000..5fac09fb --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/component/OdooProducer.java @@ -0,0 +1,94 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.component; + +import static java.util.Arrays.asList; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import com.ozonehis.eip.odoo.openmrs.client.OdooUtils; +import java.util.Collections; +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.support.DefaultProducer; +import org.openmrs.eip.EIPException; + +@Slf4j +public class OdooProducer extends DefaultProducer { + + private final OdooClient odooClient; + + public OdooProducer(Endpoint endpoint, OdooClient odooClient) { + super(endpoint); + this.odooClient = odooClient; + } + + @Override + public void process(Exchange exchange) throws Exception { + Object body = exchange.getIn().getBody(Object.class); + + String model = ((OdooEndpoint) getEndpoint()).getModel(); + String method = ((OdooEndpoint) getEndpoint()).getMethod(); + log.debug("OdooProducer: Endpoint {} Model: {}, Method {} ", getEndpoint(), model, method); + + Object attributeValue = exchange.getMessage().getHeader(Constants.HEADER_ODOO_ID_ATTRIBUTE_VALUE, Object.class); + switch (method) { + case Constants.CREATE_METHOD: + create(model, body); + break; + case Constants.WRITE_METHOD: + write(model, body, (List) attributeValue); + break; + case Constants.UNLINK_METHOD: + delete(model, body, (List) attributeValue); + break; + default: + log.error("OdooProducer: Unimplemented method name in Odoo component {} with body {}", method, body); + break; + } + } + + private void create(String model, Object body) throws Exception { + log.debug("OdooProducer: Creating data {} in Odoo", body); + Integer record = odooClient.create(model, List.of(OdooUtils.convertObjectToMap(body))); + if (record == null) { + throw new EIPException(String.format("Got null response while creating %s with body %s", model, body)); + } + log.debug("OdooProducer: Created data {} in Odoo with id: {}", body, record); + } + + private void write(String model, Object body, List ids) throws Exception { + log.debug("OdooProducer: Writing {} model for id {}", model, ids); + Boolean response = odooClient.write(model, asList(ids, OdooUtils.convertObjectToMap(body))); + if (response == null) { + throw new EIPException(String.format( + "Got null response while updating %s with %s", model, OdooUtils.convertObjectToMap(body))); + } else if (response) { + log.debug("{} updated with body {}", model, OdooUtils.convertObjectToMap(body)); + } else { + throw new EIPException( + String.format("Unable to update %s with %s", model, OdooUtils.convertObjectToMap(body))); + } + } + + private void delete(String model, Object body, List ids) throws Exception { + log.debug("OdooProducer: Deleting {} model for ids {}", model, ids); + Boolean response = odooClient.delete(model, Collections.singletonList(ids)); + if (response == null) { + throw new EIPException(String.format( + "Got null response while deleting %s with %s", model, OdooUtils.convertObjectToMap(body))); + } else if (response) { + log.debug("{} deleted with body {}", model, OdooUtils.convertObjectToMap(body)); + } else { + throw new EIPException( + String.format("Unable to delete %s with %s", model, OdooUtils.convertObjectToMap(body))); + } + } +} diff --git a/src/main/java/com/ozonehis/eip/odooopenmrs/config/OdooOpenmrsConfig.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/config/OdooOpenmrsConfig.java similarity index 50% rename from src/main/java/com/ozonehis/eip/odooopenmrs/config/OdooOpenmrsConfig.java rename to odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/config/OdooOpenmrsConfig.java index cb0e4a07..57e84636 100644 --- a/src/main/java/com/ozonehis/eip/odooopenmrs/config/OdooOpenmrsConfig.java +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/config/OdooOpenmrsConfig.java @@ -1,4 +1,11 @@ -package com.ozonehis.eip.odooopenmrs.config; +/* + * Copyright © 2021, Ozone HIS + * + * 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.config; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; diff --git a/src/main/java/com/ozonehis/eip/odooopenmrs/config/OpenmrsWatcherConfig.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/config/OpenmrsWatcherConfig.java similarity index 51% rename from src/main/java/com/ozonehis/eip/odooopenmrs/config/OpenmrsWatcherConfig.java rename to odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/config/OpenmrsWatcherConfig.java index 2a5ae7e3..611c1c99 100644 --- a/src/main/java/com/ozonehis/eip/odooopenmrs/config/OpenmrsWatcherConfig.java +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/config/OpenmrsWatcherConfig.java @@ -1,4 +1,11 @@ -package com.ozonehis.eip.odooopenmrs.config; +/* + * Copyright © 2021, Ozone HIS + * + * 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.config; import org.openmrs.eip.app.config.AppConfig; import org.springframework.context.annotation.Configuration; diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/CountryHandler.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/CountryHandler.java new file mode 100644 index 00000000..365ae494 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/CountryHandler.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.handlers; + +import static java.util.Arrays.asList; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.openmrs.eip.EIPException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class CountryHandler { + + @Autowired + private OdooClient odooClient; + + public Integer getCountryId(String countryName) { + Object[] records = odooClient.search(Constants.COUNTRY_MODEL, asList("name", "=", countryName)); + if (records.length > 1) { + throw new EIPException( + String.format("Found %s countries in odoo matching name: %s", records.length, countryName)); + } else if (records.length == 0) { + log.warn("No country found in odoo matching name: {}", countryName); + return null; + } + return (Integer) records[0]; + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/CountryStateHandler.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/CountryStateHandler.java new file mode 100644 index 00000000..d9529f4e --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/CountryStateHandler.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.handlers; + +import static java.util.Arrays.asList; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.openmrs.eip.EIPException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class CountryStateHandler { + + @Autowired + private OdooClient odooClient; + + public Integer getStateId(String stateName) { + Object[] records = odooClient.search(Constants.COUNTRY_STATE_MODEL, asList("name", "=", stateName)); + if (records.length > 1) { + throw new EIPException( + String.format("Found %s states in odoo matching name: %s", records.length, stateName)); + } else if (records.length == 0) { + log.warn("No state found in odoo matching name: {}", stateName); + return null; + } + return (Integer) records[0]; + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/PartnerHandler.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/PartnerHandler.java new file mode 100644 index 00000000..65367618 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/PartnerHandler.java @@ -0,0 +1,81 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.handlers; + +import static java.util.Arrays.asList; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import com.ozonehis.eip.odoo.openmrs.client.OdooUtils; +import com.ozonehis.eip.odoo.openmrs.mapper.odoo.PartnerMapper; +import com.ozonehis.eip.odoo.openmrs.model.Partner; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.camel.ProducerTemplate; +import org.hl7.fhir.r4.model.Patient; +import org.openmrs.eip.EIPException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class PartnerHandler { + + @Autowired + private OdooClient odooClient; + + @Autowired + private PartnerMapper partnerMapper; + + public Partner getPartnerByID(String partnerRefID) { + Object[] records = odooClient.searchAndRead( + Constants.PARTNER_MODEL, List.of(asList("ref", "=", partnerRefID)), Constants.partnerDefaultAttributes); + if (records == null) { + throw new EIPException( + String.format("Got null response while searching for Partner with reference id %s", partnerRefID)); + } else if (records.length == 1) { + log.debug("Partner exists with reference id {} record {}", partnerRefID, records[0]); + return OdooUtils.convertToObject((Map) records[0], Partner.class); + } else if (records.length == 0) { + log.warn("No Partner found with reference id {}", partnerRefID); + return null; + } else { + log.warn("Multiple Partners exists with reference id {}", partnerRefID); + throw new EIPException(String.format("Multiple Partners exists with reference id%s", partnerRefID)); + } + } + + public int createOrUpdatePartner(ProducerTemplate producerTemplate, Patient patient) { + Partner fetchedPartner = getPartnerByID(patient.getIdPart()); + if (fetchedPartner != null && fetchedPartner.getPartnerId() > 0) { + int partnerId = fetchedPartner.getPartnerId(); + log.info("Partner with reference id {} already exists, updating...", patient.getIdPart()); + Partner partner = partnerMapper.toOdoo(patient); + partner.setPartnerId(partnerId); + sendPartner(producerTemplate, "direct:odoo-update-partner-route", partner); + return partnerId; + } else { + log.info("Partner with reference id {} does not exist, creating...", patient.getIdPart()); + Partner partner = partnerMapper.toOdoo(patient); + sendPartner(producerTemplate, "direct:odoo-create-partner-route", partner); + return getPartnerByID(partner.getPartnerRef()).getPartnerId(); + } + } + + public void sendPartner(ProducerTemplate producerTemplate, String endpointUri, Partner partner) { + Map headers = new HashMap<>(); + if (endpointUri.contains("update")) { + headers.put(Constants.HEADER_ODOO_ID_ATTRIBUTE_VALUE, List.of(partner.getPartnerId())); + } + producerTemplate.sendBodyAndHeaders(endpointUri, partner, headers); + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/ProductHandler.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/ProductHandler.java new file mode 100644 index 00000000..f4235a32 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/ProductHandler.java @@ -0,0 +1,71 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.handlers; + +import static java.util.Arrays.asList; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import com.ozonehis.eip.odoo.openmrs.client.OdooUtils; +import com.ozonehis.eip.odoo.openmrs.model.Product; +import java.util.Map; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.hl7.fhir.r4.model.MedicationRequest; +import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.r4.model.ServiceRequest; +import org.openmrs.eip.EIPException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class ProductHandler { + + @Autowired + private OdooClient odooClient; + + public Product getProduct(Resource resource) { + String externalId = getProductExternalId(resource); + + Object[] records = odooClient.searchAndRead( + Constants.IR_MODEL, + asList(asList("model", "=", Constants.PRODUCT_MODEL), asList("name", "=", externalId)), + null); + if (records == null) { + throw new EIPException( + String.format("Got null response while fetching for Product with id %s", externalId)); + } else if (records.length == 1) { + log.debug("Product exists with id {} record {}", externalId, records[0]); + return OdooUtils.convertToObject((Map) records[0], Product.class); + } else if (records.length == 0) { + log.warn("No Product found with id {}", externalId); + return null; + } else { + log.warn("Multiple Products exists with id {}", externalId); + throw new EIPException(String.format("Multiple Products exists with id %s", externalId)); + } + } + + private String getProductExternalId(Resource resource) { + if (resource instanceof ServiceRequest serviceRequest) { + String id = serviceRequest.getCode().getCodingFirstRep().getCode(); + log.debug("ProductHandler: ServiceRequest code {}", id); + return id; + } else if (resource instanceof MedicationRequest medicationRequest) { + String id = + medicationRequest.getMedicationReference().getReference().split("/")[1]; + log.debug("ProductHandler: MedicationRequest reference {}", id); + return id; + } else { + throw new IllegalArgumentException( + "Unsupported resource type: " + resource.getClass().getName()); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderHandler.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderHandler.java new file mode 100644 index 00000000..0002d2e2 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderHandler.java @@ -0,0 +1,162 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.handlers; + +import static java.util.Arrays.asList; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import com.ozonehis.eip.odoo.openmrs.client.OdooUtils; +import com.ozonehis.eip.odoo.openmrs.mapper.odoo.SaleOrderMapper; +import com.ozonehis.eip.odoo.openmrs.model.Product; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrder; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrderLine; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.camel.ProducerTemplate; +import org.hl7.fhir.r4.model.Encounter; +import org.hl7.fhir.r4.model.Resource; +import org.openmrs.eip.EIPException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class SaleOrderHandler { + + @Autowired + private OdooClient odooClient; + + @Autowired + private SaleOrderLineHandler saleOrderLineHandler; + + @Autowired + private SaleOrderMapper saleOrderMapper; + + @Autowired + private ProductHandler productHandler; + + public SaleOrder getDraftSaleOrderIfExistsByVisitId(String visitId) { + Object[] records = odooClient.searchAndRead( + Constants.SALE_ORDER_MODEL, + List.of(asList("client_order_ref", "=", visitId), asList("state", "=", "draft")), + Constants.orderDefaultAttributes); + if (records == null) { + throw new EIPException( + String.format("Got null response while fetching for Sale order with client_order_ref %s", visitId)); + } else if (records.length == 1) { + SaleOrder saleOrder = OdooUtils.convertToObject((Map) records[0], SaleOrder.class); + log.debug("Sale order exists with client_order_ref {} sale order {}", visitId, saleOrder); + return saleOrder; + } else if (records.length == 0) { + log.warn("No Sale order found with client_order_ref {}", visitId); + return null; + } else { + log.warn("Multiple Sale order exists with client_order_ref {}", visitId); + throw new EIPException(String.format("Multiple Sale order found with client_order_ref %s", visitId)); + } + } + + public void sendSaleOrder(ProducerTemplate producerTemplate, String endpointUri, SaleOrder saleOrder) { + Map saleOrderHeaders = new HashMap<>(); + if (endpointUri.contains("update")) { + saleOrderHeaders.put( + com.ozonehis.eip.odoo.openmrs.Constants.HEADER_ODOO_ID_ATTRIBUTE_VALUE, + List.of(saleOrder.getOrderId())); + } + producerTemplate.sendBodyAndHeaders(endpointUri, saleOrder, saleOrderHeaders); + } + + public void updateSaleOrderIfExistsWithSaleOrderLine( + Resource resource, SaleOrder saleOrder, String encounterVisitUuid, ProducerTemplate producerTemplate) { + // If sale order exists create sale order line and link it to sale order + SaleOrderLine saleOrderLine = saleOrderLineHandler.buildSaleOrderLineIfProductExists(resource, saleOrder); + if (saleOrderLine == null) { + log.info( + "{}: Skipping create sale order line for encounter Visit {}", + resource.getClass().getName(), + encounterVisitUuid); + return; + } + + producerTemplate.sendBody("direct:odoo-create-sale-order-line-route", saleOrderLine); + log.debug( + "{}: Created sale order line {} and linked to sale order {}", + resource.getClass().getName(), + saleOrderLine, + saleOrder); + } + + public void createSaleOrderWithSaleOrderLine( + Resource resource, + Encounter encounter, + int partnerId, + String encounterVisitUuid, + ProducerTemplate producerTemplate) { + // If the sale order does not exist, create it, then create sale order line and link it to sale order + SaleOrder newSaleOrder = saleOrderMapper.toOdoo(encounter); + newSaleOrder.setOrderPartnerId(partnerId); + newSaleOrder.setOrderState("draft"); + + sendSaleOrder(producerTemplate, "direct:odoo-create-sale-order-route", newSaleOrder); + log.debug( + "{}: Created sale order with partner_id {}", resource.getClass().getName(), partnerId); + + SaleOrder fetchedSaleOrder = getDraftSaleOrderIfExistsByVisitId(encounterVisitUuid); + if (fetchedSaleOrder != null) { + SaleOrderLine saleOrderLine = + saleOrderLineHandler.buildSaleOrderLineIfProductExists(resource, fetchedSaleOrder); + if (saleOrderLine == null) { + log.info( + "{}: Skipping create sale order line and sale order for partner_id {}", + resource.getClass().getName(), + partnerId); + return; + } + + producerTemplate.sendBody("direct:odoo-create-sale-order-line-route", saleOrderLine); + log.debug( + "{}: Created sale order {} and sale order line {} and linked to sale order", + resource.getClass().getName(), + fetchedSaleOrder.getOrderId(), + saleOrderLine); + } + } + + public void deleteSaleOrderLine(Resource resource, String encounterVisitUuid, ProducerTemplate producerTemplate) { + SaleOrder saleOrder = getDraftSaleOrderIfExistsByVisitId(encounterVisitUuid); + if (saleOrder != null) { + Product product = productHandler.getProduct(resource); + if (product != null) { + SaleOrderLine saleOrderLine = saleOrderLineHandler.getSaleOrderLineIfExists( + saleOrder.getOrderId(), product.getProductResId()); + if (saleOrderLine != null) { + saleOrderLineHandler.sendSaleOrderLine( + producerTemplate, "direct:odoo-delete-sale-order-line-route", saleOrderLine); + } + } + } + } + + // Check if sale order has no sale order line, then cancel the sale order + public void cancelSaleOrderWhenNoSaleOrderLine( + int partnerId, String encounterVisitUuid, ProducerTemplate producerTemplate) { + SaleOrder saleOrder = getDraftSaleOrderIfExistsByVisitId(encounterVisitUuid); + if (saleOrder != null + && (saleOrder.getOrderLine() == null || saleOrder.getOrderLine().isEmpty())) { + log.debug("SaleOrderHandler: Count of sale order line {}", saleOrder.getOrderLine()); + saleOrder.setOrderState("cancel"); + saleOrder.setOrderPartnerId((Integer) partnerId); + sendSaleOrder(producerTemplate, "direct:odoo-update-sale-order-route", saleOrder); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderLineHandler.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderLineHandler.java new file mode 100644 index 00000000..07d632ff --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderLineHandler.java @@ -0,0 +1,122 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.handlers; + +import static java.util.Arrays.asList; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import com.ozonehis.eip.odoo.openmrs.client.OdooUtils; +import com.ozonehis.eip.odoo.openmrs.mapper.odoo.SaleOrderLineMapper; +import com.ozonehis.eip.odoo.openmrs.model.Product; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrder; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrderLine; +import com.ozonehis.eip.odoo.openmrs.model.Uom; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.camel.ProducerTemplate; +import org.hl7.fhir.r4.model.MedicationRequest; +import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.r4.model.ServiceRequest; +import org.openmrs.eip.EIPException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class SaleOrderLineHandler { + + @Autowired + private OdooClient odooClient; + + @Autowired + private ProductHandler productHandler; + + @Autowired + private UomHandler uomHandler; + + @Autowired + private SaleOrderLineMapper saleOrderLineMapper; + + public SaleOrderLine buildSaleOrderLineIfProductExists(Resource resource, SaleOrder saleOrder) { + Product product = productHandler.getProduct(resource); + log.debug("SaleOrderLineHandler: Fetched Product {}", product); + if (product == null) { // TODO: Check should we allow product not found + log.debug("SaleOrderLineHandler: No product found"); + return null; + } + + // Check if Sale order line order exists in Sale order + SaleOrderLine fetchedSaleOrderLine = + getSaleOrderLineIfExists(saleOrder.getOrderId(), product.getProductResId()); + if (fetchedSaleOrderLine != null) { + log.debug( + "SaleOrderLineHandler: Sale order line already exists for sale order {} Skipping create new sale order line", + saleOrder); + return null; + } + + SaleOrderLine saleOrderLine = saleOrderLineMapper.toOdoo(resource); + saleOrderLine.setSaleOrderLineProductId(product.getProductResId()); + saleOrderLine.setSaleOrderLineOrderId(saleOrder.getOrderId()); + if (resource instanceof MedicationRequest) { + String uomExternalId = (String) saleOrderLine.getSaleOrderLineProductUom(); + Uom uom = uomHandler.getUom(uomExternalId); + log.debug("SaleOrderLineHandler: Fetched Uom {}", uom); + // Store Uom res_id in productUom to display unit in Odoo + saleOrderLine.setSaleOrderLineProductUom(uom.getUomResId()); + } else if (resource instanceof ServiceRequest) { + // Hardcoded to 1 so that `Units` is shown for ServiceRequest + saleOrderLine.setSaleOrderLineProductUom(1); + } + + return saleOrderLine; + } + + public SaleOrderLine getSaleOrderLineIfExists(int saleOrderId, int productId) { + Object[] records = odooClient.searchAndRead( + Constants.SALE_ORDER_LINE_MODEL, + asList(asList("order_id", "=", saleOrderId), asList("product_id", "=", productId)), + null); + if (records == null) { + throw new EIPException(String.format( + "Got null response while fetching for Sale order line with sale order id %s product id %s", + saleOrderId, productId)); + } else if (records.length == 1) { + SaleOrderLine saleOrderLine = + OdooUtils.convertToObject((Map) records[0], SaleOrderLine.class); + log.debug( + "Sale order line exists with sale order id {} product id {} sale order line {}", + saleOrderId, + productId, + saleOrderLine); + return saleOrderLine; + } else if (records.length == 0) { + log.warn("No Sale order line found with sale order id {} product id {}", saleOrderId, productId); + return null; + } else { + log.warn("Multiple Sale order line found with sale order id {} product id {}", saleOrderId, productId); + throw new EIPException(String.format( + "Multiple Sale order line found with sale order id %s product id %s", saleOrderId, productId)); + } + } + + public void sendSaleOrderLine(ProducerTemplate producerTemplate, String endpointUri, SaleOrderLine saleOrderLine) { + Map saleOrderLineHeaders = new HashMap<>(); + if (endpointUri.contains("update") || endpointUri.contains("delete")) { + saleOrderLineHeaders.put( + com.ozonehis.eip.odoo.openmrs.Constants.HEADER_ODOO_ID_ATTRIBUTE_VALUE, + List.of(saleOrderLine.getSaleOrderLineId())); + } + producerTemplate.sendBodyAndHeaders(endpointUri, saleOrderLine, saleOrderLineHeaders); + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/UomHandler.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/UomHandler.java new file mode 100644 index 00000000..68306222 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/handlers/UomHandler.java @@ -0,0 +1,49 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.handlers; + +import static java.util.Arrays.asList; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.client.OdooClient; +import com.ozonehis.eip.odoo.openmrs.client.OdooUtils; +import com.ozonehis.eip.odoo.openmrs.model.Uom; +import java.util.Map; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.openmrs.eip.EIPException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class UomHandler { + + @Autowired + private OdooClient odooClient; + + public Uom getUom(String externalId) { + Object[] records = odooClient.searchAndRead( + Constants.IR_MODEL, + asList(asList("model", "=", Constants.UOM_MODEL), asList("name", "=", externalId)), + null); + if (records == null) { + throw new EIPException(String.format("Got null response while fetching for Uom with id %s", externalId)); + } else if (records.length == 1) { + log.debug("Uom exists with id {} record {}", externalId, records[0]); + return OdooUtils.convertToObject((Map) records[0], Uom.class); + } else if (records.length == 0) { + log.warn("No Uom found with id {}", externalId); + throw new EIPException(String.format("No Uom found with id %s", externalId)); + } else { + log.warn("Multiple Uom exists with id {}", externalId); + throw new EIPException(String.format("Multiple Uom exists with id %s", externalId)); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/ToFhirMapping.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/ToFhirMapping.java new file mode 100644 index 00000000..7ca50d57 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/ToFhirMapping.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.mapper; + +import org.hl7.fhir.r4.model.Resource; + +/** + * An Interface for mapping from FHIR Resources to Odoo Resources + * + * @param FHIR Resource + * @param Odoo Resource + */ +public interface ToFhirMapping { + + /** + * Maps an Odoo Resource to a FHIR Resource + * + * @param odooResource Odoo Resource + * @return FHIR Resource + */ + F toFhir(E odooResource); +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/ToOdooMapping.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/ToOdooMapping.java new file mode 100644 index 00000000..52d1a301 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/ToOdooMapping.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.mapper; + +import com.ozonehis.eip.odoo.openmrs.model.OdooResource; + +/** + * An Interface for mapping from FHIR Resources to Odoo Resources + * + * @param FHIR Resource + * @param Odoo Resource + */ +public interface ToOdooMapping { + + /** + * Maps a FHIR Resource to an Odoo Resource + * + * @param fhirResource FHIR Resource + * @return Odoo Resource + */ + E toOdoo(F fhirResource); +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/fhir/PatientMapper.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/fhir/PatientMapper.java new file mode 100644 index 00000000..d6dc1b76 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/fhir/PatientMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.mapper.fhir; + +import com.ozonehis.eip.odoo.openmrs.mapper.ToFhirMapping; +import com.ozonehis.eip.odoo.openmrs.model.Partner; +import org.hl7.fhir.r4.model.Patient; +import org.springframework.stereotype.Component; + +@Component +public class PatientMapper implements ToFhirMapping { + + @Override + public Patient toFhir(Partner odooResource) { + Patient patient = new Patient(); + patient.setId(odooResource.getPartnerRef()); // This is the patient's ID in the FHIR server + return patient; + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/PartnerMapper.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/PartnerMapper.java new file mode 100644 index 00000000..78620604 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/PartnerMapper.java @@ -0,0 +1,105 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.mapper.odoo; + +import com.ozonehis.eip.odoo.openmrs.handlers.CountryHandler; +import com.ozonehis.eip.odoo.openmrs.handlers.CountryStateHandler; +import com.ozonehis.eip.odoo.openmrs.mapper.ToOdooMapping; +import com.ozonehis.eip.odoo.openmrs.model.Partner; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import lombok.Setter; +import org.hl7.fhir.r4.model.Element; +import org.hl7.fhir.r4.model.Extension; +import org.hl7.fhir.r4.model.Identifier; +import org.hl7.fhir.r4.model.Patient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Setter +@Component +public class PartnerMapper implements ToOdooMapping { + + private static final String ADDRESS_EXTENSION_URL = "http://fhir.openmrs.org/ext/address"; + + private static final String ADDRESS1_EXTENSION = "http://fhir.openmrs.org/ext/address#address1"; + + private static final String ADDRESS2_EXTENSION = "http://fhir.openmrs.org/ext/address#address2"; + + @Autowired + private CountryHandler countryHandler; + + @Autowired + private CountryStateHandler countryStateHandler; + + @Override + public Partner toOdoo(Patient patient) { + if (patient == null) { + return null; + } + Partner partner = new Partner(); + partner.setPartnerRef(patient.getIdPart()); + partner.setPartnerActive(patient.getActive()); + String patientName = getPatientName(patient).orElse(""); + String patientIdentifier = getPreferredPatientIdentifier(patient).orElse(""); + partner.setPartnerComment(patientIdentifier); + partner.setPartnerName(patientName); + + addAddress(patient, partner); + return partner; + } + + protected Optional getPreferredPatientIdentifier(Patient patient) { + return patient.getIdentifier().stream() + .filter(identifier -> identifier.getUse() == Identifier.IdentifierUse.OFFICIAL) + .findFirst() + .map(Identifier::getValue); + } + + protected Optional getPatientName(Patient patient) { + return patient.getName().stream() + .findFirst() + .map(name -> name.getGiven().get(0) + " " + name.getFamily()); + } + + protected void addAddress(Patient patient, Partner partner) { + if (patient.hasAddress()) { + patient.getAddress().forEach(fhirAddress -> { + partner.setPartnerCity(fhirAddress.getCity()); + partner.setPartnerCountryId(countryHandler.getCountryId(fhirAddress.getCountry())); + partner.setPartnerZip(fhirAddress.getPostalCode()); + partner.setPartnerStateId(countryStateHandler.getStateId(fhirAddress.getState())); + if (fhirAddress.getType() != null) { + partner.setPartnerType(fhirAddress.getType().getDisplay()); + } + + if (fhirAddress.hasExtension()) { + List extensions = fhirAddress.getExtension(); + List addressExtensions = extensions.stream() + .filter(extension -> extension.getUrl().equals(ADDRESS_EXTENSION_URL)) + .findFirst() + .map(Element::getExtension) + .orElse(new ArrayList<>()); + + addressExtensions.stream() + .filter(extension -> extension.getUrl().equals(ADDRESS1_EXTENSION)) + .findFirst() + .ifPresent(extension -> partner.setPartnerStreet( + extension.getValue().toString())); + + addressExtensions.stream() + .filter(extension -> extension.getUrl().equals(ADDRESS2_EXTENSION)) + .findFirst() + .ifPresent(extension -> partner.setPartnerStreet2( + extension.getValue().toString())); + } + }); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/SaleOrderLineMapper.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/SaleOrderLineMapper.java new file mode 100644 index 00000000..5c38a7e1 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/SaleOrderLineMapper.java @@ -0,0 +1,92 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.mapper.odoo; + +import com.ozonehis.eip.odoo.openmrs.mapper.ToOdooMapping; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrderLine; +import lombok.extern.slf4j.Slf4j; +import org.hl7.fhir.r4.model.Dosage; +import org.hl7.fhir.r4.model.MedicationRequest; +import org.hl7.fhir.r4.model.Quantity; +import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.r4.model.ServiceRequest; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class SaleOrderLineMapper implements ToOdooMapping { + + @Override + public SaleOrderLine toOdoo(R resource) { + SaleOrderLine saleOrderLine = new SaleOrderLine(); + if (resource instanceof ServiceRequest serviceRequest) { + saleOrderLine.setSaleOrderLineProductUomQty(1.0f); // default quantity is 1 for serviceRequests. + String requesterDisplay = serviceRequest.getRequester().getDisplay(); + String serviceDisplay = serviceRequest.getCode().getText(); + saleOrderLine.setSaleOrderLineName(serviceDisplay + " | Orderer: " + requesterDisplay); + + } else if (resource instanceof MedicationRequest medicationRequest) { + if (medicationRequest.hasDispenseRequest()) { + if (medicationRequest.getDispenseRequest().hasQuantity()) { + Quantity quantity = medicationRequest.getDispenseRequest().getQuantity(); + saleOrderLine.setSaleOrderLineProductUomQty( + quantity.getValue().floatValue()); + saleOrderLine.setSaleOrderLineProductUom(quantity.getCode()); + } + } + + String requesterDisplay = medicationRequest.getRequester().getDisplay(); + String medicationDisplay = + medicationRequest.getMedicationReference().getDisplay(); + saleOrderLine.setSaleOrderLineName( + medicationDisplay + " | " + constructDosageInstructionsText(medicationRequest, saleOrderLine) + + " | Orderer: " + requesterDisplay); + + } else { + throw new IllegalArgumentException("Sale Order Mapper Unsupported resource type: " + + resource.getClass().getName()); + } + return saleOrderLine; + } + + protected String constructDosageInstructionsText(MedicationRequest medicationRequest, SaleOrderLine saleOrderLine) { + Dosage dosage = medicationRequest.getDosageInstructionFirstRep(); + StringBuilder dosageInstructions = new StringBuilder(); + + if (dosage.hasDoseAndRate()) { + if (saleOrderLine.getSaleOrderLineProductUomQty() != null) { + dosageInstructions.append(saleOrderLine.getSaleOrderLineProductUomQty()); + dosageInstructions.append(" "); + dosageInstructions.append( + dosage.getDoseAndRateFirstRep().getDoseQuantity().getUnit()); + dosageInstructions.append(" | "); + } + dosageInstructions.append( + dosage.getDoseAndRateFirstRep().getDoseQuantity().getValue()); + dosageInstructions.append(" "); + dosageInstructions.append( + dosage.getDoseAndRateFirstRep().getDoseQuantity().getUnit()); + } + + if (dosage.hasRoute()) { + dosageInstructions.append(" - "); + dosageInstructions.append(dosage.getRoute().getText()); + } + + if (dosage.hasTiming()) { + dosageInstructions.append(" - "); + dosageInstructions.append(dosage.getTiming().getCode().getText()); + dosageInstructions.append(" - "); + dosageInstructions.append(dosage.getTiming().getRepeat().getDuration()); + dosageInstructions.append(" "); + dosageInstructions.append( + dosage.getTiming().getRepeat().getDurationUnit().getDisplay()); + } + return dosageInstructions.toString(); + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/SaleOrderMapper.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/SaleOrderMapper.java new file mode 100644 index 00000000..87e3e76e --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/mapper/odoo/SaleOrderMapper.java @@ -0,0 +1,35 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.mapper.odoo; + +import com.ozonehis.eip.odoo.openmrs.mapper.ToOdooMapping; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrder; +import org.hl7.fhir.r4.model.Encounter; +import org.springframework.stereotype.Component; + +@Component +public class SaleOrderMapper implements ToOdooMapping { + + @Override + public SaleOrder toOdoo(Encounter encounter) { + SaleOrder saleOrder = new SaleOrder(); + if (encounter == null) { + return null; + } + if (encounter.hasPartOf()) { + String encounterVisitUuid = encounter.getPartOf().getReference().split("/")[1]; + saleOrder.setOrderClientOrderRef(encounterVisitUuid); + saleOrder.setOrderTypeName("Sales Order"); + saleOrder.setOrderState("draft"); // Default value is always `draft` + } else { + throw new IllegalArgumentException( + "The Encounter does not have a partOf reference. Cannot map to Sale Order."); + } + return saleOrder; + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Country.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Country.java new file mode 100644 index 00000000..f9244558 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Country.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class Country implements OdooResource { + + @JsonProperty("id") + private Integer countryId; + + @JsonProperty("name") + private String countryName; + + @JsonProperty("code") + private String countryCode; +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/CountryState.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/CountryState.java new file mode 100644 index 00000000..805f0421 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/CountryState.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class CountryState implements OdooResource { + + @JsonProperty("id") + private Integer countryStateId; + + @JsonProperty("name") + private String countryStateName; + + @JsonProperty("code") + private String countryStateCode; // Check if required +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/OdooResource.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/OdooResource.java new file mode 100644 index 00000000..19eb93ce --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/OdooResource.java @@ -0,0 +1,14 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.model; + +/** + * This interface is used to mark all the Odoo resources. + * + */ +public interface OdooResource {} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Partner.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Partner.java new file mode 100644 index 00000000..d795fd03 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Partner.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class Partner implements OdooResource { + + @JsonProperty("id") + private Integer partnerId; + + @JsonProperty("name") + private String partnerName; + + @JsonProperty("ref") + private String partnerRef; + + @JsonProperty("type") + private String partnerType; + + @JsonProperty("street") + private String partnerStreet; + + @JsonProperty("street2") + private String partnerStreet2; + + @JsonProperty("city") + private String partnerCity; + + @JsonProperty("zip") + private String partnerZip; + + @JsonProperty("country_id") + private Integer partnerCountryId; + + @JsonProperty("state_id") + private Integer partnerStateId; + + @JsonProperty("active") + private Boolean partnerActive; + + @JsonProperty("comment") + private String partnerComment; // Stores Patient Identifier +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Product.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Product.java new file mode 100644 index 00000000..230852b8 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Product.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class Product implements OdooResource { + + @JsonProperty("id") + private Integer productId; + + @JsonProperty("display_name") + private String productDisplayName; // Product Name + + @JsonProperty("name") + private String productName; // Product ID + + @JsonProperty("res_id") + private Integer productResId; +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/SaleOrder.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/SaleOrder.java new file mode 100644 index 00000000..70bf2d6f --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/SaleOrder.java @@ -0,0 +1,40 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class SaleOrder implements OdooResource { + + @JsonProperty("id") + private Integer orderId; + + @JsonProperty("client_order_ref") + private String orderClientOrderRef; + + @JsonProperty("state") + private String orderState; + + @JsonProperty("partner_id") + private Object orderPartnerId; // Can be used as a list or Integer + + @JsonProperty("order_line") + private List orderLine; + + @JsonProperty("type_name") + private String orderTypeName; +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/SaleOrderLine.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/SaleOrderLine.java new file mode 100644 index 00000000..08f276f9 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/SaleOrderLine.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class SaleOrderLine implements OdooResource { + + @JsonProperty("id") + private Integer saleOrderLineId; + + @JsonProperty("name") + private String saleOrderLineName; // Stores Description + + @JsonProperty("order_id") + private Object saleOrderLineOrderId; + + @JsonProperty("product_id") + private Object saleOrderLineProductId; + + @JsonProperty("product_uom_qty") + private Float saleOrderLineProductUomQty; + + @JsonProperty("product_uom") + private Object saleOrderLineProductUom; // Can be used as a list or Integer, Stores code of product or product name +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Uom.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Uom.java new file mode 100644 index 00000000..a1a0df46 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/model/Uom.java @@ -0,0 +1,33 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class Uom { + + @JsonProperty("id") + private Integer uomId; + + @JsonProperty("name") + private String uomName; + + @JsonProperty("res_id") + private Integer uomResId; + + @JsonProperty("display_name") + private String uomDisplayName; +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/EncounterProcessor.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/EncounterProcessor.java new file mode 100644 index 00000000..016cd856 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/EncounterProcessor.java @@ -0,0 +1,55 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.processors; + +import static org.openmrs.eip.fhir.Constants.HEADER_FHIR_EVENT_TYPE; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.handlers.SaleOrderHandler; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrder; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.hl7.fhir.r4.model.Encounter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class EncounterProcessor implements Processor { + + @Autowired + private SaleOrderHandler saleOrderHandler; + + @Override + public void process(Exchange exchange) { + Message message = exchange.getMessage(); + Encounter encounter = message.getBody(Encounter.class); + if (encounter != null && encounter.hasPeriod() && encounter.getPeriod().hasEnd()) { + String encounterVisitUuid = encounter.getIdPart(); // TODO: Check if this should be referenceId + SaleOrder saleOrder = saleOrderHandler.getDraftSaleOrderIfExistsByVisitId(encounterVisitUuid); + if (saleOrder != null) { + Map headers = new HashMap<>(); + // Check if Sale Order needs to be moved from `draft` state to `sale` state + // saleOrder.setOrderState("sale"); + headers.put(Constants.HEADER_ODOO_ID_ATTRIBUTE_VALUE, List.of(saleOrder.getOrderId())); + headers.put(HEADER_FHIR_EVENT_TYPE, "u"); + + exchange.getMessage().setHeaders(headers); + exchange.getMessage().setBody(saleOrder); + exchange.setProperty(Constants.EXCHANGE_PROPERTY_SKIP_ENCOUNTER, false); + } else { + exchange.setProperty(Constants.EXCHANGE_PROPERTY_SKIP_ENCOUNTER, true); + } + } else { + exchange.setProperty(Constants.EXCHANGE_PROPERTY_SKIP_ENCOUNTER, true); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/MedicationRequestProcessor.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/MedicationRequestProcessor.java new file mode 100644 index 00000000..c0986223 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/MedicationRequestProcessor.java @@ -0,0 +1,104 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.processors; + +import com.ozonehis.eip.odoo.openmrs.handlers.PartnerHandler; +import com.ozonehis.eip.odoo.openmrs.handlers.SaleOrderHandler; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrder; +import java.util.List; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.camel.CamelExecutionException; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.ProducerTemplate; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Encounter; +import org.hl7.fhir.r4.model.Medication; +import org.hl7.fhir.r4.model.MedicationRequest; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.Resource; +import org.openmrs.eip.fhir.Constants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class MedicationRequestProcessor implements Processor { + + @Autowired + private SaleOrderHandler saleOrderHandler; + + @Autowired + private PartnerHandler partnerHandler; + + @Override + public void process(Exchange exchange) { + try (ProducerTemplate producerTemplate = exchange.getContext().createProducerTemplate()) { + Bundle bundle = exchange.getMessage().getBody(Bundle.class); + List entries = bundle.getEntry(); + + Patient patient = null; + Encounter encounter = null; + MedicationRequest medicationRequest = null; + Medication medication = null; + + for (Bundle.BundleEntryComponent entry : entries) { + Resource resource = entry.getResource(); + if (resource instanceof Patient) { + patient = (Patient) resource; + } else if (resource instanceof Encounter) { + encounter = (Encounter) resource; + } else if (resource instanceof MedicationRequest) { + medicationRequest = (MedicationRequest) resource; + } else if (resource instanceof Medication) { + medication = (Medication) resource; + } + } + + if (patient == null || encounter == null || medicationRequest == null || medication == null) { + throw new CamelExecutionException( + "Invalid Bundle. Bundle must contain Patient, Encounter, MedicationRequest and Medication", + exchange); + } else { + log.debug("Processing MedicationRequest for Patient with UUID {}", patient.getIdPart()); + String eventType = exchange.getMessage().getHeader(Constants.HEADER_FHIR_EVENT_TYPE, String.class); + if (eventType == null) { + throw new IllegalArgumentException("Event type not found in the exchange headers."); + } + String encounterVisitUuid = encounter.getPartOf().getReference().split("/")[1]; + int partnerId = partnerHandler.createOrUpdatePartner(producerTemplate, patient); + if ("c".equals(eventType) || "u".equals(eventType)) { + if (!medicationRequest.getStatus().equals(MedicationRequest.MedicationRequestStatus.CANCELLED)) { + SaleOrder saleOrder = saleOrderHandler.getDraftSaleOrderIfExistsByVisitId(encounterVisitUuid); + if (saleOrder != null) { + saleOrderHandler.updateSaleOrderIfExistsWithSaleOrderLine( + medicationRequest, saleOrder, encounterVisitUuid, producerTemplate); + } else { + saleOrderHandler.createSaleOrderWithSaleOrderLine( + medicationRequest, encounter, partnerId, encounterVisitUuid, producerTemplate); + } + } else { + // Executed when MODIFY option is selected in OpenMRS + saleOrderHandler.deleteSaleOrderLine(medicationRequest, encounterVisitUuid, producerTemplate); + } + } else if ("d".equals(eventType)) { + // Executed when DISCONTINUE option is selected in OpenMRS + saleOrderHandler.deleteSaleOrderLine(medicationRequest, encounterVisitUuid, producerTemplate); + saleOrderHandler.cancelSaleOrderWhenNoSaleOrderLine( + partnerId, encounterVisitUuid, producerTemplate); + } else { + throw new IllegalArgumentException("Unsupported event type: " + eventType); + } + } + } catch (Exception e) { + throw new CamelExecutionException("Error processing MedicationRequest", exchange, e); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/PatientProcessor.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/PatientProcessor.java new file mode 100644 index 00000000..30afa7a8 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/PatientProcessor.java @@ -0,0 +1,70 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.processors; + +import static org.openmrs.eip.fhir.Constants.HEADER_FHIR_EVENT_TYPE; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.handlers.PartnerHandler; +import com.ozonehis.eip.odoo.openmrs.mapper.odoo.PartnerMapper; +import com.ozonehis.eip.odoo.openmrs.model.Partner; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.Getter; +import lombok.Setter; +import org.apache.camel.CamelExecutionException; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.hl7.fhir.r4.model.Patient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Setter +@Getter +@Component +public class PatientProcessor implements Processor { + + @Autowired + private PartnerMapper mapper; + + @Autowired + private PartnerHandler partnerHandler; + + @Override + public void process(Exchange exchange) { + try { + Message message = exchange.getMessage(); + Patient patient = message.getBody(Patient.class); + Partner partner = mapper.toOdoo(patient); + + if (patient == null || partner == null) { + return; + } + + String eventType = message.getHeader(HEADER_FHIR_EVENT_TYPE, String.class); + Partner fetchedPartner = partnerHandler.getPartnerByID(partner.getPartnerRef()); + if (fetchedPartner != null) { + partner.setPartnerId(fetchedPartner.getPartnerId()); + Map headers = new HashMap<>(); + headers.put(Constants.HEADER_ODOO_ID_ATTRIBUTE_VALUE, List.of(partner.getPartnerId())); + + if (eventType.equals("c") || eventType.equals("u")) { + headers.put(HEADER_FHIR_EVENT_TYPE, "u"); + } else { + headers.put(HEADER_FHIR_EVENT_TYPE, "d"); + } + exchange.getMessage().setHeaders(headers); + } + exchange.getMessage().setBody(partner); + } catch (Exception e) { + throw new CamelExecutionException("Error processing Patient", exchange, e); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/ServiceRequestProcessor.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/ServiceRequestProcessor.java new file mode 100644 index 00000000..711d56c4 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/processors/ServiceRequestProcessor.java @@ -0,0 +1,99 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.processors; + +import com.ozonehis.eip.odoo.openmrs.handlers.PartnerHandler; +import com.ozonehis.eip.odoo.openmrs.handlers.SaleOrderHandler; +import com.ozonehis.eip.odoo.openmrs.model.SaleOrder; +import java.util.List; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.camel.CamelExecutionException; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.ProducerTemplate; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Encounter; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.r4.model.ServiceRequest; +import org.openmrs.eip.fhir.Constants; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Setter +@Component +public class ServiceRequestProcessor implements Processor { + + @Autowired + private SaleOrderHandler saleOrderHandler; + + @Autowired + private PartnerHandler partnerHandler; + + @Override + public void process(Exchange exchange) { + try (ProducerTemplate producerTemplate = exchange.getContext().createProducerTemplate()) { + Bundle bundle = exchange.getMessage().getBody(Bundle.class); + List entries = bundle.getEntry(); + + Patient patient = null; + Encounter encounter = null; + ServiceRequest serviceRequest = null; + for (Bundle.BundleEntryComponent entry : entries) { + Resource resource = entry.getResource(); + if (resource instanceof Patient) { + patient = (Patient) resource; + } else if (resource instanceof Encounter) { + encounter = (Encounter) resource; + } else if (resource instanceof ServiceRequest) { + serviceRequest = (ServiceRequest) resource; + } + } + + if (patient == null || encounter == null || serviceRequest == null) { + throw new CamelExecutionException( + "Invalid Bundle. Bundle must contain Patient, Encounter and ServiceRequest", exchange); + } else { + log.debug("Processing ServiceRequest for Patient with UUID {}", patient.getIdPart()); + String eventType = exchange.getMessage().getHeader(Constants.HEADER_FHIR_EVENT_TYPE, String.class); + if (eventType == null) { + throw new IllegalArgumentException("Event type not found in the exchange headers."); + } + String encounterVisitUuid = encounter.getPartOf().getReference().split("/")[1]; + int partnerId = partnerHandler.createOrUpdatePartner(producerTemplate, patient); + if ("c".equals(eventType) || "u".equals(eventType)) { + if (serviceRequest.getStatus().equals(ServiceRequest.ServiceRequestStatus.ACTIVE) + && serviceRequest.getIntent().equals(ServiceRequest.ServiceRequestIntent.ORDER)) { + SaleOrder saleOrder = saleOrderHandler.getDraftSaleOrderIfExistsByVisitId(encounterVisitUuid); + if (saleOrder != null) { + saleOrderHandler.updateSaleOrderIfExistsWithSaleOrderLine( + serviceRequest, saleOrder, encounterVisitUuid, producerTemplate); + } else { + saleOrderHandler.createSaleOrderWithSaleOrderLine( + serviceRequest, encounter, partnerId, encounterVisitUuid, producerTemplate); + } + } else { + // Executed when MODIFY option is selected in OpenMRS + saleOrderHandler.deleteSaleOrderLine(serviceRequest, encounterVisitUuid, producerTemplate); + } + } else if ("d".equals(eventType)) { + // Executed when DISCONTINUE option is selected in OpenMRS + saleOrderHandler.deleteSaleOrderLine(serviceRequest, encounterVisitUuid, producerTemplate); + saleOrderHandler.cancelSaleOrderWhenNoSaleOrderLine( + partnerId, encounterVisitUuid, producerTemplate); + } else { + throw new IllegalArgumentException("Unsupported event type: " + eventType); + } + } + } catch (Exception e) { + throw new CamelExecutionException("Error processing ServiceRequest", exchange, e); + } + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/EncounterRouting.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/EncounterRouting.java new file mode 100644 index 00000000..f9c1155f --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/EncounterRouting.java @@ -0,0 +1,47 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.processors.EncounterProcessor; +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.hl7.fhir.r4.model.Encounter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class EncounterRouting extends RouteBuilder { + + @Autowired + private EncounterProcessor encounterProcessor; + + @Override + public void configure() throws Exception { + // spotless:off + from("direct:encounter-to-sale-order-router") + .routeId("encounter-to-sale-order-router") + .process(encounterProcessor) + .choice() + .when(simple("${exchangeProperty." + Constants.EXCHANGE_PROPERTY_SKIP_ENCOUNTER + "} == true")) + .log(LoggingLevel.INFO, "Skipping encounter processing") + .otherwise() + .log(LoggingLevel.INFO, "Processing Encounter") + .to("direct:odoo-update-sale-order-route") + .end() + .end(); + + from("direct:fhir-encounter") + .routeId("fhir-encounter-to-sale-order-router") + .filter(body().isNotNull()) + .filter(exchange -> exchange.getMessage().getBody() instanceof Encounter) + .to("direct:encounter-to-sale-order-router") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/MedicationRequestRouting.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/MedicationRequestRouting.java new file mode 100644 index 00000000..5bb36587 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/MedicationRequestRouting.java @@ -0,0 +1,58 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.processors.MedicationRequestProcessor; +import lombok.Setter; +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.hl7.fhir.r4.model.MedicationRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Setter +@Component +public class MedicationRequestRouting extends RouteBuilder { + + private static final String MEDICATION_REQUEST_ID = "medication.request.id"; + + private static final String MEDICATION_REQUEST_INCLUDE_PARAMS = + "MedicationRequest:encounter,MedicationRequest:medication,MedicationRequest:patient"; + + @Autowired + private MedicationRequestProcessor medicationRequestProcessor; + + @Override + public void configure() { + // spotless:off + from("direct:fhir-medicationrequest") + .routeId("medication-request-to-sale-order-router") + .filter(body().isNotNull()) + .filter(exchange -> exchange.getMessage().getBody() instanceof MedicationRequest) + .process(exchange -> { + MedicationRequest medicationRequest = exchange.getMessage().getBody(MedicationRequest.class); + exchange.setProperty(Constants.FHIR_RESOURCE_TYPE, medicationRequest.fhirType()); + exchange.setProperty( + MEDICATION_REQUEST_ID, + medicationRequest.getIdElement().getIdPart()); + exchange.getMessage().setBody(medicationRequest); + }) + .toD("openmrs-fhir://?id=${exchangeProperty." + MEDICATION_REQUEST_ID + "}&resource=${exchangeProperty." + + Constants.FHIR_RESOURCE_TYPE + "}&include=" + MEDICATION_REQUEST_INCLUDE_PARAMS) + .to("direct:medication-request-to-sale-order-processor") + .end(); + + from("direct:medication-request-to-sale-order-processor") + .routeId("medication-request-to-sale-order-processor") + .log(LoggingLevel.INFO, "Processing MedicationRequest") + .process(medicationRequestProcessor) + .end(); + // spotless:on + } +} diff --git a/src/main/java/com/ozonehis/eip/odooopenmrs/routes/OpenmrsWatcherInitRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/OpenmrsWatcherInitRoute.java similarity index 63% rename from src/main/java/com/ozonehis/eip/odooopenmrs/routes/OpenmrsWatcherInitRoute.java rename to odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/OpenmrsWatcherInitRoute.java index 9cdf1941..03b17238 100644 --- a/src/main/java/com/ozonehis/eip/odooopenmrs/routes/OpenmrsWatcherInitRoute.java +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/OpenmrsWatcherInitRoute.java @@ -1,4 +1,11 @@ -package com.ozonehis.eip.odooopenmrs.routes; +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes; import org.apache.camel.builder.RouteBuilder; import org.springframework.stereotype.Component; diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/PatientRouting.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/PatientRouting.java new file mode 100644 index 00000000..6766e644 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/PatientRouting.java @@ -0,0 +1,65 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes; + +import static org.openmrs.eip.fhir.Constants.HEADER_FHIR_EVENT_TYPE; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.processors.PatientProcessor; +import lombok.Setter; +import org.apache.camel.LoggingLevel; +import org.apache.camel.Predicate; +import org.apache.camel.builder.RouteBuilder; +import org.hl7.fhir.r4.model.Patient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Setter +@Component +public class PatientRouting extends RouteBuilder { + + @Value("${odoo.openmrs.enable.patient.sync}") + private boolean isPatientSyncEnabled; + + @Autowired + private PatientProcessor patientProcessor; + + Predicate isPatientSyncEnabled() { + return exchange -> isPatientSyncEnabled + || Boolean.TRUE.equals(exchange.getIn().getHeader(Constants.HEADER_ENABLE_PATIENT_SYNC, Boolean.class)); + } + + @Override + public void configure() { + // spotless:off + from("direct:patient-to-partner-router") + .routeId("patient-to-partner-router") + .filter(exchange -> exchange.getMessage().getBody() instanceof Patient) + .filter(isPatientSyncEnabled()) + .log(LoggingLevel.INFO, "Processing Patient") + .process(patientProcessor) + .choice() + .when(header(HEADER_FHIR_EVENT_TYPE).isEqualTo("c")) + .toD("direct:odoo-create-partner-route") + .endChoice() + .when(header(HEADER_FHIR_EVENT_TYPE).isEqualTo("u")) + .toD("direct:odoo-update-partner-route") + .endChoice() + .when(header(HEADER_FHIR_EVENT_TYPE).isEqualTo("d")) + .toD("direct:odoo-delete-partner-route") + .endChoice() + .end(); + + from("direct:fhir-patient") + .routeId("fhir-patient-to-partner-router") + .to("direct:patient-to-partner-router") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/ServiceRequestRouting.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/ServiceRequestRouting.java new file mode 100644 index 00000000..2ab53f94 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/ServiceRequestRouting.java @@ -0,0 +1,59 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes; + +import com.ozonehis.eip.odoo.openmrs.Constants; +import com.ozonehis.eip.odoo.openmrs.processors.ServiceRequestProcessor; +import lombok.Setter; +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.hl7.fhir.r4.model.ServiceRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Setter +@Component +public class ServiceRequestRouting extends RouteBuilder { + + private static final String SERVICE_REQUEST_ID = "service.request.id"; + + private static final String SERVICE_REQUEST_INCLUDE_PARAMS = "ServiceRequest:encounter,ServiceRequest:patient"; + + private static final String SEARCH_PARAMS = + "id=${exchangeProperty." + SERVICE_REQUEST_ID + "}&resource=${exchangeProperty." + + Constants.FHIR_RESOURCE_TYPE + "}&include=" + SERVICE_REQUEST_INCLUDE_PARAMS; + + @Autowired + private ServiceRequestProcessor serviceRequestProcessor; + + @Override + public void configure() { + // spotless:off + from("direct:fhir-servicerequest") + .routeId("service-request-to-sale-order-router") + .filter(body().isNotNull()) + .filter(exchange -> exchange.getMessage().getBody() instanceof ServiceRequest) + .process(exchange -> { + ServiceRequest serviceRequest = exchange.getMessage().getBody(ServiceRequest.class); + exchange.setProperty(Constants.FHIR_RESOURCE_TYPE, serviceRequest.fhirType()); + exchange.setProperty( + SERVICE_REQUEST_ID, serviceRequest.getIdElement().getIdPart()); + exchange.getMessage().setBody(serviceRequest); + }) + .toD("openmrs-fhir://?" + SEARCH_PARAMS) + .to("direct:service-request-to-sale-order-processor") + .end(); + + from("direct:service-request-to-sale-order-processor") + .routeId("service-request-to-sale-order-processor") + .process(serviceRequestProcessor) + .log(LoggingLevel.INFO, "Processing ServiceRequest") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/CreatePartnerRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/CreatePartnerRoute.java new file mode 100644 index 00000000..d508d3ee --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/CreatePartnerRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.partner; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class CreatePartnerRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-create-partner-route") + .log(LoggingLevel.INFO, "Creating Partner in Odoo...") + .routeId("odoo-create-partner-route") + .to("odoo://create/res.partner") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/DeletePartnerRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/DeletePartnerRoute.java new file mode 100644 index 00000000..eb659722 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/DeletePartnerRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.partner; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class DeletePartnerRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-delete-partner-route") + .log(LoggingLevel.INFO, "Deleting Partner in Odoo...") + .routeId("odoo-delete-partner-route") + .to("odoo://unlink/res.partner") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/UpdatePartnerRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/UpdatePartnerRoute.java new file mode 100644 index 00000000..0201dc46 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/partner/UpdatePartnerRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.partner; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class UpdatePartnerRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-update-partner-route") + .log(LoggingLevel.INFO, "Updating Partner in Odoo...") + .routeId("odoo-update-partner-route") + .to("odoo://write/res.partner") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/CreateSaleOrderRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/CreateSaleOrderRoute.java new file mode 100644 index 00000000..31ac489a --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/CreateSaleOrderRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.saleorder; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class CreateSaleOrderRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-create-sale-order-route") + .log(LoggingLevel.INFO, "Creating Sale Order in Odoo...") + .routeId("odoo-create-sale-order-route") + .to("odoo://create/sale.order") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/DeleteSaleOrderRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/DeleteSaleOrderRoute.java new file mode 100644 index 00000000..63295476 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/DeleteSaleOrderRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.saleorder; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class DeleteSaleOrderRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-delete-sale-order-route") + .log(LoggingLevel.INFO, "Deleting Sale Order in Odoo...") + .routeId("odoo-delete-sale-order-route") + .to("odoo://unlink/sale.order") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/UpdateSaleOrderRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/UpdateSaleOrderRoute.java new file mode 100644 index 00000000..7055f946 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorder/UpdateSaleOrderRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.saleorder; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class UpdateSaleOrderRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-update-sale-order-route") + .log(LoggingLevel.INFO, "Updating Sale Order in Odoo...") + .routeId("odoo-update-sale-order-route") + .to("odoo://write/sale.order") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/CreateSaleOrderLineRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/CreateSaleOrderLineRoute.java new file mode 100644 index 00000000..a7c08a77 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/CreateSaleOrderLineRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.saleorderline; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class CreateSaleOrderLineRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-create-sale-order-line-route") + .log(LoggingLevel.INFO, "Creating Sale Order Line in Odoo...") + .routeId("odoo-create-sale-order-line-route") + .to("odoo://create/sale.order.line") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/DeleteSaleOrderLineRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/DeleteSaleOrderLineRoute.java new file mode 100644 index 00000000..c09ec4d1 --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/DeleteSaleOrderLineRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.saleorderline; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class DeleteSaleOrderLineRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-delete-sale-order-line-route") + .log(LoggingLevel.INFO, "Deleting Sale Order Line in Odoo...") + .routeId("odoo-delete-sale-order-line-route") + .to("odoo://unlink/sale.order.line") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/UpdateSaleOrderLineRoute.java b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/UpdateSaleOrderLineRoute.java new file mode 100644 index 00000000..50b767aa --- /dev/null +++ b/odoo-openmrs/src/main/java/com/ozonehis/eip/odoo/openmrs/routes/saleorderline/UpdateSaleOrderLineRoute.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2021, Ozone HIS + * + * 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.routes.saleorderline; + +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class UpdateSaleOrderLineRoute extends RouteBuilder { + + @Override + public void configure() { + // spotless:off + from("direct:odoo-update-sale-order-line-route") + .log(LoggingLevel.INFO, "Updating Sale Order Line in Odoo...") + .routeId("odoo-update-sale-order-line-route") + .to("odoo://write/sale.order.line") + .end(); + // spotless:on + } +} diff --git a/odoo-openmrs/src/main/resources/META-INF/services/org/apache/camel/component/odoo b/odoo-openmrs/src/main/resources/META-INF/services/org/apache/camel/component/odoo new file mode 100644 index 00000000..504f21b8 --- /dev/null +++ b/odoo-openmrs/src/main/resources/META-INF/services/org/apache/camel/component/odoo @@ -0,0 +1 @@ +class=com.ozonehis.eip.odoo.openmrs.component.OdooComponent diff --git a/src/main/resources/config/application.properties b/odoo-openmrs/src/main/resources/config/application.properties similarity index 73% rename from src/main/resources/config/application.properties rename to odoo-openmrs/src/main/resources/config/application.properties index 21b03603..67c7d5b7 100644 --- a/src/main/resources/config/application.properties +++ b/odoo-openmrs/src/main/resources/config/application.properties @@ -5,18 +5,12 @@ eip.application.name=${EIP_APP_NAME:eip-odoo-openmrs} eip.home=${user.home}${file.separator}.${eip.application.name} -# Camel endpoints that need to be notified of DB events -db-event.destinations=${DB_EVENT_DESTINATIONS_ODOO} - # The interval in milliseconds between polls of the retry queue by the retry route db-event.retry.interval=${DB_EVENT_RETRY_INTERVAL:1800000} # The interval in milliseconds before the first poll of the retry queue by the retry route when the application starts. db-event.retry.initial.delay=${DB_EVENT_RETRY_INITIAL_DELAY:120000} -# A comma separated list of database tables names to watch for changes -eip.watchedTables=${EIP_WATCHED_TABLES} - # ---------------------------------------------------------------------------------------------------------------------- # *********************** Logging Configuration ************************************************************************ @@ -128,38 +122,49 @@ debezium.snapshotMode=schema_only debezium.snapshotLockingMode=extended # ---------------------------------------------------------------------------------------------------------------------- -# **************************************** Logging Configuration For Odoo Routes *************************************** -logging.level.odoo-authentication=${openmrs.eip.log.level} -logging.level.odoo-get-country=${openmrs.eip.log.level} -logging.level.odoo-get-customer=${openmrs.eip.log.level} -logging.level.odoo-get-state=${openmrs.eip.log.level} -logging.level.odoo-event-listener=${openmrs.eip.log.level} -logging.level.odoo-manage-customer=${openmrs.eip.log.level} -logging.level.save-calendar-event-in-odoo=${openmrs.eip.log.level} -logging.level.get-resource-by-name-from-odoo=${openmrs.eip.log.level} -logging.level.get-resource-by-id-from-odoo=${openmrs.eip.log.level} -logging.level.get-resource-by-ext-id-from-odoo=${openmrs.eip.log.level} -logging.level.get-partner-ids-by-user-ids=${openmrs.eip.log.level} -logging.level.get-obs-by-concept-uuid-from-encounter=${openmrs.eip.log.level} -logging.level.odoo-patient-association-handler=${openmrs.eip.log.level} -logging.level.odoo-patient-handler=${openmrs.eip.log.level} -logging.level.odoo-process-person-address=${openmrs.eip.log.level} -logging.level.convert-to-concept-uuid-if-is-mapping=${openmrs.eip.log.level} -logging.level.obs-captured-on-form-rule=${openmrs.eip.log.level} -logging.level.patient-uuid-to-odoo-customer=${openmrs.eip.log.level} -logging.level.obs-to-odoo-resource=${openmrs.eip.log.level} -logging.level.obs-to-customer=${openmrs.eip.log.level} -logging.level.odoo-cancel-quotations=${openmrs.eip.log.level} -logging.level.odoo-get-draft-quotations=${openmrs.eip.log.level} -logging.level.odoo-get-external-id-map=${openmrs.eip.log.level} -logging.level.odoo-get-order-line=${openmrs.eip.log.level} -logging.level.odoo-get-quotations=${openmrs.eip.log.level} -logging.level.odoo-manage-order-line=${openmrs.eip.log.level} -logging.level.odoo-manage-quotation=${openmrs.eip.log.level} -logging.level.odoo-order-handler=${openmrs.eip.log.level} -logging.level.odoo-process-dc-or-voided-order=${openmrs.eip.log.level} -logging.level.odoo-process-new-order=${openmrs.eip.log.level} -logging.level.odoo-process-order=${openmrs.eip.log.level} -logging.level.odoo-process-revision-order=${openmrs.eip.log.level} -logging.level.get-hsu-id=${openmrs.eip.log.level} +# *********************** OAuth2 Configuration ******************************************************************** +# Enabled Oauth when set to true, defaults to false. +oauth.enabled=${OAUTH_ENABLED:false} + +# The client Id of the account, defaults to empty. +oauth.access.token.uri=${OAUTH_ACCESS_TOKEN_URL:} + +# The client Id of the account to use to authenticate, defaults to empty. +oauth.client.id=${OAUTH_CLIENT_ID:} + +# The client secret of the account to use to authenticate, defaults to empty. +oauth.client.secret=${OAUTH_CLIENT_SECRET:} + +# Authentication scope, can be multiple values separated by commas, defaults to empty. +oauth.client.scope=${OAUTH_CLIENT_SCOPE:} +# ---------------------------------------------------------------------------------------------------------------------- + +# *********************** Odoo configuration ************************************************************************** +# +# The base URL to the Odoo instance +odoo.baseUrl=${ODOO_URL} + +# The database name to use to log into the Odoo instance +odoo.database=${ODOO_DATABASE} + +# The username for the account to use to log into the Odoo instance +odoo.username=${ODOO_USER} + +# The password for the account to use to log into the Odoo instance +odoo.password=${ODOO_PASSWORD} + +# Whether to enable the patient sync feature. If enabled, patient data will be synchronized between OpenMRS and Odoo. +odoo.openmrs.enable.patient.sync=${ODOO_OPENMRS_ENABLE_PATIENT_SYNC:true} +# ---------------------------------------------------------------------------------------------------------------------- + +# *********************** OpenMRS FHIR EIP Configuration *************************************************************** +# +# A comma separated list of FHIR resources, e.g., Patient, Encounter, Observation +eip.fhir.resources=${EIP_FHIR_RESOURCES} +# The URL of the FHIR server +eip.fhir.serverUrl=${EIP_FHIR_SERVER_URL} + +# FHIR server credentials +eip.fhir.username=${EIP_FHIR_USERNAME:} +eip.fhir.password=${EIP_FHIR_PASSWORD:} # ---------------------------------------------------------------------------------------------------------------------- diff --git a/odoo-openmrs/src/main/resources/eip-odoo-openmrs.properties b/odoo-openmrs/src/main/resources/eip-odoo-openmrs.properties new file mode 100644 index 00000000..e69de29b diff --git a/pom.xml b/pom.xml index 21d9c9f4..00807b35 100644 --- a/pom.xml +++ b/pom.xml @@ -1,15 +1,26 @@ + 4.0.0 com.ozonehis - eip-odoo-openmrs - 2.1.0-SNAPSHOT - jar + eip-odoo-openmrs-parent + 2.0.0-SNAPSHOT + pom - EIP Odoo OpenMRS + EIP Odoo OpenMRS Parent Apache camel routes that integrates Odoo and OpenMRS system + 2021 + Ozone HIS http://www.ozone-his.com @@ -21,6 +32,10 @@ + + odoo-openmrs + + mks-nexus-public-releases @@ -40,14 +55,21 @@ 17 1.18.30 2.1.0-SNAPSHOT - 4.1.0-SNAPSHOT + 4.0.0-SNAPSHOT 4.1.0 3.1.4 3.1.3 + 7.0.0 + 4.0.0-SNAPSHOT + 1.19.3 + 1.0.0-SNAPSHOT + false + ${skipTests} + ${skipTests} 2.30.0 - 1.1.0 + 2.28.0 dependencies @@ -56,37 +78,37 @@ - org.apache.camel.springboot - camel-spring-boot-dependencies - ${camel.version} - pom - import + ca.uhn.hapi.fhir + hapi-fhir-structures-r4 + ${fhir-r4.version} + + + com.ozonehis + eip-commons + ${eip.client.version} + + + org.projectlombok + lombok + 1.18.30 - - org.projectlombok - lombok - ${lombok.version} - provided - com.ozonehis eip-commons - ${eip.client.version} - provided - - - org.openmrs.eip - openmrs-watcher - ${openmrs.watcher.version} + + + org.slf4j + slf4j-reload4j + + - org.apache.xmlrpc - xmlrpc-client - ${xmlRpcClientVersion} + org.projectlombok + lombok @@ -94,28 +116,31 @@ com.ozonehis eip-commons-test ${eip.client.version} - pom test - org.openmrs.eip - openmrs-watcher - ${openmrs.watcher.version} - test-jar + org.apache.camel + camel-core + ${camel.version} test - org.openmrs.eip - commons - ${openmrs.watcher.version} + org.apache.camel + camel-test-infra-common + ${camel.version} test-jar test - - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter-engine + 5.9.3 + test + + + org.testcontainers + testcontainers + ${test.containers.version} test @@ -183,70 +208,7 @@ - eip-odoo-openmrs-${project.version} - - - true - src/main/resources - - - - - src/test/resources - - - - org.apache.maven.plugins - maven-clean-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - org.apache.maven.plugins - maven-install-plugin - 3.1.0 - - - org.apache.maven.plugins - maven-surefire-plugin - 3.2.2 - - exit - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - - - shade - - package - - - - org.openmrs.eip:* - com.ozonehis:eip-commons - org.apache.xmlrpc:xmlrpc-client - org.liquibase:* - - - - - - com.diffplug.spotless spotless-maven-plugin @@ -266,6 +228,7 @@ + ${palantirJavaFormat.version} @@ -310,43 +273,67 @@ - - net.mekomsolutions.maven.plugin - dependency-tracker-maven-plugin - 1.0.0-alpha + com.mycila + license-maven-plugin + 4.3 + + + ${project.organization.name} + info@ozone-his.com + ${project.inceptionYear} + + + +
com/mycila/maven/plugin/license/templates/MPL-2.txt
+ + **/README + src/test/resources/** + src/main/resources/** + **/target/** + +
+
+
- Compile dependency report + format - track + format + check - compile + install
- - - org.codehaus.mojo - build-helper-maven-plugin - 3.5.0 + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + ${skipUnitTests} + + **/*IntegrationTest.java + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.2.5 + + + **/*IT.java + **/*IntegrationTest.java + + ${skipIntegrationTests} + - Attach the dependency report - attach-artifact + integration-test + verify - package - - - - ${project.build.directory}/${project.artifactId}-${project.version}-dependencies.txt - txt - ${dependencyReportClassifier} - - - diff --git a/src/main/resources/camel/concept-to-order-line-processor.xml b/src/main/resources/camel/concept-to-order-line-processor.xml deleted file mode 100644 index a731629d..00000000 --- a/src/main/resources/camel/concept-to-order-line-processor.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - - - - - - product.product - - - ${exchangeProperty.orderLineConcept.get('uuid')} - - - - - - ${body.length} == 0 - - - - - ${body.length} > 1 - - - - - ${body[0].get('res_id')} - - - - - - - - - - - ${body.length} > 1 - - - - ${body.length} == 0 - - ${exchangeProperty.createQuoteIfNotExist} == true - - create - - - - - - - - ${body} - - - #{T(java.lang.Integer).valueOf(0)} - - - - - - - #{T(java.lang.Integer).valueOf(body[0].get('id'))} - - - #{T(java.lang.Integer).valueOf(body[0].get('order_line').length)} - - - - - - ${exchangeProperty.orderLineCount} > 0 - - - - - ${body.length} > 1 - - - - ${body.length} == 1 - - - - ${body[0]} - - - - - - - ${exchangeProperty.order-line} == null - - - - - - - - diff --git a/src/main/resources/camel/convert-to-concept-uuid-if-is-mapping.xml b/src/main/resources/camel/convert-to-concept-uuid-if-is-mapping.xml deleted file mode 100644 index 8b0ae5a9..00000000 --- a/src/main/resources/camel/convert-to-concept-uuid-if-is-mapping.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - ${body.indexOf(':')} > 0 - - - - ${body.split(':')[0]} - - - ${body.split(':')[1]} - - - - - - ${body} == null - - - - - ${body.get('uuid')} - - - - - - - - diff --git a/src/main/resources/camel/get-hsu-id.xml b/src/main/resources/camel/get-hsu-id.xml deleted file mode 100644 index 6a93d1a9..00000000 --- a/src/main/resources/camel/get-hsu-id.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - ${null} - - - ${null} - - - ${null} - - - - ${body.get('identifiers').size()} > 0 - - ${exchangeProperty.${routeId}-endLoop} != true - - ${body.get('identifiers').get(${exchangeProperty.CamelLoopIndex})} - - - - ${exchangeProperty.${routeId}-currentItem.get('identifierType').get('uuid')} == '{{openmrs.identifier.type.uuid}}' - - ${exchangeProperty.${routeId}-currentItem.get('identifier')} - - - true - - - - - #{getProperty('CamelLoopIndex') == body.get('identifiers').size() - 1} - - true - - - - - - - - - ${routeId}-hsuId - - - - - diff --git a/src/main/resources/camel/get-obs-by-concept-uuid-from-encounter.xml b/src/main/resources/camel/get-obs-by-concept-uuid-from-encounter.xml deleted file mode 100644 index 5d0b9df4..00000000 --- a/src/main/resources/camel/get-obs-by-concept-uuid-from-encounter.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - ${exchangeProperty.encounter.get('obs')} - - - ${routeId}-encObs - - - #{body.size() - 1} - - - ${null} - - - ${null} - - - ${null} - - - - ${body.size()} > 0 - - ${exchangeProperty.${routeId}-endLoop} != true - - ${exchangeProperty.${routeId}-encObs.get(${exchangeProperty.CamelLoopIndex})} - - - - ${exchangeProperty.${routeId}-currentItem.get('concept').get('uuid')} == ${exchangeProperty.questionConceptUuid} && ${exchangeProperty.${routeId}-currentItem.get('voided')} != true - - ${routeId}-currentItem - - - true - - - - - ${exchangeProperty.CamelLoopIndex} == ${exchangeProperty.${routeId}-lastIndex} - - true - - - - - - - ${routeId}-match - - - - - diff --git a/src/main/resources/camel/get-partner-ids-by-user-ids.xml b/src/main/resources/camel/get-partner-ids-by-user-ids.xml deleted file mode 100644 index 82dfbdf6..00000000 --- a/src/main/resources/camel/get-partner-ids-by-user-ids.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - #{T(java.util.Arrays).asList('id', 'in', body.get('userIds'))} - - - #{T(java.util.Collections).singletonList(T(java.util.Collections).singletonList(getProperty('get-partner-ids-by-user-ids-userIdCriterion')))} - - - #{T(java.util.Collections).singletonMap('fields', T(java.util.Collections).singletonList('partner_id'))} - - - #{new java.util.ArrayList(7)} - - - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('get-partner-ids-by-user-ids-rpcArgs'))} - - - - - - - diff --git a/src/main/resources/camel/get-resource-by-ext-id-from-odoo.xml b/src/main/resources/camel/get-resource-by-ext-id-from-odoo.xml deleted file mode 100644 index 3fdef28e..00000000 --- a/src/main/resources/camel/get-resource-by-ext-id-from-odoo.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - ${body.get('externalId')} - - - ${body.get('modelName')} - - - - ${routeId}-extId - - - ${routeId}-modelName - - - - - - ${body.length} > 1 - - - - - - ${body.length} == 0 - - ${null} - - - - - ${body[0].get('res_id')} - - - - - - #{new java.util.HashMap()} - - - - - - - - - - - diff --git a/src/main/resources/camel/get-resource-by-id-from-odoo.xml b/src/main/resources/camel/get-resource-by-id-from-odoo.xml deleted file mode 100644 index dc547f2d..00000000 --- a/src/main/resources/camel/get-resource-by-id-from-odoo.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - #{new java.util.ArrayList(3)} - - - - - - #{T(java.util.Collections).singletonList(T(java.util.Collections).singletonList(getProperty('get-resource-by-id-from-odoo-idCriterion')))} - - - #{new java.util.ArrayList(6)} - - - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('get-resource-by-id-from-odoo-rpcArgs'))} - - - - - - ${body.length} == 1 - - ${body[0]} - - - - - ${null} - - - - - - - - diff --git a/src/main/resources/camel/get-resource-by-name-from-odoo.xml b/src/main/resources/camel/get-resource-by-name-from-odoo.xml deleted file mode 100644 index 42843b7d..00000000 --- a/src/main/resources/camel/get-resource-by-name-from-odoo.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - #{new java.util.ArrayList(3)} - - - - - - #{T(java.util.Collections).singletonList(T(java.util.Collections).singletonList(getProperty('nameCriterion')))} - - - #{new java.util.ArrayList(6)} - - - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('rpcArgs'))} - - - - - - ${body.length} == 1 - - ${body[0]} - - - - ${body.length} == 0 - - ${null} - - - - - - - - - - - diff --git a/src/main/resources/camel/obs-captured-on-form-rule.xml b/src/main/resources/camel/obs-captured-on-form-rule.xml deleted file mode 100644 index 6fd9a096..00000000 --- a/src/main/resources/camel/obs-captured-on-form-rule.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - false - - - - - ${exchangeProperty.obs.get('encounter')} != null - - false - - - encounter - - - ${exchangeProperty.obs.get('encounter').get('uuid')} - - - full - - - - - - - ${body} != null - - $ - - - - - - - - ${exchangeProperty.encounter.get('form')} != null - - ${exchangeProperty.encounter.get('form').get('uuid')} == ${exchangeProperty.formUuid} - - true - - - - - - - - - - - - - - - - - - - - - - ${exchangeProperty.rulePassed} - - - - - diff --git a/src/main/resources/camel/obs-to-customer.xml b/src/main/resources/camel/obs-to-customer.xml deleted file mode 100644 index fdac334f..00000000 --- a/src/main/resources/camel/obs-to-customer.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - ${properties:obs.to.customer.decision.rule.endpoint:null} - - - - - ${exchangeProperty.decisionRuleEndpoint.trim()} != 'null' - - ${exchangeProperty.entity-instance} - - - - - - ${body} - - - - - - - - - - ${exchangeProperty.decisionRuleEndpoint} == 'null' || ${exchangeProperty.decisionRulePassed} == true - - ${exchangeProperty.entity-instance.get('person').get('uuid')} - - - true - - - - - - - - - - - - - diff --git a/src/main/resources/camel/obs-to-odoo-resource.xml b/src/main/resources/camel/obs-to-odoo-resource.xml deleted file mode 100644 index 233427b9..00000000 --- a/src/main/resources/camel/obs-to-odoo-resource.xml +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - - - - - - #{getProperty('event').operation == 'c' || getProperty('event').operation == 'u'} - - - - - ${exchangeProperty.entity-instance.get('voided')} != true && ${exchangeProperty.isInsertOrUpdate} == true - - ${routeId}-obsQnAnsMap - - - - - - - - ${exchangeProperty.obsQnAnsMap} == null - - - - - #{new java.util.HashMap()} - - - - {{odoo.obs.concept.question.answer.mappings}} - - ${body.trim().split("#")[0].trim()} - - - ${body.trim().split("#")[1].trim()} - - - #{new java.util.HashSet()} - - - - ${exchangeProperty.obsQn} - - - - - - ${body} - - - - - - #{T(org.apache.commons.lang3.StringUtils).split(getProperty('obsAnswers'), '^')} - - - ${body.trim()} - - - - ${exchangeProperty.obsAns} - - - - - - ${body} - - - - - - - - - - - - - - - ${exchangeProperty.entity-instance.get('concept').get('uuid')} - - - - - #{getProperty('obsQnAnsMap').containsKey(getProperty('obsQnUuid')) && getProperty('entity-instance').get('value') != null} - - - - - - #{getProperty('obsQnAnsMap').get(getProperty('obsQnUuid')).contains(getProperty('entity-instance').get('value').get('uuid'))} - - - - - - - - - - - - - - #{getProperty('entity-instance').get('value') == null} - - - - - - - - - - - - - - ${exchangeProperty.isInsertOrUpdate} != true - - - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-add-extra-customer-details.xml b/src/main/resources/camel/odoo-add-extra-customer-details.xml deleted file mode 100644 index cd29c12e..00000000 --- a/src/main/resources/camel/odoo-add-extra-customer-details.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - ${properties:odoo.dob.field:null} != null && ${properties:odoo.dob.field:null} != '' - - - ${properties:odoo.dob.field} - - - - ${exchangeProperty.person.get('birthdate')} - - - - - - - - diff --git a/src/main/resources/camel/odoo-add-extra-quotation-details.xml b/src/main/resources/camel/odoo-add-extra-quotation-details.xml deleted file mode 100644 index 5983373a..00000000 --- a/src/main/resources/camel/odoo-add-extra-quotation-details.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - ${properties:odoo.weight.field:null} != null && ${properties:odoo.weight.field:null} != '' - - - ${properties:odoo.weight.field} - - - - - - - - - $.[?(@.results)] - - $.results[0].display - - - - - '' - - - - - ${exchangeProperty.weight} != null && ${exchangeProperty.weight} != '' - - #{new java.util.ArrayList(2)} - - - - - #{T(java.util.Collections).singletonMap(getProperty('odooWeightField'), getProperty('weight'))} - - - - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('callParams'))} - - - - - - - - diff --git a/src/main/resources/camel/odoo-authentication.xml b/src/main/resources/camel/odoo-authentication.xml deleted file mode 100644 index 0cebca6f..00000000 --- a/src/main/resources/camel/odoo-authentication.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - #{new org.apache.xmlrpc.client.XmlRpcClientConfigImpl()} - - - #{new org.apache.xmlrpc.client.XmlRpcClient()} - - - - #{new java.util.ArrayList(4)} - - - - - #{getProperty('xmlrpc-client').execute(getProperty('xmlrpc-client-config'), 'authenticate', getProperty('auth-params'))} - - - - - ${body} == false - - - - - - - - - diff --git a/src/main/resources/camel/odoo-cancel-quotations.xml b/src/main/resources/camel/odoo-cancel-quotations.xml deleted file mode 100644 index 346ad8d9..00000000 --- a/src/main/resources/camel/odoo-cancel-quotations.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - #{new java.util.ArrayList(2)} - - - - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('callParams'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-get-country.xml b/src/main/resources/camel/odoo-get-country.xml deleted file mode 100644 index 06fca6d3..00000000 --- a/src/main/resources/camel/odoo-get-country.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - #{new Object[]{new Object[]{new Object[]{'name', '=', getProperty('countryName')}}}} - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('getCountryParams'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-get-customer.xml b/src/main/resources/camel/odoo-get-customer.xml deleted file mode 100644 index 04d013ae..00000000 --- a/src/main/resources/camel/odoo-get-customer.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - #{new Object[]{new Object[]{new Object[]{'ref', '=', getProperty('patient').uuid}}}} - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('getQuotationParams'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-get-draft-quotations.xml b/src/main/resources/camel/odoo-get-draft-quotations.xml deleted file mode 100644 index d0458cd5..00000000 --- a/src/main/resources/camel/odoo-get-draft-quotations.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - #{new Object[]{'partner_id', '=', getProperty('patient-odoo-id')}} - - - #{new Object[]{'state', '=', 'draft'}} - - - #{new Object[]{new Object[]{getProperty('partner-id-criterion'), getProperty('state-criterion')}}} - - - #{T(java.util.Collections).singletonMap('fields', new Object[]{'id', 'order_line'})} - - - #{new java.util.ArrayList(7)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('get-quotation-params'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-get-external-id-map.xml b/src/main/resources/camel/odoo-get-external-id-map.xml deleted file mode 100644 index b8007c47..00000000 --- a/src/main/resources/camel/odoo-get-external-id-map.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - #{new Object[]{'model', '=', getProperty('modelName')}} - - - #{new Object[]{'name', '=', getProperty('externalId')}} - - - #{new Object[]{new Object[]{getProperty('modelCriterion'), getProperty('extIdCriterion')}}} - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('getUnitsParams'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-get-order-line.xml b/src/main/resources/camel/odoo-get-order-line.xml deleted file mode 100644 index d607b586..00000000 --- a/src/main/resources/camel/odoo-get-order-line.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - #{new Object[]{'order_id', '=', getProperty('quotation-id')}} - - - #{new Object[]{'product_id', '=', getProperty('odooProductId')}} - - - #{new Object[]{new Object[]{getProperty('quotation-criterion'), getProperty('product-criterion')}}} - - - #{T(java.util.Collections).singletonMap('fields', new Object[]{'id', 'product_uom_qty', 'product_uom'})} - - - #{new java.util.ArrayList(7)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('get-order-lines-params'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-get-quotations.xml b/src/main/resources/camel/odoo-get-quotations.xml deleted file mode 100644 index e6462d08..00000000 --- a/src/main/resources/camel/odoo-get-quotations.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - #{new Object[]{'partner_id', '=', getProperty('patient-odoo-id')}} - - - #{new Object[]{new Object[]{getProperty('partnerIdCriterion')}}} - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('getQuotationParams'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-get-state.xml b/src/main/resources/camel/odoo-get-state.xml deleted file mode 100644 index 82589a60..00000000 --- a/src/main/resources/camel/odoo-get-state.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - #{new Object[]{new Object[]{new Object[]{'name', '=', getProperty('stateName')}}}} - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('getStateParams'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-integration-event-listener.xml b/src/main/resources/camel/odoo-integration-event-listener.xml deleted file mode 100644 index 5fb5c935..00000000 --- a/src/main/resources/camel/odoo-integration-event-listener.xml +++ /dev/null @@ -1,194 +0,0 @@ - - - - - - - - - #{new java.util.HashMap(6)} - - - - - - {{odoo.custom.table.resource.mappings}} - - - - - - - ${exchangeProperty.event.snapshot} == false && ${exchangeProperty.tables-resource-map.containsKey(${exchangeProperty.event.tableName})} == true - - - - #{getProperty('event').tableName == 'person_name' || getProperty('event').tableName == 'person_address' || getProperty('event').tableName == 'patient_identifier'} - - - - - ${exchangeProperty.isSubResource} == true - - - - - ${exchangeProperty.event.tableName} == 'patient_identifier' - - patient - - - patient_id - - - - - person - - - person_id - - - - - - - - - - ${body[0].get('uuid')} - - - #{getProperty("tables-resource-map").get(getProperty('event').tableName)} - - - ${exchangeProperty.event.identifier} - - - - - #{getProperty("tables-resource-map").get(getProperty('event').tableName)} - - - ${exchangeProperty.event.identifier} - - - - - - - - - - - - - ${body} != null - - $ - - - - - - ${routeId}-xmlRpcClient - - - ${routeId}-xmlRpcConfig - - - ${routeId}-odooUserId - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('odooUserIdKey')) == null} - - - - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')) == null} - - - - - - - ${exchangeProperty.event.tableName} != 'patient' && ${exchangeProperty.event.tableName} != 'person_name' && ${exchangeProperty.event.tableName} != 'person_address' && ${exchangeProperty.event.tableName} != 'patient_identifier' - - - - - - ${exchangeProperty.event.tableName} == 'patient' - - ${exchangeProperty.entity-instance} - - - - - - - - ${exchangeProperty.isSubResource} == true - - - ${exchangeProperty.event.tableName} == 'person_name' - - Person Name - - - - ${exchangeProperty.event.tableName} == 'person_address' - - Person Address - - - - - Patient Identifier - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-manage-customer.xml b/src/main/resources/camel/odoo-manage-customer.xml deleted file mode 100644 index f09e6738..00000000 --- a/src/main/resources/camel/odoo-manage-customer.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - - #{new org.apache.xmlrpc.client.XmlRpcClientConfigImpl()} - - - - - #{new java.util.ArrayList(2)} - - - #{new java.util.HashMap()} - - - - ${exchangeProperty.odoo-operation} == 'write' - - - - - - ${exchangeProperty.isPatientVoidedOrDeleted} != true - - - - ${properties:odoo.emr.id.field:null} - - - - ${exchangeProperty.emrIdField} != null && ${exchangeProperty.emrIdField.trim()} != '' - - - - - ${properties:odoo.enable.extra.customer.details.route:null} != null && ${properties:odoo.enable.extra.customer.details.route:false} == true - - - - - - ${exchangeProperty.personAddress} != null - - - - - - - - - - - - - - - - #{new java.util.ArrayList()} - - - - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(getProperty('xmlrpc-client-config'), 'execute_kw', getProperty('createParams'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-manage-order-line.xml b/src/main/resources/camel/odoo-manage-order-line.xml deleted file mode 100644 index 08c08d93..00000000 --- a/src/main/resources/camel/odoo-manage-order-line.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - - - - #{new java.util.ArrayList(2)} - - - - - ${exchangeProperty.odoo-operation} == 'unlink' - - - - - #{new java.util.HashMap(3)} - - - - - - ${properties:odoo.enable.extra.quotation.details.route:null} != null && ${properties:odoo.enable.extra.quotation.details.route:false} == true - - - - - ${exchangeProperty.odoo-operation} == 'create' - - - - - ${exchangeProperty.odoo-operation} == 'write' - - - - - ${exchangeProperty.order-quantity} != null - - - - - ${exchangeProperty.unitsId} != null - - - - - ${exchangeProperty.description} != null - - - - - - - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('call-params'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-manage-quotation.xml b/src/main/resources/camel/odoo-manage-quotation.xml deleted file mode 100644 index e163921b..00000000 --- a/src/main/resources/camel/odoo-manage-quotation.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - #{new java.util.ArrayList(2)} - - - - ${exchangeProperty.odoo-operation} == 'create' - - #{T(java.util.Collections).singletonMap('partner_id', getProperty('patient-odoo-id'))} - - - - - ${exchangeProperty.odoo-operation} == 'write' - - - #{T(java.util.Collections).singletonMap('state', 'cancel')} - - - - - - - #{new java.util.ArrayList(6)} - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('callParams'))} - - - - - - - diff --git a/src/main/resources/camel/odoo-order-handler.xml b/src/main/resources/camel/odoo-order-handler.xml deleted file mode 100644 index ad6faeb5..00000000 --- a/src/main/resources/camel/odoo-order-handler.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - ${exchangeProperty.event.operation} == 'c' && ${exchangeProperty.event.tableName} == 'orders' || ${exchangeProperty.entity-instance.get('voided')} == true - - ${exchangeProperty.entity-instance.get('action')} - - - - - ${exchangeProperty.orderAction} == 'NEW' || ${exchangeProperty.orderAction} == 'REVISE' || ${exchangeProperty.orderAction} == 'DISCONTINUE' - - ${exchangeProperty.entity-instance.get('type')} == 'drugorder' - - true - - - - - ${exchangeProperty.entity-instance.get('voided')} != true - - #{getProperty('entity-instance').get('action') == 'NEW' || getProperty('entity-instance').get('action') == 'RENEW'} - - - - - product.product - - - ${exchangeProperty.entity-instance.get('concept').get('uuid')} - - - - ${exchangeProperty.is-drug-order} == true - - ${exchangeProperty.entity-instance.get('drug').get('uuid')} - - - - - - - ${body.length} == 0 - - - - - ${body.length} > 1 - - - - - ${body[0].get('res_id')} - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-patient-association-handler.xml b/src/main/resources/camel/odoo-patient-association-handler.xml deleted file mode 100644 index 88fbf3ae..00000000 --- a/src/main/resources/camel/odoo-patient-association-handler.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - ${exchangeProperty.event.tableName} == 'patient_identifier' - - patient_id - - - - - person_id - - - - - - - - - ${body[0].get('uuid')} - - - - - - false - - - patient - - - - - - - ${body} != null - - $ - - - - - - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-patient-handler.xml b/src/main/resources/camel/odoo-patient-handler.xml deleted file mode 100644 index 9cb302d3..00000000 --- a/src/main/resources/camel/odoo-patient-handler.xml +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - - - - - - - - ${body.length} > 1 - - - - - ${body.length} == 1 - - ${body[0]} - - - - - - ${exchangeProperty.patient-odoo-id} == null && ${exchangeProperty.patient.get('voided')} == true - - - - - #{getProperty('patient-odoo-id') != null && getProperty('skipCustomerUpdate') != true} - - - - - ${exchangeProperty.updateExistingCustomer} == true || ${exchangeProperty.createCustomerIfNotExist} == true || ${properties:create.customer.if.not.exist:false} == true - - - #{getProperty('patient').get('voided') == true} - - - - ${exchangeProperty.isPatientVoidedOrDeleted} != true - - false - - - patient - - - ${exchangeProperty.patient.get('uuid')} - - - ${exchangeProperty.patient.get('person')} - - - ${exchangeProperty.person.get('display')} - - - ${exchangeProperty.person.get('preferredAddress')} - - - - ${routeId}-idTypeId - - - - - - - - ${exchangeProperty.idTypeId} == null - - - - - - - ${body.size()} == 0 - - - - - ${body[0].get("patient_identifier_type_id")} - - - - - - - - ${body[0].get("identifier")} - - - - - ${exchangeProperty.preferredAddress} != null - - - - - - - - - - #{new java.util.HashMap()} - - - - ${properties:custom.customer.data.callback.endpoint:null} - - - - - ${exchangeProperty.customDataCallback} != 'null' - - - - - - - - - - - ${exchangeProperty.patient-odoo-id} == null - - - create - - - - - - - - ${body} - - - - - - ${exchangeProperty.skipCustomerUpdate} != true - - - ${exchangeProperty.isPatientVoidedOrDeleted} == true - - - - - ${body.length} > 0 - - ${body} - - - - - - - - - - - - - - - - write - - - - - - - - - - ${exchangeProperty.patient-odoo-id} == null - - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-process-dc-or-voided-order.xml b/src/main/resources/camel/odoo-process-dc-or-voided-order.xml deleted file mode 100644 index 52938fff..00000000 --- a/src/main/resources/camel/odoo-process-dc-or-voided-order.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - unlink - - - - ${exchangeProperty.order-line} != null - - - - - - - - ${exchangeProperty.order-line-count} < 2 - - - - write - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-process-new-order.xml b/src/main/resources/camel/odoo-process-new-order.xml deleted file mode 100644 index 9a51852a..00000000 --- a/src/main/resources/camel/odoo-process-new-order.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - ${exchangeProperty.order-line} != null && ${exchangeProperty.event.tableName} == 'orders' - - - - - - - ${exchangeProperty.event.tableName} == 'orders' - - create - - - - - - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-process-order.xml b/src/main/resources/camel/odoo-process-order.xml deleted file mode 100644 index 485438e5..00000000 --- a/src/main/resources/camel/odoo-process-order.xml +++ /dev/null @@ -1,253 +0,0 @@ - - - - - - - - - false - - - patient - - - ${exchangeProperty.entity-instance.get('patient').get('uuid')} - - - - - - - - - $ - - - - - - #{getProperty('is-new') == true || getProperty('entity-instance').get('action') == 'REVISE'} - - - true - - - - - - #{getProperty('entity-instance').get('voided') == true || getProperty('entity-instance').get('action') == 'DISCONTINUE'} - - - - - ${exchangeProperty.isDcOrVoidedOrder} == true && ${exchangeProperty.patient-odoo-id} == null - - - - - - - - - - - ${body.length} > 1 - - - - ${body.length} == 0 - - ${exchangeProperty.is-new} == true || ${exchangeProperty.entity-instance.get('action')} == 'REVISE' - - create - - - - - - - - ${body} - - - #{T(java.lang.Integer).valueOf(0)} - - - - - - - #{T(java.lang.Integer).valueOf(body[0].get('id'))} - - - #{T(java.lang.Integer).valueOf(body[0].get('order_line').length)} - - - - - - ${exchangeProperty.order-line-count} > 0 - - - - - ${body.length} > 1 - - - - ${body.length} == 1 - - - - ${body[0]} - - - - - - - ${exchangeProperty.order-line} == null - - - - - - - - ${exchangeProperty.is-new} == true || ${exchangeProperty.entity-instance.get('action')} == 'REVISE' - - - ${properties:orderline.description-seperator: | } - - - - ${exchangeProperty.is-drug-order} == true - - - ${exchangeProperty.entity-instance.get('quantity')} - - - ${exchangeProperty.entity-instance.get('drug').get('display')} - - - - ${exchangeProperty.order-quantity} != null - - ${exchangeProperty.description}${exchangeProperty.seperator}${exchangeProperty.order-quantity} ${exchangeProperty.entity-instance.get('quantityUnits').get('display')} - - - uom.uom - - - ${exchangeProperty.entity-instance.get('quantityUnits').get('uuid')} - - - - - - ${body.length} == 0 - - - - - ${body.length} > 1 - - - - - ${body[0].get('res_id')} - - - - - - - ${exchangeProperty.entity-instance.get('dose')} != null - - ${exchangeProperty.description}${exchangeProperty.seperator}${exchangeProperty.entity-instance.get('dose')} ${exchangeProperty.entity-instance.get('doseUnits').get('display')} - - - #{' - '} - - - - - ${exchangeProperty.entity-instance.get('frequency')} != null - - ${exchangeProperty.description}${exchangeProperty.seperator}${exchangeProperty.entity-instance.get('frequency').get('display')} - - - #{' - '} - - - - - ${exchangeProperty.entity-instance.get('duration')} != null - - ${exchangeProperty.description}${exchangeProperty.seperator}${exchangeProperty.entity-instance.get('duration')} ${exchangeProperty.entity-instance.get('durationUnits').get('display')} - - - #{' - '} - - - - - ${exchangeProperty.entity-instance.get('dosingInstructions')} != null - - ${exchangeProperty.description}${exchangeProperty.seperator}${exchangeProperty.entity-instance.get('dosingInstructions')} - - - #{' - '} - - - - - - - ${properties:orderline.description-seperator: | } - - - - ${exchangeProperty.entity-instance.get('type')} == 'testorder' || ${exchangeProperty.entity-instance.get('type')} == 'order' - - ${exchangeProperty.entity-instance.get('display')} - - - - - ${exchangeProperty.entity-instance.get('commentToFulfiller')} != null - - ${exchangeProperty.description}${exchangeProperty.seperator}Notes: ${exchangeProperty.entity-instance.get('commentToFulfiller')} - - - - - ${exchangeProperty.entity-instance.get('orderer')} != null - - ${exchangeProperty.description}${exchangeProperty.seperator}Orderer: ${exchangeProperty.entity-instance.get('orderer').get('display').split(' - ')[1]} - - - - - - ${exchangeProperty.is-new} == true - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-process-person-address.xml b/src/main/resources/camel/odoo-process-person-address.xml deleted file mode 100644 index 47598e41..00000000 --- a/src/main/resources/camel/odoo-process-person-address.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - true - - - person - - - ${exchangeProperty.patient.get('uuid')} - - - address - - - ${exchangeProperty.preferredAddress.get('uuid')} - - - - - - - - - $ - - - - - - ${exchangeProperty.personAddress.get('stateProvince')} != null - - ${exchangeProperty.personAddress.get('stateProvince')} - - - - - - - - ${body.length} > 1 - - - - - - ${body.length} == 0 - - - - - ${body[0]} - - - - - - - - ${exchangeProperty.personAddress.get('country')} != null - - ${exchangeProperty.personAddress.get('country')} - - - - - - - - ${body.length} > 1 - - - - - - ${body.length} == 0 - - - - - ${body[0]} - - - - - - - - - - - diff --git a/src/main/resources/camel/odoo-process-revision-order.xml b/src/main/resources/camel/odoo-process-revision-order.xml deleted file mode 100644 index f21b3a60..00000000 --- a/src/main/resources/camel/odoo-process-revision-order.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - ${exchangeProperty.order-line} == null - - create - - - - - - - - - - ${exchangeProperty.is-drug-order} == true - - write - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/camel/patient-uuid-to-odoo-customer.xml b/src/main/resources/camel/patient-uuid-to-odoo-customer.xml deleted file mode 100644 index cbfe35ef..00000000 --- a/src/main/resources/camel/patient-uuid-to-odoo-customer.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - false - - - patient - - - ${body} - - - - - - - ${body} != null - - $ - - - - - - true - - - - - - - - - - - - diff --git a/src/main/resources/camel/save-calendar-event-in-odoo.xml b/src/main/resources/camel/save-calendar-event-in-odoo.xml deleted file mode 100644 index 4d77ef60..00000000 --- a/src/main/resources/camel/save-calendar-event-in-odoo.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - #{new java.util.HashMap()} - - - #{new java.util.ArrayList(3)} - - - - - - - - #{new java.util.ArrayList(6)} - - - - - - - #{T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcClientKey')).execute(T(org.openmrs.eip.AppContext).get(getProperty('xmlRpcConfigKey')), 'execute_kw', getProperty('rpcArgs'))} - - - - - - - diff --git a/src/main/resources/eip-odoo-openmrs.properties b/src/main/resources/eip-odoo-openmrs.properties deleted file mode 100644 index 2ebbb7a6..00000000 --- a/src/main/resources/eip-odoo-openmrs.properties +++ /dev/null @@ -1,90 +0,0 @@ -# *********************** OAuth2 Configuration ******************************************************************** -# Enabled Oauth when set to true, defaults to false. -oauth.enabled=${OAUTH_ENABLED:false} - -# The client Id of the account, defaults to empty. -oauth.access.token.uri=${OAUTH_ACCESS_TOKEN_URL:} - -# The client Id of the account to use to authenticate, defaults to empty. -oauth.client.id=${OAUTH_CLIENT_ID:} - -# The client secret of the account to use to authenticate, defaults to empty. -oauth.client.secret=${OAUTH_CLIENT_SECRET:} - -# Authentication scope, can be multiple values separated by commas, defaults to empty. -oauth.client.scope=${OAUTH_CLIENT_SCOPE:} -# ---------------------------------------------------------------------------------------------------------------------- - -# *********************** Odoo configuration ************************************************************************** -# -# The base URL to the Odoo instance -odoo.baseUrl=${ODOO_URL} - -# The database name to use to log into the Odoo instance -odoo.database=${ODOO_DATABASE} - -# The username for the account to use to log into the Odoo instance -odoo.username=${ODOO_USER} - -# The password for the account to use to log into the Odoo instance -odoo.password=${ODOO_PASSWORD} - -# The address type to use for customer addresses in Odoo -odoo.customer.address.type=contact - -odoo.handler.route=odoo-order-handler - -# Custom table to OpenMRS REST resource name mappings -odoo.custom.table.resource.mappings=orders:order,test_order:order,drug_order:order - -# Custom property for the res.partner model in odoo -odoo.emr.id.field=${ODOO_CUSTOMER_EXTERNAL_ID} - -# Custom property for the res.partner model in odoo to capture customer's date of birth -odoo.dob.field=${ODOO_CUSTOMER_DOB_FIELD} - -# Custom property for the res.partner model in odoo to capture customer's weight -odoo.weight.field=${ODOO_CUSTOMER_WEIGHT_FIELD} - -# Used to turn on or off the route that allows to sync extra patient details like weight and/or date of birth -odoo.enable.extra.customer.details.route=${ODOO_ENABLE_EXTRA_CUSTOMER_FIELDS_ROUTE} - -# Used to turn on or off the route that allows to sync extra patient details like weight as part of the customer quotation -odoo.enable.extra.quotation.details.route=${ODOO_ENABLE_EXTRA_QUOTATION_FIELDS_ROUTE} - -# Camel route to be invoked via the direct component via the direct component to process obs events to manage resources -# in odoo -obs.to.odoo.resource.handler.route=obs-to-customer - -# Comma-separated list of Obs question and answer mappings, note that you can provider multiple answers separated by a -# charet(^) character, questions and answers are separated by a colon e.g. obs-qn-1:obs-ans-a^obs-ans-b:obs-qn-2,true -odoo.obs.concept.question.answer.mappings= - -# Camel endpoint to be called when processing an obs event to decide if the associated patient should be added to odoo -# or not -obs.to.customer.decision.rule.endpoint= -# ---------------------------------------------------------------------------------------------------------------------- - -# *********************** Configuration of the OpenMRS Web App ********************************************************* -# -# OpenMRS user credentials -openmrs.username=${OPENMRS_USER} - -openmrs.password=${OPENMRS_PASSWORD} - -# OpenMRS base url -openmrs.baseUrl=${OPENMRS_URL} - -# The results encounter type for all patient result observations -results.encounterType.uuid=${OPENMRS_RESULTS_ENCOUNTER_TYPE_UUID} - -concept.complex.uuid=${OPENMRS_CONCEPT_COMPLEX_UUID} - -openmrs.identifier.type.uuid=${OPENMRS_IDENTIFIER_TYPE_UUD} - -# true/false flag to indicate whether to create a new customer in Odoo if it does not exist -create.customer.if.not.exist=${CREATE_CUSTOMER_IF_NOT_EXIST} - -# UUID for concept that is used to record a patient's weight. It is usually 5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -emr.weight.concept=${EMR_WEIGHT_CONCEPT} -# ---------------------------------------------------------------------------------------------------------------------- diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOdooApiRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOdooApiRouteTest.java deleted file mode 100644 index 0d709377..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOdooApiRouteTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import org.apache.camel.Exchange; -import org.apache.camel.support.DefaultExchange; -import org.apache.xmlrpc.client.XmlRpcClient; -import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.mockito.Mock; -import org.openmrs.eip.AppContext; -import org.openmrs.eip.mysql.watcher.route.BaseWatcherRouteTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; - -@ActiveProfiles("test") -@Import({TestConfig.class}) -@TestPropertySource(properties = "odoo.database=" + BaseOdooApiRouteTest.APP_PROP_ODOO_DB) -@TestPropertySource(properties = "odoo.password=" + BaseOdooApiRouteTest.APP_PROP_ODOO_PASS) -public abstract class BaseOdooApiRouteTest extends BaseWatcherRouteTest { - - private static final String ODOO_USER_ID_KEY = "routeId-odooUserId"; - - private static final String RPC_CLIENT_KEY = "routeId-xmlRpcClient"; - - private static final String RPC_CFG_KEY = "routeId-xmlRpcConfig"; - - protected static final String APP_PROP_ODOO_DB = "odoo-db"; - - protected static final String APP_PROP_ODOO_PASS = "odoo-pass"; - - protected static final Integer USER_ID = 5; - - @Mock - protected XmlRpcClient mockXmlRpcClient; - - @Mock - protected XmlRpcClientConfigImpl mockXmlRpcClientConfig; - - @BeforeEach - public void beforeBaseOdooApiRouteTestMethod() { - AppContext.add(ODOO_USER_ID_KEY, USER_ID); - AppContext.add(RPC_CLIENT_KEY, mockXmlRpcClient); - AppContext.add(RPC_CFG_KEY, mockXmlRpcClientConfig); - } - - @AfterEach - public void afterBaseOdooApiRouteTestMethod() { - AppContext.remove(ODOO_USER_ID_KEY); - AppContext.remove(RPC_CLIENT_KEY); - AppContext.remove(RPC_CFG_KEY); - } - - protected Exchange buildExchange() { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ODOO_USER_ID_KEY, ODOO_USER_ID_KEY); - exchange.setProperty(OdooTestConstants.EX_PROP_RPC_CLIENT_KEY, RPC_CLIENT_KEY); - exchange.setProperty(OdooTestConstants.EX_PROP_RPC_CFG_KEY, RPC_CFG_KEY); - return exchange; - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOdooRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOdooRouteTest.java deleted file mode 100644 index 7c4235fe..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOdooRouteTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.camel.Exchange; -import org.junit.jupiter.api.BeforeEach; -import org.openmrs.eip.AppContext; -import org.openmrs.eip.Constants; -import org.openmrs.eip.EIPException; -import org.openmrs.eip.mysql.watcher.route.BaseWatcherRouteTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.jdbc.SqlConfig; - -@ActiveProfiles("test") -@Import({TestConfig.class}) -@TestPropertySource(properties = {"camel.springboot.routes-collector-enabled=false"}) -@Sql( - value = {"classpath:sql/test_data.sql"}, - config = - @SqlConfig(dataSource = Constants.OPENMRS_DATASOURCE_NAME, transactionManager = "openmrsTestTxManager")) -// @DirtiesContext tells the testing framework to close and recreate the context for later tests. -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public abstract class BaseOdooRouteTest extends BaseWatcherRouteTest { - - protected final ObjectMapper mapper = new ObjectMapper(); - - static { - container.executeLiquibase("liquibase/liquibase-openmrs.xml"); - } - - @Override - protected String getErrorMessage(Exchange e) { - return e.getProperty("error", EIPException.class).getMessage(); - } - - @BeforeEach - public void setupBaseOdooRouteTest() { - AppContext.remove(OdooTestConstants.ODOO_USER_ID_KEY); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOrderOdooRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOrderOdooRouteTest.java deleted file mode 100644 index a7801a72..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/BaseOrderOdooRouteTest.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import org.springframework.test.context.TestPropertySource; - -@TestPropertySource( - properties = - "eip.watchedTables=patient,person_name,person_address,patient_identifier,orders,test_order,drug_order") -@TestPropertySource(properties = "odoo.handler.route=odoo-order-handler") -@TestPropertySource(properties = "odoo.custom.table.resource.mappings=orders:order,test_order:order,drug_order:order") -public abstract class BaseOrderOdooRouteTest extends BaseOdooRouteTest {} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ConceptToOrderLineProcessorRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/ConceptToOrderLineProcessorRouteTest.java deleted file mode 100644 index 8427cc7d..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ConceptToOrderLineProcessorRouteTest.java +++ /dev/null @@ -1,250 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.HashMap; -import java.util.Map; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class ConceptToOrderLineProcessorRouteTest extends BaseOdooRouteTest { - - protected static final String ROUTE_ID = "concept-to-order-line-processor"; - - protected static final String CONCEPT_UUID = "concept-uuid"; - - @EndpointInject("mock:odoo-get-external-id-map") - private MockEndpoint mockExtIdMapEndpoint; - - @EndpointInject("mock:odoo-get-draft-quotations") - private MockEndpoint mockGetDraftQuotesEndpoint; - - @EndpointInject("mock:odoo-manage-quotation") - private MockEndpoint mockManageQuoteEndpoint; - - @EndpointInject("mock:odoo-get-order-line") - private MockEndpoint mockGetOrderLineEndpoint; - - @BeforeEach - public void setup() throws Exception { - mockExtIdMapEndpoint.reset(); - mockGetDraftQuotesEndpoint.reset(); - mockGetOrderLineEndpoint.reset(); - mockManageQuoteEndpoint.reset(); - - loadXmlRoutesInCamelDirectory("concept-to-order-line-processor.xml"); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_GET_EXT_ID) - .skipSendToOriginalEndpoint() - .to(mockExtIdMapEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_GET_QUOTES) - .skipSendToOriginalEndpoint() - .to(mockGetDraftQuotesEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_MANAGE_QUOTE) - .skipSendToOriginalEndpoint() - .to(mockManageQuoteEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_GET_LINE) - .skipSendToOriginalEndpoint() - .to(mockGetOrderLineEndpoint); - } - }); - - mockExtIdMapEndpoint.expectedMessageCount(1); - mockExtIdMapEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_MODEL_NAME, OdooTestConstants.ODOO_RES_PRODUCT); - mockExtIdMapEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_EXTERNAL_ID, CONCEPT_UUID); - } - - @AfterEach - public void tearDown() throws Exception { - mockExtIdMapEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldFailIfThereIsNoMatchingProductFoundInOdoo() { - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_LINE_CONCEPT, singletonMap("uuid", CONCEPT_UUID)); - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - producerTemplate.send(OdooTestConstants.URI_CONCEPT_LINE_PROCESSOR, exchange); - - assertEquals("No product found in odoo mapped to uuid: " + CONCEPT_UUID, getErrorMessage(exchange)); - } - - @Test - public void shouldFailIfMultipleProductsAreFoundInOdooMappedToTheConcept() { - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_LINE_CONCEPT, singletonMap("uuid", CONCEPT_UUID)); - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {emptyMap(), emptyMap()})); - - producerTemplate.send(OdooTestConstants.URI_CONCEPT_LINE_PROCESSOR, exchange); - - assertEquals("Found 2 products in odoo mapped to uuid: " + CONCEPT_UUID, getErrorMessage(exchange)); - } - - @Test - public void shouldFailIfThereAreMultipleQuotesForThePatient() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_LINE_CONCEPT, singletonMap("uuid", CONCEPT_UUID)); - final Integer expectedProductId = 6; - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_PRODUCT_ID, expectedProductId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {emptyMap(), emptyMap()})); - - producerTemplate.send(OdooTestConstants.URI_CONCEPT_LINE_PROCESSOR, exchange); - - mockGetDraftQuotesEndpoint.assertIsSatisfied(); - assertEquals("Found 2 existing draft quotation(s) for the same patient in odoo", getErrorMessage(exchange)); - } - - @Test - public void shouldCreateANewQuoteIfNoneExistsAndCreateQuoteIfNotExistIsSetToTrue() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_LINE_CONCEPT, singletonMap("uuid", CONCEPT_UUID)); - exchange.setProperty(OdooTestConstants.EX_PROP_CREATE_QUOTE_IF_NOT_EXIST, true); - final Integer expectedProductId = 6; - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_PRODUCT_ID, expectedProductId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - producerTemplate.send(OdooTestConstants.URI_CONCEPT_LINE_PROCESSOR, exchange); - - mockGetDraftQuotesEndpoint.assertIsSatisfied(); - mockManageQuoteEndpoint.assertIsSatisfied(); - assertEquals(quoteId, exchange.getProperty(OdooTestConstants.EX_PROP_QUOTE_ID)); - assertEquals(0, exchange.getProperty(OdooTestConstants.EX_PROP_LINE_COUNT)); - } - - @Test - public void shouldNotCreateANewQuoteIfNoneExistsAndCreateQuoteIfNotExistIsNotSetToTrue() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_LINE_CONCEPT, singletonMap("uuid", CONCEPT_UUID)); - final Integer expectedProductId = 6; - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_PRODUCT_ID, expectedProductId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - mockManageQuoteEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_CONCEPT_LINE_PROCESSOR, exchange); - - mockGetDraftQuotesEndpoint.assertIsSatisfied(); - mockManageQuoteEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldFetchTheExistingLineOnTheExistingQuoteForThePatient() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_LINE_CONCEPT, singletonMap("uuid", CONCEPT_UUID)); - final Integer expectedProductId = 6; - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_PRODUCT_ID, expectedProductId); - final Integer quoteId = 7; - Map quote = new HashMap(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - mockManageQuoteEndpoint.expectedMessageCount(0); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - Map orderLine = singletonMap("id", 123); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {orderLine})); - - producerTemplate.send(OdooTestConstants.URI_CONCEPT_LINE_PROCESSOR, exchange); - - mockGetDraftQuotesEndpoint.assertIsSatisfied(); - mockManageQuoteEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(quoteId, exchange.getProperty(OdooTestConstants.EX_PROP_QUOTE_ID)); - assertEquals(orderLine, exchange.getProperty(OdooTestConstants.EX_PROP_ORDER_LINE)); - assertEquals(orderLines.length, exchange.getProperty(OdooTestConstants.EX_PROP_LINE_COUNT)); - } - - @Test - public void shouldFetchTheExistingLineOnTheExistingQuoteForThePatientAndSetNoOrderLineOnTheExchangeIfNoneExists() - throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_LINE_CONCEPT, singletonMap("uuid", CONCEPT_UUID)); - final Integer expectedProductId = 6; - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_PRODUCT_ID, expectedProductId); - final Integer quoteId = 7; - Map quote = new HashMap(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - mockManageQuoteEndpoint.expectedMessageCount(0); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - producerTemplate.send(OdooTestConstants.URI_CONCEPT_LINE_PROCESSOR, exchange); - - mockGetDraftQuotesEndpoint.assertIsSatisfied(); - mockManageQuoteEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(quoteId, exchange.getProperty(OdooTestConstants.EX_PROP_QUOTE_ID)); - assertEquals(orderLines.length, exchange.getProperty(OdooTestConstants.EX_PROP_LINE_COUNT)); - assertNull(exchange.getProperty(OdooTestConstants.EX_PROP_ORDER_LINE)); - } - - @Test - public void shouldFailIfThereAreMultipleLinesOnTheExistingQuoteForThePatient() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_LINE_CONCEPT, singletonMap("uuid", CONCEPT_UUID)); - final Integer expectedProductId = 6; - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_PRODUCT_ID, expectedProductId); - final Integer quoteId = 7; - Map quote = new HashMap(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - mockManageQuoteEndpoint.expectedMessageCount(0); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {emptyMap(), emptyMap()})); - - producerTemplate.send(OdooTestConstants.URI_CONCEPT_LINE_PROCESSOR, exchange); - - mockGetDraftQuotesEndpoint.assertIsSatisfied(); - mockManageQuoteEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(quoteId, exchange.getProperty(OdooTestConstants.EX_PROP_QUOTE_ID)); - assertEquals(orderLines.length, exchange.getProperty(OdooTestConstants.EX_PROP_LINE_COUNT)); - assertEquals( - "Found 2 items for the same product added to the draft quotation in odoo", getErrorMessage(exchange)); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ConvertToConceptUuidIfIsMappingRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/ConvertToConceptUuidIfIsMappingRouteTest.java deleted file mode 100644 index 0b832407..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ConvertToConceptUuidIfIsMappingRouteTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.openmrs.eip.Constants.EX_PROP_CONCEPT_CODE; -import static org.openmrs.eip.Constants.EX_PROP_CONCEPT_SOURCE; - -import java.util.Collections; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class ConvertToConceptUuidIfIsMappingRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "convert-to-concept-uuid-if-is-mapping"; - - @EndpointInject("mock:get-concept-by-mapping-from-openmrs") - private MockEndpoint mockGetConceptByMapEndpoint; - - @BeforeEach - public void setup() throws Exception { - - loadXmlRoutesInCamelDirectory(ROUTE_ID + ".xml"); - - mockGetConceptByMapEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_GET_CONCEPT_BY_MAPPING) - .skipSendToOriginalEndpoint() - .to(mockGetConceptByMapEndpoint); - } - }); - } - - @Test - public void shouldConvertAConceptMappingToAUuid() throws Exception { - final String source = "test-source"; - final String code = "test-code"; - final String expectedConceptUuid = "test-uuid"; - final Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(source + ":" + code); - mockGetConceptByMapEndpoint.expectedMessageCount(1); - mockGetConceptByMapEndpoint.expectedPropertyReceived(EX_PROP_CONCEPT_SOURCE, source); - mockGetConceptByMapEndpoint.expectedPropertyReceived(EX_PROP_CONCEPT_CODE, code); - mockGetConceptByMapEndpoint.whenAnyExchangeReceived(e -> { - e.getIn().setBody(Collections.singletonMap("uuid", expectedConceptUuid)); - }); - - producerTemplate.send(OdooTestConstants.URI_CONVERT_TO_CONCEPT_UUID, exchange); - - mockGetConceptByMapEndpoint.assertIsSatisfied(); - assertEquals(expectedConceptUuid, exchange.getIn().getBody(String.class)); - } - - @Test - public void shouldFailIfNoConceptIsFoundMatchingTheMapping() throws Exception { - final String source = "test-source"; - final String code = "test-code"; - final Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(source + ":" + code); - mockGetConceptByMapEndpoint.expectedMessageCount(1); - mockGetConceptByMapEndpoint.expectedPropertyReceived(EX_PROP_CONCEPT_SOURCE, source); - mockGetConceptByMapEndpoint.expectedPropertyReceived(EX_PROP_CONCEPT_CODE, code); - mockGetConceptByMapEndpoint.whenAnyExchangeReceived(e -> { - e.getIn().setBody(null); - }); - - producerTemplate.send(OdooTestConstants.URI_CONVERT_TO_CONCEPT_UUID, exchange); - - mockGetConceptByMapEndpoint.assertIsSatisfied(); - assertEquals( - "No concept found with mapping matching source: " + source + " and code: " + code, - getErrorMessage(exchange)); - } - - @Test - public void shouldReturnTheOriginalValueForANonValidConceptMapping() throws Exception { - final String testConceptUuid = "test-uuid"; - final Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(testConceptUuid); - mockGetConceptByMapEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_CONVERT_TO_CONCEPT_UUID, exchange); - - mockGetConceptByMapEndpoint.assertIsSatisfied(); - assertEquals(testConceptUuid, exchange.getIn().getBody(String.class)); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetHsuIdRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetHsuIdRouteTest.java deleted file mode 100644 index 55632660..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetHsuIdRouteTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.Collections; -import java.util.HashMap; -import org.apache.camel.Exchange; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.test.context.TestPropertySource; - -@TestPropertySource( - properties = OdooTestConstants.APP_PROP_NAME_ID_TYPE_UUID + "=" + GetHsuIdRouteTest.HSU_ID_TYPE_UUID) -public class GetHsuIdRouteTest extends BaseOdooRouteTest { - - protected static final String HSU_ID_TYPE_UUID = "hsu-id-type-uuid"; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("get-hsu-id.xml"); - } - - @Test - public void shouldReturnNullIfThePatientHasNoIdentifier() { - Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(singletonMap("identifiers", Collections.emptyList())); - - producerTemplate.send(OdooTestConstants.URI_GET_HSU_ID, exchange); - - assertNull(exchange.getIn().getBody()); - assertNull(getException(exchange)); - } - - @Test - public void shouldReturnNullIfNoMatchIsFound() { - Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn() - .setBody(singletonMap( - "identifiers", asList(singletonMap("identifierType", singletonMap("uuid", "other-id-type"))))); - - producerTemplate.send(OdooTestConstants.URI_GET_HSU_ID, exchange); - - assertNull(exchange.getIn().getBody()); - assertNull(getException(exchange)); - } - - @Test - public void shouldReturnTheHSUIdentifier() { - final String expectedHsuId = "hsu id"; - var hsuId = new HashMap<>(); - hsuId.put("identifier", expectedHsuId); - hsuId.put("identifierType", singletonMap("uuid", HSU_ID_TYPE_UUID)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn() - .setBody(singletonMap( - "identifiers", - asList( - singletonMap("identifierType", singletonMap("uuid", "other-id-type")), - hsuId, - singletonMap("identifierType", singletonMap("uuid", "other-id-type"))))); - - producerTemplate.send(OdooTestConstants.URI_GET_HSU_ID, exchange); - - assertEquals(expectedHsuId, exchange.getIn().getBody()); - assertNull(getException(exchange)); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetObsByConceptUuidFromEncounterRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetObsByConceptUuidFromEncounterRouteTest.java deleted file mode 100644 index ddbdf211..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetObsByConceptUuidFromEncounterRouteTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.List; -import org.apache.camel.Exchange; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class GetObsByConceptUuidFromEncounterRouteTest extends BaseOdooRouteTest { - - private static final String URI = "direct:" + OdooTestConstants.ROUTE_ID_GET_CONCEPT_BY_UUID_FROM_ENC; - - public static final String EX_PROP_OBS_QN_CONCEPT_UUID = "questionConceptUuid"; - - public static final String EX_PROP_ENC = "encounter"; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory(OdooTestConstants.ROUTE_ID_GET_CONCEPT_BY_UUID_FROM_ENC + ".xml"); - } - - @Test - public void shouldReturnNullIfTheEncounterHasNoObs() { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_ENC, singletonMap("obs", emptyList())); - - producerTemplate.send(URI, exchange); - - assertNull(exchange.getIn().getBody()); - assertNull(getException(exchange)); - } - - @Test - public void shouldReturnNullIfNoMatchIsFound() { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty( - EX_PROP_ENC, - singletonMap("obs", List.of(singletonMap("concept", singletonMap("uuid", "concept-uuid1"))))); - - producerTemplate.send(URI, exchange); - - assertNull(exchange.getIn().getBody()); - } - - @Test - public void shouldReturnTheConceptWithAMatchingConceptUuid() { - final String conceptUuid = "concept-uuid"; - var expectObs = singletonMap("concept", singletonMap("uuid", conceptUuid)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_OBS_QN_CONCEPT_UUID, conceptUuid); - exchange.setProperty( - EX_PROP_ENC, - singletonMap( - "obs", - asList( - singletonMap("concept", singletonMap("uuid", "concept-uuid1")), - expectObs, - singletonMap("concept", singletonMap("uuid", "concept-uuid2"))))); - - producerTemplate.send(URI, exchange); - - assertEquals(expectObs, exchange.getIn().getBody()); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetObsByQuestionInEncounterRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetObsByQuestionInEncounterRouteTest.java deleted file mode 100644 index 9e3c9721..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetObsByQuestionInEncounterRouteTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.camel.Exchange; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class GetObsByQuestionInEncounterRouteTest extends BaseOdooRouteTest { - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory(OdooTestConstants.ROUTE_ID_GET_CONCEPT_BY_UUID_FROM_ENC + ".xml"); - } - - @Test - public void shouldSetBodyToTheMatchingObsIfTheEncounterHasIt() { - final String qnUuid = "question-concept-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - var expectedObs = singletonMap("concept", singletonMap("uuid", qnUuid)); - var encResource = singletonMap( - "obs", - asList( - singletonMap("concept", singletonMap("uuid", "test-1")), - expectedObs, - singletonMap("concept", singletonMap("uuid", "test-2")))); - exchange.setProperty(OdooTestConstants.EX_PROP_ENC, encResource); - exchange.setProperty(OdooTestConstants.EX_PROP_QN_CONCEPT_UUID, qnUuid); - - producerTemplate.send(OdooTestConstants.URI_GET_CONCEPT_BY_UUID_FROM_ENC, exchange); - - assertEquals(expectedObs, exchange.getIn().getBody()); - } - - @Test - public void shouldSetBodyToTheMatchingObsIfTheEncounterHasItAndIsTheLastInTheList() { - final String qnUuid = "question-concept-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - var expectedObs = singletonMap("concept", singletonMap("uuid", qnUuid)); - var encResource = - singletonMap("obs", asList(singletonMap("concept", singletonMap("uuid", "test-1")), expectedObs)); - exchange.setProperty(OdooTestConstants.EX_PROP_ENC, encResource); - exchange.setProperty(OdooTestConstants.EX_PROP_QN_CONCEPT_UUID, qnUuid); - - producerTemplate.send(OdooTestConstants.URI_GET_CONCEPT_BY_UUID_FROM_ENC, exchange); - - assertEquals(expectedObs, exchange.getIn().getBody()); - } - - @Test - public void shouldSetBodyToNullIfTheEncounterDoesNotHaveIt() { - Exchange exchange = new DefaultExchange(camelContext); - Map encResource = singletonMap("obs", asList(singletonMap("concept", singletonMap("uuid", "test-1")))); - exchange.setProperty(OdooTestConstants.EX_PROP_ENC, encResource); - exchange.setProperty(OdooTestConstants.EX_PROP_QN_CONCEPT_UUID, "question-concept-uuid"); - - producerTemplate.send(OdooTestConstants.URI_GET_CONCEPT_BY_UUID_FROM_ENC, exchange); - - assertNull(exchange.getIn().getBody()); - } - - @Test - public void shouldIgnoredVoidedObs() { - final String qnUuid = "question-concept-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - var expectedObs = new HashMap<>(); - expectedObs.put("concept", singletonMap("uuid", qnUuid)); - expectedObs.put("uuid", qnUuid); - expectedObs.put("voided", true); - var encResource = singletonMap("obs", List.of(expectedObs)); - exchange.setProperty(OdooTestConstants.EX_PROP_ENC, encResource); - exchange.setProperty(OdooTestConstants.EX_PROP_QN_CONCEPT_UUID, qnUuid); - - producerTemplate.send(OdooTestConstants.URI_GET_CONCEPT_BY_UUID_FROM_ENC, exchange); - - assertNull(exchange.getIn().getBody()); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByExtIdFromOdooRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByExtIdFromOdooRouteTest.java deleted file mode 100644 index 3db9b820..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByExtIdFromOdooRouteTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.HashMap; -import java.util.Map; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class GetResourceByExtIdFromOdooRouteTest extends BaseOdooRouteTest { - - public static final String PARAM_EXT_ID = "externalId"; - - @EndpointInject("mock:" + OdooTestConstants.ROUTE_ID_GET_EXT_ID_MAP) - private MockEndpoint mockGetExtIdMapEndpoint; - - @EndpointInject("mock:" + OdooTestConstants.ROUTE_ID_GET_RES_BY_ID_FROM_ODOO) - private MockEndpoint mockGetResByIdEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory(OdooTestConstants.ROUTE_ID_GET_RES_BY_EXT_ID_FROM_ODOO + ".xml"); - - mockGetExtIdMapEndpoint.reset(); - mockGetResByIdEndpoint.reset(); - - advise(OdooTestConstants.ROUTE_ID_GET_RES_BY_EXT_ID_FROM_ODOO, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_GET_EXT_ID) - .skipSendToOriginalEndpoint() - .to(mockGetExtIdMapEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_GET_RES_BY_ID_FROM_ODOO) - .skipSendToOriginalEndpoint() - .to(mockGetResByIdEndpoint); - } - }); - } - - @Test - public void shouldGetTheResourceFromOdooMatchingTheNameAndModel() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - final int resId = 5; - final String extId = "test id"; - final String modelName = "res.test"; - Map params = new HashMap(); - params.put(PARAM_EXT_ID, extId); - params.put(OdooTestConstants.PARAM_MODEL_NAME, modelName); - exchange.getIn().setBody(params); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(PARAM_EXT_ID, extId); - mockGetExtIdMapEndpoint.expectedPropertyReceived(OdooTestConstants.PARAM_MODEL_NAME, modelName); - Map[] expectedExtMaps = new Map[] {singletonMap("res_id", resId)}; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedExtMaps)); - Map getResByIdParams = new HashMap(); - getResByIdParams.put(GetResourceByIdFromOdooRouteTest.PARAM_ID, resId); - getResByIdParams.put(OdooTestConstants.PARAM_MODEL_NAME, modelName); - final String expectedRes = "{test}"; - mockGetResByIdEndpoint.expectedMessageCount(1); - mockGetResByIdEndpoint.expectedBodiesReceived(getResByIdParams); - mockGetResByIdEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedRes)); - - producerTemplate.send(OdooTestConstants.URI_GET_RES_BY_EXT_ID_FROM_ODOO, exchange); - - assertEquals(expectedRes, exchange.getIn().getBody()); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - mockGetResByIdEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldReturnNullIfNoResourceIsFoundMatchingTheExternalId() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - final String extId = "test id"; - final String modelName = "res.test"; - Map params = new HashMap(); - params.put(PARAM_EXT_ID, extId); - params.put(OdooTestConstants.PARAM_MODEL_NAME, modelName); - exchange.getIn().setBody(params); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(PARAM_EXT_ID, extId); - mockGetExtIdMapEndpoint.expectedPropertyReceived(OdooTestConstants.PARAM_MODEL_NAME, modelName); - mockGetExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - mockGetResByIdEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_GET_RES_BY_EXT_ID_FROM_ODOO, exchange); - - assertNull(exchange.getIn().getBody()); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - mockGetResByIdEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldFailIfMultipleResourceAreFoundMatchingTheExternalId() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - final String extId = "test id"; - final String modelName = "res.test"; - Map params = new HashMap(); - params.put(PARAM_EXT_ID, extId); - params.put(OdooTestConstants.PARAM_MODEL_NAME, modelName); - exchange.getIn().setBody(params); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(PARAM_EXT_ID, extId); - mockGetExtIdMapEndpoint.expectedPropertyReceived(OdooTestConstants.PARAM_MODEL_NAME, modelName); - Map[] expectedExtMaps = new Map[] {singletonMap("res_id", 1), singletonMap("res_id", 2)}; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedExtMaps)); - mockGetResByIdEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_GET_RES_BY_EXT_ID_FROM_ODOO, exchange); - - mockGetExtIdMapEndpoint.assertIsSatisfied(); - mockGetResByIdEndpoint.assertIsSatisfied(); - assertEquals( - "Found " + expectedExtMaps.length + " resources(" + modelName + ") in odoo mapped to external id: " - + extId, - getErrorMessage(exchange)); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByIdFromOdooRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByIdFromOdooRouteTest.java deleted file mode 100644 index ac258a23..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByIdFromOdooRouteTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.ODOO_OP_SEARCH_READ; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.ODOO_RPC_METHOD; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.URI_GET_RES_BY_ID_FROM_ODOO; -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import org.apache.camel.Exchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class GetResourceByIdFromOdooRouteTest extends BaseOdooApiRouteTest { - - public static final String MODEL_NAME_GROUPS = "res.groups"; - - public static final String PARAM_ID = "id"; - - public static final String PARAM_MODEL_NAME = "modelName"; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("get-resource-by-id-from-odoo.xml"); - } - - @Test - public void shouldGetTheResourceFromOdooMatchingTheNameAndModel() throws Exception { - Exchange exchange = buildExchange(); - final int groupId = 3; - var params = new HashMap<>(); - params.put(PARAM_ID, groupId); - params.put(PARAM_MODEL_NAME, MODEL_NAME_GROUPS); - exchange.getIn().setBody(params); - final var rpcArgs = new ArrayList<>(); - rpcArgs.add(APP_PROP_ODOO_DB); - rpcArgs.add(USER_ID); - rpcArgs.add(APP_PROP_ODOO_PASS); - rpcArgs.add(MODEL_NAME_GROUPS); - rpcArgs.add(ODOO_OP_SEARCH_READ); - rpcArgs.add(singletonList(singletonList(asList("id", "=", groupId)))); - final Object expectedItem = "test"; - when(mockXmlRpcClient.execute(mockXmlRpcClientConfig, ODOO_RPC_METHOD, rpcArgs)) - .thenReturn(new Object[] {expectedItem}); - - producerTemplate.send(URI_GET_RES_BY_ID_FROM_ODOO, exchange); - - assertEquals(expectedItem, exchange.getIn().getBody()); - } - - @Test - public void shouldSetTheBodyToNullIfNoMatchIsFound() throws Exception { - Exchange exchange = buildExchange(); - final int groupId = 3; - var params = new HashMap<>(); - params.put(PARAM_ID, groupId); - params.put(PARAM_MODEL_NAME, MODEL_NAME_GROUPS); - exchange.getIn().setBody(params); - final var rpcArgs = new ArrayList<>(); - rpcArgs.add(APP_PROP_ODOO_DB); - rpcArgs.add(USER_ID); - rpcArgs.add(APP_PROP_ODOO_PASS); - rpcArgs.add(MODEL_NAME_GROUPS); - rpcArgs.add(ODOO_OP_SEARCH_READ); - rpcArgs.add(singletonList(singletonList(asList("id", "=", groupId)))); - when(mockXmlRpcClient.execute(mockXmlRpcClientConfig, ODOO_RPC_METHOD, rpcArgs)) - .thenReturn(new Object[] {}); - - producerTemplate.send(URI_GET_RES_BY_ID_FROM_ODOO, exchange); - - assertNull(exchange.getIn().getBody()); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByNameFromOdooRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByNameFromOdooRouteTest.java deleted file mode 100644 index 183d79cd..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/GetResourceByNameFromOdooRouteTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.ArrayList; -import org.apache.camel.Exchange; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class GetResourceByNameFromOdooRouteTest extends BaseOdooApiRouteTest { - - public static final String EX_PROP_NAME = "name"; - - public static final String EX_PROP_MODEL_NAME = "modelName"; - - private static final String ODOO_USER_ID_KEY = "routeId-odooUserId"; - - private static final String RPC_CLIENT_KEY = "routeId-xmlRpcClient"; - - private static final String RPC_CFG_KEY = "routeId-xmlRpcConfig"; - - protected static final String APP_PROP_ODOO_DB = "odoo-db"; - - protected static final String APP_PROP_ODOO_PASS = "odoo-pass"; - - protected static final Integer USER_ID = 5; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("get-resource-by-name-from-odoo.xml"); - } - - @Test - public void shouldGetTheResourceFromOdooMatchingTheNameAndModel() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - final String groupName = "Test group name"; - exchange.setProperty(EX_PROP_NAME, groupName); - exchange.setProperty(EX_PROP_MODEL_NAME, OdooTestConstants.MODEL_NAME_GROUPS); - var rpcArgs = new ArrayList<>(); - rpcArgs.add(APP_PROP_ODOO_DB); - rpcArgs.add(USER_ID); - rpcArgs.add(APP_PROP_ODOO_PASS); - rpcArgs.add(OdooTestConstants.MODEL_NAME_GROUPS); - rpcArgs.add(OdooTestConstants.ODOO_OP_SEARCH_READ); - rpcArgs.add(singletonList(singletonList(asList("name", "=", groupName)))); - Object expectedItem = "test"; - exchange.getIn().setBody(expectedItem); - - producerTemplate.send(OdooTestConstants.URI_GET_RES_BY_NAME_FROM_ODOO, exchange); - - assertNotNull(exchange); - assertEquals(expectedItem, exchange.getMessage().getBody(String.class)); - } - - @Test - public void shouldSetTheBodyToNullIfNoMatchIsFound() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - final String groupName = "Test group name"; - exchange.setProperty(EX_PROP_NAME, groupName); - exchange.setProperty(EX_PROP_MODEL_NAME, OdooTestConstants.MODEL_NAME_GROUPS); - final var rpcArgs = new ArrayList<>(); - rpcArgs.add(APP_PROP_ODOO_DB); - rpcArgs.add(USER_ID); - rpcArgs.add(APP_PROP_ODOO_PASS); - rpcArgs.add(OdooTestConstants.MODEL_NAME_GROUPS); - rpcArgs.add(OdooTestConstants.ODOO_OP_SEARCH_READ); - rpcArgs.add(singletonList(singletonList(asList("name", "=", groupName)))); - - producerTemplate.send(OdooTestConstants.URI_GET_RES_BY_NAME_FROM_ODOO, exchange); - - assertNull(exchange.getIn().getBody()); - } - - @Test - public void shouldFailIfMultipleMatchesAreFound() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - final String groupName = "Test group name"; - exchange.setProperty(EX_PROP_NAME, groupName); - exchange.setProperty(EX_PROP_MODEL_NAME, OdooTestConstants.MODEL_NAME_GROUPS); - final var rpcArgs = new ArrayList<>(); - rpcArgs.add(APP_PROP_ODOO_DB); - rpcArgs.add(USER_ID); - rpcArgs.add(APP_PROP_ODOO_PASS); - rpcArgs.add(OdooTestConstants.MODEL_NAME_GROUPS); - rpcArgs.add(OdooTestConstants.ODOO_OP_SEARCH_READ); - rpcArgs.add(singletonList(singletonList(asList("name", "=", groupName)))); - - try { - producerTemplate.send(OdooTestConstants.URI_GET_RES_BY_NAME_FROM_ODOO, exchange); - } catch (Exception e) { - assertTrue(e.getMessage().contains("Found 2 resources")); - assertEquals( - "Found 2 resources (" + OdooTestConstants.MODEL_NAME_GROUPS + ") in odoo with name: " + groupName, - e.getMessage()); - } - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsCapturedOnFormRuleRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsCapturedOnFormRuleRouteTest.java deleted file mode 100644 index 3cd77c46..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsCapturedOnFormRuleRouteTest.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import ch.qos.logback.classic.Level; -import java.util.Map; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class ObsCapturedOnFormRuleRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "obs-captured-on-form-rule"; - - public static final String EX_PROP_OBS = "obs"; - - public static final String EX_PROP_FORM_UUID = "formUuid"; - - @EndpointInject(OdooTestConstants.URI_MOCK_GET_ENTITY_BY_UUID) - private MockEndpoint mockFetchResourceEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory(ROUTE_ID + ".xml"); - - mockFetchResourceEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_GET_ENTITY_BY_UUID) - .skipSendToOriginalEndpoint() - .to(mockFetchResourceEndpoint); - } - }); - } - - @Test - public void shouldSetBodyToTrueIfTheObsWasRecordedOnTheFormWithTheSpecifiedUuid() throws Exception { - final String encounterUuid = "enc-uuid"; - final String formUuid = "form-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - Map encResource = singletonMap("form", singletonMap("uuid", formUuid)); - Map obsResource = singletonMap("encounter", singletonMap("uuid", encounterUuid)); - exchange.setProperty(EX_PROP_OBS, obsResource); - exchange.setProperty(EX_PROP_FORM_UUID, formUuid); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "encounter"); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_ID, encounterUuid); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RES_REP, "full"); - final String encJson = mapper.writeValueAsString(encResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(encJson)); - - producerTemplate.send(OdooTestConstants.URI_OBS_CAPTURED_ON_FORM, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - assertTrue(exchange.getIn().getBody(Boolean.class)); - } - - @Test - public void shouldSetBodyToFalseIfTheObsWasRecordedOnAFormWithADifferentUuid() throws Exception { - final String encounterUuid = "enc-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - Map encResource = singletonMap("form", singletonMap("uuid", "another-form-uuid")); - Map obsResource = singletonMap("encounter", singletonMap("uuid", encounterUuid)); - exchange.setProperty(EX_PROP_OBS, obsResource); - exchange.setProperty(EX_PROP_FORM_UUID, "form-uuid"); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "encounter"); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_ID, encounterUuid); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RES_REP, "full"); - final String encJson = mapper.writeValueAsString(encResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(encJson)); - - producerTemplate.send(OdooTestConstants.URI_OBS_CAPTURED_ON_FORM, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - assertFalse(exchange.getIn().getBody(Boolean.class)); - } - - @Test - public void shouldSetBodyToFalseForAFormLessEncounter() throws Exception { - final String encounterUuid = "enc-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(encounterUuid); - Map obsResource = singletonMap("encounter", singletonMap("uuid", encounterUuid)); - exchange.setProperty(EX_PROP_OBS, obsResource); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "encounter"); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_ID, encounterUuid); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(emptyMap())); - - producerTemplate.send(OdooTestConstants.URI_OBS_CAPTURED_ON_FORM, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.INFO, "Obs encounter does not belong to any form"); - assertFalse(exchange.getIn().getBody(Boolean.class)); - } - - @Test - public void shouldSetBodyToFalseForAnEncounterLessObs() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_OBS, emptyMap()); - mockFetchResourceEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_OBS_CAPTURED_ON_FORM, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - assertFalse(exchange.getIn().getBody(Boolean.class)); - assertMessageLogged(Level.INFO, "Obs does not belong to any encounter"); - } - - @Test - public void shouldFailIfNoEncounterIsFoundMatchingTheEncounterUuid() throws Exception { - final String encounterUuid = "enc-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(encounterUuid); - Map obsResource = singletonMap("encounter", singletonMap("uuid", encounterUuid)); - exchange.setProperty(EX_PROP_OBS, obsResource); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "encounter"); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_ID, encounterUuid); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(null)); - - producerTemplate.send(OdooTestConstants.URI_OBS_CAPTURED_ON_FORM, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - assertEquals("No encounter found with uuid: " + encounterUuid, getErrorMessage(exchange)); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsToCustomerRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsToCustomerRouteTest.java deleted file mode 100644 index 9179e8af..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsToCustomerRouteTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Collections.singletonMap; -import static org.openmrs.eip.mysql.watcher.WatcherConstants.PROP_EVENT; -import static org.springframework.test.context.support.TestPropertySourceUtils.addInlinedPropertiesToEnvironment; - -import ch.qos.logback.classic.Level; -import java.util.HashMap; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openmrs.eip.mysql.watcher.Event; - -public class ObsToCustomerRouteTest extends BaseOdooRouteTest { - - private static final String URI_TEST_RULE = "mock:test-rule"; - - private static final String TABLE = "obs"; - - private static final String OBS_UUID = "obs-uuid-1"; - - private static final String PATIENT_UUID = "patient-uuid"; - - private static final String PROP_DECISION_RULE = "obs.to.customer.decision.rule.endpoint"; - - private static final String EX_PROP_SKIP_CUSTOMER_UPDATE = "skipCustomerUpdate"; - - @EndpointInject("mock:patient-uuid-to-odoo-customer") - private MockEndpoint mockPatientUuidToCustomerEndpoint; - - @EndpointInject(URI_TEST_RULE) - private MockEndpoint mockTestRuleEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("obs-to-customer.xml"); - - mockTestRuleEndpoint.reset(); - mockPatientUuidToCustomerEndpoint.reset(); - - advise(OdooTestConstants.ROUTE_ID_OBS_TO_CUSTOMER, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_PATIENT_UUID_TO_CUSTOMER) - .skipSendToOriginalEndpoint() - .to(mockPatientUuidToCustomerEndpoint); - } - }); - } - - @Test - public void shouldSkipAnObsThatFailsTheDecisionRule() throws Exception { - addInlinedPropertiesToEnvironment(env, PROP_DECISION_RULE + "=" + URI_TEST_RULE); - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "c"); - exchange.setProperty(PROP_EVENT, event); - var obsResource = new HashMap<>(); - obsResource.put("uuid", OBS_UUID); - var patientResource = new HashMap<>(); - patientResource.put("uuid", PATIENT_UUID); - obsResource.put("person", patientResource); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, obsResource); - mockPatientUuidToCustomerEndpoint.expectedMessageCount(0); - mockTestRuleEndpoint.expectedMessageCount(1); - mockTestRuleEndpoint.expectedBodiesReceived(obsResource); - mockTestRuleEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(false)); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_CUSTOMER, exchange); - - mockPatientUuidToCustomerEndpoint.assertIsSatisfied(); - mockTestRuleEndpoint.assertIsSatisfied(); - mockTestRuleEndpoint.expectedBodyReceived(); - assertMessageLogged( - Level.INFO, "Skipping obs event because it failed the decision rules defined in -> " + URI_TEST_RULE); - } - - @Test - public void shouldProcessAnObsThatPassesTheDecisionRule() throws Exception { - addInlinedPropertiesToEnvironment(env, PROP_DECISION_RULE + "=" + URI_TEST_RULE); - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "c"); - exchange.setProperty(PROP_EVENT, event); - var obsResource = new HashMap<>(); - obsResource.put("uuid", OBS_UUID); - obsResource.put("person", singletonMap("uuid", PATIENT_UUID)); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, obsResource); - mockPatientUuidToCustomerEndpoint.expectedMessageCount(1); - mockPatientUuidToCustomerEndpoint.expectedPropertyReceived(EX_PROP_SKIP_CUSTOMER_UPDATE, true); - mockPatientUuidToCustomerEndpoint.expectedBodiesReceived(PATIENT_UUID); - mockTestRuleEndpoint.expectedMessageCount(1); - mockTestRuleEndpoint.expectedBodiesReceived(obsResource); - mockTestRuleEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(true)); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_CUSTOMER, exchange); - - mockPatientUuidToCustomerEndpoint.assertIsSatisfied(); - mockPatientUuidToCustomerEndpoint.expectedBodyReceived(); - mockTestRuleEndpoint.assertIsSatisfied(); - mockTestRuleEndpoint.expectedBodyReceived(); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsToOdooResourceRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsToOdooResourceRouteTest.java deleted file mode 100644 index 1223d51f..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/ObsToOdooResourceRouteTest.java +++ /dev/null @@ -1,271 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Collections.singleton; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.openmrs.eip.mysql.watcher.WatcherConstants.PROP_EVENT; - -import ch.qos.logback.classic.Level; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openmrs.eip.AppContext; -import org.openmrs.eip.mysql.watcher.Event; -import org.springframework.test.context.TestPropertySource; - -@TestPropertySource( - properties = "camel.springboot.xml-routes=classpath*:camel/obs/" - + OdooTestConstants.ROUTE_ID_OBS_TO_ODOO_RESOURCE + ".xml") -@TestPropertySource(properties = "eip.watchedTables=obs") -@TestPropertySource(properties = "odoo.handler.route=odoo-prp-handler") -@TestPropertySource(properties = "odoo.custom.table.resource.mappings=obs:obs") -@TestPropertySource( - properties = "odoo.obs.concept.question.answer.mappings=" + ObsToOdooResourceRouteTest.CONCEPT_UUID_1 - + "#" + ObsToOdooResourceRouteTest.CONCEPT_UUID_A + "," + ObsToOdooResourceRouteTest.CONCEPT_SOURCE_2 - + ":" - + ObsToOdooResourceRouteTest.CONCEPT_CODE_2 + "#" + ObsToOdooResourceRouteTest.CONCEPT_UUID_B + "^" - + ObsToOdooResourceRouteTest.CONCEPT_SOURCE_C + ":" + ObsToOdooResourceRouteTest.CONCEPT_CODE_C) -@TestPropertySource( - properties = OdooTestConstants.APP_PROP_NAME_OBS_TO_ODOO_HANDLER + "=" - + ObsToOdooResourceRouteTest.ROUTE_OBS_TO_ODOO_RES_HANDLER) -public class ObsToOdooResourceRouteTest extends BaseOdooRouteTest { - - private static final String TABLE = "obs"; - - private static final String OBS_UUID = "obs-uuid-1"; - - protected static final String CONCEPT_UUID_1 = "concept-uuid-1"; - - protected static final String CONCEPT_UUID_2 = "concept-uuid-2"; - - protected static final String CONCEPT_SOURCE_2 = "concept-source-2"; - - protected static final String CONCEPT_CODE_2 = "concept-code-2"; - - protected static final String CONCEPT_UUID_A = "concept-uuid-a"; - - protected static final String CONCEPT_UUID_B = "concept-uuid-b"; - - protected static final String CONCEPT_UUID_C = "concept-uuid-c"; - - protected static final String CONCEPT_SOURCE_C = "concept-source-c"; - - protected static final String CONCEPT_CODE_C = "concept-code-c"; - - private static final String EX_PROP_OBS_QN_ANS_MAP = "obsQnAnsMap"; - - private static final String OBS_QN_ANS_MAP_KEY = OdooTestConstants.ROUTE_ID_OBS_TO_ODOO_RESOURCE + "-obsQnAnsMap"; - - protected static final String ROUTE_OBS_TO_ODOO_RES_HANDLER = "obs-to-odoo-res-test-handler"; - - @EndpointInject("mock:convert-to-concept-uuid-if-is-mapping") - private MockEndpoint mockConvertToConceptUuidEndpoint; - - @EndpointInject("mock:" + ROUTE_OBS_TO_ODOO_RES_HANDLER) - private MockEndpoint mockObsToOdooResHandlerEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("obs-to-odoo-resource.xml"); - - mockObsToOdooResHandlerEndpoint.reset(); - mockConvertToConceptUuidEndpoint.reset(); - AppContext.remove(OBS_QN_ANS_MAP_KEY); - - advise(OdooTestConstants.ROUTE_ID_OBS_TO_ODOO_RESOURCE, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_CONVERT_TO_CONCEPT_UUID) - .skipSendToOriginalEndpoint() - .to(mockConvertToConceptUuidEndpoint); - interceptSendToEndpoint("direct:" + ROUTE_OBS_TO_ODOO_RES_HANDLER) - .skipSendToOriginalEndpoint() - .to(mockObsToOdooResHandlerEndpoint); - } - }); - - mockConvertToConceptUuidEndpoint.expectedMessageCount(5); - mockConvertToConceptUuidEndpoint.expectedBodiesReceived( - CONCEPT_UUID_1, - CONCEPT_UUID_A, - CONCEPT_SOURCE_2 + ":" + CONCEPT_CODE_2, - CONCEPT_UUID_B, - CONCEPT_SOURCE_C + ":" + CONCEPT_CODE_C); - mockConvertToConceptUuidEndpoint.whenExchangeReceived(3, e -> e.getIn().setBody(CONCEPT_UUID_2)); - mockConvertToConceptUuidEndpoint.whenExchangeReceived(5, e -> e.getIn().setBody(CONCEPT_UUID_C)); - } - - @AfterEach - public void after() throws Exception { - mockConvertToConceptUuidEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldProcessAnObsInsertEvent() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "c"); - exchange.setProperty(PROP_EVENT, event); - Map obsResource = new HashMap(); - obsResource.put("uuid", OBS_UUID); - obsResource.put("concept", singletonMap("uuid", CONCEPT_UUID_1)); - obsResource.put("value", singletonMap("uuid", CONCEPT_UUID_A)); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, obsResource); - mockObsToOdooResHandlerEndpoint.expectedMessageCount(1); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_ODOO_RESOURCE, exchange); - - mockObsToOdooResHandlerEndpoint.assertIsSatisfied(); - mockConvertToConceptUuidEndpoint.assertIsSatisfied(); - Map> obsQnAnsMap = exchange.getProperty(EX_PROP_OBS_QN_ANS_MAP, Map.class); - assertNotNull(obsQnAnsMap); - assertEquals(1, obsQnAnsMap.get(CONCEPT_UUID_1).size()); - assertEquals(2, obsQnAnsMap.get(CONCEPT_UUID_2).size()); - assertTrue(obsQnAnsMap.get(CONCEPT_UUID_1).contains(CONCEPT_UUID_A)); - assertTrue(obsQnAnsMap.get(CONCEPT_UUID_2).contains(CONCEPT_UUID_B)); - assertTrue(obsQnAnsMap.get(CONCEPT_UUID_2).contains(CONCEPT_UUID_C)); - } - - @Test - public void shouldSkipAnObsWithANullValue() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "c"); - exchange.setProperty(PROP_EVENT, event); - Map obsResource = new HashMap(); - obsResource.put("uuid", OBS_UUID); - obsResource.put("concept", singletonMap("uuid", CONCEPT_UUID_1)); - obsResource.put("value", null); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, obsResource); - mockObsToOdooResHandlerEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_ODOO_RESOURCE, exchange); - - mockObsToOdooResHandlerEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.DEBUG, "Skipping obs because it's value is null"); - } - - @Test - public void shouldProcessAnObsUpdateEvent() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "u"); - exchange.setProperty(PROP_EVENT, event); - Map obsResource = new HashMap(); - obsResource.put("uuid", OBS_UUID); - obsResource.put("concept", singletonMap("uuid", CONCEPT_UUID_1)); - obsResource.put("value", singletonMap("uuid", CONCEPT_UUID_A)); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, obsResource); - mockObsToOdooResHandlerEndpoint.expectedMessageCount(1); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_ODOO_RESOURCE, exchange); - - mockObsToOdooResHandlerEndpoint.assertIsSatisfied(); - Map> obsQnAnsMap = exchange.getProperty(EX_PROP_OBS_QN_ANS_MAP, Map.class); - assertNotNull(obsQnAnsMap); - assertEquals(1, obsQnAnsMap.get(CONCEPT_UUID_1).size()); - assertEquals(2, obsQnAnsMap.get(CONCEPT_UUID_2).size()); - assertTrue(obsQnAnsMap.get(CONCEPT_UUID_1).contains(CONCEPT_UUID_A)); - assertTrue(obsQnAnsMap.get(CONCEPT_UUID_2).contains(CONCEPT_UUID_B)); - assertTrue(obsQnAnsMap.get(CONCEPT_UUID_2).contains(CONCEPT_UUID_C)); - } - - @Test - public void shouldSkipAnObsDeleteEvent() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "d"); - exchange.setProperty(PROP_EVENT, event); - mockObsToOdooResHandlerEndpoint.expectedMessageCount(0); - mockConvertToConceptUuidEndpoint.expectedMessageCount(0); - producerTemplate.send(OdooTestConstants.URI_OBS_TO_ODOO_RESOURCE, exchange); - - mockObsToOdooResHandlerEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_OBS_QN_ANS_MAP)); - assertMessageLogged(Level.DEBUG, "Skipping deleted obs"); - } - - @Test - public void shouldSkipAnEventForAVoidedObs() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "c"); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, singletonMap("voided", true)); - mockObsToOdooResHandlerEndpoint.expectedMessageCount(0); - mockConvertToConceptUuidEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_ODOO_RESOURCE, exchange); - - mockObsToOdooResHandlerEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_OBS_QN_ANS_MAP)); - assertMessageLogged(Level.DEBUG, "Skipping voided obs"); - } - - @Test - public void shouldUseTheObsQuestionAndAnswersMapFromTheEipContextCache() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "c"); - exchange.setProperty(PROP_EVENT, event); - Map obsResource = new HashMap(); - obsResource.put("uuid", OBS_UUID); - obsResource.put("concept", singletonMap("uuid", CONCEPT_UUID_1)); - obsResource.put("value", singletonMap("uuid", CONCEPT_UUID_A)); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, obsResource); - final String questionConceptUuid = "test-qn-concept"; - final String answerConceptUuid = "test-ans-concept"; - Map cachedObsQnAnsMap = singletonMap(questionConceptUuid, singleton(answerConceptUuid)); - AppContext.add(OBS_QN_ANS_MAP_KEY, cachedObsQnAnsMap); - mockObsToOdooResHandlerEndpoint.expectedMessageCount(0); - mockConvertToConceptUuidEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_ODOO_RESOURCE, exchange); - - mockObsToOdooResHandlerEndpoint.assertIsSatisfied(); - assertEquals(cachedObsQnAnsMap, exchange.getProperty(EX_PROP_OBS_QN_ANS_MAP, Map.class)); - } - - @Test - public void shouldSkipAnEventForAnObsWithNonMonitoredQuestionConcept() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "c"); - exchange.setProperty(PROP_EVENT, event); - Map obsResource = new HashMap(); - obsResource.put("uuid", OBS_UUID); - obsResource.put("value", singletonMap("uuid", CONCEPT_UUID_A)); - obsResource.put("concept", singletonMap("uuid", "some-question-concept-uuid")); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, obsResource); - mockObsToOdooResHandlerEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_ODOO_RESOURCE, exchange); - - mockObsToOdooResHandlerEndpoint.assertIsSatisfied(); - assertMessageLogged( - Level.DEBUG, "Skipping Obs because the question concept doesn't match any configured question"); - } - - @Test - public void shouldSkipAnEventForAnObsWithNonMonitoredAnswerConcept() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - Event event = createEvent(TABLE, "1", OBS_UUID, "c"); - exchange.setProperty(PROP_EVENT, event); - Map obsResource = new HashMap(); - obsResource.put("uuid", OBS_UUID); - obsResource.put("concept", singletonMap("uuid", CONCEPT_UUID_1)); - obsResource.put("value", singletonMap("uuid", "some-answer-concept-uuid")); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, obsResource); - mockObsToOdooResHandlerEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_OBS_TO_ODOO_RESOURCE, exchange); - - mockObsToOdooResHandlerEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.DEBUG, "Skipping Obs because the answer concept doesn't match any configured answer"); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAddExtraCustomerDetailsRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAddExtraCustomerDetailsRouteTest.java deleted file mode 100644 index 26b21745..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAddExtraCustomerDetailsRouteTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.HashMap; -import org.apache.camel.Exchange; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.support.TestPropertySourceUtils; - -@TestPropertySource( - properties = { - "openmrs.baseUrl=www.openmrs.baseUrl", - "odoo.dob.field=x_customer_dob_field", - "odoo.enable.extra.customer.details.route=true" - }) -public class OdooAddExtraCustomerDetailsRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "odoo-add-extra-customer-details"; - - public static final String PATIENT_RESOURCE = "patient"; - - public static final String PERSON_RESOURCE = "person"; - - public static final String PATIENT_DATA = "patientData"; - - public static final String EX_PROP_CUSTOM_DATA = "customPatientData"; - - public static final String ID_TYPE_UUID = "8d79403a-c2cc-11de-8d13-0010c6dffd0f"; - - public static final String ID_TYPE_ID_KEY = "odoo-patient-handler-idTypeId"; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory(ROUTE_ID + ".xml"); - } - - @AfterEach - public void tearDown() { - TestPropertySourceUtils.addInlinedPropertiesToEnvironment(env, "create.customer.if.not.exist=false"); - } - - @Test - public void shouldAddPatientDateOfBirthToOdooCustomer() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - exchange.setProperty(PATIENT_RESOURCE, patientResource); - - var personResource = new HashMap<>(); - personResource.put("birthdate", "1971-03-15T00:00:00.000+0000"); - - exchange.setProperty(PERSON_RESOURCE, personResource); - - var patientData = new HashMap<>(); - exchange.setProperty(PATIENT_DATA, patientData); - - producerTemplate.send(OdooTestConstants.URI_ADD_EXTRA_CUSTOMER_DETAILS, exchange); - - assertEquals("1971-03-15T00:00:00.000+0000", patientData.get("x_customer_dob_field")); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAddExtraQuotationDetailsRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAddExtraQuotationDetailsRouteTest.java deleted file mode 100644 index bb51c4fb..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAddExtraQuotationDetailsRouteTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openmrs.eip.AppContext; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.support.TestPropertySourceUtils; - -@TestPropertySource( - properties = { - "emr.weight.concept=5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", - "odoo.weight.field=x_customer_weight_field", - "odoo.enable.extra.quotation.details.route=true" - }) -public class OdooAddExtraQuotationDetailsRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "odoo-add-extra-quotation-details"; - - public static final String PATIENT_RESOURCE = "patient"; - - public static final String PERSON_RESOURCE = "person"; - - public static final String PATIENT_DATA = "patientData"; - - public static final String EX_PROP_CUSTOM_DATA = "customPatientData"; - - public static final String ID_TYPE_UUID = "8d79403a-c2cc-11de-8d13-0010c6dffd0f"; - - public static final String ID_TYPE_ID_KEY = "odoo-patient-handler-idTypeId"; - - @EndpointInject("mock:openmrs-patient-weight-endpoint") - private MockEndpoint openmrsPatientWeightEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory(ROUTE_ID + ".xml"); - - AppContext.remove(ID_TYPE_ID_KEY); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - weaveByToString(".*/ws/rest/v1/obs\\?concept=.*").replace().toD("mock:openmrs-patient-weight-endpoint"); - } - }); - } - - @AfterEach - public void tearDown() { - TestPropertySourceUtils.addInlinedPropertiesToEnvironment(env, "create.customer.if.not.exist=false"); - } - - @Test - public void shouldAddPatientWeightToOdooCustomerQuotation() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - exchange.setProperty(PATIENT_RESOURCE, patientResource); - - openmrsPatientWeightEndpoint.expectedMessageCount(1); - openmrsPatientWeightEndpoint.expectedPropertyReceived("patient", patientResource); - - openmrsPatientWeightEndpoint.whenAnyExchangeReceived(e -> { - e.getIn() - .setBody( - "{\"results\": [{\"uuid\": \"c9067a98-e847-4d2a-a737-aeaf34e1ba15\", \"display\": \"Weight (kg): 55.0\"}, {\"uuid\": \"d0879297-d1b2-4a3a-b700-c0a37bebab35\", \"display\": \"Weight (kg): 95.0\"}, {\"uuid\": \"f9167f7d-8faa-4e47-adbf-b208c0dac6bb\", \"display\": \"Weight (kg): 78.0\"}]}"); - }); - - var patientData = new HashMap<>(); - exchange.setProperty(PATIENT_DATA, patientData); - - producerTemplate.send(OdooTestConstants.URI_ADD_EXTRA_QUOTATION_DETAILS, exchange); - - openmrsPatientWeightEndpoint.assertIsSatisfied(); - var requestData = (ArrayList) exchange.getProperty("requestData"); - assertEquals("Weight (kg): 55.0", ((Map) requestData.get(1)).get("x_customer_weight_field")); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAuthenticationRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAuthenticationRouteTest.java deleted file mode 100644 index 50b139a7..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooAuthenticationRouteTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static org.junit.jupiter.api.Assertions.fail; - -import org.apache.camel.EndpointInject; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -@Disabled -public class OdooAuthenticationRouteTest extends BaseOdooRouteTest { - - @EndpointInject("mock:http") - private MockEndpoint mockHttpEndpoint; - - @Test - public void shouldAuthenticateWithOdoo() throws Exception { - advise("odoo-event-listener", new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.ODOO_BASE_URL) - .skipSendToOriginalEndpoint() - .to(mockHttpEndpoint); - } - }); - fail("Not yet implemented"); - mockHttpEndpoint.expectedMessageCount(1); - mockHttpEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldFailIfTheAuthenticateCredentialsAreWrong() throws Exception { - fail("Not yet implemented"); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooIntegrationEventListenerRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooIntegrationEventListenerRouteTest.java deleted file mode 100644 index 57735015..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooIntegrationEventListenerRouteTest.java +++ /dev/null @@ -1,277 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_ENTITY; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.openmrs.eip.mysql.watcher.WatcherConstants.PROP_EVENT; - -import java.util.HashMap; -import java.util.Map; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.apache.xmlrpc.client.XmlRpcClient; -import org.apache.xmlrpc.client.XmlRpcClientConfig; -import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openmrs.eip.AppContext; -import org.openmrs.eip.mysql.watcher.Event; -import org.springframework.test.context.TestPropertySource; - -@TestPropertySource(properties = "odoo.custom.table.resource.mappings=obs:obs,encounter:encounter") -public class OdooIntegrationEventListenerRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "odoo-event-listener"; - - @EndpointInject("mock:odoo-auth") - private MockEndpoint mockAuthEndpoint; - - @EndpointInject("mock:odoo-entity-handler") - private MockEndpoint mockEntityHandlerEndpoint; - - @EndpointInject("mock:odoo-patient-handler") - private MockEndpoint mockPatientHandlerEndpoint; - - @EndpointInject("mock:odoo-patient-association-handler") - private MockEndpoint mockPatientAssociationEndpoint; - - @EndpointInject(OdooTestConstants.URI_MOCK_GET_ENTITY_BY_UUID) - private MockEndpoint mockFetchResourceEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("odoo-integration-event-listener.xml"); - loadXmlRoutesInCamelDirectory("odoo-patient-association-handler.xml"); - - mockFetchResourceEndpoint.reset(); - mockAuthEndpoint.reset(); - mockEntityHandlerEndpoint.reset(); - mockPatientHandlerEndpoint.reset(); - mockPatientAssociationEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_ODOO_AUTH) - .skipSendToOriginalEndpoint() - .to(mockAuthEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_GET_ENTITY_BY_UUID) - .skipSendToOriginalEndpoint() - .to(mockFetchResourceEndpoint); - interceptSendToEndpoint("direct:odoo-entity-handler") - .skipSendToOriginalEndpoint() - .to(mockEntityHandlerEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_PATIENT_HANDLER) - .skipSendToOriginalEndpoint() - .to(mockPatientHandlerEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_PATIENT_ASSOCIATION_HANDLER) - .skipSendToOriginalEndpoint() - .to(mockPatientAssociationEndpoint); - } - }); - } - - @Test - public void shouldSkipSnapshotEvents() { - Event event = createEvent("orders", "1", "some-uuid", "c"); - event.setSnapshot(true); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - - producerTemplate.send(OdooTestConstants.LISTENER_URI, exchange); - - assertNotNull(exchange.getProperty(OdooTestConstants.EX_PROP_TABLE_RESOURCE_MAP)); - assertNull(exchange.getProperty(EX_PROP_ENTITY)); - } - - @Test - public void shouldSkipNonMonitoredTables() { - Event event = createEvent("visit", "1", "some_uuid", "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - - producerTemplate.send(OdooTestConstants.LISTENER_URI, exchange); - - assertNotNull(exchange.getProperty(OdooTestConstants.EX_PROP_TABLE_RESOURCE_MAP)); - assertNull(exchange.getProperty(EX_PROP_ENTITY)); - } - - @Test - public void shouldInvokeTheConfiguredObsHandler() throws Exception { - final String obsUuid = "obs_uuid"; - Event event = createEvent("obs", "1", obsUuid, "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - var obsResource = new HashMap<>(); - obsResource.put("uuid", obsUuid); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "obs"); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_ID, obsUuid); - final String obsJson = mapper.writeValueAsString(obsResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(obsJson)); - mockEntityHandlerEndpoint.expectedMessageCount(1); - - mockEntityHandlerEndpoint.reset(); - producerTemplate.send(OdooTestConstants.LISTENER_URI, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockEntityHandlerEndpoint.assertIsSatisfied(); - var map = exchange.getProperty(OdooTestConstants.EX_PROP_TABLE_RESOURCE_MAP, Map.class); - assertNotNull(map); - assertEquals(6, map.size()); - assertEquals("patient", map.get("patient")); - assertEquals("name", map.get("person_name")); - assertEquals("address", map.get("person_address")); - assertEquals("identifier", map.get("patient_identifier")); - assertEquals("obs", map.get("obs")); - assertEquals("encounter", map.get("encounter")); - } - - @Test - public void shouldProcessAnEventForAPatient() throws Exception { - Event event = createEvent("patient", "5", OdooTestConstants.PATIENT_UUID, "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - mockAuthEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockEntityHandlerEndpoint.expectedMessageCount(0); - mockPatientAssociationEndpoint.expectedMessageCount(0); - mockPatientAssociationEndpoint.expectedMessageCount(0); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - var patientResource = singletonMap("uuid", OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - - producerTemplate.send(OdooTestConstants.LISTENER_URI, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockAuthEndpoint.assertIsSatisfied(); - mockEntityHandlerEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - mockPatientAssociationEndpoint.assertIsSatisfied(); - assertEquals(patientResource, exchange.getProperty(EX_PROP_ENTITY)); - assertNotNull(exchange.getProperty(OdooTestConstants.EX_PROP_TABLE_RESOURCE_MAP)); - } - - @Test - public void shouldUseTheCachedOdooUserIdAndNotAuthenticateWithOdoo() throws Exception { - final int odooUserid = 9; - AppContext.add(OdooTestConstants.ODOO_USER_ID_KEY, odooUserid); - Event event = createEvent("patient", "5", OdooTestConstants.PATIENT_UUID, "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - mockAuthEndpoint.expectedMessageCount(0); - mockEntityHandlerEndpoint.expectedMessageCount(0); - mockPatientAssociationEndpoint.expectedMessageCount(0); - mockPatientAssociationEndpoint.expectedMessageCount(0); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_PATIENT, patientResource); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - - producerTemplate.send(OdooTestConstants.LISTENER_URI, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockAuthEndpoint.assertIsSatisfied(); - mockEntityHandlerEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - mockPatientAssociationEndpoint.assertIsSatisfied(); - assertEquals(patientResource, exchange.getProperty(EX_PROP_ENTITY)); - assertEquals( - OdooTestConstants.ODOO_USER_ID_KEY, exchange.getProperty(OdooTestConstants.EX_PROP_ODOO_USER_ID_KEY)); - assertEquals(odooUserid, AppContext.get(OdooTestConstants.ODOO_USER_ID_KEY)); - assertNotNull(exchange.getProperty(OdooTestConstants.EX_PROP_TABLE_RESOURCE_MAP)); - } - - @Test - public void shouldAuthenticateWithOdooIfNoOdooUserIdIsCached() throws Exception { - Event event = createEvent("patient", "5", OdooTestConstants.PATIENT_UUID, "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - mockEntityHandlerEndpoint.expectedMessageCount(0); - mockPatientAssociationEndpoint.expectedMessageCount(0); - mockPatientAssociationEndpoint.expectedMessageCount(0); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_PATIENT, patientResource); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockAuthEndpoint.expectedMessageCount(1); - final int odooUserid = 8; - mockAuthEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(odooUserid)); - - producerTemplate.send(OdooTestConstants.LISTENER_URI, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockAuthEndpoint.assertIsSatisfied(); - mockEntityHandlerEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - mockPatientAssociationEndpoint.assertIsSatisfied(); - assertEquals(patientResource, exchange.getProperty(EX_PROP_ENTITY)); - assertEquals( - OdooTestConstants.ODOO_USER_ID_KEY, exchange.getProperty(OdooTestConstants.EX_PROP_ODOO_USER_ID_KEY)); - assertEquals(odooUserid, AppContext.get(OdooTestConstants.ODOO_USER_ID_KEY)); - assertNotNull(exchange.getProperty(OdooTestConstants.EX_PROP_TABLE_RESOURCE_MAP)); - } - - @Test - public void shouldCreateAndCacheTheXmlRpcClientAndConfig() throws Exception { - assertNull(AppContext.get(OdooTestConstants.RPC_CLIENT_KEY)); - assertNull(AppContext.get(OdooTestConstants.RPC_CONFIG_KEY)); - final String obsUuid = "obs_uuid"; - Event event = createEvent("obs", "1", obsUuid, "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - var obsResource = new HashMap<>(); - obsResource.put("uuid", obsUuid); - final String obsJson = mapper.writeValueAsString(obsResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(obsJson)); - - producerTemplate.send(OdooTestConstants.LISTENER_URI, exchange); - - assertNotNull(AppContext.get(OdooTestConstants.RPC_CLIENT_KEY)); - assertNotNull(AppContext.get(OdooTestConstants.RPC_CONFIG_KEY)); - } - - @Test - public void shouldNotCreateNewXmlRpcClientAndConfigIfTheCacheAlreadyContainsOne() throws Exception { - XmlRpcClient client = new XmlRpcClient(); - XmlRpcClientConfig config = new XmlRpcClientConfigImpl(); - AppContext.add(OdooTestConstants.RPC_CLIENT_KEY, client); - AppContext.add(OdooTestConstants.RPC_CONFIG_KEY, config); - final String obsUuid = "obs_uuid"; - Event event = createEvent("obs", "1", obsUuid, "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - var obsResource = new HashMap<>(); - obsResource.put("uuid", obsUuid); - final String obsJson = mapper.writeValueAsString(obsResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(obsJson)); - - producerTemplate.send(OdooTestConstants.LISTENER_URI, exchange); - - assertEquals(client, AppContext.get(OdooTestConstants.RPC_CLIENT_KEY)); - assertEquals(config, AppContext.get(OdooTestConstants.RPC_CONFIG_KEY)); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooOrderHandlerRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooOrderHandlerRouteTest.java deleted file mode 100644 index 36ceaa0a..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooOrderHandlerRouteTest.java +++ /dev/null @@ -1,337 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.openmrs.eip.mysql.watcher.WatcherConstants.PROP_EVENT; - -import ch.qos.logback.classic.Level; -import java.util.HashMap; -import java.util.Map; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openmrs.eip.EIPException; -import org.openmrs.eip.mysql.watcher.Event; - -public class OdooOrderHandlerRouteTest extends BaseOrderOdooRouteTest { - - private static final String ROUTE_ID = "odoo-order-handler"; - - @EndpointInject("mock:odoo-get-external-id-map") - private MockEndpoint mockExtIdMapEndpoint; - - @EndpointInject("mock:odoo-process-order") - private MockEndpoint mockProcessOrderEndpoint; - - @EndpointInject(OdooTestConstants.URI_MOCK_GET_ENTITY_BY_UUID) - private MockEndpoint mockFetchResourceEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("odoo-order-handler.xml"); - - mockFetchResourceEndpoint.reset(); - mockExtIdMapEndpoint.reset(); - mockProcessOrderEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_GET_ENTITY_BY_UUID) - .skipSendToOriginalEndpoint() - .to(mockFetchResourceEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_GET_EXT_ID) - .skipSendToOriginalEndpoint() - .to(mockExtIdMapEndpoint); - interceptSendToEndpoint(OdooTestConstants.URI_PROCESS_ORDER) - .skipSendToOriginalEndpoint() - .to(mockProcessOrderEndpoint); - } - }); - } - - @Test - public void shouldSkipADeleteEvent() throws Exception { - final String op = "d"; - Event event = createEvent("orders", "1", OdooTestConstants.ORDER_UUID_2, op); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - assertMessageLogged(Level.INFO, "Skipping event with operation: " + op); - } - - @Test - public void shouldSkipAnUpdateEvent() throws Exception { - final String op = "u"; - Event event = createEvent("orders", "1", OdooTestConstants.ORDER_UUID_2, op); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - assertMessageLogged(Level.INFO, "Skipping event with operation: " + op); - } - - @Test - public void shouldProcessANewTestOrder() throws Exception { - final String op = "c"; - final Integer expectedProductId = 4; - final String conceptUuid = "test-concept-uuid"; - Event event = createEvent("orders", "1", OdooTestConstants.ORDER_UUID_1, op); - Map orderResource = new HashMap(); - orderResource.put("action", "NEW"); - orderResource.put("concept", singletonMap("uuid", conceptUuid)); - orderResource.put("type", "testorder"); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockExtIdMapEndpoint.expectedMessageCount(1); - mockProcessOrderEndpoint.expectedMessageCount(1); - mockExtIdMapEndpoint.expectedPropertyReceived("modelName", "product.product"); - mockExtIdMapEndpoint.expectedPropertyReceived("externalId", conceptUuid); - mockProcessOrderEndpoint.expectedPropertyReceived("odooProductId", expectedProductId); - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - mockExtIdMapEndpoint.assertIsSatisfied(); - mockProcessOrderEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty("is-drug-order")); - assertTrue(exchange.getProperty("is-new", Boolean.class)); - } - - @Test - public void shouldProcessANewDrugOrder() throws Exception { - final String op = "c"; - final Integer expectedProductId = 5; - final String drugUuid = "drug-uuid"; - Event event = createEvent("orders", "2", OdooTestConstants.ORDER_UUID_2, op); - Map orderResource = new HashMap(); - orderResource.put("action", "NEW"); - orderResource.put("type", "drugorder"); - orderResource.put("concept", singletonMap("uuid", "concept-uuid")); - orderResource.put("drug", singletonMap("uuid", drugUuid)); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockExtIdMapEndpoint.expectedMessageCount(1); - mockProcessOrderEndpoint.expectedMessageCount(1); - mockExtIdMapEndpoint.expectedPropertyReceived("modelName", "product.product"); - mockExtIdMapEndpoint.expectedPropertyReceived("externalId", drugUuid); - mockProcessOrderEndpoint.expectedPropertyReceived("odooProductId", expectedProductId); - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - mockExtIdMapEndpoint.assertIsSatisfied(); - mockProcessOrderEndpoint.assertIsSatisfied(); - assertTrue(exchange.getProperty("is-drug-order", Boolean.class)); - assertTrue(exchange.getProperty("is-new", Boolean.class)); - } - - @Test - public void shouldProcessARevisionOrder() throws Exception { - final String orderUuid = "36170d8e-d201-4d94-ae89-0be0b0b6d8ba"; - final String op = "c"; - final Integer expectedProductId = 5; - final String drugUuid = "drug-uuid"; - Event event = createEvent("orders", "3", orderUuid, op); - Map orderResource = new HashMap(); - orderResource.put("action", "REVISE"); - orderResource.put("type", "drugorder"); - orderResource.put("concept", singletonMap("uuid", "concept-uuid")); - orderResource.put("drug", singletonMap("uuid", drugUuid)); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockExtIdMapEndpoint.expectedMessageCount(1); - mockProcessOrderEndpoint.expectedMessageCount(1); - mockExtIdMapEndpoint.expectedPropertyReceived("modelName", "product.product"); - mockExtIdMapEndpoint.expectedPropertyReceived("externalId", drugUuid); - mockProcessOrderEndpoint.expectedPropertyReceived("odooProductId", expectedProductId); - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - mockExtIdMapEndpoint.assertIsSatisfied(); - mockProcessOrderEndpoint.assertIsSatisfied(); - assertTrue(exchange.getProperty("is-drug-order", Boolean.class)); - assertFalse(exchange.getProperty("is-new", Boolean.class)); - } - - @Test - public void shouldProcessADiscontinuationOrder() throws Exception { - final String orderUuid = "46170d8e-d201-4d94-ae89-0be0b0b6d8ba"; - final String op = "c"; - final Integer expectedProductId = 5; - final String conceptUuid = "concept-uuid"; - Event event = createEvent("orders", "4", orderUuid, op); - Map orderResource = new HashMap(); - orderResource.put("action", "REVISE"); - orderResource.put("concept", singletonMap("uuid", conceptUuid)); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockExtIdMapEndpoint.expectedMessageCount(1); - mockProcessOrderEndpoint.expectedMessageCount(1); - mockExtIdMapEndpoint.expectedPropertyReceived("modelName", "product.product"); - mockExtIdMapEndpoint.expectedPropertyReceived("externalId", conceptUuid); - mockProcessOrderEndpoint.expectedPropertyReceived("odooProductId", expectedProductId); - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - mockExtIdMapEndpoint.assertIsSatisfied(); - mockProcessOrderEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty("is-drug-order")); - assertFalse(exchange.getProperty("is-new", Boolean.class)); - } - - @Test - public void shouldProcessAVoidedOrder() throws Exception { - final String op = "u"; - final Integer expectedProductId = 6; - final String drugUuid = "drug-uuid"; - Event event = createEvent("orders", "2", OdooTestConstants.ORDER_UUID_2, op); - Map orderResource = new HashMap(); - orderResource.put("action", "REVISE"); - orderResource.put("type", "drugorder"); - orderResource.put("concept", singletonMap("uuid", "concept-uuid")); - orderResource.put("drug", singletonMap("uuid", drugUuid)); - orderResource.put("voided", true); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockExtIdMapEndpoint.expectedMessageCount(1); - mockProcessOrderEndpoint.expectedMessageCount(1); - mockExtIdMapEndpoint.expectedPropertyReceived("modelName", "product.product"); - mockExtIdMapEndpoint.expectedPropertyReceived("externalId", drugUuid); - mockProcessOrderEndpoint.expectedPropertyReceived("odooProductId", expectedProductId); - Map[] expectedBody = new Map[] {singletonMap("res_id", expectedProductId)}; - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(expectedBody)); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - mockExtIdMapEndpoint.assertIsSatisfied(); - mockProcessOrderEndpoint.assertIsSatisfied(); - assertTrue(exchange.getProperty("is-drug-order", Boolean.class)); - assertNull(exchange.getProperty("is-new")); - } - - @Test - public void shouldFailIfNoProductIsFoundInOdooMatchingTheExternalId() throws Exception { - final String op = "c"; - Event event = createEvent("orders", "1", OdooTestConstants.ORDER_UUID_1, op); - final String conceptUuid = "test-concept-uuid"; - Map orderResource = new HashMap(); - orderResource.put("action", "NEW"); - orderResource.put("type", "testorder"); - orderResource.put("concept", singletonMap("uuid", conceptUuid)); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockExtIdMapEndpoint.expectedMessageCount(1); - mockProcessOrderEndpoint.expectedMessageCount(0); - mockExtIdMapEndpoint.expectedPropertyReceived("modelName", "product.product"); - mockExtIdMapEndpoint.expectedPropertyReceived("externalId", conceptUuid); - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - mockExtIdMapEndpoint.assertIsSatisfied(); - mockProcessOrderEndpoint.assertIsSatisfied(); - final String expectError = "No product found in odoo mapped to uuid: " + conceptUuid; - assertEquals( - expectError, exchange.getProperty("error", EIPException.class).getMessage()); - } - - @Test - public void shouldFailIfMultipleProductsAreFoundInOdooMatchingTheExternalId() throws Exception { - final String op = "c"; - Event event = createEvent("orders", "1", OdooTestConstants.ORDER_UUID_1, op); - final String conceptUuid = "test-concept-uuid"; - Map orderResource = new HashMap(); - orderResource.put("action", "NEW"); - orderResource.put("type", "testorder"); - orderResource.put("concept", singletonMap("uuid", conceptUuid)); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockExtIdMapEndpoint.expectedMessageCount(1); - mockProcessOrderEndpoint.expectedMessageCount(0); - mockExtIdMapEndpoint.expectedPropertyReceived("modelName", "product.product"); - mockExtIdMapEndpoint.expectedPropertyReceived("externalId", conceptUuid); - mockExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {emptyMap(), emptyMap()})); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - mockExtIdMapEndpoint.assertIsSatisfied(); - mockProcessOrderEndpoint.assertIsSatisfied(); - final String expectError = "Found 2 products in odoo mapped to uuid: " + conceptUuid; - assertEquals( - expectError, exchange.getProperty("error", EIPException.class).getMessage()); - } - - @Test - public void shouldSkipARenewOrderActionThatIsNotSupported() throws Exception { - Event event = createEvent("orders", "1", OdooTestConstants.ORDER_UUID_1, "c"); - final String action = "RENEW"; - Map orderResource = new HashMap(); - orderResource.put("action", action); - orderResource.put("type", "testorder"); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - assertMessageLogged(Level.WARN, "Don't know how to handle Order with action: " + action); - } - - @Test - public void shouldSkipAnUnknownOrderAction() throws Exception { - Event event = createEvent("orders", "1", OdooTestConstants.ORDER_UUID_1, "c"); - final String action = "UNKNOWN_ACTION"; - Map orderResource = new HashMap(); - orderResource.put("action", action); - orderResource.put("type", "testorder"); - final String orderJson = mapper.writeValueAsString(orderResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(orderJson)); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - - producerTemplate.send(OdooTestConstants.URI_ORDER_HANDLER, exchange); - - assertMessageLogged(Level.WARN, "Don't know how to handle Order with action: " + action); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooPatientAssociationHandlerRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooPatientAssociationHandlerRouteTest.java deleted file mode 100644 index 2b6474e0..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooPatientAssociationHandlerRouteTest.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_ENTITY; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_IS_SUBRESOURCE; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_RESOURCE_ID; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_RESOURCE_NAME; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.PATIENT_ID_UUID; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.PATIENT_UUID; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.URI_GET_ENTITY_BY_UUID; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.URI_MOCK_GET_ENTITY_BY_UUID; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.URI_PATIENT_ASSOCIATION_HANDLER; -import static java.util.Collections.singletonMap; -import static org.openmrs.eip.mysql.watcher.WatcherConstants.PROP_EVENT; - -import ch.qos.logback.classic.Level; -import java.util.HashMap; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openmrs.eip.mysql.watcher.Event; - -public class OdooPatientAssociationHandlerRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "odoo-patient-association-handler"; - - public static final String EX_PROP_PATIENT = "patient"; - - @EndpointInject("mock:odoo-patient-handler") - private MockEndpoint mockPatientHandlerEndpoint; - - @EndpointInject(URI_MOCK_GET_ENTITY_BY_UUID) - private MockEndpoint mockFetchResourceEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("odoo-patient-association-handler.xml"); - - mockFetchResourceEndpoint.reset(); - mockPatientHandlerEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(URI_GET_ENTITY_BY_UUID) - .skipSendToOriginalEndpoint() - .to(mockFetchResourceEndpoint); - interceptSendToEndpoint("direct:odoo-patient-handler") - .skipSendToOriginalEndpoint() - .to(mockPatientHandlerEndpoint); - } - }); - } - - @Test - public void shouldLoadThePatientWhenProcessingPersonName() throws Exception { - final String personUuid = "ba3b12d1-5c4f-415f-871b-b98a22137604"; - var personResource = singletonMap("uuid", personUuid); - var nameResource = new HashMap<>(); - final String nameUuid = "0bca417f-fc68-40d7-ae6f-cffca7a5eff1"; - nameResource.put("uuid", nameUuid); - nameResource.put("person", personResource); - var patientResource = new HashMap<>(); - patientResource.put("uuid", personUuid); - Event event = createEvent("person_name", "1", nameUuid, "c"); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(EX_PROP_ENTITY, nameResource); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_ID, personUuid); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - - mockFetchResourceEndpoint.reset(); - mockPatientHandlerEndpoint.reset(); - - producerTemplate.send(URI_PATIENT_ASSOCIATION_HANDLER, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldLoadThePatientWhenProcessingPersonAddress() throws Exception { - final String personUuid = "ba3b12d1-5c4f-415f-871b-b98a22137604"; - var personResource = singletonMap("uuid", personUuid); - var addressResource = new HashMap<>(); - final String addressUuid = "359022bf-4a58-4732-8cce-1e57f72f47b0"; - addressResource.put("uuid", addressUuid); - addressResource.put("person", personResource); - var patientResource = new HashMap<>(); - patientResource.put("uuid", personUuid); - Event event = createEvent("person_address", "1", addressUuid, "c"); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(EX_PROP_ENTITY, addressResource); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_ID, personUuid); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockFetchResourceEndpoint.reset(); - mockPatientHandlerEndpoint.reset(); - - producerTemplate.send(URI_PATIENT_ASSOCIATION_HANDLER, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldLoadThePatientWhenProcessingPatientIdentifier() throws Exception { - var patientResource = new HashMap<>(); - patientResource.put("uuid", PATIENT_UUID); - var idResource = new HashMap<>(); - idResource.put("uuid", PATIENT_ID_UUID); - idResource.put("patient", patientResource); - Event event = createEvent("patient_identifier", "1", PATIENT_ID_UUID, "c"); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(EX_PROP_ENTITY, idResource); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_ID, PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockFetchResourceEndpoint.reset(); - mockPatientHandlerEndpoint.reset(); - - producerTemplate.send(URI_PATIENT_ASSOCIATION_HANDLER, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldFailIfNoPatientIsFound() throws Exception { - final String personUuid = "ba3b12d1-5c4f-415f-871b-b98a22137604"; - var personResource = singletonMap("uuid", personUuid); - var addressResource = new HashMap<>(); - final String addressUuid = "359022bf-4a58-4732-8cce-1e57f72f47b0"; - addressResource.put("uuid", addressUuid); - addressResource.put("person", personResource); - Event event = createEvent("person_address", "1", addressUuid, "c"); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - addressResource.put("person", personResource); - exchange.setProperty(EX_PROP_ENTITY, addressResource); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_ID, personUuid); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(null)); - mockPatientHandlerEndpoint.expectedMessageCount(0); - - producerTemplate.send(URI_PATIENT_ASSOCIATION_HANDLER, exchange); - - mockPatientHandlerEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.WARN, "No associated patient found with uuid: " + personUuid); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooPatientHandlerRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooPatientHandlerRouteTest.java deleted file mode 100644 index 60d81a0b..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooPatientHandlerRouteTest.java +++ /dev/null @@ -1,455 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_ODOO_PATIENT_ID; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.openmrs.eip.mysql.watcher.WatcherConstants.PROP_EVENT; - -import ch.qos.logback.classic.Level; -import java.util.HashMap; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openmrs.eip.AppContext; -import org.openmrs.eip.mysql.watcher.Event; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.support.TestPropertySourceUtils; - -@TestPropertySource(properties = "openmrs.identifier.type.uuid=" + OdooPatientHandlerRouteTest.ID_TYPE_UUID) -public class OdooPatientHandlerRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "odoo-patient-handler"; - - public static final String EX_PROP_PATIENT = "patient"; - - public static final String EX_PROP_CREATE_CUSTOMER = "createCustomerIfNotExist"; - - public static final String EX_PROP_CUSTOM_DATA = "customPatientData"; - - public static final String ID_TYPE_UUID = "8d79403a-c2cc-11de-8d13-0010c6dffd0f"; - - public static final String ID_TYPE_ID_KEY = "odoo-patient-handler-idTypeId"; - - @EndpointInject("mock:odoo-get-customer") - private MockEndpoint mockGetCustomerEndpoint; - - @EndpointInject("mock:odoo-manage-customer") - private MockEndpoint mockManageCustomerEndpoint; - - @EndpointInject("mock:odoo-get-quotations") - private MockEndpoint mockGetQuotesEndpoint; - - @EndpointInject("mock:odoo-cancel-quotations") - private MockEndpoint mockCancelQuotesEndpoint; - - @EndpointInject("mock:odoo-process-person-address") - private MockEndpoint mockProcessAddressEndpoint; - - @EndpointInject("mock:callback-get-custom-customer-data") - private MockEndpoint mockGetCustomDataEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory(ROUTE_ID + ".xml"); - - AppContext.remove(ID_TYPE_ID_KEY); - mockGetCustomerEndpoint.reset(); - mockManageCustomerEndpoint.reset(); - mockProcessAddressEndpoint.reset(); - mockGetQuotesEndpoint.reset(); - mockCancelQuotesEndpoint.reset(); - mockGetCustomDataEndpoint.reset(); - mockGetCustomerEndpoint.expectedMessageCount(1); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint("direct:odoo-get-customer") - .skipSendToOriginalEndpoint() - .to(mockGetCustomerEndpoint); - interceptSendToEndpoint("direct:callback-get-custom-customer-data") - .skipSendToOriginalEndpoint() - .to(mockGetCustomDataEndpoint); - interceptSendToEndpoint("direct:odoo-manage-customer") - .skipSendToOriginalEndpoint() - .to(mockManageCustomerEndpoint); - interceptSendToEndpoint("direct:odoo-process-person-address") - .skipSendToOriginalEndpoint() - .to(mockProcessAddressEndpoint); - interceptSendToEndpoint("direct:odoo-get-quotations") - .skipSendToOriginalEndpoint() - .to(mockGetQuotesEndpoint); - interceptSendToEndpoint("direct:odoo-cancel-quotations") - .skipSendToOriginalEndpoint() - .to(mockCancelQuotesEndpoint); - } - }); - } - - @AfterEach - public void tearDown() throws Exception { - mockGetCustomerEndpoint.assertIsSatisfied(); - TestPropertySourceUtils.addInlinedPropertiesToEnvironment(env, "create.customer.if.not.exist=false"); - } - - @Test - public void shouldFailIfThePatientHasMultipleCustomerRecordsInOdoo() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - var patientResource = singletonMap("uuid", OdooTestConstants.PATIENT_UUID); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {1, 2})); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - assertEquals( - "Found 2 existing customers in odoo with ref: " + OdooTestConstants.PATIENT_UUID, - getErrorMessage(exchange)); - } - - @Test - public void shouldSkipPatientsWithNoCustomerRecordAndTheEventIsForAPatient() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - assertMessageLogged(Level.DEBUG, "Patient has no customer record in Odoo, there is nothing to be processed"); - } - - @Test - public void shouldSkipPatientsWithNoCustomerRecordAndTheEventIsForAPersonName() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - assertMessageLogged(Level.DEBUG, "Patient has no customer record in Odoo, there is nothing to be processed"); - } - - @Test - public void shouldSkipPatientsWithNoCustomerRecordAndTheEventIsForAPersonAddress() throws Exception { - final Exchange exchange = new DefaultExchange(camelContext); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - assertMessageLogged(Level.DEBUG, "Patient has no customer record in Odoo, there is nothing to be processed"); - } - - @Test - public void shouldAddPatientToOdooIfTheyDoNotExistAddCreateCustomerPropIsSetToTrue() throws Exception { - Event event = createEvent("orders", "1", "order-uuid", "c"); - final Exchange exchange = new DefaultExchange(camelContext); - var personResource = new HashMap<>(); - final String name = "Test User"; - personResource.put("display", name); - var addressResource = new HashMap<>(); - addressResource.put("address1", "25 Ocean drive"); - personResource.put("preferredAddress", addressResource); - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - patientResource.put("person", personResource); - exchange.setProperty(EX_PROP_ODOO_PATIENT_ID, 12); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(EX_PROP_CREATE_CUSTOMER, true); - exchange.setProperty(PROP_EVENT, event); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - mockProcessAddressEndpoint.expectedMessageCount(1); - mockProcessAddressEndpoint.expectedPropertyReceived("preferredAddress", addressResource); - final int countryId = 4; - final int stateId = 5; - final int patientId = 12; - mockProcessAddressEndpoint.whenAnyExchangeReceived(e -> { - e.setProperty("odooCountryId", countryId); - e.setProperty("odooStateId", stateId); - }); - - mockGetCustomDataEndpoint.expectedMessageCount(0); - mockManageCustomerEndpoint.expectedMessageCount(1); - mockManageCustomerEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_WRITE); - mockManageCustomerEndpoint.expectedPropertyReceived("patient-name", name); - mockManageCustomerEndpoint.expectedPropertyReceived("patient", patientResource); - mockManageCustomerEndpoint.expectedPropertyReceived("patientIdentifier", "12345"); - mockManageCustomerEndpoint.expectedPropertyReceived("preferredAddress", addressResource); - mockManageCustomerEndpoint.expectedPropertyReceived("odooCountryId", countryId); - mockManageCustomerEndpoint.expectedPropertyReceived("odooStateId", stateId); - mockManageCustomerEndpoint.whenAnyExchangeReceived(e -> { - e.getIn().setBody(patientId); - }); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - // mockProcessAddressEndpoint.assertIsSatisfied(); - mockManageCustomerEndpoint.assertIsSatisfied(); - assertEquals(patientId, exchange.getProperty(EX_PROP_ODOO_PATIENT_ID)); - assertFalse(exchange.getProperty("isPatientVoidedOrDeleted", Boolean.class)); - } - - @Test - public void - shouldAddPatientToOdooIfTheyDoNotExistAddCreateCustomerPropIsSetToFalseGivenshouldSyncAnyPatientAsCustomerIsTrue() - throws Exception { - // setup - TestPropertySourceUtils.addInlinedPropertiesToEnvironment(env, "create.customer.if.not.exist=true"); - Event event = createEvent("orders", "1", "order-uuid", "c"); - final Exchange exchange = new DefaultExchange(camelContext); - var personResource = new HashMap<>(); - final String name = "Test User"; - personResource.put("display", name); - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - patientResource.put("person", personResource); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(EX_PROP_ODOO_PATIENT_ID, 12); - exchange.setProperty(EX_PROP_CREATE_CUSTOMER, false); - exchange.setProperty(PROP_EVENT, event); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - mockGetCustomDataEndpoint.expectedMessageCount(0); - mockProcessAddressEndpoint.expectedMessageCount(0); - mockManageCustomerEndpoint.expectedMessageCount(1); - mockManageCustomerEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - mockManageCustomerEndpoint.expectedPropertyReceived("patient-name", name); - mockManageCustomerEndpoint.expectedPropertyReceived("patient", patientResource); - mockManageCustomerEndpoint.expectedPropertyReceived("patientIdentifier", "12345"); - final int patientId = 12; - mockManageCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientId)); - - // replay - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - // verify - mockProcessAddressEndpoint.assertIsSatisfied(); - // mockManageCustomerEndpoint.assertIsSatisfied(); - mockGetCustomDataEndpoint.assertIsSatisfied(); - assertEquals(patientId, exchange.getProperty(EX_PROP_ODOO_PATIENT_ID)); - assertFalse(exchange.getProperty("isPatientVoidedOrDeleted", Boolean.class)); - assertMessageLogged(Level.DEBUG, "Patient has no address"); - } - - @Test - public void shouldAddPatientWithoutAddressToOdooIfTheyDoNotExistAndCreateCustomerPropIsSetToTrue() - throws Exception { - Event event = createEvent("orders", "1", "order-uuid", "c"); - final Exchange exchange = new DefaultExchange(camelContext); - var personResource = new HashMap<>(); - final String name = "Test User"; - personResource.put("display", name); - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - patientResource.put("person", personResource); - exchange.setProperty(EX_PROP_ODOO_PATIENT_ID, 12); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(EX_PROP_CREATE_CUSTOMER, true); - exchange.setProperty(PROP_EVENT, event); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - mockGetCustomDataEndpoint.expectedMessageCount(0); - mockProcessAddressEndpoint.expectedMessageCount(0); - mockManageCustomerEndpoint.expectedMessageCount(1); - mockManageCustomerEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - mockManageCustomerEndpoint.expectedPropertyReceived("patient-name", name); - mockManageCustomerEndpoint.expectedPropertyReceived("patient", patientResource); - mockManageCustomerEndpoint.expectedPropertyReceived("patientIdentifier", "12345"); - final int patientId = 12; - mockManageCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientId)); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - mockProcessAddressEndpoint.assertIsSatisfied(); - // mockManageCustomerEndpoint.assertIsSatisfied(); - mockGetCustomDataEndpoint.assertIsSatisfied(); - assertEquals(patientId, exchange.getProperty(EX_PROP_ODOO_PATIENT_ID)); - assertFalse(exchange.getProperty("isPatientVoidedOrDeleted", Boolean.class)); - assertMessageLogged(Level.DEBUG, "Patient has no address"); - } - - @Test - public void shouldUpdatePatientInOdooIfTheyAlreadyExist() throws Exception { - final int patientId = 16; - Event event = createEvent("orders", "1", "order-uuid", "c"); - final Exchange exchange = new DefaultExchange(camelContext); - var personResource = new HashMap<>(); - final String name = "Another Test User"; - personResource.put("display", name); - var addressResource = new HashMap<>(); - addressResource.put("address1s", "26 Oceanic drives"); - personResource.put("preferredAddress", addressResource); - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - patientResource.put("person", personResource); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(PROP_EVENT, event); - mockGetCustomDataEndpoint.expectedMessageCount(0); - mockGetCustomerEndpoint.expectedMessageCount(1); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {patientId})); - - final int countryId = 4; - final int stateId = 5; - mockProcessAddressEndpoint.expectedMessageCount(1); - mockProcessAddressEndpoint.expectedPropertyReceived("preferredAddress", addressResource); - mockProcessAddressEndpoint.whenAnyExchangeReceived(e -> { - e.setProperty("odooCountryId", countryId); - e.setProperty("odooStateId", stateId); - }); - - mockManageCustomerEndpoint.expectedMessageCount(1); - mockManageCustomerEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_WRITE); - mockManageCustomerEndpoint.expectedPropertyReceived("patient-name", name); - mockManageCustomerEndpoint.expectedPropertyReceived("patient", patientResource); - mockManageCustomerEndpoint.expectedPropertyReceived("patientIdentifier", "12345"); - mockManageCustomerEndpoint.expectedPropertyReceived("preferredAddress", addressResource); - mockManageCustomerEndpoint.expectedPropertyReceived("odooCountryId", countryId); - mockManageCustomerEndpoint.expectedPropertyReceived("odooStateId", stateId); - mockManageCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientId)); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - // mockProcessAddressEndpoint.assertIsSatisfied(); - mockManageCustomerEndpoint.assertIsSatisfied(); - mockGetCustomDataEndpoint.assertIsSatisfied(); - assertEquals(patientId, exchange.getProperty(EX_PROP_ODOO_PATIENT_ID)); - assertFalse(exchange.getProperty("isPatientVoidedOrDeleted", Boolean.class)); - } - - @Test - public void shouldNotUpdateTheCustomerInOdooIfTheyAlreadyExistWhenSkipCustomerUpdateIsSetToTrue() throws Exception { - final int patientId = 16; - Event event = createEvent("orders", "1", "order-uuid", "c"); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_PATIENT, new HashMap<>()); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(OdooTestConstants.EX_PROP_SKIP_CUSTOMER_UPDATE, true); - mockGetCustomerEndpoint.expectedMessageCount(1); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {patientId})); - mockProcessAddressEndpoint.expectedMessageCount(0); - mockGetCustomDataEndpoint.expectedMessageCount(0); - mockManageCustomerEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - mockGetCustomDataEndpoint.assertIsSatisfied(); - mockProcessAddressEndpoint.assertIsSatisfied(); - mockManageCustomerEndpoint.assertIsSatisfied(); - assertEquals(patientId, exchange.getProperty(EX_PROP_ODOO_PATIENT_ID)); - assertNull(exchange.getProperty("isPatientVoidedOrDeleted")); - } - - @Test - public void shouldNotAddAVoidedPatientToOdooIfTheyDoNotExist() throws Exception { - Event event = createEvent("orders", "1", "some-uuid", "c"); - final Exchange exchange = new DefaultExchange(camelContext); - var patientResource = new HashMap<>(); - patientResource.put("patientVoided", true); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(PROP_EVENT, event); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - assertMessageLogged( - Level.INFO, "No action to take for voided patient since they have no customer record in odoo"); - } - - @Test - public void shouldInactiveCustomerAndCancelTheirQuotationsForAVoidedPatientThatExistsInOdoo() throws Exception { - final Integer patientId = 18; - Event event = createEvent("patient", "1", OdooTestConstants.PATIENT_UUID, "u"); - final Exchange exchange = new DefaultExchange(camelContext); - var patientResource = singletonMap("voided", true); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(PROP_EVENT, event); - mockProcessAddressEndpoint.expectedMessageCount(0); - mockGetCustomDataEndpoint.expectedMessageCount(0); - - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {patientId})); - - mockManageCustomerEndpoint.expectedMessageCount(1); - mockManageCustomerEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_WRITE); - - mockGetQuotesEndpoint.expectedMessageCount(1); - mockGetQuotesEndpoint.expectedPropertyReceived(EX_PROP_ODOO_PATIENT_ID, patientId); - final Integer[] quotationIds = new Integer[] {1, 2}; - mockGetQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quotationIds)); - - mockCancelQuotesEndpoint.expectedMessageCount(1); - mockCancelQuotesEndpoint.expectedPropertyReceived("quotationIds", quotationIds); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - mockProcessAddressEndpoint.assertIsSatisfied(); - mockManageCustomerEndpoint.assertIsSatisfied(); - mockGetQuotesEndpoint.assertIsSatisfied(); - mockCancelQuotesEndpoint.assertIsSatisfied(); - mockGetCustomDataEndpoint.assertIsSatisfied(); - assertTrue(exchange.getProperty("isPatientVoidedOrDeleted", Boolean.class)); - } - - @Test - public void shouldNotCallCancelQuotationsForAVoidedPatientIfTheyHaveNone() throws Exception { - final Integer patientId = 18; - Event event = createEvent("patient", "1", OdooTestConstants.PATIENT_UUID, "u"); - final Exchange exchange = new DefaultExchange(camelContext); - var patientResource = singletonMap("voided", true); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(PROP_EVENT, event); - mockProcessAddressEndpoint.expectedMessageCount(0); - mockCancelQuotesEndpoint.expectedMessageCount(0); - - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {patientId})); - - mockManageCustomerEndpoint.expectedMessageCount(1); - mockManageCustomerEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_WRITE); - - mockGetQuotesEndpoint.expectedMessageCount(1); - mockGetQuotesEndpoint.expectedPropertyReceived(EX_PROP_ODOO_PATIENT_ID, patientId); - mockGetQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - - mockProcessAddressEndpoint.assertIsSatisfied(); - mockManageCustomerEndpoint.assertIsSatisfied(); - mockGetQuotesEndpoint.assertIsSatisfied(); - mockCancelQuotesEndpoint.assertIsSatisfied(); - assertTrue(exchange.getProperty("isPatientVoidedOrDeleted", Boolean.class)); - } - - @Test - public void shouldFailIfNoPatientIdentifierTypeIsFoundMatchingTheUuid() throws Exception { - Event event = createEvent("orders", "1", "order-uuid", "c"); - final Exchange exchange = new DefaultExchange(camelContext); - producerTemplate.send( - "sql:UPDATE patient_identifier_type set uuid = 'other' WHERE uuid = '" + ID_TYPE_UUID - + "'?dataSource=#openmrsDataSource", - exchange); - exchange.setProperty(EX_PROP_PATIENT, new HashMap<>()); - exchange.setProperty(EX_PROP_CREATE_CUSTOMER, true); - exchange.setProperty(PROP_EVENT, event); - mockGetCustomerEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - mockProcessAddressEndpoint.expectedMessageCount(0); - mockManageCustomerEndpoint.expectedMessageCount(0); - - try { - producerTemplate.send(OdooTestConstants.URI_PATIENT_HANDLER, exchange); - } catch (Exception e) { - assertTrue(e.getMessage().contains("No patient identifier type found with uuid: " + ID_TYPE_UUID)); - } - - mockGetCustomerEndpoint.assertIsSatisfied(); - mockProcessAddressEndpoint.assertIsSatisfied(); - mockManageCustomerEndpoint.assertIsSatisfied(); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessDiscontinueOrVoidedOrderRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessDiscontinueOrVoidedOrderRouteTest.java deleted file mode 100644 index c3ff7aee..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessDiscontinueOrVoidedOrderRouteTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import java.util.Collections; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class OdooProcessDiscontinueOrVoidedOrderRouteTest extends BaseOrderOdooRouteTest { - - private static final String ROUTE_ID = "odoo-process-dc-or-voided-order"; - - public static final String URI_PROCESS_DC_OR_REV_ORDER = "direct:odoo-process-dc-or-voided-order"; - - public static final String EX_PROP_ORDER_LINE = "order-line"; - - public static final String EX_PROP_ORDER_LINE_COUNT = "order-line-count"; - - @EndpointInject("mock:odoo-manage-order-line") - private MockEndpoint mockManageOrderLineEndpoint; - - @EndpointInject("mock:odoo-manage-quotation") - private MockEndpoint mockManageQuotationEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("odoo-process-dc-or-voided-order.xml"); - - mockManageOrderLineEndpoint.reset(); - mockManageQuotationEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint("direct:odoo-manage-order-line") - .skipSendToOriginalEndpoint() - .to(mockManageOrderLineEndpoint); - interceptSendToEndpoint("direct:odoo-manage-quotation") - .skipSendToOriginalEndpoint() - .to(mockManageQuotationEndpoint); - } - }); - } - - @Test - public void shouldProcessOrderWithNoLine() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_ORDER_LINE_COUNT, 2); - mockManageOrderLineEndpoint.expectedMessageCount(0); - mockManageQuotationEndpoint.expectedMessageCount(0); - - producerTemplate.send(URI_PROCESS_DC_OR_REV_ORDER, exchange); - - mockManageOrderLineEndpoint.assertIsSatisfied(); - mockManageQuotationEndpoint.assertIsSatisfied(); - Assertions.assertEquals( - OdooTestConstants.ODOO_OP_UNLINK, exchange.getProperty(OdooTestConstants.EX_PROP_ODOO_OP)); - } - - @Test - public void shouldRemoveTheOrderLineFromTheQuote() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_ORDER_LINE, Collections.emptyMap()); - exchange.setProperty(EX_PROP_ORDER_LINE_COUNT, 2); - mockManageOrderLineEndpoint.expectedMessageCount(1); - mockManageQuotationEndpoint.expectedMessageCount(0); - mockManageOrderLineEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_UNLINK); - - producerTemplate.send(URI_PROCESS_DC_OR_REV_ORDER, exchange); - - mockManageOrderLineEndpoint.assertIsSatisfied(); - mockManageQuotationEndpoint.assertIsSatisfied(); - Assertions.assertEquals( - OdooTestConstants.ODOO_OP_UNLINK, exchange.getProperty(OdooTestConstants.EX_PROP_ODOO_OP)); - } - - @Test - public void shouldCancelTheQuotationIfItHasNoMoreOrderLines() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_ORDER_LINE_COUNT, 1); - mockManageQuotationEndpoint.expectedMessageCount(1); - mockManageQuotationEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_WRITE); - - producerTemplate.send(URI_PROCESS_DC_OR_REV_ORDER, exchange); - - mockManageQuotationEndpoint.assertIsSatisfied(); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessNewOrderRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessNewOrderRouteTest.java deleted file mode 100644 index 1c87bda2..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessNewOrderRouteTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.openmrs.eip.mysql.watcher.WatcherConstants.PROP_EVENT; - -import ch.qos.logback.classic.Level; -import java.util.Collections; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.openmrs.eip.mysql.watcher.Event; - -public class OdooProcessNewOrderRouteTest extends BaseOrderOdooRouteTest { - - private static final String ROUTE_ID = "odoo-process-new-order"; - - public static final String URI_PROCESS_NEW_ORDER = "direct:odoo-process-new-order"; - - public static final String EX_PROP_ORDER_LINE = "order-line"; - - @EndpointInject("mock:odoo-manage-order-line") - private MockEndpoint mockManageOrderLineEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("odoo-process-new-order.xml"); - - mockManageOrderLineEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint("direct:odoo-manage-order-line") - .skipSendToOriginalEndpoint() - .to(mockManageOrderLineEndpoint); - } - }); - } - - @Test - public void shouldFailIfThereIsAnExistingOrderLineWhenProcessingAnOrderEvent() { - Event event = createEvent("orders", "1", "order-uuid", "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - exchange.setProperty(EX_PROP_ORDER_LINE, Collections.emptyMap()); - - producerTemplate.send(URI_PROCESS_NEW_ORDER, exchange); - - assertEquals( - "There is already an existing order line on the quotation for the same orderable in odoo", - getErrorMessage(exchange)); - } - - @Test - public void shouldIgnoreDrugOrderTableEvent() throws Exception { - final String tableName = "drug_order"; - Event event = createEvent(tableName, "1", "order-uuid", "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - mockManageOrderLineEndpoint.expectedMessageCount(0); - - producerTemplate.send(URI_PROCESS_NEW_ORDER, exchange); - - mockManageOrderLineEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.INFO, "Ignoring event for new order from subclass table: " + tableName); - } - - @Test - public void shouldIgnoreTestOrderTableEvent() throws Exception { - final String tableName = "test_order"; - Event event = createEvent(tableName, "1", "order-uuid", "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - mockManageOrderLineEndpoint.expectedMessageCount(0); - - producerTemplate.send(URI_PROCESS_NEW_ORDER, exchange); - - mockManageOrderLineEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.INFO, "Ignoring event for new order from subclass table: " + tableName); - } - - @Test - public void shouldProcessOrderTableEvent() throws Exception { - Event event = createEvent("orders", "1", "order-uuid", "c"); - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(PROP_EVENT, event); - mockManageOrderLineEndpoint.expectedMessageCount(1); - mockManageOrderLineEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - - producerTemplate.send(URI_PROCESS_NEW_ORDER, exchange); - - mockManageOrderLineEndpoint.assertIsSatisfied(); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessOrderRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessOrderRouteTest.java deleted file mode 100644 index c19d785f..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessOrderRouteTest.java +++ /dev/null @@ -1,1840 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; - -import ch.qos.logback.classic.Level; -import java.util.HashMap; -import java.util.Map; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -@Disabled("This test is takes too long to run") -public class OdooProcessOrderRouteTest extends BaseOrderOdooRouteTest { - - private static final String ROUTE_ID = "odoo-process-order"; - - public static final String EX_PROP_IS_NEW = "is-new"; - - public static final String EX_PROP_IS_DRUG_ORDER = "is-drug-order"; - - public static final String EX_PROP_MODEL_NAME = "modelName"; - - public static final String EX_PROP_EXT_ID = "externalId"; - - public static final String EX_PROP_PATIENT = "patient"; - - public static final String EX_PROP_ORDER_LINE = "order-line"; - - public static final String EX_PROP_ORDER_LINE_COUNT = "order-line-count"; - - public static final String EX_PROP_QUOTE_ID = "quotation-id"; - - public static final String EX_PROP_UNITS_ID = "unitsId"; - - public static final String EX_PROP_CREATE_CUSTOMER = "createCustomerIfNotExist"; - - public static final String EX_PROP_DESC = "description"; - - @EndpointInject("mock:odoo-patient-handler") - private MockEndpoint mockPatientHandlerEndpoint; - - @EndpointInject("mock:odoo-get-draft-quotations") - private MockEndpoint mockGetDraftQuotesEndpoint; - - @EndpointInject("mock:odoo-manage-quotation") - private MockEndpoint mockManageQuoteEndpoint; - - @EndpointInject("mock:odoo-get-order-line") - private MockEndpoint mockGetOrderLineEndpoint; - - @EndpointInject("mock:odoo-get-external-id-map") - private MockEndpoint mockGetExtIdMapEndpoint; - - @EndpointInject("mock:odoo-process-new-order") - private MockEndpoint mockProcessNewOrderEndpoint; - - @EndpointInject("mock:odoo-process-revision-order") - private MockEndpoint mockProcessRevOrderEndpoint; - - @EndpointInject("mock:odoo-process-dc-or-voided-order") - private MockEndpoint mockProcessDcOrVoidedOrderEndpoint; - - @EndpointInject(OdooTestConstants.URI_MOCK_GET_ENTITY_BY_UUID) - private MockEndpoint mockFetchResourceEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("odoo-process-order.xml"); - - mockFetchResourceEndpoint.reset(); - mockPatientHandlerEndpoint.reset(); - mockGetDraftQuotesEndpoint.reset(); - mockManageQuoteEndpoint.reset(); - mockGetOrderLineEndpoint.reset(); - mockGetExtIdMapEndpoint.reset(); - mockProcessNewOrderEndpoint.reset(); - mockProcessRevOrderEndpoint.reset(); - mockProcessDcOrVoidedOrderEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint(OdooTestConstants.URI_GET_ENTITY_BY_UUID) - .skipSendToOriginalEndpoint() - .to(mockFetchResourceEndpoint); - interceptSendToEndpoint("direct:odoo-patient-handler") - .skipSendToOriginalEndpoint() - .to(mockPatientHandlerEndpoint); - interceptSendToEndpoint("direct:odoo-get-draft-quotations") - .skipSendToOriginalEndpoint() - .to(mockGetDraftQuotesEndpoint); - interceptSendToEndpoint("direct:odoo-manage-quotation") - .skipSendToOriginalEndpoint() - .to(mockManageQuoteEndpoint); - interceptSendToEndpoint("direct:odoo-get-order-line") - .skipSendToOriginalEndpoint() - .to(mockGetOrderLineEndpoint); - interceptSendToEndpoint("direct:odoo-get-external-id-map") - .skipSendToOriginalEndpoint() - .to(mockGetExtIdMapEndpoint); - interceptSendToEndpoint("direct:odoo-process-new-order") - .skipSendToOriginalEndpoint() - .to(mockProcessNewOrderEndpoint); - interceptSendToEndpoint("direct:odoo-process-revision-order") - .skipSendToOriginalEndpoint() - .to(mockProcessRevOrderEndpoint); - interceptSendToEndpoint("direct:odoo-process-dc-or-voided-order") - .skipSendToOriginalEndpoint() - .to(mockProcessDcOrVoidedOrderEndpoint); - } - }); - } - - @AfterEach - public void tearDown() throws Exception { - mockFetchResourceEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - mockGetDraftQuotesEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldFailIfThereIsMultipleDraftQuotationsForThePatient() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {emptyMap(), emptyMap()})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - assertEquals( - "Found 2 existing draft quotation(s) for the same patient created by this system in odoo", - getErrorMessage(exchange)); - } - - @Test - public void shouldProcessANewOrderForAPatientWithNoExistingQuote() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - } - - @Test - public void shouldProcessARevisionOrderForAPatientWithNoExistingQuote() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "REVISE"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - } - - @Test - public void shouldProcessADiscontinueOrderAndThePatientHasNoExistingQuote() throws Exception { - mockManageQuoteEndpoint.reset(); - mockProcessNewOrderEndpoint.reset(); - mockProcessRevOrderEndpoint.reset(); - mockProcessDcOrVoidedOrderEndpoint.reset(); - mockFetchResourceEndpoint.reset(); - mockPatientHandlerEndpoint.reset(); - mockGetDraftQuotesEndpoint.reset(); - - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertFalse(exchange.getProperty(EX_PROP_CREATE_CUSTOMER, Boolean.class)); - } - - @Test - public void shouldProcessAVoidedOrderAndThePatientHasNoExistingQuote() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - orderResource.put("voided", true); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertFalse(exchange.getProperty(EX_PROP_CREATE_CUSTOMER, Boolean.class)); - } - - @Test - public void shouldProcessANewOrderForAPatientWithAnExistingQuote() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - final Integer quoteId = 7; - var quote = new HashMap<>(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - var orderLine = singletonMap("id", 123); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {orderLine})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(orderLine, exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(orderLines.length, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - } - - @Test - public void shouldProcessARevisionOrderForAPatientWithAnExistingQuote() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "REVISE"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - final Integer quoteId = 7; - var quote = new HashMap<>(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - var orderLine = singletonMap("id", 123); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {orderLine})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(orderLine, exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(orderLines.length, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - } - - @Test - public void shouldProcessADiscontinueOrderAndThePatientHasAnExistingQuote() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - final Integer quoteId = 7; - var quote = new HashMap<>(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - var orderLine = singletonMap("id", 123); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {orderLine})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(orderLine, exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(orderLines.length, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertFalse(exchange.getProperty(EX_PROP_CREATE_CUSTOMER, Boolean.class)); - } - - @Test - public void shouldProcessAVoidedOrderAndThePatientHasAnExistingQuote() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - orderResource.put("voided", true); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - final Integer quoteId = 7; - var quote = new HashMap<>(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - var orderLine = singletonMap("id", 123); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {orderLine})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(orderLine, exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(orderLines.length, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertFalse(exchange.getProperty(EX_PROP_CREATE_CUSTOMER, Boolean.class)); - } - - @Test - public void shouldFailIfMultipleLinesAreFoundForTheSameOrderableOnAnExistingQuotation() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - final Integer quoteId = 7; - var quote = new HashMap<>(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {emptyMap(), emptyMap()})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(orderLines.length, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals( - "Found 2 lines for the same product added to the draft quotation in odoo", getErrorMessage(exchange)); - } - - @Test - public void - shouldProcessOrderIfNoLineIsFoundForTheOrderableOnAnExistingQuotationAndOrderLineCountWasGreaterThanZero() - throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_ORDER_LINE_COUNT, 2); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - final Integer quoteId = 7; - var quote = new HashMap<>(); - quote.put("id", quoteId); - Integer[] orderLines = new Integer[] {1, 2}; - quote.put("order_line", orderLines); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - - mockGetOrderLineEndpoint.expectedMessageCount(1); - mockGetOrderLineEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - - assertEquals(orderLines.length, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertMessageLogged(Level.INFO, "No order line found on the draft quotation in odoo"); - } - - @Test - public void shouldNotProcessAVoidedOrderForAPatientWithNoOdooRecord() throws Exception { - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - orderResource.put("voided", true); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockGetDraftQuotesEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockPatientHandlerEndpoint.assertIsSatisfied(); - assertMessageLogged( - Level.INFO, - "No action to take for a voided or discontinuation order because the patient has no customer record in odoo"); - } - - @Test - public void shouldNotProcessADiscontinueOrderForAPatientWithNoOdooRecord() throws Exception { - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockGetDraftQuotesEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockPatientHandlerEndpoint.assertIsSatisfied(); - assertMessageLogged( - Level.INFO, - "No action to take for a voided or discontinuation order because the patient has no customer record in odoo"); - } - - @Test - public void shouldProcessAnOrderWithNoExistingLineForAnExistingQuotation() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedMessageCount(0); - mockGetOrderLineEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - final Integer quoteId = 7; - var quote = new HashMap<>(); - quote.put("id", quoteId); - quote.put("order_line", new Integer[] {}); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {quote})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetOrderLineEndpoint.assertIsSatisfied(); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertMessageLogged(Level.INFO, "No order line found on the draft quotation in odoo"); - } - - @Test - public void shouldProcessQuantityDetailsAndDosingInstructionsForANewDrugOrder() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Integer qty = 2; - final String tabs = "Tabs"; - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnitsResource = new HashMap<>(); - quantityUnitsResource.put("uuid", qtyUnitsUuid); - quantityUnitsResource.put("display", tabs); - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - orderResource.put("quantity", qty); - orderResource.put("quantityUnits", quantityUnitsResource); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - final Integer unitsId = 4; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived( - e -> e.getIn().setBody(new Map[] {singletonMap("res_id", unitsId)})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals(unitsId, exchange.getProperty(EX_PROP_UNITS_ID)); // Aspirin | 2 Tabs | 500.0 mg - Daily - 1 Week - final String description = drugName + " | " + qty + " " + tabs + " | " + dose.toString() + " " + mg + " - " - + daily + " - " + duration + " " + week; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldProcessQuantityDetailsAndDosingInstructionsForANewDrugOrderAppedingOrdererToDescription() - throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - var ordererResource = new HashMap<>(); - ordererResource.put("display", "Test - Test User"); - orderResource.put("orderer", ordererResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Integer qty = 2; - final String tabs = "Tabs"; - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnitsResource = new HashMap<>(); - quantityUnitsResource.put("uuid", qtyUnitsUuid); - quantityUnitsResource.put("display", tabs); - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - orderResource.put("quantity", qty); - orderResource.put("quantityUnits", quantityUnitsResource); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - final Integer unitsId = 4; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived( - e -> e.getIn().setBody(new Map[] {singletonMap("res_id", unitsId)})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals(unitsId, exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + qty + " " + tabs + " | " + dose.toString() + " " + mg + " - " - + daily + " - " + duration + " " + week + " | " + "Orderer: " - + ((String) ordererResource.get("display")).split(" - ")[1]; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldProcessQuantityDetailsAndDosingInstructionsWithAdditionalInstructionsForANewDrugOrder() - throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Integer qty = 2; - final String tabs = "Tabs"; - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnitsResource = new HashMap<>(); - quantityUnitsResource.put("uuid", qtyUnitsUuid); - quantityUnitsResource.put("display", tabs); - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - orderResource.put("quantity", qty); - orderResource.put("quantityUnits", quantityUnitsResource); - orderResource.put("dosingInstructions", "Follow these additional instructions"); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - final Integer unitsId = 4; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived( - e -> e.getIn().setBody(new Map[] {singletonMap("res_id", unitsId)})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals(unitsId, exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + qty + " " + tabs + " | " + dose.toString() + " " + mg + " - " - + daily + " - " + duration + " " + week + " - " + "Follow these additional instructions"; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void - shouldProcessQuantityDetailsAndDosingInstructionsForANewDrugOrderAppedingCommentToFulfillerToDescription() - throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - orderResource.put("commentToFulfiller", "Some comment to fulfiller"); - var ordererResource = new HashMap<>(); - ordererResource.put("display", "Test - Test User"); - orderResource.put("orderer", ordererResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Integer qty = 2; - final String tabs = "Tabs"; - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnitsResource = new HashMap<>(); - quantityUnitsResource.put("uuid", qtyUnitsUuid); - quantityUnitsResource.put("display", tabs); - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - orderResource.put("quantity", qty); - orderResource.put("quantityUnits", quantityUnitsResource); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - final Integer unitsId = 4; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived( - e -> e.getIn().setBody(new Map[] {singletonMap("res_id", unitsId)})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals(unitsId, exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + qty + " " + tabs + " | " + dose.toString() + " " + mg + " - " - + daily + " - " + duration + " " + week + " | " + "Notes: " + orderResource.get("commentToFulfiller") - + " | " + "Orderer: " + ((String) ordererResource.get("display")).split(" - ")[1]; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldAppendCommentToFulfillerToDescription() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - orderResource.put("type", "order"); - orderResource.put("commentToFulfiller", "Some comment to fulfiller"); - var ordererResource = new HashMap<>(); - ordererResource.put("display", "Test - Test User"); - orderResource.put("orderer", ordererResource); - final String orderName = "Some order"; - orderResource.put("display", orderName); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, false); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - mockGetExtIdMapEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - final String description = orderName + " | " + "Notes: " + orderResource.get("commentToFulfiller") + " | " - + "Orderer: " + ((String) ordererResource.get("display")).split(" - ")[1]; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldProcessQuantityDetailsAndDosingInstructionsForARevisionDrugOrder() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "REVISE"); - orderResource.put("patient", patientResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(1); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Integer qty = 2; - final String tabs = "Tabs"; - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnitsResource = new HashMap<>(); - quantityUnitsResource.put("uuid", qtyUnitsUuid); - quantityUnitsResource.put("display", tabs); - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - orderResource.put("quantity", qty); - orderResource.put("quantityUnits", quantityUnitsResource); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - final Integer unitsId = 4; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived( - e -> e.getIn().setBody(new Map[] {singletonMap("res_id", unitsId)})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals(unitsId, exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + qty + " " + tabs + " | " + dose.toString() + " " + mg + " - " - + daily + " - " + duration + " " + week; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldProcessQuantityDetailsAndDosingInstructionsForARevisionDrugOrderAppedingOrdererToDescription() - throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "REVISE"); - orderResource.put("patient", patientResource); - var ordererResource = new HashMap<>(); - ordererResource.put("display", "Test - Test User"); - orderResource.put("orderer", ordererResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(1); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Integer qty = 2; - final String tabs = "Tabs"; - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnitsResource = new HashMap<>(); - quantityUnitsResource.put("uuid", qtyUnitsUuid); - quantityUnitsResource.put("display", tabs); - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - orderResource.put("quantity", qty); - orderResource.put("quantityUnits", quantityUnitsResource); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - final Integer unitsId = 4; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived( - e -> e.getIn().setBody(new Map[] {singletonMap("res_id", unitsId)})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals(unitsId, exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + qty + " " + tabs + " | " + dose + " " + mg + " - " - + daily + " - " + duration + " " + week + " | " + "Orderer: " - + ((String) ordererResource.get("display")).split(" - ")[1]; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void - shouldProcessQuantityDetailsAndDosingInstructionsForARevisionDrugOrderAppendingCommentToFulfillerToDescription() - throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "REVISE"); - orderResource.put("patient", patientResource); - var ordererResource = new HashMap<>(); - ordererResource.put("display", "Test - Test User"); - orderResource.put("orderer", ordererResource); - orderResource.put("commentToFulfiller", "Some comment to fulfiller"); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - exchange.setProperty(EX_PROP_UNITS_ID, 4); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(0); - mockProcessRevOrderEndpoint.expectedMessageCount(1); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Integer qty = 2; - final String tabs = "Tabs"; - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnitsResource = new HashMap<>(); - quantityUnitsResource.put("uuid", qtyUnitsUuid); - quantityUnitsResource.put("display", tabs); - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - orderResource.put("quantity", qty); - orderResource.put("quantityUnits", quantityUnitsResource); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - final Integer unitsId = 4; - mockGetExtIdMapEndpoint.whenAnyExchangeReceived( - e -> e.getIn().setBody(new Map[] {singletonMap("res_id", unitsId)})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals(unitsId, exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + qty + " " + tabs + " | " + dose + " " + mg + " - " - + daily + " - " + duration + " " + week + " | " + "Notes: " + orderResource.get("commentToFulfiller") - + " | " + "Orderer: " + ((String) ordererResource.get("display")).split(" - ")[1]; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldNotProcessQuantityDetailsIfTheyAreNoSetOnTheDrugOrder() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - orderResource.put("drug", singletonMap("display", "Aspirin")); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockGetExtIdMapEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertNull(exchange.getProperty(EX_PROP_UNITS_ID)); - } - - @Test - public void shouldFailIfTheQuantityUnitsAreNotMappedToAnyOdooUnits() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - orderResource.put("drug", singletonMap("display", "Aspirin")); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnits = singletonMap("uuid", qtyUnitsUuid); - orderResource.put("quantity", 2); - orderResource.put("quantityUnits", quantityUnits); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - mockGetExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals("No units of measure found in odoo mapped to uuid: " + qtyUnitsUuid, getErrorMessage(exchange)); - } - - @Test - public void shouldFailIfTheQuantityUnitsAreMappedToMultipleOdooUnits() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "NEW"); - orderResource.put("patient", patientResource); - orderResource.put("drug", singletonMap("display", "Aspirin")); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty( - OdooTestConstants.EX_PROP_TABLE_RESOURCE_MAP, singletonMap("patient", "patientRepository")); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final String qtyUnitsUuid = "some-units-uuid"; - final var quantityUnits = singletonMap("uuid", qtyUnitsUuid); - orderResource.put("quantity", 2); - orderResource.put("quantityUnits", quantityUnits); - mockGetExtIdMapEndpoint.expectedMessageCount(1); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_MODEL_NAME, "uom.uom"); - mockGetExtIdMapEndpoint.expectedPropertyReceived(EX_PROP_EXT_ID, qtyUnitsUuid); - mockGetExtIdMapEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {emptyMap(), emptyMap()})); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertEquals("Found 2 units of measure in odoo mapped to uuid: " + qtyUnitsUuid, getErrorMessage(exchange)); - } - - @Test - public void shouldSetDosingInstructionsWithNoDurationForDrugOrder() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - mockGetExtIdMapEndpoint.expectedMessageCount(0); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertNull(exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + dose.toString() + " " + mg + " - " + daily; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldSetDosingInstructionsWithNoQuantityForADrugOrder() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertNull(exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = - drugName + " | " + dose.toString() + " " + mg + " - " + daily + " - " + duration + " " + week; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldSetDosingInstructionsWithNoFrequencyForADrugOrder() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - orderResource.put("patient", patientResource); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final Double dose = 500.0; - final String mg = "mg"; - final var doseUnitsResource = singletonMap("display", mg); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("dose", dose); - orderResource.put("doseUnits", doseUnitsResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertNull(exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + dose.toString() + " " + mg + " - " + duration + " " + week; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } - - @Test - public void shouldSetDosingInstructionsWithNoDoseForADrugOrder() throws Exception { - final Integer odooPatientId = 5; - var patientResource = new HashMap<>(); - patientResource.put("uuid", OdooTestConstants.PATIENT_UUID); - var orderResource = new HashMap<>(); - orderResource.put("action", "DISCONTINUE"); - final String drugName = "Aspirin"; - orderResource.put("drug", singletonMap("display", drugName)); - orderResource.put("patient", patientResource); - final Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(OdooTestConstants.EX_PROP_ENTITY, orderResource); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_RESOURCE_ID, OdooTestConstants.PATIENT_UUID); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - exchange.setProperty(EX_PROP_IS_NEW, true); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockProcessNewOrderEndpoint.expectedMessageCount(1); - mockProcessRevOrderEndpoint.expectedMessageCount(0); - mockProcessDcOrVoidedOrderEndpoint.expectedMessageCount(0); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_CUSTOMER, true); - mockPatientHandlerEndpoint.whenAnyExchangeReceived( - e -> e.setProperty(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId)); - - mockGetDraftQuotesEndpoint.expectedMessageCount(1); - mockGetDraftQuotesEndpoint.expectedPropertyReceived(OdooTestConstants.EX_PROP_ODOO_PATIENT_ID, odooPatientId); - mockGetDraftQuotesEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Map[] {})); - - mockManageQuoteEndpoint.expectedMessageCount(1); - mockManageQuoteEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - final Integer quoteId = 9; - mockManageQuoteEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(quoteId)); - - final String daily = "Daily"; - final var frequencyResource = singletonMap("display", daily); - final Integer duration = 1; - final String week = "Week"; - final var durationUnitsResource = singletonMap("display", week); - orderResource.put("frequency", frequencyResource); - orderResource.put("duration", duration); - orderResource.put("durationUnits", durationUnitsResource); - - producerTemplate.send(OdooTestConstants.URI_PROCESS_ORDER, exchange); - - mockManageQuoteEndpoint.reset(); - mockProcessRevOrderEndpoint.reset(); - mockGetExtIdMapEndpoint.reset(); - mockProcessNewOrderEndpoint.reset(); - mockProcessDcOrVoidedOrderEndpoint.reset(); - - mockManageQuoteEndpoint.assertIsSatisfied(); - mockProcessNewOrderEndpoint.assertIsSatisfied(); - mockProcessRevOrderEndpoint.assertIsSatisfied(); - mockProcessDcOrVoidedOrderEndpoint.assertIsSatisfied(); - mockGetExtIdMapEndpoint.assertIsSatisfied(); - - assertNull(exchange.getProperty(EX_PROP_ORDER_LINE)); - assertEquals(0, exchange.getProperty(EX_PROP_ORDER_LINE_COUNT)); - assertEquals(quoteId, exchange.getProperty(EX_PROP_QUOTE_ID)); - assertNull(exchange.getProperty(EX_PROP_UNITS_ID)); - final String description = drugName + " | " + daily + " - " + duration + " " + week; - assertEquals(description, exchange.getProperty(EX_PROP_DESC)); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessPersonAddressRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessPersonAddressRouteTest.java deleted file mode 100644 index 93b39ba7..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessPersonAddressRouteTest.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Collections.singletonMap; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import ch.qos.logback.classic.Level; -import java.util.HashMap; -import java.util.Map; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper; - -public class OdooProcessPersonAddressRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "odoo-process-person-address"; - - public static final String URI_PROCESS_ADDRESS = "direct:odoo-process-person-address"; - - public static final String EX_PROP_PATIENT = "patient"; - - public static final String EX_PROP_PREF_ADDRESS = "preferredAddress"; - - public static final String EX_PROP_IS_SUB_RES = "isSubResource"; - - public static final String EX_PROP_RES = "resourceName"; - - public static final String EX_PROP_RES_ID = "resourceId"; - - public static final String EX_PROP_SUB_RES = "subResourceName"; - - public static final String EX_PROP_SUB_RES_ID = "subResourceId"; - - public static final String EX_PROP_STATE_ID = "odooStateId"; - - public static final String EX_PROP_COUNTRY_ID = "odooCountryId"; - - public static final String EX_PROP_STATE = "stateName"; - - public static final String EX_PROP_COUNTRY = "countryName"; - - public static final String ADDRESS_UUID = "359022bf-4a58-4732-8cce-1e57f72f47b0"; - - @EndpointInject("mock:odoo-get-state") - private MockEndpoint mockGetStateEndpoint; - - @EndpointInject("mock:odoo-get-country") - private MockEndpoint mockGetCountryEndpoint; - - @EndpointInject("mock:get-entity-by-uuid-from-openmrs") - private MockEndpoint mockFetchResourceEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("odoo-process-person-address.xml"); - - mockFetchResourceEndpoint.reset(); - mockGetStateEndpoint.reset(); - mockGetCountryEndpoint.reset(); - - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_IS_SUB_RES, true); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RES, "person"); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_SUB_RES, "address"); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint("direct:odoo-get-state") - .skipSendToOriginalEndpoint() - .to(mockGetStateEndpoint); - interceptSendToEndpoint("direct:odoo-get-country") - .skipSendToOriginalEndpoint() - .to(mockGetCountryEndpoint); - interceptSendToEndpoint("direct:get-entity-by-uuid-from-openmrs") - .skipSendToOriginalEndpoint() - .to(mockFetchResourceEndpoint); - } - }); - } - - @Test - public void shouldProcessStateAndCountryIfTheyExistOnTheAddress() throws Exception { - final Integer stateId = 6; - final Integer countryId = 8; - final String state = "TX"; - final String country = "US"; - Exchange exchange = new DefaultExchange(camelContext); - var patientResource = singletonMap("uuid", OdooTestConstants.PATIENT_UUID); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(EX_PROP_PREF_ADDRESS, singletonMap("uuid", ADDRESS_UUID)); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RES_ID, OdooTestConstants.PATIENT_UUID); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_SUB_RES_ID, ADDRESS_UUID); - Map addressResource = new HashMap(); - addressResource.put("stateProvince", state); - addressResource.put("country", country); - final String addressJson = new ObjectMapper().writeValueAsString(addressResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(addressJson)); - - mockGetStateEndpoint.expectedMessageCount(1); - mockGetStateEndpoint.expectedPropertyReceived(EX_PROP_STATE, state); - mockGetStateEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {stateId})); - - mockGetCountryEndpoint.expectedMessageCount(1); - mockGetCountryEndpoint.expectedPropertyReceived(EX_PROP_COUNTRY, country); - mockGetCountryEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {countryId})); - - producerTemplate.send(URI_PROCESS_ADDRESS, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockGetStateEndpoint.assertIsSatisfied(); - mockGetCountryEndpoint.assertIsSatisfied(); - assertEquals(stateId, exchange.getProperty(EX_PROP_STATE_ID)); - assertEquals(countryId, exchange.getProperty(EX_PROP_COUNTRY_ID)); - } - - @Test - public void shouldNotSetStateOrCountryIfTheyExistOnTheAddressAndHaveNoMuchInOdoo() throws Exception { - final String state = "TX"; - final String country = "US"; - Exchange exchange = new DefaultExchange(camelContext); - Map patientResource = singletonMap("uuid", OdooTestConstants.PATIENT_UUID); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(EX_PROP_PREF_ADDRESS, singletonMap("uuid", ADDRESS_UUID)); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RES_ID, OdooTestConstants.PATIENT_UUID); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_SUB_RES_ID, ADDRESS_UUID); - Map addressResource = new HashMap(); - addressResource.put("stateProvince", state); - addressResource.put("country", country); - final String addressJson = new ObjectMapper().writeValueAsString(addressResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(addressJson)); - - mockGetStateEndpoint.expectedMessageCount(1); - mockGetStateEndpoint.expectedPropertyReceived(EX_PROP_STATE, state); - mockGetStateEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - - mockGetCountryEndpoint.expectedMessageCount(1); - mockGetCountryEndpoint.expectedPropertyReceived(EX_PROP_COUNTRY, country); - mockGetCountryEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {})); - - producerTemplate.send(URI_PROCESS_ADDRESS, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockGetStateEndpoint.assertIsSatisfied(); - mockGetCountryEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.WARN, "No state found in odoo matching name: " + state); - assertMessageLogged(Level.WARN, "No country found in odoo matching name: " + country); - } - - @Test - public void shouldFailIfMultipleStatesAreFoundInOdooMatchingTheStateUuid() throws Exception { - final String state = "TX"; - Exchange exchange = new DefaultExchange(camelContext); - Map patientResource = singletonMap("uuid", OdooTestConstants.PATIENT_UUID); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(EX_PROP_PREF_ADDRESS, singletonMap("uuid", ADDRESS_UUID)); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RES_ID, OdooTestConstants.PATIENT_UUID); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_SUB_RES_ID, ADDRESS_UUID); - final String addressJson = new ObjectMapper().writeValueAsString(singletonMap("stateProvince", state)); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(addressJson)); - - mockGetStateEndpoint.expectedMessageCount(1); - mockGetStateEndpoint.expectedPropertyReceived(EX_PROP_STATE, state); - mockGetStateEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {6, 7})); - - producerTemplate.send(URI_PROCESS_ADDRESS, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockGetStateEndpoint.assertIsSatisfied(); - mockGetCountryEndpoint.assertIsSatisfied(); - assertEquals("Found 2 states in odoo matching name: " + state, getErrorMessage(exchange)); - } - - @Test - public void shouldFailIfMultipleCountriesAreFoundInOdooMatchingTheCountryUuid() throws Exception { - final Integer stateId = 6; - final String state = "TX"; - final String country = "US"; - Exchange exchange = new DefaultExchange(camelContext); - Map patientResource = singletonMap("uuid", OdooTestConstants.PATIENT_UUID); - exchange.setProperty(EX_PROP_PATIENT, patientResource); - exchange.setProperty(EX_PROP_PREF_ADDRESS, singletonMap("uuid", ADDRESS_UUID)); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RES_ID, OdooTestConstants.PATIENT_UUID); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_SUB_RES_ID, ADDRESS_UUID); - Map addressResource = new HashMap(); - addressResource.put("stateProvince", state); - addressResource.put("country", country); - final String addressJson = new ObjectMapper().writeValueAsString(addressResource); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(addressJson)); - - mockGetStateEndpoint.expectedMessageCount(1); - mockGetStateEndpoint.expectedPropertyReceived(EX_PROP_STATE, state); - mockGetStateEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {stateId})); - - mockGetCountryEndpoint.expectedMessageCount(1); - mockGetCountryEndpoint.expectedPropertyReceived(EX_PROP_COUNTRY, country); - mockGetCountryEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(new Integer[] {8, 9})); - - producerTemplate.send(URI_PROCESS_ADDRESS, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockGetStateEndpoint.assertIsSatisfied(); - mockGetCountryEndpoint.assertIsSatisfied(); - assertEquals(stateId, exchange.getProperty(EX_PROP_STATE_ID)); - assertEquals("Found 2 countries in odoo matching name: " + country, getErrorMessage(exchange)); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessRevisionOrderRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessRevisionOrderRouteTest.java deleted file mode 100644 index 3a112390..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooProcessRevisionOrderRouteTest.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import ch.qos.logback.classic.Level; -import java.util.Collections; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class OdooProcessRevisionOrderRouteTest extends BaseOrderOdooRouteTest { - - private static final String ROUTE_ID = "odoo-process-revision-order"; - - public static final String URI_PROCESS_REV_ORDER = "direct:odoo-process-revision-order"; - - public static final String EX_PROP_ORDER_LINE = "order-line"; - - public static final String EX_PROP_IS_DRUG_ORDER = "is-drug-order"; - - public static final String EX_PROP_QTY = "order-quantity"; - - public static final String EX_PROP_UNITS_ID = "unitsId"; - - @EndpointInject("mock:odoo-manage-order-line") - private MockEndpoint mockManageOrderLineEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("odoo-process-revision-order.xml"); - - mockManageOrderLineEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint("direct:odoo-manage-order-line") - .skipSendToOriginalEndpoint() - .to(mockManageOrderLineEndpoint); - } - }); - } - - @Test - public void shouldAddAnOrderLineInOdooIfNoneExists() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - mockManageOrderLineEndpoint.expectedMessageCount(1); - mockManageOrderLineEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_CREATE); - - producerTemplate.send(URI_PROCESS_REV_ORDER, exchange); - - mockManageOrderLineEndpoint.assertIsSatisfied(); - Assertions.assertEquals( - OdooTestConstants.ODOO_OP_CREATE, exchange.getProperty(OdooTestConstants.EX_PROP_ODOO_OP)); - assertMessageLogged(Level.INFO, "Adding new order line to the quotation"); - } - - @Test - public void shouldIgnoreANonDrugOrderWhenThereIsAnExistingLineInOdoo() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_ORDER_LINE, Collections.emptyMap()); - mockManageOrderLineEndpoint.expectedMessageCount(0); - - producerTemplate.send(URI_PROCESS_REV_ORDER, exchange); - - mockManageOrderLineEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.INFO, "There is nothing to update in odoo about a non drug order"); - } - - @Test - public void shouldUpdateTheExistingOrderLineInOdooForADrugOrder() throws Exception { - Exchange exchange = new DefaultExchange(camelContext); - exchange.setProperty(EX_PROP_ORDER_LINE, Collections.emptyMap()); - exchange.setProperty(EX_PROP_IS_DRUG_ORDER, true); - mockManageOrderLineEndpoint.expectedMessageCount(1); - mockManageOrderLineEndpoint.expectedPropertyReceived( - OdooTestConstants.EX_PROP_ODOO_OP, OdooTestConstants.ODOO_OP_WRITE); - - producerTemplate.send(URI_PROCESS_REV_ORDER, exchange); - - mockManageOrderLineEndpoint.assertIsSatisfied(); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooTestConstants.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooTestConstants.java deleted file mode 100644 index 11ac5218..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooTestConstants.java +++ /dev/null @@ -1,285 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -public class OdooTestConstants { - - public static final String EX_PROP_TABLE_RESOURCE_MAP = "tables-resource-map"; - - public static final String EX_PROP_ENTITY = "entity-instance"; - - public static final String EX_PROP_IS_SUBRESOURCE = "isSubResource"; - - public static final String EX_PROP_RESOURCE_NAME = "resourceName"; - - public static final String EX_PROP_RESOURCE_ID = "resourceId"; - - public static final String EX_PROP_SUB_RESOURCE_NAME = "subResourceName"; - - public static final String EX_PROP_SUB_RESOURCE_ID = "subResourceId"; - - public static final String EX_PROP_RES_REP = "resourceRepresentation"; - - public static final String EX_PROP_ODOO_OP = "odoo-operation"; - - public static final String EX_PROP_ODOO_PATIENT_ID = "patient-odoo-id"; - - public static final String EX_PROP_PATIENT = "patient"; - - public static final String EX_PROP_CREATE_IF_NOT_EXISTS = "createCustomerIfNotExist"; - - public static final String EX_PROP_MODEL_NAME = "modelName"; - - public static final String EX_PROP_EXTERNAL_ID = "externalId"; - - public static final String EX_PROP_PRODUCT_ID = "odooProductId"; - - public static final String EX_PROP_ODOO_USER_ID_KEY = "odooUserIdKey"; - - public static final String EX_PROP_RPC_CLIENT_KEY = "xmlRpcClientKey"; - - public static final String EX_PROP_RPC_CFG_KEY = "xmlRpcConfigKey"; - - public static final String EX_PROP_QUOTE_ID = "quotation-id"; - - public static final String EX_PROP_LINE_COUNT = "orderLineCount"; - - public static final String EX_PROP_CREATE_QUOTE_IF_NOT_EXIST = "createQuoteIfNotExist"; - - public static final String EX_PROP_LINE_CONCEPT = "orderLineConcept"; - - public static final String EX_PROP_ORDER_LINE = "order-line"; - - public static final String EX_PROP_SKIP_CUSTOMER_UPDATE = "skipCustomerUpdate"; - - public static final String EX_PROP_QTY = "order-quantity"; - - public static final String EX_PROP_ENC = "encounter"; - - public static final String EX_PROP_QN_CONCEPT_UUID = "questionConceptUuid"; - - public static final String ROUTE_ID_OBS_TO_ODOO_RESOURCE = "obs-to-odoo-resource"; - - public static final String ROUTE_ID_SAVE_CALENDAR_EVENT = "save-calendar-event-in-odoo"; - - public static final String ROUTE_ID_GET_RES_BY_NAME_FROM_ODOO = "get-resource-by-name-from-odoo"; - - public static final String ROUTE_ID_GET_RES_BY_ID_FROM_ODOO = "get-resource-by-id-from-odoo"; - - public static final String ROUTE_ID_GET_EXT_ID_MAP = "odoo-get-external-id-map"; - - public static final String ROUTE_ID_GET_RES_BY_EXT_ID_FROM_ODOO = "get-resource-by-ext-id-from-odoo"; - - public static final String ROUTE_ID_GET_CONCEPT_BY_UUID_FROM_ENC = "get-obs-by-concept-uuid-from-encounter"; - - public static final String ROUTE_ID_OBS_TO_CUSTOMER = "obs-to-customer"; - - public static final String ROUTE_ID_OBS_TO_RES_HANDLER = "obs-to-odoo-resource-handler"; - - public static final String ROUTE_ID_GET_PARTNERS_BY_USERS = "get-partner-ids-by-user-ids"; - - public static final String ROUTE_ID_OBS_TO_ADMISSION_EVENT = "obs-to-admission-calendar-event"; - - public static final String ROUTE_ID_OBS_TO_DISCHARGE_EVENT = "obs-to-discharge-calendar-event"; - - public static final String ROUTE_ID_GET_OBS_BY_QN_FORM_VISIT = "get-obs-by-qn-on-form-in-visit"; - - public static final String ROUTE_ID_OBS_TO_INVOICE_EVENT = "obs-to-invoicing-calendar-event"; - - public static final String ROUTE_ID_GET_HSU_ID = "get-hsu-id"; - - public static final String ROUTE_ID_GET_MOST_RECENT_ENC_BY_FORM_AND_VISIT = "get-most-recent-enc-by-form-in-visit"; - - public static final String ROUTE_ID_FORM_VALIDATED_RULE = "is-obs-form-validated-rule"; - - public static final String ROUTE_ID_IS_ENC_VALIDATED = "is-encounter-validated"; - - public static final String ROUTE_ID_OBS_CAPTURED_ON_FORM = "obs-captured-on-form-rule"; - - public static final String URI_ODOO_AUTH = "direct:odoo-authentication"; - - public static final String URI_ORDER_HANDLER = "direct:odoo-order-handler"; - - public static final String URI_PATIENT_HANDLER = "direct:odoo-patient-handler"; - - public static final String URI_PATIENT_ASSOCIATION_HANDLER = "direct:odoo-patient-association-handler"; - - public static final String URI_ADD_EXTRA_CUSTOMER_DETAILS = "direct:odoo-add-extra-customer-details"; - - public static final String URI_ADD_EXTRA_QUOTATION_DETAILS = "direct:odoo-add-extra-quotation-details"; - - public static final String URI_GET_EXT_ID = "direct:" + ROUTE_ID_GET_EXT_ID_MAP; - - public static final String URI_GET_QUOTES = "direct:odoo-get-draft-quotations"; - - public static final String URI_GET_LINE = "direct:odoo-get-order-line"; - - public static final String URI_MANAGE_QUOTE = "direct:odoo-manage-quotation"; - - public static final String URI_PROCESS_ORDER = "direct:odoo-process-order"; - - public static final String URI_GET_ENTITY_BY_UUID = "direct:get-entity-by-uuid-from-openmrs"; - - public static final String URI_MOCK_GET_ENTITY_BY_UUID = "mock:get-entity-by-uuid-from-openmrs"; - - public static final String URI_OBS_TO_ODOO_RESOURCE = "direct:" + ROUTE_ID_OBS_TO_ODOO_RESOURCE; - - public static final String URI_PATIENT_UUID_TO_CUSTOMER = "direct:patient-uuid-to-odoo-customer"; - - public static final String URI_OBS_TO_ORDER_LINE = "direct:odoo-obs-to-order-line"; - - public static final String URI_VOIDED_OBS_PROCESSOR = "direct:voided-obs-to-order-line-processor"; - - public static final String URI_NON_VOIDED_OBS_PROCESSOR = "direct:non-voided-obs-to-order-line-processor"; - - public static final String URI_UUID_TO_CUSTOMER = "direct:patient-uuid-to-odoo-customer"; - - public static final String URI_FORM_VALIDATED_RULE = "direct:" + ROUTE_ID_FORM_VALIDATED_RULE; - - public static final String URI_CONCEPT_LINE_PROCESSOR = "direct:concept-to-order-line-processor"; - - public static final String URI_GET_CONCEPT_BY_MAPPING = "direct:get-concept-by-mapping-from-openmrs"; - - public static final String URI_CONVERT_TO_CONCEPT_UUID = "direct:convert-to-concept-uuid-if-is-mapping"; - - public static final String URI_PRP_HANDLER = "direct:odoo-prp-handler"; - - public static final String URI_PERSON_HANDLER = "direct:odoo-person-handler"; - - public static final String URI_CUSTOM_DATA = "direct:callback-get-custom-customer-data"; - - public static final String URI_MANAGE_ORDER_LINE = "direct:odoo-manage-order-line"; - - public static final String URI_OBS_CAPTURED_ON_FORM = "direct:" + ROUTE_ID_OBS_CAPTURED_ON_FORM; - - public static final String URI_SAVE_CALENDAR_EVENT = "direct:" + ROUTE_ID_SAVE_CALENDAR_EVENT; - - public static final String URI_GET_RES_BY_NAME_FROM_ODOO = "direct:" + ROUTE_ID_GET_RES_BY_NAME_FROM_ODOO; - - public static final String URI_GET_RES_BY_ID_FROM_ODOO = "direct:" + ROUTE_ID_GET_RES_BY_ID_FROM_ODOO; - - public static final String URI_GET_CONCEPT_BY_UUID_FROM_ENC = "direct:" + ROUTE_ID_GET_CONCEPT_BY_UUID_FROM_ENC; - - public static final String URI_OBS_TO_CUSTOMER = "direct:" + ROUTE_ID_OBS_TO_CUSTOMER; - - public static final String URI_OBS_TO_RES_HANDLER = "direct:" + ROUTE_ID_OBS_TO_RES_HANDLER; - - public static final String URI_GET_PARTNERS_BY_USERS = "direct:" + ROUTE_ID_GET_PARTNERS_BY_USERS; - - public static final String URI_OBS_TO_ADMISSION_EVENT = "direct:" + ROUTE_ID_OBS_TO_ADMISSION_EVENT; - - public static final String URI_OBS_TO_DISCHARGE_EVENT = "direct:" + ROUTE_ID_OBS_TO_DISCHARGE_EVENT; - - public static final String URI_OBS_TO_INVOICE_EVENT = "direct:" + ROUTE_ID_OBS_TO_INVOICE_EVENT; - - public static final String URI_GET_OBS_BY_QN_FORM_VISIT = "direct:" + ROUTE_ID_GET_OBS_BY_QN_FORM_VISIT; - - public static final String URI_GET_RES_BY_EXT_ID_FROM_ODOO = "direct:" + ROUTE_ID_GET_RES_BY_EXT_ID_FROM_ODOO; - - public static final String URI_GET_MOST_RECENT_ENC_BY_FORM_AND_VISIT = - "direct:" + ROUTE_ID_GET_MOST_RECENT_ENC_BY_FORM_AND_VISIT; - - public static final String URI_GET_HSU_ID = "direct:" + ROUTE_ID_GET_HSU_ID; - - public static final String URI_IS_ENC_VALIDATED = "direct:" + ROUTE_ID_IS_ENC_VALIDATED; - - public static final String ODOO_BASE_URL = "http://test.odoo.test"; - - public static final String LISTENER_URI = "direct:odoo-event-listener"; - - public static final String ORDER_UUID_1 = "16170d8e-d201-4d94-ae89-0be0b0b6d8ba"; - - public static final String ORDER_UUID_2 = "26170d8e-d201-4d94-ae89-0be0b0b6d8ba"; - - public static final String PATIENT_UUID = "ba3b12d1-5c4f-415f-871b-b98a22137604"; - - public static final String NAME_UUID = "0bca417f-fc68-40d7-ae6f-cffca7a5eff1"; - - public static final String ADDRESS_UUID = "359022bf-4a58-4732-8cce-1e57f72f47b0"; - - public static final String PATIENT_ID_UUID = "148bcfc1-360a-44b5-9539-e8718cd6e46f"; - - public static final String ODOO_OP_CREATE = "create"; - - public static final String ODOO_OP_WRITE = "write"; - - public static final String ODOO_OP_UNLINK = "unlink"; - - public static final String ODOO_OP_SEARCH_READ = "search_read"; - - public static final String ODOO_RES_PRODUCT = "product.product"; - - public static final String ODOO_USER_ID_KEY = "odoo-event-listener-odooUserId"; - - public static final String RPC_CLIENT_KEY = "odoo-event-listener-xmlRpcClient"; - - public static final String RPC_CONFIG_KEY = "odoo-event-listener-xmlRpcConfig"; - - public static final String ODOO_RPC_METHOD = "execute_kw"; - - public static final String APP_PROP_NAME_OBS_TO_ODOO_HANDLER = "obs.to.odoo.resource.handler.route"; - - public static final String APP_PROP_NAME_ID_TYPE_UUID = "openmrs.identifier.type.uuid"; - - public static final String APP_PROP_NAME_GRP_EXT_ID = "odoo.dormitory.notification.group.ext.id"; - - public static final String APP_PROP_NAME_INVOICE_GRP_EXT_ID = "odoo.final.assmt.notification.group.ext.id"; - - public static final String APP_PROP_NAME_BASIC_SERVICE_PLAN_FORM_UUID = "basic.service.plan.form.uuid"; - - public static final String APP_PROP_NAME_FINAL_ASSMT_FORM_UUID = "final.assessment.outcome.form.uuid"; - - public static final String APP_PROP_NAME_FINAL_ASSMT_CONCEPT = "final.assmt.decision.question.concept"; - - public static final String APP_PROP_NAME_CLOSE_EOS_CONCEPT = "close.eos.concept"; - - public static final String CONCEPT_UUID_VALIDATED = "1382a47a-3e63-11e9-b210-d663bd873d93"; - - public static final String CONCEPT_UUID_YES = "1065AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - - public static final String CONCEPT_UUID_PATIENT_TYPE = "5b2efd02-be26-4789-b5ec-7c5ceb428725"; - - public static final String CONCEPT_UUID_INPATIENT = "a0b86497-cb21-46ad-9a9b-c99db8db9528"; - - public static final String CONCEPT_UUID_ASSMT_DECISION = "675b4e02-1a96-4eda-af84-b6ebe0d715a4"; - - public static final String CONCEPT_UUID_CLOSE_EOS = "9bc5c6f2-7c82-11e9-8f9e-2a86e4085a59"; - - public static final String CONCEPT_UUID_SERVICE_CAT = "0c04b4c6-5576-40f7-aca0-d48196982b9d"; - - public static final String CONCEPT_UUID_SERVICE_CAT_AT = "ea311fa0-494b-4d7f-87d7-0a2b6b3ae347"; - - public static final String CONCEPT_UUID_SERVICE_CAT_NON_AT = "09bb157f-129d-4cb4-88fb-bc662d5b0633"; - - public static final String CONCEPT_UUID_SERVICE = "db7d6df3-2a53-4fa1-8498-ae26811f16c3"; - - public static final String CONCEPT_UUID_SERVICE_IND_PRE = "5bfc19cb-be53-4dfd-a182-b722282f97aa"; - - public static final String CONCEPT_UUID_SERVICE_IND_POST = "ba39d381-2e95-4749-b106-03ab1b8dd8a5"; - - public static final String CONCEPT_UUID_SERVICE_GRP_PRE = "3fc9d7e3-5328-42fa-943d-59e5a0742177"; - - public static final String CONCEPT_UUID_SERVICE_GRP_POST = "d7d97492-ce31-4c6f-be38-46d66f75199a"; - - public static final String CONCEPT_UUID_SERVICE_IND_NON_AT = "4d13460e-4fef-4501-9309-cde5c3fc588b"; - - public static final String CONCEPT_UUID_SERVICE_GRP_OTHER = "c9a058a8-4c8e-41e0-b20b-ec6cd8ad71e6"; - - public static final String CONCEPT_UUID_PHYSIO_IND_AT = "2be9c9a4-afd4-448e-a10b-eeb1e7436fff"; - - public static final String CONCEPT_UUID_PHYSIO_GRP_PRE_AT = "34aeea30-eff2-4c24-ae25-a16dbd051c88"; - - public static final String CONCEPT_UUID_PHYSIO_GRP_POST_AT = "55c42975-2d0a-4e31-b07b-d9fcc032ac05"; - - public static final String CONCEPT_UUID_PHYSIO_IND_NON_AT = "6f99160c-33ce-4726-b2bf-a167bea31249"; - - public static final String CONCEPT_UUID_PHYSIO_GRP_OTHER = "6350915f-8694-49d8-82df-688ac523b895"; - - public static final String BASIC_SERVICE_PLAN_FORM_UUID = "3b07b00c-1623-4380-af4a-4bb68244eff5"; - - public static final String FINAL_ASSMT_FORM_UUID = "5fa318a9-eade-ea79-a96e-d91754135a5c"; - - public static final String PHYSIO_FORM_UUID = "3c07n00f-1623-4380-af4a-4cn68244ptt3"; - - public static final String PARAM_MODEL_NAME = "modelName"; - - public static final String MODEL_NAME_GROUPS = "res.groups"; -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooTestUtils.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooTestUtils.java deleted file mode 100644 index 79992992..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/OdooTestUtils.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonMap; - -import java.util.HashMap; -import java.util.Map; - -public class OdooTestUtils { - - public static Map createConcept(String uuid, String display) { - var res = new HashMap<>(); - res.put("uuid", uuid); - res.put("display", display); - return res; - } - - public static Map createCodedObs(String conceptUuid, String valueUuid) { - return createCodedObs(conceptUuid, valueUuid, null, null); - } - - public static Map createCodedObs( - String conceptUuid, String valueUuid, String conceptDisplay, String valueDisplay) { - var res = new HashMap<>(); - res.put("concept", createConcept(conceptUuid, conceptDisplay)); - res.put("value", createConcept(valueUuid, valueDisplay)); - return res; - } - - public static Map createNumericObs(String conceptUuid, N valueNumeric) { - var obsRes = new HashMap<>(); - obsRes.put("concept", singletonMap("uuid", conceptUuid)); - obsRes.put("value", valueNumeric); - return obsRes; - } - - public static Map createPatientId(String id, String identifierTypeUuid) { - var res = new HashMap<>(); - res.put("identifier", id); - res.put("identifierType", singletonMap("uuid", identifierTypeUuid)); - return res; - } - - public static Map createEnc(String encUuid, Map... obs) { - var res = new HashMap<>(); - res.put("uuid", encUuid); - res.put("obs", asList(obs)); - return res; - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/PatientUuidToOdooCustomerRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/PatientUuidToOdooCustomerRouteTest.java deleted file mode 100644 index 9347bfe9..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/PatientUuidToOdooCustomerRouteTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_CREATE_IF_NOT_EXISTS; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_IS_SUBRESOURCE; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_PATIENT; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_RESOURCE_ID; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.EX_PROP_RESOURCE_NAME; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.URI_MOCK_GET_ENTITY_BY_UUID; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.URI_PATIENT_UUID_TO_CUSTOMER; - -import ch.qos.logback.classic.Level; -import java.util.HashMap; -import org.apache.camel.EndpointInject; -import org.apache.camel.Exchange; -import org.apache.camel.builder.AdviceWithRouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.support.DefaultExchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class PatientUuidToOdooCustomerRouteTest extends BaseOdooRouteTest { - - private static final String ROUTE_ID = "patient-uuid-to-odoo-customer"; - - @EndpointInject(URI_MOCK_GET_ENTITY_BY_UUID) - private MockEndpoint mockFetchResourceEndpoint; - - @EndpointInject("mock:odoo-patient-handler") - private MockEndpoint mockPatientHandlerEndpoint; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("patient-uuid-to-odoo-customer.xml"); - - mockPatientHandlerEndpoint.reset(); - mockFetchResourceEndpoint.reset(); - - advise(ROUTE_ID, new AdviceWithRouteBuilder() { - - @Override - public void configure() { - interceptSendToEndpoint("direct:get-entity-by-uuid-from-openmrs") - .skipSendToOriginalEndpoint() - .to(mockFetchResourceEndpoint); - interceptSendToEndpoint("direct:odoo-patient-handler") - .skipSendToOriginalEndpoint() - .to(mockPatientHandlerEndpoint); - } - }); - } - - @Test - public void shouldAddTheCustomerInOdooIfThePatientIsFoundInOpenmrs() throws Exception { - final String patientUuid = "patient-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(patientUuid); - var patientResource = new HashMap<>(); - patientResource.put("uuid", patientUuid); - final String patientJson = mapper.writeValueAsString(patientResource); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_ID, patientUuid); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(patientJson)); - mockPatientHandlerEndpoint.expectedMessageCount(1); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_CREATE_IF_NOT_EXISTS, true); - mockPatientHandlerEndpoint.expectedPropertyReceived(EX_PROP_PATIENT, patientResource); - - producerTemplate.send(URI_PATIENT_UUID_TO_CUSTOMER, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - } - - @Test - public void shouldNotAddTheCustomerInOdooIfThePatientIsNotFoundInOpenmrs() throws Exception { - final String patientUuid = "patient-uuid"; - Exchange exchange = new DefaultExchange(camelContext); - exchange.getIn().setBody(patientUuid); - mockFetchResourceEndpoint.expectedMessageCount(1); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_IS_SUBRESOURCE, false); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_NAME, "patient"); - mockFetchResourceEndpoint.expectedPropertyReceived(EX_PROP_RESOURCE_ID, patientUuid); - mockFetchResourceEndpoint.whenAnyExchangeReceived(e -> e.getIn().setBody(null)); - mockPatientHandlerEndpoint.expectedMessageCount(0); - - producerTemplate.send(URI_PATIENT_UUID_TO_CUSTOMER, exchange); - - mockFetchResourceEndpoint.assertIsSatisfied(); - mockPatientHandlerEndpoint.assertIsSatisfied(); - assertMessageLogged(Level.INFO, "No patient found in OpenMRS with uuid: " + patientUuid); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/SaveCalendarEventInOdooRouteTest.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/SaveCalendarEventInOdooRouteTest.java deleted file mode 100644 index 0e86b49d..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/SaveCalendarEventInOdooRouteTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.ODOO_OP_CREATE; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.ODOO_RPC_METHOD; -import static com.ozonehis.eip.odooopenmrs.route.OdooTestConstants.URI_SAVE_CALENDAR_EVENT; -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import org.apache.camel.Exchange; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -public class SaveCalendarEventInOdooRouteTest extends BaseOdooApiRouteTest { - - private static final String MODEL_NAME = "calendar.event"; - - public static final String EX_PROP_SUBJECT = "subject"; - - public static final String EX_PROP_DESCRIPTION = "description"; - - public static final String EX_PROP_ATTENDEE_PARTNER_IDS = "attendeePartnerIds"; - - public static final String EX_PROP_START = "startDateTime"; - - public static final String EX_PROP_DURATION = "duration"; - - @BeforeEach - public void setup() throws Exception { - loadXmlRoutesInCamelDirectory("save-calendar-event-in-odoo.xml"); - } - - @Test - public void shouldCallCreateTheCalendarEventInOdoo() throws Exception { - Exchange exchange = buildExchange(); - final String subject = "Test Subject name"; - final String description = "Test Description"; - final List partnerIds = asList(3, 4); - exchange.setProperty(EX_PROP_SUBJECT, subject); - exchange.setProperty(EX_PROP_DESCRIPTION, description); - exchange.setProperty(EX_PROP_ATTENDEE_PARTNER_IDS, partnerIds); - LocalDateTime start = LocalDateTime.of(2022, 1, 1, 1, 0, 0, 0); - exchange.setProperty(EX_PROP_START, start); - exchange.setProperty(EX_PROP_DURATION, 120); - final var rpcArgs = new ArrayList<>(); - rpcArgs.add(APP_PROP_ODOO_DB); - rpcArgs.add(USER_ID); - rpcArgs.add(APP_PROP_ODOO_PASS); - rpcArgs.add(MODEL_NAME); - rpcArgs.add(ODOO_OP_CREATE); - var eventData = new HashMap<>(); - eventData.put("name", subject); - eventData.put("description", description); - eventData.put("start", "2022-01-01 01:00:00"); - eventData.put("stop", "2022-01-01 03:00:00"); - eventData.put("partner_ids", singletonList(asList(6, 0, partnerIds))); - rpcArgs.add(singletonList(eventData)); - final int expectedEventId = 21; - Mockito.when(mockXmlRpcClient.execute(mockXmlRpcClientConfig, ODOO_RPC_METHOD, rpcArgs)) - .thenReturn(expectedEventId); - - producerTemplate.send(URI_SAVE_CALENDAR_EVENT, exchange); - - assertEquals(expectedEventId, exchange.getIn().getBody()); - } -} diff --git a/src/test/java/com/ozonehis/eip/odooopenmrs/route/TestConfig.java b/src/test/java/com/ozonehis/eip/odooopenmrs/route/TestConfig.java deleted file mode 100644 index e0f8fb7c..00000000 --- a/src/test/java/com/ozonehis/eip/odooopenmrs/route/TestConfig.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.ozonehis.eip.odooopenmrs.route; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ComponentScan({"org.openmrs.eip", "com.ozonehis.eip"}) -public class TestConfig {} diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties deleted file mode 100644 index 267cccf6..00000000 --- a/src/test/resources/application-test.properties +++ /dev/null @@ -1,75 +0,0 @@ -# *********************** General EIP sender properties **************************************************************** -# -# Camel endpoints that need to be notified of DB events -db-event.destinations=direct:odoo-event-listener - -# A comma separated list of database tables names to watch for changes -eip.watchedTables=patient,person_name,person_address,patient_identifier -# ---------------------------------------------------------------------------------------------------------------------- - -# *********************** Odoo configuration ************************************************************************** -# -# The base URL to the Odoo instance -odoo.baseUrl=http://test.odoo.test - -# The database name to use to log into the Odoo instance -odoo.database=odoo-db - -# The username for the account to use to log into the Odoo instance -odoo.username=test-odoo - -# The password for the account to use to log into the Odoo instance -odoo.password=password - -# The address type to use for customer addresses in Odoo -odoo.customer.address.type=contact - -odoo.handler.route=odoo-order-handler - -# Custom table to OpenMRS REST resource name mappings -odoo.custom.table.resource.mappings=orders:order,test_order:order,drug_order:order - -odoo.obs.concept.question.answer.mappings= - -obs.to.odoo.resource.handler.route= - - -# Custom property for the res.partner model in odoo -odoo.emr.id.field= - -# Custom property for the res.partner model in odoo to capture customer's date of birth -odoo.dob.field= - -# Custom property for the res.partner model in odoo to capture customer's weight -odoo.weight.field= - -# Used to turn on or off the route that allows to sync extra patient details like weight and/or date of birth -odoo.enable.extra.customer.details.route=false - -# Used to turn on or off the route that allows to sync extra patient details like weight as part of the customer quotation -odoo.enable.extra.quotation.details.route=false -#---------------------------------------------------------------------------------------------------------------------- - -# *********************** Configuration of the OpenMRS Web App ********************************************************* -# -# OpenMRS user credentials -openmrs.username=admin - -openmrs.password=Admin123 - -# OpenMRS base url -openmrs.baseUrl=http://localhost:8080/openmrs - -# The results encounter type for all patient result observations -results.encounterType.uuid=3c6838e6-d91b-42ff-a77e-6c536a04524a - -concept.complex.uuid=fc4afd13-c4fa-4283-8f6c-7e508bc5cba0 - -openmrs.identifier.type.uuid=779f59fc-b566-494d-b39d-fcb6c49feb56 - -# true/false flag to indicate whether to create a new customer in Odoo if it does not exist -create.customer.if.not.exist=false - -# UUID for concept that is used to record a patient's weight. It is usually 5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -emr.weight.concept=5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -# ---------------------------------------------------------------------------------------------------------------------- diff --git a/src/test/resources/liquibase/liquibase-openmrs.xml b/src/test/resources/liquibase/liquibase-openmrs.xml deleted file mode 100644 index 3590b9ed..00000000 --- a/src/test/resources/liquibase/liquibase-openmrs.xml +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - - - - - - Adding person table - - - - - - - - - - - - - - - - - - - - - - Adding patient table - - - - - - - - - - - - - - - - Adding person_name table - - - - - - - - - - - - - - - - - - - - - - - - Adding person_address table - - - - - - - - - - - - - - - - - - - - - - - - - - - - Adding patient_identifier_type table - - - - - - - - - - - - - - - - - - - - - Adding patient_identifier table - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/sql/demo_data_script.sql b/src/test/resources/sql/demo_data_script.sql deleted file mode 100644 index 6ac8d946..00000000 --- a/src/test/resources/sql/demo_data_script.sql +++ /dev/null @@ -1,103 +0,0 @@ -select * from patient; -select * from patient_identifier_type; -select * from patient_identifier; -select * from person; -select * from person_name; -select * from person_address; - -update patient set date_created = now() where patient_id =1; -update person_name set date_created = now() where person_name_id =1; -update person_address set date_created = now() where person_address_id =1; - -select * from obs; -select * from orders; -select * from drug_order; -select * from concept; -select * from concept_name; -select * from encounter_type; -select * from encounter; -select * from provider; -select * from order_frequency; - -insert into obs(person_id,concept_id,value_coded,obs_datetime,status,creator,date_created,voided,uuid) -values((select person_id from person where uuid='person-uuid-1'), 4, 5, now(), 'FINAL', 1, now(), 0, 'obs-uuid-1'); - - --- Start Patient record and Metadata -insert into person(gender,birthdate,creator,date_created,voided,uuid) values('M', now(), 1, now(), 0, 'person-uuid-1'); -INSERT INTO person_name (person_id,given_name,family_name,creator,date_created,voided,uuid) -VALUES ((select person_id from person where uuid='person-uuid-1'), 'Jimmy', 'Senyomo', 1, now(), 0, 'name-uuid-1'); - -insert into patient(patient_id,creator,date_created,voided,allergy_status) -values ((select person_id from person where uuid='person-uuid-1'), 1, now(), 0,'Unknown'); - -INSERT INTO patient_identifier (patient_id,identifier,identifier_type,preferred,location_id,creator,date_created,voided,uuid) -VALUES ((select person_id from person where uuid='person-uuid-1'), '12345', 2, 1, null, 1, now(), 0, 'patient-id-uuid-1'); - -insert into encounter_type(name,creator,date_created,retired,uuid) values('Adult Initial', 1, now(), 0, 'enc-type-uuid-1'); - -insert into encounter(encounter_type,patient_id,encounter_datetime,creator,date_created,voided,uuid) -values((select encounter_type_id from encounter_type where uuid='enc-type-uuid-1'), (select person_id from person where uuid='person-uuid-1'), now(), 1, now(), 0, 'enc-uuid-1'); - -insert into concept(datatype_id,class_id,creator,date_created,retired,uuid) -values (4, 11, 1, now(), 0, 'concept-uuid-1'); -- dose units - -insert into concept_name (concept_id,name,locale,creator,date_created,voided,uuid) -values ((select concept_id from concept where uuid='concept-uuid-1'), 'Mg', 'en', 1, now(), 0, 'concept-name-uuid-1'); - -insert into concept(datatype_id,class_id,creator,date_created,retired,uuid) -values (4, 11, 1, now(), 0, 'concept-uuid-2'); -- route - -insert into concept_name (concept_id,name,locale,creator,date_created,voided,uuid) -values ((select concept_id from concept where uuid='concept-uuid-2'), 'Mouth', 'en', 1, now(), 0, 'concept-name-uuid-2'); - - -insert into concept(datatype_id,class_id,creator,date_created,retired,uuid) -values (4, 11, 1, now(), 0, 'concept-uuid-3'); -- qty - -insert into concept_name (concept_id,name,locale,creator,date_created,voided,uuid) -values ((select concept_id from concept where uuid='concept-uuid-3'), 'Tabs', 'en', 1, now(), 0, 'concept-name-uuid-3'); - -insert into concept(datatype_id,class_id,creator,date_created,retired,uuid) -values (4, 11, 1, now(), 0, 'concept-uuid-4'); -- frequency - -insert into concept_name (concept_id,name,locale,creator,date_created,voided,uuid) -values ((select concept_id from concept where uuid='concept-uuid-4'), 'Twice Daily', 'en', 1, now(), 0, 'concept-name-uuid-4'); - -insert into concept(datatype_id,class_id,creator,date_created,retired,uuid) -values (4, 11, 1, now(), 0, 'concept-uuid-5'); -- drug - -insert into concept_name (concept_id,name,locale,creator,date_created,voided,uuid) -values ((select concept_id from concept where uuid='concept-uuid-5'), 'Acetaminophen', 'en', 1, now(), 0, 'concept-name-uuid-5'); - -insert into concept(datatype_id,class_id,is_set,creator,date_created,retired,uuid) -values (4, 11, 1, 1, now(), 0, 'concept-uuid-6'); -- routes set - -insert into concept(datatype_id,class_id,is_set,creator,date_created,retired,uuid) -values (4, 11, 1, 1, now(), 0, 'concept-uuid-7'); -- dose units set - -insert into concept(datatype_id,class_id,is_set,creator,date_created,retired,uuid) -values (4, 11, 1, 1, now(), 0, 'concept-uuid-8'); -- qty units set - -insert into concept_set (concept_id,concept_set,creator,date_created,uuid) -values ((select concept_id from concept where uuid='concept-uuid-1'), (select concept_id from concept where uuid='concept-uuid-7'), 1, now(), 'set-uuid-1'); - -insert into concept_set (concept_id,concept_set,creator,date_created,uuid) -values ((select concept_id from concept where uuid='concept-uuid-2'), (select concept_id from concept where uuid='concept-uuid-6'), 1, now(), 'set-uuid-2'); - -insert into concept_set (concept_id,concept_set,creator,date_created,uuid) -values ((select concept_id from concept where uuid='concept-uuid-3'), (select concept_id from concept where uuid='concept-uuid-8'), 1, now(), 'set-uuid-3'); - -insert into provider(person_id,creator,date_created,retired,uuid) -values (1, 1, now(), 0, 'provider-uuid-1'); - -insert into order_frequency(frequency_per_day,concept_id,creator,date_created,retired,uuid) -values (4, (select concept_id from concept where uuid='concept-uuid-4'), 1, now(), 0, 'frequency-uuid-1'); - -INSERT INTO drug (drug_id,concept_id,combination,creator,date_created,retired,uuid) -VALUES (1, (select concept_id from concept where uuid='concept-uuid-5'), 0, 1, now(), 0, 'drug-uuid-1'); - -update global_property set property_value = 'concept-uuid-6' where property = 'order.drugRoutesConceptUuid'; -update global_property set property_value = 'concept-uuid-7' where property = 'order.drugDosingUnitsConceptUuid'; -update global_property set property_value = 'concept-uuid-8' where property = 'order.drugDispensingUnitsConceptUuid'; --- End Patient record and Metadata diff --git a/src/test/resources/sql/test_data.sql b/src/test/resources/sql/test_data.sql deleted file mode 100644 index d82e30c1..00000000 --- a/src/test/resources/sql/test_data.sql +++ /dev/null @@ -1,67 +0,0 @@ -INSERT INTO person (person_id,gender,voided,uuid) -VALUES (1, 'M', 0,'ba3b12d1-5c4f-415f-871b-b98a22137604'), - (2, 'F', 0,'2d93d0cc-6534-48ed-bebc-4accda9471a5'); - -INSERT INTO person_name (person_name_id,person_id,given_name,family_name,uuid) -VALUES (1, 1, 'John', 'Doe', '0bca417f-fc68-40d7-ae6f-cffca7a5eff1'), - (2, 2, 'Mary', 'Jane', '448bcfc0-360a-44b5-9539-e8718cd6e46e'); - -INSERT INTO person_address (person_address_id,person_id,address1,address2,city_village,state_province,postal_code,country,uuid) -VALUES (1, 1, '25 Ocean Drive', 'Apt 1', 'Fort Lauderdale', 'FL', '33301', 'United States', '359022bf-4a58-4732-8cce-1e57f72f47b0'); - -INSERT INTO patient (patient_id) -VALUES (1), - (2); - -INSERT INTO patient_identifier_type (patient_identifier_type_id,name,uuid) -VALUES (1, 'OpenMRS Id', '8d79403a-c2cc-11de-8d13-0010c6dffd0f'); - - -INSERT INTO patient_identifier (patient_identifier_id,patient_id,identifier,identifier_type,preferred,voided,uuid) -VALUES (1, 1, 'UVWYY', 1, 1, 1, '148bcfc1-360a-44b5-9539-e8718cd6e46f'), - (2, 1, '12345', 1, 1, 0, '248bcfc1-360a-44b5-9539-e8718cd6e46f'), - (3, 2, 'QWERT', 1, 1, 0, '348bcfc1-360a-44b5-9539-e8718cd6e46f'); - -/*INSERT INTO care_setting (care_setting_id,name,care_setting_type,creator,date_created,retired,uuid) -VALUES (1, 'Out-Patient', 'OUTPATIENT', 1, '2020-03-05 00:00:00', 1, '638bcfc0-360a-44a3-9539-e8718cd6e4d8'); - -INSERT INTO encounter_type (encounter_type_id,name,creator,date_created,retired,uuid) -VALUES (1, 'Adult Initial', 1, '2020-03-05 00:00:00', 0, '1d93d0cc-6534-48ed-bebc-4accda9471a5'); - -INSERT INTO encounter (encounter_id,encounter_type,patient_id,encounter_datetime,creator,date_created,voided,uuid) -VALUES (1, 1, 1, '2020-03-05 00:00:00', 1, '2020-03-05 00:00:00', 0, '5ade95d0-e095-43fc-b94f-7c585b7300f0'), - (2, 1, 2, '2020-03-05 00:00:00', 1, '2020-03-05 00:00:00', 0, '6ade95d0-e095-43fc-b94f-7c585b7300f0'); - -INSERT INTO concept_datatype (concept_datatype_id, name,creator,date_created,retired,uuid) -VALUES (1, 'N/A', 1, '2020-03-05 00:00:00', 0, '4e6dcb16-d43e-46bb-b6bf-7088b9b82139'); - -INSERT INTO concept_class (concept_class_id,name,creator,date_created,retired,uuid) -VALUES (1, 'Finding', 1, '2020-03-05 00:00:00', 0, 'f4464518-f5e2-4aab-a54e-1f1a2ec6d431'), - (2, 'Units Of Measure', 1, '2020-03-05 00:00:00', 0, 'e30d8601-07f8-413a-9d11-cdfbb28196ec'); - -INSERT INTO concept (concept_id,datatype_id,class_id,is_set,creator,date_created,retired,uuid) -VALUES (1, 1, 1, 0, 1, '2020-03-05 00:00:00', 0, '945584a3-6c4a-4cb5-ba66-964aa9614239'), - (2, 1, 2, 0, 1, '2020-03-05 00:00:00', 0, '845584a3-6c4a-4cb5-ba66-964aa9614239'), - (3, 1, 2, 0, 1, '2020-03-05 00:00:00', 0, '745584a3-6c4a-4cb5-ba66-964aa9614239'); - -INSERT INTO drug (drug_id,concept_id,combination,creator,date_created,retired,uuid) -VALUES (1, 1, 0, 1, '2020-03-05 00:00:00', 0, '1a93d0dd-6534-48ed-bebc-4aeeda9471e6'); - -INSERT INTO provider (provider_id, creator,date_created,retired,uuid) -VALUES (1, 1, '2020-03-05 00:00:00', 0, '675584a3-6c4a-4cb5-ea66-964aa9614239'); - -INSERT INTO order_type (order_type_id, name,java_class_name,creator,date_created,retired,uuid) -VALUES (1, 'Test Order', 'org.openmrs.TestOrder', 1, '2020-03-05 00:00:00', 0, '2e93d0cc-6534-48ed-bebc-4aeeda9471a5'); - -INSERT INTO orders (order_id,order_type_id,patient_id,encounter_id,concept_id,urgency,order_number,order_action,care_setting,orderer,previous_order_id,creator,date_activated,date_created,voided,uuid) -VALUES (1, 1, 2, 1, 1, 'NO-URGENCY', 'ORD-1','NEW', 1, 1, null, 1, '2020-03-05 00:00:00', '2020-03-05 00:00:00', 0, '16170d8e-d201-4d94-ae89-0be0b0b6d8ba'), - (2, 1, 1, 2, 1, 'NO-URGENCY', 'ORD-2','NEW', 1, 1, null, 1, '2020-03-05 00:00:00', '2020-03-05 00:00:00', 0, '26170d8e-d201-4d94-ae89-0be0b0b6d8ba'), - (3, 1, 1, 2, 1, 'NO-URGENCY', 'ORD-3','REVISE', 1, 1, 2, 1, '2020-03-05 00:00:00', '2020-03-05 00:00:00', 0, '36170d8e-d201-4d94-ae89-0be0b0b6d8ba'), - (4, 1, 1, 2, 1, 'NO-URGENCY', 'ORD-4','DISCONTINUE', 1, 1, 3, 1, '2020-03-05 00:00:00', '2020-03-05 00:00:00', 0, '46170d8e-d201-4d94-ae89-0be0b0b6d8ba'); - -INSERT INTO test_order (order_id) -VALUES (1); - -INSERT INTO drug_order (order_id,drug_inventory_id,dispense_as_written,quantity,quantity_units) -VALUES (2, 1, 0, 2.0, 2), - (3, 1, 0, 3.0, 3);*/