From f14d693c43be76cb4da94f987c4dfe11ba026567 Mon Sep 17 00:00:00 2001 From: Siddharth Vaish Date: Mon, 9 Dec 2024 15:03:42 +0530 Subject: [PATCH] Fix Patient weight sync and DOB sync --- .../odoo/openmrs/handlers/PartnerHandler.java | 7 ++-- .../openmrs/handlers/SaleOrderHandler.java | 23 +++++----- .../processors/ServiceRequestProcessor.java | 1 - .../openmrs/handlers/PartnerHandlerTest.java | 17 +++----- .../handlers/SaleOrderHandlerTest.java | 42 +++++++++---------- 5 files changed, 41 insertions(+), 49 deletions(-) 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 index c244579..89f5822 100644 --- 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 @@ -17,7 +17,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.camel.ProducerTemplate; @@ -44,11 +43,11 @@ public class PartnerHandler { @Autowired private OdooUtils odooUtils; - @Getter - public List partnerDefaultAttributes = - asList("id", "name", "ref", "street", "street2", "city", "zip", "active", "comment", odooCustomerDobField); + public List partnerDefaultAttributes; public Partner getPartnerByID(String partnerRefID) { + partnerDefaultAttributes = asList( + "id", "name", "ref", "street", "street2", "city", "zip", "active", "comment", odooCustomerDobField); Object[] records = odooClient.searchAndRead( Constants.PARTNER_MODEL, List.of(asList("ref", "=", partnerRefID)), partnerDefaultAttributes); if (records == null) { 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 index 1fef5d6..d58e56f 100644 --- 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 @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.camel.ProducerTemplate; @@ -64,17 +63,17 @@ public class SaleOrderHandler { @Autowired private OdooUtils odooUtils; - @Getter - public List orderDefaultAttributes = asList( - "id", - "client_order_ref", - "partner_id", - "state", - "order_line", - odooCustomerWeightField, - odooCustomerDobField); + public List orderDefaultAttributes; public SaleOrder getDraftSaleOrderIfExistsByVisitId(String visitId) { + orderDefaultAttributes = asList( + "id", + "client_order_ref", + "partner_id", + "state", + "order_line", + odooCustomerWeightField, + odooCustomerDobField); Object[] records = odooClient.searchAndRead( Constants.SALE_ORDER_MODEL, List.of(asList("client_order_ref", "=", visitId), asList("state", "=", "draft")), @@ -123,7 +122,9 @@ public void updateSaleOrderIfExistsWithSaleOrderLine( } // Update sale order with Patient Weight if not already present - if (saleOrder.getPartnerWeight() == null || saleOrder.getPartnerWeight().isEmpty()) { + if (saleOrder.getPartnerWeight() == null + || saleOrder.getPartnerWeight().isEmpty() + || saleOrder.getPartnerWeight().equals("false")) { updateSaleOrderWithPatientWeight(partnerId, patientID, saleOrder, producerTemplate); } producerTemplate.sendBody("direct:odoo-create-sale-order-line-route", saleOrderLine); 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 index 163ab36..10d30e2 100644 --- 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 @@ -69,7 +69,6 @@ public void process(Exchange exchange) { } String encounterVisitUuid = encounter.getPartOf().getReference().split("/")[1]; Partner partner = partnerHandler.createOrUpdatePartner(producerTemplate, patient); - // 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)) { diff --git a/odoo-openmrs/src/test/java/com/ozonehis/eip/odoo/openmrs/handlers/PartnerHandlerTest.java b/odoo-openmrs/src/test/java/com/ozonehis/eip/odoo/openmrs/handlers/PartnerHandlerTest.java index ae3e0aa..1b3e364 100644 --- a/odoo-openmrs/src/test/java/com/ozonehis/eip/odoo/openmrs/handlers/PartnerHandlerTest.java +++ b/odoo-openmrs/src/test/java/com/ozonehis/eip/odoo/openmrs/handlers/PartnerHandlerTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -81,9 +82,7 @@ public void shouldReturnPartnerWhenOnlyOneGetPartnerByID() { // Mock behavior when(odooClient.searchAndRead( - Constants.PARTNER_MODEL, - List.of(asList("ref", "=", PARTNER_REF_ID)), - partnerHandler.getPartnerDefaultAttributes())) + eq(Constants.PARTNER_MODEL), eq(List.of(asList("ref", "=", PARTNER_REF_ID))), any())) .thenReturn(partners); // Act @@ -107,9 +106,7 @@ public void shouldThrowErrorWhenMultiplePartnersWithSameIdExists() { // Mock behavior when(odooClient.searchAndRead( - Constants.PARTNER_MODEL, - List.of(asList("ref", "=", PARTNER_REF_ID)), - partnerHandler.getPartnerDefaultAttributes())) + eq(Constants.PARTNER_MODEL), eq(List.of(asList("ref", "=", PARTNER_REF_ID))), any())) .thenReturn(partners); // Verify @@ -132,9 +129,7 @@ public void shouldReturnPartnerIdAndUpdatePartnerWhenGetPartnerByID() { // Mock behavior ProducerTemplate producerTemplate = Mockito.mock(ProducerTemplate.class); when(odooClient.searchAndRead( - Constants.PARTNER_MODEL, - List.of(asList("ref", "=", patient.getIdPart())), - partnerHandler.getPartnerDefaultAttributes())) + eq(Constants.PARTNER_MODEL), eq(List.of(asList("ref", "=", patient.getIdPart()))), any())) .thenReturn(partners); when(partnerMapper.toOdoo(patient)).thenReturn(getPartner()); @@ -158,9 +153,7 @@ public void shouldReturnPartnerIdAndCreatePartnerWhenPartnerDoesNotExists() { // Mock behavior ProducerTemplate producerTemplate = Mockito.mock(ProducerTemplate.class); when(odooClient.searchAndRead( - Constants.PARTNER_MODEL, - List.of(asList("ref", "=", patient.getIdPart())), - partnerHandler.getPartnerDefaultAttributes())) + eq(Constants.PARTNER_MODEL), eq(List.of(asList("ref", "=", patient.getIdPart()))), any())) .thenReturn(new Object[] {}) .thenReturn(new Object[] {getPartnerMap()}); when(partnerMapper.toOdoo(patient)).thenReturn(getPartner()); diff --git a/odoo-openmrs/src/test/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderHandlerTest.java b/odoo-openmrs/src/test/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderHandlerTest.java index 70ec971..13b2622 100644 --- a/odoo-openmrs/src/test/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderHandlerTest.java +++ b/odoo-openmrs/src/test/java/com/ozonehis/eip/odoo/openmrs/handlers/SaleOrderHandlerTest.java @@ -101,9 +101,9 @@ public void shouldReturnSaleOrderWhenOnlyOneSaleOrderExistsWithVisitId() { // Mock behavior when(odooClient.searchAndRead( - Constants.SALE_ORDER_MODEL, - List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft")), - saleOrderHandler.getOrderDefaultAttributes())) + eq(Constants.SALE_ORDER_MODEL), + eq(List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft"))), + any())) .thenReturn(saleOrders); // Act @@ -127,9 +127,9 @@ public void shouldThrowErrorWhenMultipleSaleOrderExistsWithSameVisitId() { // Mock behavior when(odooClient.searchAndRead( - Constants.SALE_ORDER_MODEL, - List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft")), - saleOrderHandler.getOrderDefaultAttributes())) + eq(Constants.SALE_ORDER_MODEL), + eq(List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft"))), + any())) .thenReturn(saleOrders); // Verify @@ -143,9 +143,9 @@ public void shouldReturnNullWhenNoSaleOrderExistsWithVisitId() { // Mock behavior when(odooClient.searchAndRead( - Constants.SALE_ORDER_MODEL, - List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft")), - saleOrderHandler.getOrderDefaultAttributes())) + eq(Constants.SALE_ORDER_MODEL), + eq(List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft"))), + any())) .thenReturn(saleOrders); // Act @@ -159,9 +159,9 @@ public void shouldReturnNullWhenNoSaleOrderExistsWithVisitId() { public void shouldThrowErrorWhenNullResponseFromClient() { // Mock behavior when(odooClient.searchAndRead( - Constants.SALE_ORDER_MODEL, - List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft")), - saleOrderHandler.getOrderDefaultAttributes())) + eq(Constants.SALE_ORDER_MODEL), + eq(List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft"))), + any())) .thenReturn(null); // Verify @@ -203,9 +203,9 @@ public void shouldCreateSaleOrderWithSaleOrderLine() { // Mock behaviour when(saleOrderMapper.toOdoo(encounter)).thenReturn(saleOrder); when(odooClient.searchAndRead( - Constants.SALE_ORDER_MODEL, - List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft")), - saleOrderHandler.getOrderDefaultAttributes())) + eq(Constants.SALE_ORDER_MODEL), + eq(List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft"))), + any())) .thenReturn(new Object[] {saleOrderMap}); when(saleOrderLineHandler.buildSaleOrderLineIfProductExists(resource, saleOrder)) .thenReturn(saleOrderLine); @@ -238,9 +238,9 @@ public void shouldDeleteSaleOrderLine() { // Mock behaviour when(odooClient.searchAndRead( - Constants.SALE_ORDER_MODEL, - List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft")), - saleOrderHandler.getOrderDefaultAttributes())) + eq(Constants.SALE_ORDER_MODEL), + eq(List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft"))), + any())) .thenReturn(new Object[] {saleOrderMap}); when(productHandler.getProduct(resource)).thenReturn(product); when(saleOrderLineHandler.getSaleOrderLineIfExists(saleOrder.getOrderId(), product.getProductResId())) @@ -269,9 +269,9 @@ public void shouldCancelSaleOrderWhenNoSaleOrderLine() { // Mock behaviour when(odooClient.searchAndRead( - Constants.SALE_ORDER_MODEL, - List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft")), - saleOrderHandler.getOrderDefaultAttributes())) + eq(Constants.SALE_ORDER_MODEL), + eq(List.of(asList("client_order_ref", "=", VISIT_ID_1), asList("state", "=", "draft"))), + any())) .thenReturn(new Object[] {saleOrderMap}); ProducerTemplate producerTemplate = Mockito.mock(ProducerTemplate.class);