Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4f6371f
fix(employee-master): validate username uniqueness on edit, stop clea…
Aug 25, 2026
7190d37
feat(admin): add username rename API with audit trail propagation
Aug 31, 2026
cd20896
fix(admin): make username rename preview index-friendly and exact
Aug 31, 2026
4d42252
Revert "fix(admin): make username rename preview index-friendly and e…
Aug 31, 2026
c1df922
refactor(admin): drive username rename updates by primary key
Aug 31, 2026
98c2f34
feat(admin): drop the username rename preview endpoint
Sep 1, 2026
beb3994
feat(admin): accept an optional new Employee ID on username rename
Sep 1, 2026
400bb62
feat(admin): add username/employee ID availability endpoint
Sep 1, 2026
9ebf661
feat(admin): update username and employee ID independently
Sep 2, 2026
14cde07
feat(admin): address the rename target by userID
Sep 2, 2026
be4c3cc
fix(admin): return the employee ID in the rename response
Sep 2, 2026
9fed960
feat(admin): drop row/table counts from the rename response
Sep 2, 2026
547aab1
Revert "fix(employee-master): validate username uniqueness on edit, s…
Sep 2, 2026
6571d39
revert: undo the employee edit page username/Employee ID changes
Sep 2, 2026
a28369b
style(admin): remove comments from the username rename classes
Sep 2, 2026
a3489c1
fix(admin): address the scan findings on the username rename
Sep 2, 2026
29d1378
fix(admin): stop logging request-derived strings on rename
Sep 2, 2026
87635fc
fix(admin): build rename SQL from constants, not formatted strings
Sep 2, 2026
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.username;

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.username.UsernameRenameRequest;
import com.iemr.admin.service.username.UsernameRenameService;
import com.iemr.admin.utils.mapper.OutputMapper;
import com.iemr.admin.utils.response.OutputResponse;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;

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

@Autowired

Check warning on line 47 in src/main/java/com/iemr/admin/controller/username/UsernameRenameController.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=AaBhPxlbfKau5aNsCDHn&open=AaBhPxlbfKau5aNsCDHn&pullRequest=146
private UsernameRenameService usernameRenameService;

@Operation(summary = "Rename a username and repoint its audit records")
@RequestMapping(value = "/renameUsername", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, headers = "Authorization")

Check warning on line 51 in src/main/java/com/iemr/admin/controller/username/UsernameRenameController.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=AaBhPxlbfKau5aNsCDHo&open=AaBhPxlbfKau5aNsCDHo&pullRequest=146
public String renameUsername(@RequestBody UsernameRenameRequest renameRequest, HttpServletRequest request) {
OutputResponse response = new OutputResponse();
try {
logger.info("renameUsername received request");
response.setResponse(OutputMapper.gsonWithoutExpose().toJson(usernameRenameService.rename(renameRequest)));
} catch (Exception e) {
logger.error("renameUsername failed", e);
response.setError(e);
}
logger.info("renameUsername sending response");
return response.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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.username;

public class UsernameRenameRequest {
private Integer userID;

private String oldUserName;
private String newUserName;

private String newEmployeeId;

private boolean updateContactFields = true;

public Integer getUserID() {
return userID;
}

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

public String getOldUserName() {
return oldUserName;
}

public void setOldUserName(String oldUserName) {
this.oldUserName = oldUserName;
}

public String getNewUserName() {
return newUserName;
}

public void setNewUserName(String newUserName) {
this.newUserName = newUserName;
}

public String getNewEmployeeId() {
return newEmployeeId;
}

public void setNewEmployeeId(String newEmployeeId) {
this.newEmployeeId = newEmployeeId;
}

public boolean isUpdateContactFields() {
return updateContactFields;
}

public void setUpdateContactFields(boolean updateContactFields) {
this.updateContactFields = updateContactFields;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.username;

public class UsernameRenameResponse {
private String oldUserName;
private String newUserName;

private String oldEmployeeId;
private String newEmployeeId;

private boolean userNameUpdated;
private boolean employeeIdUpdated;

public boolean isUserNameUpdated() {
return userNameUpdated;
}

public void setUserNameUpdated(boolean userNameUpdated) {
this.userNameUpdated = userNameUpdated;
}

public boolean isEmployeeIdUpdated() {
return employeeIdUpdated;
}

public void setEmployeeIdUpdated(boolean employeeIdUpdated) {
this.employeeIdUpdated = employeeIdUpdated;
}

public String getOldEmployeeId() {
return oldEmployeeId;
}

public void setOldEmployeeId(String oldEmployeeId) {
this.oldEmployeeId = oldEmployeeId;
}

public String getNewEmployeeId() {
return newEmployeeId;
}

public void setNewEmployeeId(String newEmployeeId) {
this.newEmployeeId = newEmployeeId;
}

public String getOldUserName() {
return oldUserName;
}

public void setOldUserName(String oldUserName) {
this.oldUserName = oldUserName;
}

public String getNewUserName() {
return newUserName;
}

public void setNewUserName(String newUserName) {
this.newUserName = newUserName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* 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.repository.username;

import java.util.List;
import java.util.regex.Pattern;

public final class UsernameAuditTables {
private UsernameAuditTables() {
}

private static final Pattern SQL_IDENTIFIER = Pattern.compile("\\w+(\\.\\w+)?");

private static String identifier(String name) {

Check warning on line 33 in src/main/java/com/iemr/admin/repository/username/UsernameAuditTables.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this method into "AuditTable".

See more on https://sonarcloud.io/project/issues?id=PSMRI_Admin-API&issues=AaBhkfNHK4KaJIlFNXAU&open=AaBhkfNHK4KaJIlFNXAU&pullRequest=146
if (name == null || !SQL_IDENTIFIER.matcher(name).matches()) {
throw new IllegalArgumentException("Illegal SQL identifier: " + name);
}
return name;
}

public static final class AuditTable {
private final String qualifiedName;
private final String createdByColumn;
private final String modifiedByColumn;
private final String primaryKeyColumn;
private final String renameSql;

public AuditTable(String qualifiedName, String createdByColumn, String modifiedByColumn,
String primaryKeyColumn) {
this.qualifiedName = identifier(qualifiedName);
this.createdByColumn = identifier(createdByColumn);
this.modifiedByColumn = identifier(modifiedByColumn);
this.primaryKeyColumn = identifier(primaryKeyColumn);
this.renameSql = String.format(
"UPDATE %1$s SET %2$s = :newUserName, %3$s = :newUserName "
+ "WHERE %4$s IN (SELECT %4$s FROM (SELECT %4$s FROM %1$s WHERE %2$s = :oldUserName)"
+ " AS temp)",
this.qualifiedName, this.createdByColumn, this.modifiedByColumn, this.primaryKeyColumn);
}

public String getRenameSql() {
return renameSql;
}

public String getQualifiedName() {
return qualifiedName;
}

public String getCreatedByColumn() {
return createdByColumn;
}

public String getModifiedByColumn() {
return modifiedByColumn;
}

public String getPrimaryKeyColumn() {
return primaryKeyColumn;
}
}

private static AuditTable pascal(String qualifiedName, String primaryKeyColumn) {
return new AuditTable(qualifiedName, "CreatedBy", "ModifiedBy", primaryKeyColumn);
}

private static AuditTable snake(String qualifiedName, String primaryKeyColumn) {
return new AuditTable(qualifiedName, "created_by", "updated_by", primaryKeyColumn);
}

public static final List<AuditTable> TABLES = List.of(
pascal("db_identity.i_beneficiarydetails_rmnch", "beneficiaryDetails_RmnchId"),
pascal("db_identity.i_beneficiaryfamilymapping", "BenFamilyMapId"),
pascal("db_identity.i_beneficiarydetails", "BeneficiaryDetailsId"),
pascal("db_identity.i_beneficiarymapping", "BenMapId"),
pascal("db_identity.i_beneficiaryidentity", "BenIdentityId"),
pascal("db_identity.i_householddetails", "houseHoldDetailsId"),
pascal("db_identity.i_beneficiaryimage", "BenImageId"),
pascal("db_identity.i_beneficiaryaddress", "BenAddressID"),
pascal("db_identity.i_beneficiaryservicemapping", "BenServiceMapID"),
pascal("db_identity.m_beneficiaryregidmapping", "BenRegId"),
pascal("db_identity.i_bornbirthdeatils", "BornBirthDeatilsId"),
pascal("db_identity.i_beneficiarycontacts", "BenContactsID"),
pascal("db_identity.i_beneficiaryconsent", "BenConsentID"),
pascal("db_identity.i_benfamilytag", "BenFamilyTagId"),

snake("db_iemr.eligible_couple_tracking", "id"),
snake("db_iemr.t_pregnant_woman_register", "id"),
snake("db_iemr.t_eligible_couple_register", "id"),
snake("db_iemr.t_delivery_outcome", "id"),
snake("db_iemr.t_infant_register", "id"),
snake("db_iemr.t_pnc_visit", "ID"),
snake("db_iemr.t_anc_visit", "ID"),
snake("db_iemr.t_child_register", "ID"),
snake("db_iemr.t_pmsma", "id"),

pascal("db_iemr.t_cbacdetails", "id"),
pascal("db_iemr.t_pnccare", "id"),
pascal("db_iemr.t_anccare", "ID"),
pascal("db_iemr.t_benvisitdetail", "BenVisitID"),
pascal("db_iemr.t_childvaccinedetail1", "ID"));
}
Loading
Loading