Skip to content

Commit 05bde36

Browse files
authored
Add User Details for Clinical Staff in t_visitdetails When a Patient Visits the Facility (#128)
* fix: add clinical staff details * fix: pom version * fix: build issue on pom version
1 parent c7d6829 commit 05bde36

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.iemr.inventory</groupId>
77
<artifactId>inventory-api</artifactId>
8-
<version>3.6.2</version>
8+
<version>3.9.0</version>
99
<packaging>war</packaging>
1010
<name>Inventory-API</name>
1111
<description>Inventory Page</description>

src/main/java/com/iemr/inventory/repo/stockExit/PatientIssueRepo.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ List<T_PatientIssue> findByFacilityIDAndCreatedDateBetweenOrderByCreatedDateDesc
4545
+ " WHERE beneficiary_reg_id = :benRegID AND beneficiary_visit_code = :benVisitCode ", nativeQuery = true)
4646
public int updateBenStatusFlowAfterPharma(@Param("benRegID") Long benRegID,
4747
@Param("benVisitCode") Long benVisitCode);
48-
48+
49+
// Store the responsible pharmacist's user ID against the visit when drugs are dispensed
50+
@Transactional
51+
@Modifying
52+
@Query(value = " UPDATE t_benvisitdetail SET PharmacistID = :pharmacistID "
53+
+ " WHERE BeneficiaryRegID = :benRegID AND VisitCode = :benVisitCode ", nativeQuery = true)
54+
public int updatePharmacistID(@Param("pharmacistID") Long pharmacistID, @Param("benRegID") Long benRegID,
55+
@Param("benVisitCode") Long benVisitCode);
56+
4957
@Transactional
5058
@Modifying
5159
@Query("update T_PatientIssue p set p.vanSerialNo=p.patientIssueID where p.vanSerialNo is null and p.patientIssueID>0")

src/main/java/com/iemr/inventory/repo/users/UserLoginRepo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ public interface UserLoginRepo extends CrudRepository<M_User, Long> {
1313
@Query(" SELECT u FROM M_User u WHERE u.userID = :userID AND u.Deleted = false ")
1414
public M_User getUserByUserID(@Param("userID") Long userID);
1515

16+
// Resolve the responsible staff member by the username captured in createdBy
17+
@Query(" SELECT u FROM M_User u WHERE u.UserName = :userName AND u.Deleted = false ")
18+
public M_User getUserByUserName(@Param("userName") String userName);
19+
1620
}

src/main/java/com/iemr/inventory/service/stockExit/StockExitServiceImpl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public class StockExitServiceImpl implements StockExitService {
6767
@Autowired
6868
PatientIssueRepo patientIssueRepo;
6969

70+
@Autowired
71+
com.iemr.inventory.repo.users.UserLoginRepo userLoginRepo;
72+
7073
@Autowired
7174
StoreSelfConsumptionRepo storeSelfConsumptionRepo;
7275
@Autowired
@@ -141,9 +144,26 @@ public Integer issuePatientDrugs(T_PatientIssue patientIssue) throws InventoryEx
141144
private int updateBenFlowAfterPharmaTransaction(T_PatientIssue patientIssue) throws InventoryException {
142145
int i = 0;
143146
i = patientIssueRepo.updateBenStatusFlowAfterPharma(patientIssue.getBenRegID(), patientIssue.getVisitCode());
147+
// Store the responsible pharmacist's user ID (resolved from the createdBy
148+
// username) against the visit. A null/unresolved user must never block dispensing.
149+
Long pharmacistID = resolveUserId(patientIssue.getCreatedBy());
150+
if (pharmacistID != null)
151+
patientIssueRepo.updatePharmacistID(pharmacistID, patientIssue.getBenRegID(), patientIssue.getVisitCode());
144152
return i;
145153
}
146154

155+
/**
156+
* Resolve the numeric user ID of the responsible staff member from the username
157+
* captured in createdBy. Returns null if the username is blank or cannot be
158+
* resolved, so an unknown staff member never blocks the dispensing transaction.
159+
*/
160+
private Long resolveUserId(String username) {
161+
if (username == null || username.trim().isEmpty())
162+
return null;
163+
com.iemr.inventory.data.user.M_User user = userLoginRepo.getUserByUserName(username.trim());
164+
return user != null ? (long) user.getUserID() : null;
165+
}
166+
147167
@Transactional(propagation = Propagation.MANDATORY)
148168
public Integer saveItemExit(List<ItemStockExit> itemissueListUpdated, Long issueID, String issueType) {
149169
logger.info("saving ItemStockExit");

0 commit comments

Comments
 (0)