From 1f0e3446bc0f58537824ebe55c1fd8a0c31cb4df Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Wed, 7 Aug 2024 17:58:24 +0100 Subject: [PATCH] add method to fetch inventory row by medical code and lot code --- .../manager/MedicalInventoryManager.java | 13 +++++++++---- .../manager/MedicalInventoryRowManager.java | 13 +++++++++++++ .../service/MedicalInventoryRowIoOperation.java | 12 ++++++++++++ .../MedicalInventoryRowIoOperationRepository.java | 3 +++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index bde0aeb01..5ab051d2e 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -229,7 +229,7 @@ private void validateMedicalInventory(MedicalInventory medInventory) throws OHDa @Transactional(rollbackFor = OHServiceException.class) public void validateInventory(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { - LocalDateTime movFrom = inventory.getInventoryDate(); + LocalDateTime movFrom = inventory.getLastModifiedDate(); LocalDateTime movTo = TimeTools.getNow(); List movements = movBrowserManager.getMovements(null, null, null, null, movFrom, movTo, null, null, null, null); if (!movements.isEmpty()) { @@ -240,7 +240,7 @@ public void validateInventory(MedicalInventory inventory, List movs = groupedByMedical.get(medical); - if (!movs.isEmpty()) { + if (movs != null) { for (Movement mov: movs) { String lotCodeOfMovement = mov.getLot().getCode(); Lot lot = movStockInsertingManager.getLot(lotCodeOfMovement); @@ -248,11 +248,16 @@ public void validateInventory(MedicalInventory inventory, List getMedicalInventoryRowByInventoryId(int invento public Optional getMedicalInventoryRowById(Integer id) throws OHServiceException { return repository.findById(id); } + + /** + * Return {@link MedicalInventoryRow} for passed param. + * + * @param medicalCode - the medical code. + * @param lotCode - the lot code. + * @return the {@link MedicalInventoryRow} object. + * @throws OHServiceException + */ + public MedicalInventoryRow getMedicalInventoryRowByMedicalCodeAndLotCode(Integer medicalCode, String lotCode) throws OHServiceException { + return repository.findByMedicalCodeAndLotCode(medicalCode, lotCode); + } } diff --git a/src/main/java/org/isf/medicalinventory/service/MedicalInventoryRowIoOperationRepository.java b/src/main/java/org/isf/medicalinventory/service/MedicalInventoryRowIoOperationRepository.java index a4e3749e4..a1faab4c2 100644 --- a/src/main/java/org/isf/medicalinventory/service/MedicalInventoryRowIoOperationRepository.java +++ b/src/main/java/org/isf/medicalinventory/service/MedicalInventoryRowIoOperationRepository.java @@ -34,4 +34,7 @@ public interface MedicalInventoryRowIoOperationRepository extends JpaRepository< @Query(value = "select medinvrow from MedicalInventoryRow medinvrow where medinvrow.inventory.id = :inventoryId") List findByInventoryId(@Param("inventoryId") int inventoryId); + + @Query(value = "select medinvrow from MedicalInventoryRow medinvrow where medinvrow.medical.code = :medicalCode and medinvrow.lot.code = :lotCode") + MedicalInventoryRow findByMedicalCodeAndLotCode(@Param("medicalCode") int medicalCode, @Param("lotCode") String lotCode); }