Skip to content
Merged
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.admin</groupId>
<artifactId>admin-api</artifactId>
<version>3.8.2</version>
<version>3.8.4</version>
<packaging>war</packaging>
<name>Admin-API</name>
<description>Admin Page</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,12 @@ public String UserRoleMappings(@RequestBody String userRoleMapping, HttpServletR
Previleges1097_3[] predata1 = pre.get(x).getPrevileges();
for (Previleges1097_3 previl : predata1) {

// Each role in the ID array must become its own saved row. This used to
// build a single M_UserServiceRoleMapping2 across all iterations of this
// loop and only add it to resList1 once, after the loop β€” so a batched
// request carrying multiple roles (e.g. Nurse + Counsellor) silently
// discarded every role but the last one. Moving the object creation and
// the add() call inside the loop saves one row per role, as intended.
Priveleges1097_2[] predata2 = previl.getID();
for (Priveleges1097_2 previl1 : predata2) {
resDataMap1 = new M_UserServiceRoleMapping2();
Expand All @@ -1800,22 +1806,22 @@ public String UserRoleMappings(@RequestBody String userRoleMapping, HttpServletR
if (previl1.getTeleConsultation() != null) {
resDataMap1.setTeleConsultation(previl1.getTeleConsultation());
}
resDataMap1.setUserID(employeeMaster.get(x).getUserID());
resDataMap1.setProviderServiceMapID(previl.getProviderServiceMapID());
resDataMap1.setWorkingLocationID(previl.getWorkingLocationID());
resDataMap1.setStateID(previl.getStateID());
resDataMap1.setDistrictID(previl.getDistrictID());
resDataMap1.setCreatedBy(employeeMaster.get(x).getCreatedBy());
resDataMap1.setServiceProviderID(employeeMaster.get(x).getServiceProviderID());
resDataMap1.setBlockID(previl.getBlockID());
resDataMap1.setBlockName(previl.getBlockName());
resDataMap1.setVillageID(previl.getVillageID());
resDataMap1.setVillageName(previl.getVillageName());
resDataMap1.setFacilityID(previl.getFacilityID());
resDataMap1.setNikshayTUID(previl.getNikshayTUID());
resDataMap1.setNikshayFacilityID(previl.getNikshayFacilityID());
resList1.add(resDataMap1);
}
resDataMap1.setUserID(employeeMaster.get(x).getUserID());
resDataMap1.setProviderServiceMapID(previl.getProviderServiceMapID());
resDataMap1.setWorkingLocationID(previl.getWorkingLocationID());
resDataMap1.setStateID(previl.getStateID());
resDataMap1.setDistrictID(previl.getDistrictID());
resDataMap1.setCreatedBy(employeeMaster.get(x).getCreatedBy());
resDataMap1.setServiceProviderID(employeeMaster.get(x).getServiceProviderID());
resDataMap1.setBlockID(previl.getBlockID());
resDataMap1.setBlockName(previl.getBlockName());
resDataMap1.setVillageID(previl.getVillageID());
resDataMap1.setVillageName(previl.getVillageName());
resDataMap1.setFacilityID(previl.getFacilityID());
resDataMap1.setNikshayTUID(previl.getNikshayTUID());
resDataMap1.setNikshayFacilityID(previl.getNikshayFacilityID());
resList1.add(resDataMap1);

}
x++;
Expand Down Expand Up @@ -1863,11 +1869,15 @@ public String updateUserRoleMapping(@RequestBody String updateUserRoleMapping, H
}
}

// Soft-delete other active mappings for same user+service to prevent duplicates
// (e.g. old roleID 122 rows left over when new roleID 128 mapping was created)
if (pre.getUserID() != null && pre.getProviderServiceMapID() != null && pre.getuSRMappingID() != null) {
// Soft-delete other active mappings for same user+service+role to prevent
// duplicates (e.g. a stale leftover row still claiming this same role).
// Scoped by roleID as well as user+service β€” otherwise this deletes every
// OTHER role the user holds under this service line too, not just true
// duplicates of the role being saved here.
if (pre.getUserID() != null && pre.getProviderServiceMapID() != null && pre.getRoleID() != null
&& pre.getuSRMappingID() != null) {
employeeMasterInter.softDeleteOldMappings(
pre.getUserID(), pre.getProviderServiceMapID(), pre.getuSRMappingID());
pre.getUserID(), pre.getProviderServiceMapID(), pre.getRoleID(), pre.getuSRMappingID());
}

usrRole.setUserID(pre.getUserID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,15 @@ boolean existsByUserIDAndRoleIDAndProviderServiceMapIDAndFacilityIDAndDeletedFal
// Fix 2: count active USR rows for supervisor (check if other facilities remain)
long countByUserIDAndRoleIDAndDeletedFalse(Integer userID, Integer roleID);

// Soft-delete old duplicate mappings for same user+service, excluding the current row being updated
// Soft-delete old duplicate mappings for the SAME user+service+role, excluding
// the current row being updated. Previously left roleID out of the WHERE
// clause entirely, so updating any one role's mapping soft-deleted every
// OTHER active role that user held under the same service line (e.g. saving
// Registration Officer wiped out an unrelated, already-active Counsellor
// mapping) instead of only cleaning up true duplicates of the same role.
@Transactional
@Modifying
@Query("UPDATE M_UserServiceRoleMapping2 u SET u.deleted = true WHERE u.userID = :userID AND u.providerServiceMapID = :providerServiceMapID AND u.uSRMappingID != :excludeUSRMappingID AND u.deleted = false")
int softDeleteOldMappings(@Param("userID") Integer userID, @Param("providerServiceMapID") Integer providerServiceMapID, @Param("excludeUSRMappingID") Integer excludeUSRMappingID);
@Query("UPDATE M_UserServiceRoleMapping2 u SET u.deleted = true WHERE u.userID = :userID AND u.providerServiceMapID = :providerServiceMapID AND u.roleID = :roleID AND u.uSRMappingID != :excludeUSRMappingID AND u.deleted = false")
int softDeleteOldMappings(@Param("userID") Integer userID, @Param("providerServiceMapID") Integer providerServiceMapID, @Param("roleID") Integer roleID, @Param("excludeUSRMappingID") Integer excludeUSRMappingID);

}
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ Boolean checkingEmpDetails(String userName, String aadhaarNo, String getpAN, Str
// Fix 2: cascade soft-delete asha_supervisor_mapping rows when a user is deactivated
void cascadeDeleteAshaMappingsForUser(Integer userID);

// Soft-delete other active mappings for same user+service, excluding the row being updated
int softDeleteOldMappings(Integer userID, Integer providerServiceMapID, Integer excludeUSRMappingID);
// Soft-delete other active mappings for same user+service+role, excluding the row being updated
int softDeleteOldMappings(Integer userID, Integer providerServiceMapID, Integer roleID, Integer excludeUSRMappingID);

// Fix 2: smart cascade β€” for supervisor with multiple facilities, only delete mappings for this facility
void cascadeDeleteAshaMappingsForDeactivation(M_UserServiceRoleMapping2 usrRole);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,8 @@ public void cascadeDeleteAshaMappingsForUser(Integer userID) {
}

@Override
public int softDeleteOldMappings(Integer userID, Integer providerServiceMapID, Integer excludeUSRMappingID) {
return employeeMasterRepo.softDeleteOldMappings(userID, providerServiceMapID, excludeUSRMappingID);
public int softDeleteOldMappings(Integer userID, Integer providerServiceMapID, Integer roleID, Integer excludeUSRMappingID) {
return employeeMasterRepo.softDeleteOldMappings(userID, providerServiceMapID, roleID, excludeUSRMappingID);
}

@Override
Expand Down
Loading