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 @@ -6,7 +6,7 @@

<groupId>com.iemr.common-API</groupId>
<artifactId>common-api</artifactId>
<version>3.8.0</version>
<version>3.8.1</version>
<packaging>war</packaging>

<name>Common-API</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.iemr.common.model.user.ForceLogoutRequestModel;
import com.iemr.common.model.user.LoginRequestModel;
import com.iemr.common.service.recaptcha.CaptchaValidationService;
import com.iemr.common.service.users.AshaSupervisorLoginService;
import com.iemr.common.service.users.IEMRAdminUserService;
import com.iemr.common.utils.CookieUtil;
import com.iemr.common.utils.JwtUtil;
Expand Down Expand Up @@ -117,6 +118,9 @@
@Autowired
SecurePassword securePassword;

@Autowired

Check warning on line 121 in src/main/java/com/iemr/common/controller/users/IEMRAdminController.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_Common-API&issues=AZ0ohsQua7K9fovmRR-U&open=AZ0ohsQua7K9fovmRR-U&pullRequest=385
private AshaSupervisorLoginService ashaSupervisorLoginService;

@Operation(summary = "New user authentication")
@RequestMapping(value = "/userAuthenticateNew", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
public String userAuthenticateNew(
Expand Down Expand Up @@ -232,6 +236,46 @@
responseObj = iemrAdminUserServiceImpl.generateKeyAndValidateIP(responseObj, remoteAddress,
request.getRemoteHost());

// Facility data for ALL users - common pattern, empty if not applicable
try {

Check warning on line 240 in src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested try block into a separate method.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0ohsQua7K9fovmRR-S&open=AZ0ohsQua7K9fovmRR-S&pullRequest=385
if (mUser.size() == 1) {
User loggedInUser = mUser.get(0);
String userRoleName = "";
if (loggedInUser.getM_UserServiceRoleMapping() != null) {
for (UserServiceRoleMapping usrm : loggedInUser.getM_UserServiceRoleMapping()) {
if (usrm.getM_Role() != null && usrm.getM_Role().getRoleName() != null) {
userRoleName = usrm.getM_Role().getRoleName();
break;
}
}
}
JSONObject facilityData = ashaSupervisorLoginService
.buildFacilityLoginData(loggedInUser.getUserID(), userRoleName);

// User details
JSONObject userObj = new JSONObject();
userObj.put("userId", loggedInUser.getUserID());

Check failure on line 257 in src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "userId" 4 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0ohsQua7K9fovmRR-T&open=AZ0ohsQua7K9fovmRR-T&pullRequest=385
userObj.put("employeeId", loggedInUser.getEmployeeID() != null ? loggedInUser.getEmployeeID() : JSONObject.NULL);
userObj.put("role", userRoleName);
String first = loggedInUser.getFirstName() != null ? loggedInUser.getFirstName() : "";
String last = loggedInUser.getLastName() != null ? loggedInUser.getLastName() : "";
userObj.put("fullName", (first + " " + last).trim());

JSONObject demographics = new JSONObject();
String genderName = ashaSupervisorLoginService.getGenderName(loggedInUser.getGenderID());
demographics.put("gender", genderName != null ? genderName : JSONObject.NULL);
demographics.put("dob", loggedInUser.getdOB() != null ? loggedInUser.getdOB().toString() : JSONObject.NULL);
demographics.put("mobile", loggedInUser.getEmergencyContactNo() != null ? loggedInUser.getEmergencyContactNo() : JSONObject.NULL);
demographics.put("email", loggedInUser.getEmailID() != null ? loggedInUser.getEmailID() : JSONObject.NULL);
userObj.put("demographics", demographics);

facilityData.put("user", userObj);
responseObj.put("facilityData", facilityData);
}
} catch (Exception e) {
logger.error("Error fetching facility login data: " + e.getMessage(), e);
}

// Add tokens to response for mobile
if (isMobile && !mUser.isEmpty()) {
responseObj.put("jwtToken", jwtToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.iemr.common.data.users;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "asha_supervisor_mapping")
@Data
@NoArgsConstructor
public class AshaSupervisorMapping {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "supervisorUserID")
private Integer supervisorUserID;

@Column(name = "ashaUserID")
private Integer ashaUserID;

@Column(name = "facilityID")
private Integer facilityID;

@Column(name = "deleted", insertable = false, updatable = true)
private Boolean deleted;
}
7 changes: 7 additions & 0 deletions src/main/java/com/iemr/common/data/users/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public class User implements Serializable {
@Expose
private Status m_status;

@Expose
@Column(name = "EmployeeID")
private String employeeID;
@Expose
@Column(name = "AadhaarNo")
private String aadhaarNo;
Expand Down Expand Up @@ -515,6 +518,10 @@ public String getAgentID() {
return agentID;
}

public String getEmployeeID() {
return employeeID;
}

public String getAgentPassword() {
return agentPassword;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
private MaritalStatusModel maritalstatus;
private Integer statusID;
private StatusModel status;
private String employeeID;
private String aadhaarNo;
private String pAN;
private Timestamp dOB;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.iemr.common.repository.users;

import java.util.ArrayList;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.iemr.common.data.users.AshaSupervisorMapping;

@Repository
public interface AshaSupervisorLoginRepo extends CrudRepository<AshaSupervisorMapping, Long> {

ArrayList<AshaSupervisorMapping> findBySupervisorUserIDAndDeletedFalse(Integer supervisorUserID);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.iemr.common.repository.users;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.iemr.common.data.users.AshaSupervisorMapping;

@Repository
public interface FacilityLoginRepo extends CrudRepository<AshaSupervisorMapping, Long> {

// Get user's facility IDs from m_UserServiceRoleMapping (for ANY user)
@Query(value = "SELECT DISTINCT usrm.FacilityID "
+ "FROM m_UserServiceRoleMapping usrm "
+ "WHERE usrm.UserID = :userID AND usrm.Deleted = false "
+ "AND usrm.FacilityID IS NOT NULL", nativeQuery = true)
List<Integer> getUserFacilityIDs(@Param("userID") Integer userID);

// Get facility details with geo names and facilityType
@Query(value = "SELECT DISTINCT f.FacilityID, f.FacilityName, "
+ "f.StateID, COALESCE(s.StateName,'') AS stateName, "
+ "f.DistrictID, COALESCE(d.DistrictName,'') AS districtName, "
+ "f.BlockID, COALESCE(b.BlockName,'') AS blockName, "
+ "COALESCE(f.RuralUrban,'') AS ruralUrban, "
+ "COALESCE(ft.FacilityTypeName,'') AS facilityTypeName "
+ "FROM m_facility f "
+ "LEFT JOIN m_state s ON s.StateID = f.StateID "
+ "LEFT JOIN m_district d ON d.DistrictID = f.DistrictID "
+ "LEFT JOIN m_districtblock b ON b.BlockID = f.BlockID "
+ "LEFT JOIN m_facilitytype ft ON ft.FacilityTypeID = f.FacilityTypeID "
+ "WHERE f.FacilityID IN :facilityIDs AND f.Deleted = false", nativeQuery = true)
List<Object[]> getFacilityDetails(@Param("facilityIDs") List<Integer> facilityIDs);

// ASHA login: get supervisor details
@Query(value = "SELECT asm.supervisorUserID, u.FirstName, u.LastName, u.ContactNo, "
+ "COALESCE(u.EmployeeID,'') AS employeeID "
+ "FROM asha_supervisor_mapping asm "
+ "JOIN m_User u ON u.UserID = asm.supervisorUserID "
+ "WHERE asm.ashaUserID = :ashaUserID AND asm.deleted = false "
+ "AND u.Deleted = false LIMIT 1", nativeQuery = true)
List<Object[]> getSupervisorForAsha(@Param("ashaUserID") Integer ashaUserID);

@Query(value = "SELECT GenderName FROM m_gender WHERE GenderID = :genderID", nativeQuery = true)
String getGenderName(@Param("genderID") Integer genderID);

// Villages mapped to facilities
@Query(value = "SELECT fvm.FacilityID, fvm.DistrictBranchID, dbm.VillageName "
+ "FROM facility_village_mapping fvm "
+ "JOIN m_DistrictBranchMapping dbm ON dbm.DistrictBranchID = fvm.DistrictBranchID "
+ "WHERE fvm.FacilityID IN :facilityIDs AND fvm.Deleted = false", nativeQuery = true)
List<Object[]> getVillagesForFacilities(@Param("facilityIDs") List<Integer> facilityIDs);

// ASHA login: get peers at same facility (ANM, CHO, etc.)
@Query(value = "SELECT DISTINCT usrm.UserID, u.FirstName, u.LastName, r.RoleName, "
+ "COALESCE(u.EmployeeID,'') AS employeeID "
+ "FROM m_UserServiceRoleMapping usrm "
+ "JOIN m_User u ON u.UserID = usrm.UserID "
+ "JOIN m_Role r ON r.RoleID = usrm.RoleID "
+ "WHERE usrm.FacilityID IN :facilityIDs "
+ "AND usrm.UserID != :currentUserID "
+ "AND usrm.Deleted = false AND u.Deleted = false", nativeQuery = true)
List<Object[]> getPeersAtFacility(@Param("facilityIDs") List<Integer> facilityIDs,
@Param("currentUserID") Integer currentUserID);
}
Loading
Loading