Skip to content

Commit

Permalink
OP-1368 | Make Inventory status language independent (#1460)
Browse files Browse the repository at this point in the history
* 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 <david@malkovsky.org>

---------

Co-authored-by: ArnaudFofou <gui.fofou@umi2growcameroun.com>
Co-authored-by: David B Malkovsky <david@malkovsky.org>
Co-authored-by: Alessandro Domanico <alessandro.domanico@yahoo.it>
  • Loading branch information
4 people authored Dec 3, 2024
1 parent eb11fa3 commit e2d6d0b
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -71,6 +74,8 @@ public class MedicalInventoryManager {
private final SupplierBrowserManager supplierManager;

private final WardBrowserManager wardManager;

protected Map<String, String> statusHashMap;

public MedicalInventoryManager(MedicalInventoryIoOperation medicalInventoryIoOperation, MedicalInventoryRowManager medicalInventoryRowManager,
MedicalDsrStockMovementTypeBrowserManager medicalDsrStockMovementTypeBrowserManager,
Expand Down Expand Up @@ -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<String> getStatusList() {
if (statusHashMap == null) {
buildStatusHashMap();
}
List<String> 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<String, String> entry : statusHashMap.entrySet()) {
if (entry.getKey().equals(key)) {
return entry.getValue();
}
}
return "";
}
}

0 comments on commit e2d6d0b

Please sign in to comment.