From 75a701adf4f8b37be95fbfac1897e394760b929e Mon Sep 17 00:00:00 2001 From: parvathy00 Date: Fri, 5 Jan 2024 12:51:45 +0530 Subject: [PATCH 1/4] Deepti, Parvathy | BAH-3299 | Add. Sorting Based on dateCreated --- .../feed/openerp/domain/encounter/MapERPOrders.java | 2 ++ .../feed/openerp/domain/encounter/OpenERPOrder.java | 13 +++++++++++-- .../openerp/domain/encounter/OpenERPOrders.java | 2 ++ .../openerp/domain/encounter/OpenMRSDrugOrder.java | 7 +++++++ .../feed/openerp/domain/encounter/OpenMRSOrder.java | 7 +++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrders.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrders.java index cca8ceb4..11ab77d3 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrders.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrders.java @@ -64,6 +64,7 @@ private String mapOpenERPOrders() throws IOException { openERPOrder.setProductId(drugOrder.getDrugUuid()); openERPOrder.setProductName(drugOrder.getDrugName()); openERPOrder.setAction(drugOrder.getAction()); + openERPOrder.setDateCreated(drugOrder.getDateActivated()); openERPOrder.setQuantity(drugOrder.getQuantity()); openERPOrder.setQuantityUnits(drugOrder.getQuantityUnits()); openERPOrder.setVoided(drugOrder.isVoided()); @@ -87,6 +88,7 @@ private String mapOpenERPOrders() throws IOException { openERPOrder.setProductId(order.getConceptUuid()); openERPOrder.setProductName(order.getConceptName()); openERPOrder.setAction(order.getAction()); + openERPOrder.setDateCreated(order.getDateCreated()); openERPOrder.setQuantity((double) 1); openERPOrder.setQuantityUnits("Unit(s)"); openERPOrder.setVoided(order.isVoided()); diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrder.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrder.java index ca05239b..d64e1dec 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrder.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrder.java @@ -1,5 +1,7 @@ package org.bahmni.feed.openerp.domain.encounter; +import java.util.Date; + public class OpenERPOrder { private String orderId; private String previousOrderId; @@ -18,6 +20,7 @@ public class OpenERPOrder { private String providerName; private String dispensed; private String conceptName; + private Date dateCreated; public String getEncounterId() { @@ -52,8 +55,6 @@ public void setType(String type) { this.type = type; } - - public String getDescription() { return description; } @@ -119,6 +120,14 @@ public void setAction(String action) { this.action = action; } + public Date getDateCreated() { + return dateCreated; + } + + public void setDateCreated(Date dateCreated) { + this.dateCreated = dateCreated; + } + public String getPreviousOrderId() { return previousOrderId; } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java index 8eb0a15b..eb2ca557 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java @@ -1,6 +1,7 @@ package org.bahmni.feed.openerp.domain.encounter; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class OpenERPOrders { @@ -21,6 +22,7 @@ public void add(OpenERPOrder order) { openERPOrders = new ArrayList<>(); } openERPOrders.add(order); + Collections.sort(openERPOrders, (order1, order2) -> order1.getDateCreated().compareTo(order2.getDateCreated())); } public void setOpenERPOrders(List openERPOrders) { diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSDrugOrder.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSDrugOrder.java index 50fa59ea..d9317885 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSDrugOrder.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSDrugOrder.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.util.Date; + @JsonIgnoreProperties(ignoreUnknown = true) public class OpenMRSDrugOrder { private OpenMRSConcept concept; @@ -13,6 +15,7 @@ public class OpenMRSDrugOrder { private String uuid; private String previousOrderUuid; private String orderType; + private Date dateActivated; private boolean voided; public OpenMRSConcept getConcept() { @@ -43,6 +46,10 @@ public String getAction() { return action; } + public Date getDateActivated() { + return dateActivated; + } + public String getUuid() { return uuid; } diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSOrder.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSOrder.java index 6e0bc9ad..b19896c1 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSOrder.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenMRSOrder.java @@ -1,11 +1,14 @@ package org.bahmni.feed.openerp.domain.encounter; +import java.util.Date; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class OpenMRSOrder { private OpenMRSConcept concept; private String action; + private Date dateCreated; private String uuid; private String orderType; private String orderNumber; @@ -21,6 +24,10 @@ public String getAction() { return action; } + public Date getDateCreated() { + return dateCreated; + } + public String getUuid() { return uuid; } From 292ca5e6a7db473f2f5e676489ccccc97411d28c Mon Sep 17 00:00:00 2001 From: parvathy00 Date: Mon, 8 Jan 2024 18:27:47 +0530 Subject: [PATCH 2/4] Deepti,Parvathy | BAH-3299 | Refactor. Removed Duplicate Orders from OpenERPOrders --- .../domain/encounter/OpenERPOrders.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java index eb2ca557..61f79fb8 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java @@ -1,8 +1,6 @@ package org.bahmni.feed.openerp.domain.encounter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; public class OpenERPOrders { private String id; @@ -14,7 +12,19 @@ public OpenERPOrders(String id){ } public List getOpenERPOrders() { - return openERPOrders; + return removeDuplicateOrders(openERPOrders); + } + + public List removeDuplicateOrders(List orders) { + Map latestOrders = new LinkedHashMap<>(); + + for (OpenERPOrder order : orders) { + latestOrders.merge(order.getProductId(), order, (existingOrder, newOrder) -> + (existingOrder.getDateCreated().before(newOrder.getDateCreated())) ? newOrder : existingOrder + ); + } + + return new ArrayList<>(latestOrders.values()); } public void add(OpenERPOrder order) { @@ -22,7 +32,6 @@ public void add(OpenERPOrder order) { openERPOrders = new ArrayList<>(); } openERPOrders.add(order); - Collections.sort(openERPOrders, (order1, order2) -> order1.getDateCreated().compareTo(order2.getDateCreated())); } public void setOpenERPOrders(List openERPOrders) { @@ -36,4 +45,4 @@ public String getId() { public void setId(String id) { this.id = id; } -} +} \ No newline at end of file From 757768f4af047f32dd284baeb3310e7daa96426f Mon Sep 17 00:00:00 2001 From: parvathy00 Date: Tue, 9 Jan 2024 16:28:06 +0530 Subject: [PATCH 3/4] Parvathy | BAH-3299 | Add. Unit test for removeDuplicateOrders method --- .../domain/encounter/OpenERPOrders.java | 1 + .../encounter/OpenERPOrdersTest.java | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/OpenERPOrdersTest.java diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java index 61f79fb8..3d2f1bfc 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java @@ -15,6 +15,7 @@ public List getOpenERPOrders() { return removeDuplicateOrders(openERPOrders); } + //Filters orders to keep only the latest action for each product. This is necessary for ensuring consistent and accurate quotation generation, particularly when order objects may not be in chronological order. public List removeDuplicateOrders(List orders) { Map latestOrders = new LinkedHashMap<>(); diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/OpenERPOrdersTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/OpenERPOrdersTest.java new file mode 100644 index 00000000..82b52564 --- /dev/null +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/OpenERPOrdersTest.java @@ -0,0 +1,44 @@ +package org.bahmni.feed.openerp.domain.labOrderType.encounter; + +import org.bahmni.feed.openerp.domain.encounter.OpenERPOrder; +import org.bahmni.feed.openerp.domain.encounter.OpenERPOrders; +import org.junit.Test; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import static org.junit.Assert.assertEquals; + +public class OpenERPOrdersTest { + + @Test + public void shouldRemoveDuplicateOrders() { + OpenERPOrder order1 = new OpenERPOrder(); + order1.setProductId("1"); + order1.setDateCreated(new Date(1704718128000L)); + + OpenERPOrder order2 = new OpenERPOrder(); + order2.setProductId("2"); + order2.setDateCreated(new Date(17047181283000L)); + + OpenERPOrder order3 = new OpenERPOrder(); + order3.setProductId("1"); + order3.setDateCreated(new Date(1704718125000L)); + + OpenERPOrder order4 = new OpenERPOrder(); + order4.setProductId("3"); + order4.setDateCreated(new Date(1704718131000L)); + + OpenERPOrders openerpOrders = new OpenERPOrders("123"); + openerpOrders.add(order1); + openerpOrders.add(order2); + openerpOrders.add(order3); + openerpOrders.add(order4); + + List result = openerpOrders.removeDuplicateOrders(openerpOrders.getOpenERPOrders()); + + List expected = Arrays.asList(order1, order2, order4); + + assertEquals(expected, result); + } +} + From d9e4409955fafdcb78b06358632cdaee15513f56 Mon Sep 17 00:00:00 2001 From: parvathy00 Date: Tue, 9 Jan 2024 16:43:25 +0530 Subject: [PATCH 4/4] Parvathy | BAH-3299 | Refactor. Changed test file path --- .../domain/{labOrderType => }/encounter/MapERPOrdersTest.java | 2 +- .../{labOrderType => }/encounter/OpenERPOrdersTest.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) rename openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/{labOrderType => }/encounter/MapERPOrdersTest.java (98%) rename openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/{labOrderType => }/encounter/OpenERPOrdersTest.java (86%) diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/MapERPOrdersTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrdersTest.java similarity index 98% rename from openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/MapERPOrdersTest.java rename to openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrdersTest.java index 9ec4fbfe..3fa8d4a4 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/MapERPOrdersTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/MapERPOrdersTest.java @@ -1,4 +1,4 @@ -package org.bahmni.feed.openerp.domain.labOrderType.encounter; +package org.bahmni.feed.openerp.domain.encounter; import org.bahmni.feed.openerp.ObjectMapperRepository; import org.bahmni.feed.openerp.domain.encounter.MapERPOrders; diff --git a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/OpenERPOrdersTest.java b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrdersTest.java similarity index 86% rename from openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/OpenERPOrdersTest.java rename to openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrdersTest.java index 82b52564..4a4ae8d0 100644 --- a/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/labOrderType/encounter/OpenERPOrdersTest.java +++ b/openerp-atomfeed-service/src/test/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrdersTest.java @@ -1,7 +1,5 @@ -package org.bahmni.feed.openerp.domain.labOrderType.encounter; +package org.bahmni.feed.openerp.domain.encounter; -import org.bahmni.feed.openerp.domain.encounter.OpenERPOrder; -import org.bahmni.feed.openerp.domain.encounter.OpenERPOrders; import org.junit.Test; import java.util.Arrays; import java.util.Date;