Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Patient weight and DOB sync #37

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,11 +43,11 @@ public class PartnerHandler {
@Autowired
private OdooUtils odooUtils;

@Getter
public List<String> partnerDefaultAttributes =
asList("id", "name", "ref", "street", "street2", "city", "zip", "active", "comment", odooCustomerDobField);
public List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,17 +63,17 @@ public class SaleOrderHandler {
@Autowired
private OdooUtils odooUtils;

@Getter
public List<String> orderDefaultAttributes = asList(
"id",
"client_order_ref",
"partner_id",
"state",
"order_line",
odooCustomerWeightField,
odooCustomerDobField);
public List<String> 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")),
Expand Down Expand Up @@ -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")) {
Comment on lines +125 to +127
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not supposed to get the actual numeric weight of the partner instead of a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in Odoo if the field is null it is set as False that's why we cast it to String in our eip routes.

updateSaleOrderWithPatientWeight(partnerId, patientID, saleOrder, producerTemplate);
}
producerTemplate.sendBody("direct:odoo-create-sale-order-line-route", saleOrderLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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());

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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);

Expand Down
Loading