diff --git a/src/main/java/com/iemr/admin/controller/employeemaster/EmployeeMasterController.java b/src/main/java/com/iemr/admin/controller/employeemaster/EmployeeMasterController.java index 35b6ed67..33d980ca 100644 --- a/src/main/java/com/iemr/admin/controller/employeemaster/EmployeeMasterController.java +++ b/src/main/java/com/iemr/admin/controller/employeemaster/EmployeeMasterController.java @@ -1813,6 +1813,8 @@ public String UserRoleMappings(@RequestBody String userRoleMapping, HttpServletR resDataMap1.setVillageID(previl.getVillageID()); resDataMap1.setVillageName(previl.getVillageName()); resDataMap1.setFacilityID(previl.getFacilityID()); + resDataMap1.setNikshayTUID(previl.getNikshayTUID()); + resDataMap1.setNikshayFacilityID(previl.getNikshayFacilityID()); resList1.add(resDataMap1); } @@ -1861,6 +1863,13 @@ 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) { + employeeMasterInter.softDeleteOldMappings( + pre.getUserID(), pre.getProviderServiceMapID(), pre.getuSRMappingID()); + } + usrRole.setUserID(pre.getUserID()); usrRole.setRoleID(pre.getRoleID()); usrRole.setAgentPassword(pre.getAgentPassword()); @@ -1874,6 +1883,8 @@ public String updateUserRoleMapping(@RequestBody String updateUserRoleMapping, H usrRole.setVillageID(pre.getVillageID()); usrRole.setVillageName(pre.getVillageName()); usrRole.setFacilityID(pre.getFacilityID()); + usrRole.setNikshayTUID(pre.getNikshayTUID()); + usrRole.setNikshayFacilityID(pre.getNikshayFacilityID()); if (pre.getTeleConsultation() != null) { usrRole.setTeleConsultation(pre.getTeleConsultation()); diff --git a/src/main/java/com/iemr/admin/controller/nikshay/NikshayLocationController.java b/src/main/java/com/iemr/admin/controller/nikshay/NikshayLocationController.java new file mode 100644 index 00000000..c5c71263 --- /dev/null +++ b/src/main/java/com/iemr/admin/controller/nikshay/NikshayLocationController.java @@ -0,0 +1,172 @@ +/* +* 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.nikshay; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.iemr.admin.data.locationmaster.DistrictBranchMapping; +import com.iemr.admin.data.locationmaster.M_District; +import com.iemr.admin.data.nikshay.NikshayFacility; +import com.iemr.admin.data.nikshay.NikshayTU; +import com.iemr.admin.data.nikshay.NikshayVillageFacilityMapping; +import com.iemr.admin.data.rolemaster.StateMasterForRole; +import com.iemr.admin.repo.locationmaster.DistrictBranchMappingRepo; +import com.iemr.admin.repo.locationmaster.MdistrictRepo; +import com.iemr.admin.repo.nikshay.NikshayFacilityRepo; +import com.iemr.admin.repo.nikshay.NikshayTURepo; +import com.iemr.admin.repo.nikshay.NikshayVillageFacilityMappingRepo; +import com.iemr.admin.repository.rolemaster.StateMasterRepo; +import com.iemr.admin.utils.response.OutputResponse; + +import io.swagger.v3.oas.annotations.Operation; + +/** + * Read-only cascading lookups for Stop TB's Nikshay location hierarchy: + * State (reused, existing) -> District (reused, existing) -> + * TU -> Facility -> Village (all new, or reused via the village mapping). + * + * Every endpoint here only reads existing/new tables — nothing is inserted + * or altered from these calls. + */ +@RestController +public class NikshayLocationController { + + private final Logger logger = LoggerFactory.getLogger(NikshayLocationController.class); + + @Autowired + private StateMasterRepo stateMasterRepo; + + @Autowired + private MdistrictRepo mdistrictRepo; + + @Autowired + private NikshayTURepo nikshayTURepo; + + @Autowired + private NikshayFacilityRepo nikshayFacilityRepo; + + @Autowired + private NikshayVillageFacilityMappingRepo nikshayVillageFacilityMappingRepo; + + @Autowired + private DistrictBranchMappingRepo districtBranchMappingRepo; + + @Operation(summary = "Get all states (reused from AMRIT's existing state master)") + @GetMapping(value = "/nikshay/location/states", produces = "application/json") + public String getStates() { + OutputResponse response = new OutputResponse(); + try { + ArrayList states = stateMasterRepo.getAllState(); + response.setResponse(states.toString()); + } catch (Exception e) { + logger.error("Error fetching Nikshay states: " + e.getMessage(), e); + response.setError(e); + } + return response.toString(); + } + + @Operation(summary = "Get districts for a state (reused from AMRIT's existing district master)") + @GetMapping(value = "/nikshay/location/districts", produces = "application/json") + public String getDistricts(@RequestParam("stateID") Integer stateID) { + OutputResponse response = new OutputResponse(); + try { + ArrayList districts = mdistrictRepo.getAllDistrictByStateId(stateID); + response.setResponse(districts.toString()); + } catch (Exception e) { + logger.error("Error fetching districts for stateID " + stateID + ": " + e.getMessage(), e); + response.setError(e); + } + return response.toString(); + } + + @Operation(summary = "Get Nikshay TUs for a district") + @GetMapping(value = "/nikshay/location/tus", produces = "application/json") + public String getTUs(@RequestParam("districtID") Integer districtID) { + OutputResponse response = new OutputResponse(); + try { + List tus = nikshayTURepo.findByDistrictID(districtID); + response.setResponse(tus.toString()); + } catch (Exception e) { + logger.error("Error fetching Nikshay TUs for districtID " + districtID + ": " + e.getMessage(), e); + response.setError(e); + } + return response.toString(); + } + + @Operation(summary = "Get Nikshay facilities for one or more TUs (comma-separated tuIDs)") + @GetMapping(value = "/nikshay/location/facilities", produces = "application/json") + public String getFacilities(@RequestParam("tuIDs") String tuIDs) { + OutputResponse response = new OutputResponse(); + try { + List ids = parseIntCsv(tuIDs); + List facilities = nikshayFacilityRepo.findByTUIDs(ids); + response.setResponse(facilities.toString()); + } catch (Exception e) { + logger.error("Error fetching Nikshay facilities for tuIDs " + tuIDs + ": " + e.getMessage(), e); + response.setError(e); + } + return response.toString(); + } + + @Operation(summary = "Get villages for one or more Nikshay facilities (comma-separated facilityIDs), " + + "resolved to AMRIT's existing village master") + @GetMapping(value = "/nikshay/location/villages", produces = "application/json") + public String getVillages(@RequestParam("facilityIDs") String facilityIDs) { + OutputResponse response = new OutputResponse(); + try { + List ids = parseIntCsv(facilityIDs); + List mappings = nikshayVillageFacilityMappingRepo.findByFacilityIDs(ids); + + List amritVillageIDs = mappings.stream() + .map(NikshayVillageFacilityMapping::getAmritVillageID) + .distinct() + .collect(Collectors.toList()); + + List villages = new ArrayList<>(); + districtBranchMappingRepo.findAllById(amritVillageIDs).forEach(villages::add); + + response.setResponse(villages.toString()); + } catch (Exception e) { + logger.error("Error fetching villages for facilityIDs " + facilityIDs + ": " + e.getMessage(), e); + response.setError(e); + } + return response.toString(); + } + + private List parseIntCsv(String csv) { + return Arrays.stream(csv.split(",")) + .map(String::trim) + .filter(s -> !s.isEmpty()) + .map(Integer::parseInt) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/iemr/admin/data/employeemaster/M_UserServiceRoleMapping2.java b/src/main/java/com/iemr/admin/data/employeemaster/M_UserServiceRoleMapping2.java index ad6575a6..0680c079 100644 --- a/src/main/java/com/iemr/admin/data/employeemaster/M_UserServiceRoleMapping2.java +++ b/src/main/java/com/iemr/admin/data/employeemaster/M_UserServiceRoleMapping2.java @@ -423,6 +423,15 @@ public class M_UserServiceRoleMapping2 { @Column(name = "isOutbound") private Boolean outbound; + // Stop TB / Nikshay location scope — populated only when serviceName = "Stop TB" + @Expose + @Column(name = "NikshayTUID") + private Integer nikshayTUID; + + @Expose + @Column(name = "NikshayFacilityID") + private Integer nikshayFacilityID; + public M_UserServiceRoleMapping2() { } diff --git a/src/main/java/com/iemr/admin/data/nikshay/NikshayFacility.java b/src/main/java/com/iemr/admin/data/nikshay/NikshayFacility.java new file mode 100644 index 00000000..a3835721 --- /dev/null +++ b/src/main/java/com/iemr/admin/data/nikshay/NikshayFacility.java @@ -0,0 +1,98 @@ +/* +* 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.data.nikshay; + +import java.sql.Timestamp; + +import com.google.gson.annotations.Expose; +import com.iemr.admin.utils.mapper.OutputMapper; + +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 jakarta.persistence.Transient; +import lombok.Data; + +/** + * Nikshay's PHC/HWC/CHC facility master. Verified against production data + * that AMRIT's existing m_facility has no meaningful overlap with Nikshay's + * facility list (0 matches out of 343,615) — kept as its own table rather + * than reusing m_facility. + */ +@Data +@Entity +@Table(name = "m_nikshay_facility") +public class NikshayFacility { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Expose + @Column(name = "NikshayFacilityID") + private Integer nikshayFacilityID; + + @Expose + @Column(name = "NikshayCode") + private String nikshayCode; + + @Expose + @Column(name = "FacilityName") + private String facilityName; + + @Expose + @Column(name = "FacilityCode") + private String facilityCode; + + @Expose + @Column(name = "NikshayTUID") + private Integer nikshayTUID; + + @Expose + @Column(name = "Deleted") + private Boolean deleted = false; + + @Expose + @Column(name = "CreatedBy") + private String createdBy; + + @Expose + @Column(name = "CreatedDate", insertable = false, updatable = false) + private Timestamp createdDate; + + @Expose + @Column(name = "ModifiedBy") + private String modifiedBy; + + @Expose + @Column(name = "LastModDate", insertable = false, updatable = false) + private Timestamp lastModDate; + + @Transient + private OutputMapper outputMapper = new OutputMapper(); + + @Override + public String toString() { + return outputMapper.gson().toJson(this); + } +} diff --git a/src/main/java/com/iemr/admin/data/nikshay/NikshayTU.java b/src/main/java/com/iemr/admin/data/nikshay/NikshayTU.java new file mode 100644 index 00000000..3be331c2 --- /dev/null +++ b/src/main/java/com/iemr/admin/data/nikshay/NikshayTU.java @@ -0,0 +1,94 @@ +/* +* 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.data.nikshay; + +import java.sql.Timestamp; + +import com.google.gson.annotations.Expose; +import com.iemr.admin.utils.mapper.OutputMapper; + +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 jakarta.persistence.Transient; +import lombok.Data; + +/** + * Nikshay's TU (Tuberculosis Unit) master — Nikshay's own sub-district + * administrative unit, referred to as "Block" on some Nikshay screens. + * No equivalent exists in AMRIT's own masters; linked only to the + * existing m_District table by DistrictID. + */ +@Data +@Entity +@Table(name = "m_nikshay_tu") +public class NikshayTU { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Expose + @Column(name = "NikshayTUID") + private Integer nikshayTUID; + + @Expose + @Column(name = "NikshayCode") + private String nikshayCode; + + @Expose + @Column(name = "TUName") + private String tUName; + + @Expose + @Column(name = "DistrictID") + private Integer districtID; + + @Expose + @Column(name = "Deleted") + private Boolean deleted = false; + + @Expose + @Column(name = "CreatedBy") + private String createdBy; + + @Expose + @Column(name = "CreatedDate", insertable = false, updatable = false) + private Timestamp createdDate; + + @Expose + @Column(name = "ModifiedBy") + private String modifiedBy; + + @Expose + @Column(name = "LastModDate", insertable = false, updatable = false) + private Timestamp lastModDate; + + @Transient + private OutputMapper outputMapper = new OutputMapper(); + + @Override + public String toString() { + return outputMapper.gson().toJson(this); + } +} diff --git a/src/main/java/com/iemr/admin/data/nikshay/NikshayVillageFacilityMapping.java b/src/main/java/com/iemr/admin/data/nikshay/NikshayVillageFacilityMapping.java new file mode 100644 index 00000000..fad7b422 --- /dev/null +++ b/src/main/java/com/iemr/admin/data/nikshay/NikshayVillageFacilityMapping.java @@ -0,0 +1,83 @@ +/* +* 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.data.nikshay; + +import java.sql.Timestamp; + +import com.google.gson.annotations.Expose; +import com.iemr.admin.utils.mapper.OutputMapper; + +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 jakarta.persistence.Transient; +import lombok.Data; + +/** + * Links an existing AMRIT village (m_DistrictBranchMapping.DistrictBranchID) + * to the Nikshay Facility/TU it falls under. Built once from the location + * import's name-matching results — used to trace a beneficiary's existing + * village back to their Nikshay Facility/TU without asking the field worker + * to re-select it per case. + */ +@Data +@Entity +@Table(name = "m_nikshay_village_facility_mapping") +public class NikshayVillageFacilityMapping { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Expose + @Column(name = "MappingID") + private Integer mappingID; + + @Expose + @Column(name = "AmritVillageID") + private Integer amritVillageID; + + @Expose + @Column(name = "NikshayFacilityID") + private Integer nikshayFacilityID; + + @Expose + @Column(name = "NikshayTUID") + private Integer nikshayTUID; + + @Expose + @Column(name = "CreatedBy") + private String createdBy; + + @Expose + @Column(name = "CreatedDate", insertable = false, updatable = false) + private Timestamp createdDate; + + @Transient + private OutputMapper outputMapper = new OutputMapper(); + + @Override + public String toString() { + return outputMapper.gson().toJson(this); + } +} diff --git a/src/main/java/com/iemr/admin/repo/blocking/MProviderservicemappingBlockingRepo.java b/src/main/java/com/iemr/admin/repo/blocking/MProviderservicemappingBlockingRepo.java index 1b7b082c..e0a0ffe6 100644 --- a/src/main/java/com/iemr/admin/repo/blocking/MProviderservicemappingBlockingRepo.java +++ b/src/main/java/com/iemr/admin/repo/blocking/MProviderservicemappingBlockingRepo.java @@ -85,7 +85,7 @@ void blockProviderByProviderIdAndServiceId(@Param("serviceProviderID") Integer s @Query(" SELECT distinct srm.providerServiceMapID,srm.serviceProviderID,srm.serviceID," + " sm.serviceName as serviceName," + " sm.isNational as isNational " + " FROM M_Providerservicemapping_Blocking srm " + " JOIN srm.m_ServicemasterForBlocking sm" - + " WHERE srm.serviceProviderID =:serviceProviderID AND srm.deleted=false" + " GROUP BY sm.serviceName") + + " WHERE srm.serviceProviderID =:serviceProviderID AND srm.deleted=false") ArrayList getServiceLiensUsingProvider(@Param("serviceProviderID") Integer serviceProviderID); @Transactional diff --git a/src/main/java/com/iemr/admin/repo/employeemaster/EmployeeMasterRepo.java b/src/main/java/com/iemr/admin/repo/employeemaster/EmployeeMasterRepo.java index 401b0c1c..204a8f65 100644 --- a/src/main/java/com/iemr/admin/repo/employeemaster/EmployeeMasterRepo.java +++ b/src/main/java/com/iemr/admin/repo/employeemaster/EmployeeMasterRepo.java @@ -155,4 +155,9 @@ 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 + @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); + } diff --git a/src/main/java/com/iemr/admin/repo/nikshay/NikshayFacilityRepo.java b/src/main/java/com/iemr/admin/repo/nikshay/NikshayFacilityRepo.java new file mode 100644 index 00000000..1d5916cc --- /dev/null +++ b/src/main/java/com/iemr/admin/repo/nikshay/NikshayFacilityRepo.java @@ -0,0 +1,41 @@ +/* +* 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.repo.nikshay; + +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.admin.data.nikshay.NikshayFacility; + +@Repository +public interface NikshayFacilityRepo extends CrudRepository { + + @Query("select f from NikshayFacility f where f.nikshayTUID in (:tuIDs) and f.deleted = false order by f.facilityName") + List findByTUIDs(@Param("tuIDs") List tuIDs); + + @Query("select f from NikshayFacility f where f.nikshayFacilityID in (:facilityIDs) and f.deleted = false") + List findByIds(@Param("facilityIDs") List facilityIDs); +} diff --git a/src/main/java/com/iemr/admin/repo/nikshay/NikshayTURepo.java b/src/main/java/com/iemr/admin/repo/nikshay/NikshayTURepo.java new file mode 100644 index 00000000..ba25505b --- /dev/null +++ b/src/main/java/com/iemr/admin/repo/nikshay/NikshayTURepo.java @@ -0,0 +1,41 @@ +/* +* 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.repo.nikshay; + +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.admin.data.nikshay.NikshayTU; + +@Repository +public interface NikshayTURepo extends CrudRepository { + + @Query("select t from NikshayTU t where t.districtID = :districtID and t.deleted = false order by t.tUName") + List findByDistrictID(@Param("districtID") Integer districtID); + + @Query("select t from NikshayTU t where t.nikshayTUID in (:tuIDs) and t.deleted = false") + List findByIds(@Param("tuIDs") List tuIDs); +} diff --git a/src/main/java/com/iemr/admin/repo/nikshay/NikshayVillageFacilityMappingRepo.java b/src/main/java/com/iemr/admin/repo/nikshay/NikshayVillageFacilityMappingRepo.java new file mode 100644 index 00000000..55ba9b54 --- /dev/null +++ b/src/main/java/com/iemr/admin/repo/nikshay/NikshayVillageFacilityMappingRepo.java @@ -0,0 +1,42 @@ +/* +* 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.repo.nikshay; + +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.admin.data.nikshay.NikshayVillageFacilityMapping; + +@Repository +public interface NikshayVillageFacilityMappingRepo extends CrudRepository { + + @Query("select m from NikshayVillageFacilityMapping m where m.nikshayFacilityID in (:facilityIDs)") + List findByFacilityIDs(@Param("facilityIDs") List facilityIDs); + + // Reverse lookup: given a beneficiary's existing village ID, find their Nikshay Facility/TU + @Query("select m from NikshayVillageFacilityMapping m where m.amritVillageID = :amritVillageID") + List findByAmritVillageID(@Param("amritVillageID") Integer amritVillageID); +} diff --git a/src/main/java/com/iemr/admin/repository/rolemaster/M_UserservicerolemappingForRoleProviderAdminRepo.java b/src/main/java/com/iemr/admin/repository/rolemaster/M_UserservicerolemappingForRoleProviderAdminRepo.java index 759be90f..b6937b5e 100644 --- a/src/main/java/com/iemr/admin/repository/rolemaster/M_UserservicerolemappingForRoleProviderAdminRepo.java +++ b/src/main/java/com/iemr/admin/repository/rolemaster/M_UserservicerolemappingForRoleProviderAdminRepo.java @@ -49,15 +49,14 @@ public interface M_UserservicerolemappingForRoleProviderAdminRepo * serviceProviderID, Integer serviceID); */ - @Query("SELECT sm.serviceName as serviceName," + + @Query("SELECT DISTINCT sm.serviceName as serviceName," + " ssm.serviceID," + " sm.isNational as isNational," + " ssm.statusID" + " FROM M_UserservicerolemappingForRoleProviderAdmin usr" + " JOIN usr.stateServiceMapping ssm" + " JOIN ssm.serviceMaster sm" + - " WHERE usr.userID = :userID AND ssm.statusID = 2 AND usr.deleted = false" + - " GROUP BY sm.serviceName") + " WHERE usr.userID = :userID AND ssm.statusID = 2 AND usr.deleted = false") ArrayList getServiceByServiceProviderIds(@Param("userID") Integer serviceProviderID); @Query("SELECT distinct ssm.stateID," + " sm.stateName, " + " ssm.providerServiceMapID," + " ssm.statusID" diff --git a/src/main/java/com/iemr/admin/service/bulkRegistration/BulkRegistrationServiceImpl.java b/src/main/java/com/iemr/admin/service/bulkRegistration/BulkRegistrationServiceImpl.java index d1b5a9f1..4bd00125 100644 --- a/src/main/java/com/iemr/admin/service/bulkRegistration/BulkRegistrationServiceImpl.java +++ b/src/main/java/com/iemr/admin/service/bulkRegistration/BulkRegistrationServiceImpl.java @@ -305,7 +305,7 @@ private void saveUserUser(Employee employee, Integer row, String authorization, mUser.setTitleID(getTitleId(employee.getTitle())); mUser.setFirstName(employee.getFirstName()); mUser.setLastName(employee.getLastName()); - mUser.setUserName(employee.getContactNo()); + mUser.setUserName(employee.getUserName()); mUser.setdOB(convertStringIntoDate(employee.getDob())); mUser.setEmployeeID(employee.getUserName()); mUser.setEmergencyContactNo(String.valueOf(employee.getEmergencyContactNo())); diff --git a/src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterInter.java b/src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterInter.java index 81b5f454..d6feae0d 100644 --- a/src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterInter.java +++ b/src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterInter.java @@ -166,6 +166,9 @@ 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); + // Fix 2: smart cascade — for supervisor with multiple facilities, only delete mappings for this facility void cascadeDeleteAshaMappingsForDeactivation(M_UserServiceRoleMapping2 usrRole); diff --git a/src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterServiceImpl.java b/src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterServiceImpl.java index f4c07f36..2421909b 100644 --- a/src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterServiceImpl.java +++ b/src/main/java/com/iemr/admin/service/employeemaster/EmployeeMasterServiceImpl.java @@ -1024,6 +1024,11 @@ public void cascadeDeleteAshaMappingsForUser(Integer userID) { ashaSupervisorMappingService.cascadeDeleteByUserID(userID, "Admin"); } + @Override + public int softDeleteOldMappings(Integer userID, Integer providerServiceMapID, Integer excludeUSRMappingID) { + return employeeMasterRepo.softDeleteOldMappings(userID, providerServiceMapID, excludeUSRMappingID); + } + @Override public void cascadeDeleteAshaMappingsForDeactivation(M_UserServiceRoleMapping2 usrRole) { Integer userID = usrRole.getUserID(); diff --git a/src/main/java/com/iemr/admin/service/employeemaster/EmployeeSignatureServiceImpl.java b/src/main/java/com/iemr/admin/service/employeemaster/EmployeeSignatureServiceImpl.java index b22175c2..58e5ccee 100644 --- a/src/main/java/com/iemr/admin/service/employeemaster/EmployeeSignatureServiceImpl.java +++ b/src/main/java/com/iemr/admin/service/employeemaster/EmployeeSignatureServiceImpl.java @@ -27,6 +27,7 @@ import com.iemr.admin.data.employeemaster.EmployeeSignature; import com.iemr.admin.repo.employeemaster.EmployeeSignatureRepo; +import org.json.JSONObject; @Service public class EmployeeSignatureServiceImpl implements EmployeeSignatureService { diff --git a/src/main/java/com/iemr/admin/to/employeemaster/Previleges1097_3.java b/src/main/java/com/iemr/admin/to/employeemaster/Previleges1097_3.java index d8bb0f33..903e18dd 100644 --- a/src/main/java/com/iemr/admin/to/employeemaster/Previleges1097_3.java +++ b/src/main/java/com/iemr/admin/to/employeemaster/Previleges1097_3.java @@ -34,6 +34,8 @@ public class Previleges1097_3 { private String[] villageID; private String[] villageName; private Integer facilityID; + private Integer nikshayTUID; + private Integer nikshayFacilityID; public Integer getProviderServiceMapID() { return providerServiceMapID; @@ -95,4 +97,16 @@ public Integer getFacilityID() { public void setFacilityID(Integer facilityID) { this.facilityID = facilityID; } + public Integer getNikshayTUID() { + return nikshayTUID; + } + public void setNikshayTUID(Integer nikshayTUID) { + this.nikshayTUID = nikshayTUID; + } + public Integer getNikshayFacilityID() { + return nikshayFacilityID; + } + public void setNikshayFacilityID(Integer nikshayFacilityID) { + this.nikshayFacilityID = nikshayFacilityID; + } } diff --git a/src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java b/src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java index 2eca1607..db771d13 100644 --- a/src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java +++ b/src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java @@ -111,7 +111,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo } - try { String jwtFromCookie = getJwtTokenFromCookies(request); String jwtFromHeader = request.getHeader(Constants.JWT_TOKEN);