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

BAH-3299 | Handle Inconsistent Behaviour of Quotation Updation #100

Merged
merged 4 commits into from
Jan 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 @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.bahmni.feed.openerp.domain.encounter;

import java.util.Date;

public class OpenERPOrder {
private String orderId;
private String previousOrderId;
Expand All @@ -18,6 +20,7 @@ public class OpenERPOrder {
private String providerName;
private String dispensed;
private String conceptName;
private Date dateCreated;


public String getEncounterId() {
Expand Down Expand Up @@ -52,8 +55,6 @@ public void setType(String type) {
this.type = type;
}



public String getDescription() {
return description;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.bahmni.feed.openerp.domain.encounter;

import java.util.ArrayList;
import java.util.List;
import java.util.*;

public class OpenERPOrders {
private String id;
Expand All @@ -13,7 +12,20 @@ public OpenERPOrders(String id){
}

public List<OpenERPOrder> getOpenERPOrders() {
return openERPOrders;
return removeDuplicateOrders(openERPOrders);
}

parvathy00 marked this conversation as resolved.
Show resolved Hide resolved
//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<OpenERPOrder> removeDuplicateOrders(List<OpenERPOrder> orders) {
Map<String, OpenERPOrder> latestOrders = new LinkedHashMap<>();

for (OpenERPOrder order : orders) {
parvathy00 marked this conversation as resolved.
Show resolved Hide resolved
latestOrders.merge(order.getProductId(), order, (existingOrder, newOrder) ->
(existingOrder.getDateCreated().before(newOrder.getDateCreated())) ? newOrder : existingOrder
);
}

return new ArrayList<>(latestOrders.values());
}

public void add(OpenERPOrder order) {
Expand All @@ -34,4 +46,4 @@ public String getId() {
public void setId(String id) {
this.id = id;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.Date;

@JsonIgnoreProperties(ignoreUnknown = true)
public class OpenMRSDrugOrder {
private OpenMRSConcept concept;
Expand All @@ -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() {
Expand Down Expand Up @@ -43,6 +46,10 @@ public String getAction() {
return action;
}

public Date getDateActivated() {
return dateActivated;
}

public String getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +24,10 @@ public String getAction() {
return action;
}

public Date getDateCreated() {
return dateCreated;
}

public String getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.bahmni.feed.openerp.domain.encounter;

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<OpenERPOrder> result = openerpOrders.removeDuplicateOrders(openerpOrders.getOpenERPOrders());

List<OpenERPOrder> expected = Arrays.asList(order1, order2, order4);

assertEquals(expected, result);
}
}

Loading