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
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,32 @@ public interface FacilityLoginRepo extends CrudRepository<AshaSupervisorMapping,
+ "AND usrm.Deleted = false AND u.Deleted = false", nativeQuery = true)
List<Object[]> getPeersAtFacility(@Param("facilityIDs") List<Integer> facilityIDs,
@Param("currentUserID") Integer currentUserID);

// Supervisor login: get mapped ASHAs with facility details
@Query(value = "SELECT DISTINCT u.UserID, u.FirstName, u.LastName, "
+ "COALESCE(u.EmployeeID,'') AS employeeID, "
+ "f.FacilityID, f.FacilityName, "
+ "COALESCE(ft.FacilityTypeName,'') AS facilityTypeName "
+ "FROM asha_supervisor_mapping asm "
+ "JOIN m_User u ON u.UserID = asm.ashaUserID "
+ "JOIN m_facility f ON f.FacilityID = asm.facilityID "
+ "LEFT JOIN m_facilitytype ft ON ft.FacilityTypeID = f.FacilityTypeID "
+ "WHERE asm.supervisorUserID = :supervisorUserID "
+ "AND asm.deleted = false AND u.Deleted = false AND f.Deleted = false", nativeQuery = true)
List<Object[]> getMappedAshasBySupervisor(@Param("supervisorUserID") Integer supervisorUserID);

// CHO/ANM login: get ASHAs at same facilities
@Query(value = "SELECT DISTINCT u.UserID, u.FirstName, u.LastName, "
+ "COALESCE(u.EmployeeID,'') AS employeeID, "
+ "f.FacilityID, f.FacilityName, "
+ "COALESCE(ft.FacilityTypeName,'') AS facilityTypeName "
+ "FROM m_UserServiceRoleMapping usrm "
+ "JOIN m_User u ON u.UserID = usrm.UserID "
+ "JOIN m_Role r ON r.RoleID = usrm.RoleID "
+ "JOIN m_facility f ON f.FacilityID = usrm.FacilityID "
+ "LEFT JOIN m_facilitytype ft ON ft.FacilityTypeID = f.FacilityTypeID "
+ "WHERE usrm.FacilityID IN :facilityIDs "
+ "AND r.RoleName = 'ASHA' "
+ "AND usrm.Deleted = false AND u.Deleted = false AND f.Deleted = false", nativeQuery = true)
List<Object[]> getAshaListByFacilities(@Param("facilityIDs") List<Integer> facilityIDs);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
// ASHA gets a single facility (first mapped)
Object[] row = facilityRows.get(0);
JSONObject facility = new JSONObject();
facility.put("facilityId", row[0]);

Check failure on line 76 in src/main/java/com/iemr/common/service/users/AshaSupervisorLoginService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ4gEQsDUxy7cFtdXsmm&open=AZ4gEQsDUxy7cFtdXsmm&pullRequest=409
facility.put("facilityName", str(row[1]));

Check failure on line 77 in src/main/java/com/iemr/common/service/users/AshaSupervisorLoginService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ4gEQsDUxy7cFtdXsml&open=AZ4gEQsDUxy7cFtdXsml&pullRequest=409
facility.put("facilityType", str(row[9]));

Check failure on line 78 in src/main/java/com/iemr/common/service/users/AshaSupervisorLoginService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ4gEQsDUxy7cFtdXsmi&open=AZ4gEQsDUxy7cFtdXsmi&pullRequest=409
result.put("facility", facility);

// Supervisor details
Expand All @@ -83,10 +83,10 @@
if (supervisorRows != null && !supervisorRows.isEmpty()) {
Object[] sRow = supervisorRows.get(0);
JSONObject supervisor = new JSONObject();
supervisor.put("userId", sRow[0]);

Check failure on line 86 in src/main/java/com/iemr/common/service/users/AshaSupervisorLoginService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ4gEQsDUxy7cFtdXsmk&open=AZ4gEQsDUxy7cFtdXsmk&pullRequest=409
supervisor.put("fullName", fullName(sRow[1], sRow[2]));

Check failure on line 87 in src/main/java/com/iemr/common/service/users/AshaSupervisorLoginService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "fullName" 3 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ4gEQsDUxy7cFtdXsmn&open=AZ4gEQsDUxy7cFtdXsmn&pullRequest=409
supervisor.put("mobile", str(sRow[3]));
supervisor.put("employeeId", str(sRow[4]).isEmpty() ? JSONObject.NULL : str(sRow[4]));

Check failure on line 89 in src/main/java/com/iemr/common/service/users/AshaSupervisorLoginService.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "employeeId" 3 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ4gEQsDUxy7cFtdXsmj&open=AZ4gEQsDUxy7cFtdXsmj&pullRequest=409
result.put("supervisor", supervisor);
} else {
result.put("supervisor", JSONObject.NULL);
Expand Down Expand Up @@ -141,13 +141,11 @@
}
result.put("facilities", facilitiesArray);

// Count distinct ASHAs mapped to this supervisor
Set<Integer> ashaUserIDs = new HashSet<>();
for (AshaSupervisorMapping m : mappings) {
if (m.getAshaUserID() != null)
ashaUserIDs.add(m.getAshaUserID());
}
result.put("totalAshaCount", ashaUserIDs.size());
// Fetch mapped ASHAs with facility details
List<Object[]> ashaRows = facilityLoginRepo.getMappedAshasBySupervisor(supervisorUserID);
JSONArray ashaList = buildAshaList(ashaRows);
result.put("ashaList", ashaList);
result.put("totalAshaCount", ashaList.length());
}

// ==================== General Facility User (CHO, ANM, etc.)
Expand All @@ -173,10 +171,33 @@
facilitiesArray.put(facility);
}
result.put("facilities", facilitiesArray);

// ASHAs at same facilities
List<Object[]> ashaRows = facilityLoginRepo.getAshaListByFacilities(facilityIDs);
JSONArray ashaList = buildAshaList(ashaRows);
result.put("ashaList", ashaList);
result.put("totalAshaCount", ashaList.length());
}

// ==================== Shared Helpers ====================

private JSONArray buildAshaList(List<Object[]> rows) {
JSONArray list = new JSONArray();
if (rows == null)
return list;
for (Object[] row : rows) {
JSONObject asha = new JSONObject();
asha.put("userId", row[0]);
asha.put("fullName", fullName(row[1], row[2]));
asha.put("employeeId", str(row[3]).isEmpty() ? JSONObject.NULL : str(row[3]));
asha.put("facilityId", row[4]);
asha.put("facilityName", str(row[5]));
asha.put("facilityType", str(row[6]));
list.put(asha);
}
return list;
}

private void populateLocation(JSONObject result, Object[] facilityRow) {
JSONObject location = new JSONObject();
location.put("state", str(facilityRow[3]));
Expand Down
Loading