diff --git a/pom.xml b/pom.xml index 058e5d5d..1dcc6441 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.iemr.inventory inventory-api - 3.6.2 + 3.9.0 war Inventory-API Inventory Page diff --git a/src/main/java/com/iemr/inventory/repo/stockExit/PatientIssueRepo.java b/src/main/java/com/iemr/inventory/repo/stockExit/PatientIssueRepo.java index 63a48a4d..a3384fff 100644 --- a/src/main/java/com/iemr/inventory/repo/stockExit/PatientIssueRepo.java +++ b/src/main/java/com/iemr/inventory/repo/stockExit/PatientIssueRepo.java @@ -45,7 +45,15 @@ List findByFacilityIDAndCreatedDateBetweenOrderByCreatedDateDesc + " WHERE beneficiary_reg_id = :benRegID AND beneficiary_visit_code = :benVisitCode ", nativeQuery = true) public int updateBenStatusFlowAfterPharma(@Param("benRegID") Long benRegID, @Param("benVisitCode") Long benVisitCode); - + + // Store the responsible pharmacist's user ID against the visit when drugs are dispensed + @Transactional + @Modifying + @Query(value = " UPDATE t_benvisitdetail SET PharmacistID = :pharmacistID " + + " WHERE BeneficiaryRegID = :benRegID AND VisitCode = :benVisitCode ", nativeQuery = true) + public int updatePharmacistID(@Param("pharmacistID") Long pharmacistID, @Param("benRegID") Long benRegID, + @Param("benVisitCode") Long benVisitCode); + @Transactional @Modifying @Query("update T_PatientIssue p set p.vanSerialNo=p.patientIssueID where p.vanSerialNo is null and p.patientIssueID>0") diff --git a/src/main/java/com/iemr/inventory/repo/users/UserLoginRepo.java b/src/main/java/com/iemr/inventory/repo/users/UserLoginRepo.java index 86226689..509aec2d 100644 --- a/src/main/java/com/iemr/inventory/repo/users/UserLoginRepo.java +++ b/src/main/java/com/iemr/inventory/repo/users/UserLoginRepo.java @@ -13,4 +13,8 @@ public interface UserLoginRepo extends CrudRepository { @Query(" SELECT u FROM M_User u WHERE u.userID = :userID AND u.Deleted = false ") public M_User getUserByUserID(@Param("userID") Long userID); + // Resolve the responsible staff member by the username captured in createdBy + @Query(" SELECT u FROM M_User u WHERE u.UserName = :userName AND u.Deleted = false ") + public M_User getUserByUserName(@Param("userName") String userName); + } diff --git a/src/main/java/com/iemr/inventory/service/stockExit/StockExitServiceImpl.java b/src/main/java/com/iemr/inventory/service/stockExit/StockExitServiceImpl.java index 469bd6e6..e2a0122c 100644 --- a/src/main/java/com/iemr/inventory/service/stockExit/StockExitServiceImpl.java +++ b/src/main/java/com/iemr/inventory/service/stockExit/StockExitServiceImpl.java @@ -67,6 +67,9 @@ public class StockExitServiceImpl implements StockExitService { @Autowired PatientIssueRepo patientIssueRepo; + @Autowired + com.iemr.inventory.repo.users.UserLoginRepo userLoginRepo; + @Autowired StoreSelfConsumptionRepo storeSelfConsumptionRepo; @Autowired @@ -141,9 +144,26 @@ public Integer issuePatientDrugs(T_PatientIssue patientIssue) throws InventoryEx private int updateBenFlowAfterPharmaTransaction(T_PatientIssue patientIssue) throws InventoryException { int i = 0; i = patientIssueRepo.updateBenStatusFlowAfterPharma(patientIssue.getBenRegID(), patientIssue.getVisitCode()); + // Store the responsible pharmacist's user ID (resolved from the createdBy + // username) against the visit. A null/unresolved user must never block dispensing. + Long pharmacistID = resolveUserId(patientIssue.getCreatedBy()); + if (pharmacistID != null) + patientIssueRepo.updatePharmacistID(pharmacistID, patientIssue.getBenRegID(), patientIssue.getVisitCode()); return i; } + /** + * Resolve the numeric user ID of the responsible staff member from the username + * captured in createdBy. Returns null if the username is blank or cannot be + * resolved, so an unknown staff member never blocks the dispensing transaction. + */ + private Long resolveUserId(String username) { + if (username == null || username.trim().isEmpty()) + return null; + com.iemr.inventory.data.user.M_User user = userLoginRepo.getUserByUserName(username.trim()); + return user != null ? (long) user.getUserID() : null; + } + @Transactional(propagation = Propagation.MANDATORY) public Integer saveItemExit(List itemissueListUpdated, Long issueID, String issueType) { logger.info("saving ItemStockExit");