@@ -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