From e2d6d0b49a09c06a1a536720ce74a03ab8c26012 Mon Sep 17 00:00:00 2001 From: FOFOU FONZAM Gui Arnaud Date: Tue, 3 Dec 2024 01:40:30 +0100 Subject: [PATCH] OP-1368 | Make Inventory status language independent (#1460) * update file step_a104_add_inventory_in_pharmacy.sql * add method to manage status * update src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java * revert the changes * Update src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java Co-authored-by: David B Malkovsky --------- Co-authored-by: ArnaudFofou Co-authored-by: David B Malkovsky Co-authored-by: Alessandro Domanico --- .../manager/MedicalInventoryManager.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 30e2b1101..7fe74f3b7 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -23,8 +23,10 @@ import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -49,6 +51,7 @@ import org.isf.utils.exception.model.OHExceptionMessage; import org.isf.utils.exception.model.OHSeverityLevel; import org.isf.utils.time.TimeTools; +import org.isf.utils.validator.DefaultSorter; import org.isf.ward.manager.WardBrowserManager; import org.isf.ward.model.Ward; import org.springframework.data.domain.Page; @@ -71,6 +74,8 @@ public class MedicalInventoryManager { private final SupplierBrowserManager supplierManager; private final WardBrowserManager wardManager; + + protected Map statusHashMap; public MedicalInventoryManager(MedicalInventoryIoOperation medicalInventoryIoOperation, MedicalInventoryRowManager medicalInventoryRowManager, MedicalDsrStockMovementTypeBrowserManager medicalDsrStockMovementTypeBrowserManager, @@ -514,4 +519,47 @@ public MedicalInventory actualizeMedicalInventoryRow(MedicalInventory inventory) } return this.updateMedicalInventory(inventory, true); } + + private void buildStatusHashMap() { + statusHashMap = new HashMap<>(4); + statusHashMap.put("canceled", MessageBundle.getMessage("angal.inventory.status.canceled.txt")); + statusHashMap.put("draft", MessageBundle.getMessage("angal.inventory.status.draft.txt")); + statusHashMap.put("done", MessageBundle.getMessage("angal.inventory.status.done.txt")); + statusHashMap.put("validated", MessageBundle.getMessage("angal.inventory.status.validated.txt")); + } + + /** + * Return a list of status: + * draft, + * done, + * canceled, + * validated + * + * @return + */ + public List getStatusList() { + if (statusHashMap == null) { + buildStatusHashMap(); + } + List statusList = new ArrayList<>(statusHashMap.values()); + statusList.sort(new DefaultSorter(MessageBundle.getMessage("angal.inventory.status.draft.txt"))); + return statusList; + } + + /** + * Return a value of the key on statusHashMap. + * @param key - the key of status + * @return the value of the key or empty string if key is not on statusHashMap. + */ + public String getStatusByKey(String key) { + if (statusHashMap == null) { + buildStatusHashMap(); + } + for (Map.Entry entry : statusHashMap.entrySet()) { + if (entry.getKey().equals(key)) { + return entry.getValue(); + } + } + return ""; + } }