Skip to content
Open
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.iemr.inventory</groupId>
<artifactId>inventory-api</artifactId>
<version>3.6.2</version>
<version>3.9.0</version>
<packaging>war</packaging>
<name>Inventory-API</name>
<description>Inventory Page</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ List<T_PatientIssue> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ public interface UserLoginRepo extends CrudRepository<M_User, Long> {
@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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public class StockExitServiceImpl implements StockExitService {
@Autowired
PatientIssueRepo patientIssueRepo;

@Autowired
com.iemr.inventory.repo.users.UserLoginRepo userLoginRepo;

@Autowired
StoreSelfConsumptionRepo storeSelfConsumptionRepo;
@Autowired
Expand Down Expand Up @@ -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<ItemStockExit> itemissueListUpdated, Long issueID, String issueType) {
logger.info("saving ItemStockExit");
Expand Down
Loading