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
@@ -0,0 +1,63 @@
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.admin.controller.villagemapping;

import javax.ws.rs.core.MediaType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.iemr.admin.model.villagemapping.VillageUpdateRequest;
import com.iemr.admin.service.villagemapping.VillageUpdateService;
import com.iemr.admin.utils.mapper.OutputMapper;
import com.iemr.admin.utils.response.OutputResponse;

import io.swagger.v3.oas.annotations.Operation;

@RestController
@RequestMapping(value = "/villageMapping")
public class VillageUpdateController {
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Autowired

Check warning on line 46 in src/main/java/com/iemr/admin/controller/villagemapping/VillageUpdateController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this field injection and use constructor injection instead.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Admin-API&issues=AaDwtUcE3f2ysA7ZO6s6&open=AaDwtUcE3f2ysA7ZO6s6&pullRequest=153
private VillageUpdateService villageUpdateService;

@Operation(summary = "Replace a village on a user's work location mapping and move their beneficiary addresses")
@RequestMapping(value = "/updateVillage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, headers = "Authorization")

Check warning on line 50 in src/main/java/com/iemr/admin/controller/villagemapping/VillageUpdateController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "@RequestMapping(method = RequestMethod.POST)" with "@PostMapping"

See more on https://sonarcloud.io/project/issues?id=PSMRI_Admin-API&issues=AaDwtUcE3f2ysA7ZO6s7&open=AaDwtUcE3f2ysA7ZO6s7&pullRequest=153
public String updateVillage(@RequestBody VillageUpdateRequest updateRequest) {
OutputResponse response = new OutputResponse();
try {
logger.info("updateVillage received request");
response.setResponse(OutputMapper.gsonWithoutExpose().toJson(villageUpdateService.updateVillage(updateRequest)));
} catch (Exception e) {
logger.error("updateVillage failed", e);
response.setError(e);
}
logger.info("updateVillage sending response");
return response.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.admin.model.villagemapping;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public class VillageUpdateRequest {
private Integer userID;
private String userName;

@JsonProperty("uSRMappingID")
private Integer uSRMappingID;

private Integer oldVillageID;
private String oldVillageName;

private Integer newVillageID;
private String newVillageName;

private String modifiedBy;

public Integer getUserID() {
return userID;
}

public void setUserID(Integer userID) {
this.userID = userID;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

@JsonProperty("uSRMappingID")
public Integer getuSRMappingID() {
return uSRMappingID;
}

@JsonProperty("uSRMappingID")
public void setuSRMappingID(Integer uSRMappingID) {
this.uSRMappingID = uSRMappingID;
}

public Integer getOldVillageID() {
return oldVillageID;
}

public void setOldVillageID(Integer oldVillageID) {
this.oldVillageID = oldVillageID;
}

public String getOldVillageName() {
return oldVillageName;
}

public void setOldVillageName(String oldVillageName) {
this.oldVillageName = oldVillageName;
}

public Integer getNewVillageID() {
return newVillageID;
}

public void setNewVillageID(Integer newVillageID) {
this.newVillageID = newVillageID;
}

public String getNewVillageName() {
return newVillageName;
}

public void setNewVillageName(String newVillageName) {
this.newVillageName = newVillageName;
}

public String getModifiedBy() {
return modifiedBy;
}

public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.admin.model.villagemapping;

public class VillageUpdateResponse {
private Integer uSRMappingID;
private String userName;

private Integer oldVillageID;
private String oldVillageName;
private Integer newVillageID;
private String newVillageName;

private long permanentAddressesUpdated;
private long currentAddressesUpdated;
private boolean allAddressesUpdated;

public Integer getuSRMappingID() {
return uSRMappingID;
}

public void setuSRMappingID(Integer uSRMappingID) {
this.uSRMappingID = uSRMappingID;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public Integer getOldVillageID() {
return oldVillageID;
}

public void setOldVillageID(Integer oldVillageID) {
this.oldVillageID = oldVillageID;
}

public String getOldVillageName() {
return oldVillageName;
}

public void setOldVillageName(String oldVillageName) {
this.oldVillageName = oldVillageName;
}

public Integer getNewVillageID() {
return newVillageID;
}

public void setNewVillageID(Integer newVillageID) {
this.newVillageID = newVillageID;
}

public String getNewVillageName() {
return newVillageName;
}

public void setNewVillageName(String newVillageName) {
this.newVillageName = newVillageName;
}

public long getPermanentAddressesUpdated() {
return permanentAddressesUpdated;
}

public void setPermanentAddressesUpdated(long permanentAddressesUpdated) {
this.permanentAddressesUpdated = permanentAddressesUpdated;
}

public long getCurrentAddressesUpdated() {
return currentAddressesUpdated;
}

public void setCurrentAddressesUpdated(long currentAddressesUpdated) {
this.currentAddressesUpdated = currentAddressesUpdated;
}

public boolean isAllAddressesUpdated() {
return allAddressesUpdated;
}

public void setAllAddressesUpdated(boolean allAddressesUpdated) {
this.allAddressesUpdated = allAddressesUpdated;
}
}
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);

}
Loading
Loading