diff --git a/src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java b/src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java index 9c4d52e7..c38b49e0 100644 --- a/src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java +++ b/src/main/java/com/iemr/common/data/customization/SectionAndFieldsMapping.java @@ -11,6 +11,8 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import jakarta.persistence.Transient; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import lombok.Data; @Entity @@ -96,6 +98,12 @@ public class SectionAndFieldsMapping { @Column(name = "FieldTitle") private String fieldTitle; + @Column(name = "ProjectID") + @Expose + @NotNull(message="ProjectId is Required") + @Min(value=1, message = "ProjectId must be possitive") + private Integer projectId; + @Transient private String[] options; diff --git a/src/main/java/com/iemr/common/data/customization/SectionFieldsMappingDTO.java b/src/main/java/com/iemr/common/data/customization/SectionFieldsMappingDTO.java index f9dba52e..9f890c6f 100644 --- a/src/main/java/com/iemr/common/data/customization/SectionFieldsMappingDTO.java +++ b/src/main/java/com/iemr/common/data/customization/SectionFieldsMappingDTO.java @@ -14,6 +14,7 @@ public class SectionFieldsMappingDTO { private String sectionName; private String createdBy; private Integer serviceProviderId; + private Integer projectId; private List fields; } diff --git a/src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java b/src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java index 79b770d2..038e34ef 100644 --- a/src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java +++ b/src/main/java/com/iemr/common/repo/customization/SectionAndFieldsMappingRepo.java @@ -16,14 +16,15 @@ public interface SectionAndFieldsMappingRepo extends CrudRepository findBySectionIdAndSectionNameAndServiceProviderId( // @Param("sectionId") Integer sectionId, @Param("serviceProviderId") Integer serviceProviderId); - @Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.sectionId = :sectionId AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId= 0)") + + @Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName AND (sfm.serviceProviderId = :serviceProviderId OR sfm.serviceProviderId = 0) AND (sfm.projectId = :projectId OR sfm.projectId = 0)") List findSectionIdAndSectionNameAndServiceProviderId( - @Param("sectionId") Integer sectionId, @Param("serviceProviderId") Integer serviceProviderId); + @Param("sectionId") Integer sectionId, @Param("serviceProviderId") Integer serviceProviderId, @Param("projectId") Integer projectId); @Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.id = :id") SectionAndFieldsMapping getById(@Param("id") Integer id); - @Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId") - List getByFieldName(@Param("fieldName") String fieldName,@Param("serviceProviderId") Integer serviceProviderId); + @Query("SELECT sfm FROM SectionAndFieldsMapping sfm WHERE sfm.fieldName = :fieldName and sfm.serviceProviderId = :serviceProviderId and sfm.projectId = :projectId") + List getByFieldName(@Param("fieldName") String fieldName,@Param("serviceProviderId") Integer serviceProviderId,@Param("projectId") Integer projectId); } diff --git a/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java b/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java index d1b18598..27943239 100644 --- a/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java +++ b/src/main/java/com/iemr/common/service/customization/CustomizationServiceImpl.java @@ -180,14 +180,15 @@ public String saveSectionAndFields(SectionFieldsMappingDTO sectionFieldsMappingD try { if (sectionFieldsMappingDTO != null && sectionFieldsMappingDTO.getFields() != null - && sectionFieldsMappingDTO.getFields().size() > 0) { + && sectionFieldsMappingDTO.getFields().size() > 0 && sectionFieldsMappingDTO.getProjectId() != null) { SectionAndFieldsMapping sectionAndFieldsMapping; List sectionAndFieldsMappingList = new ArrayList<>(); for (SectionAndFieldsMapping sectionFieldsMapping : sectionFieldsMappingDTO.getFields()) { List byFieldName = sectionAndFieldsMappingRepo - .getByFieldName(sectionFieldsMapping.getFieldName(),sectionFieldsMapping.getServiceProviderId()); + .getByFieldName(sectionFieldsMapping.getFieldName(),sectionFieldsMapping.getServiceProviderId(),sectionFieldsMappingDTO.getProjectId()); sectionAndFieldsMapping = new SectionAndFieldsMapping(); sectionAndFieldsMapping.setSectionId(sectionFieldsMappingDTO.getSectionId()); + sectionAndFieldsMapping.setProjectId(sectionFieldsMappingDTO.getProjectId()); sectionAndFieldsMapping.setCreatedBy(sectionFieldsMappingDTO.getCreatedBy()); sectionAndFieldsMapping.setAllowMax(sectionFieldsMapping.getAllowMax()); sectionAndFieldsMapping.setFieldName(sectionFieldsMapping.getFieldName()); @@ -284,16 +285,19 @@ public String fetchMappedFields(String request, String Authorization) throws Exc SectionAndFieldsMapping sectionAndFieldsMapping = InputMapper.gson().fromJson(request, SectionAndFieldsMapping.class); try { + if(sectionAndFieldsMapping.getProjectId() == null) { + throw new IllegalArgumentException("ProjectId is required"); + } List resultSet = sectionAndFieldsMappingRepo .findSectionIdAndSectionNameAndServiceProviderId(sectionAndFieldsMapping.getSectionId(), - sectionAndFieldsMapping.getServiceProviderId()); + sectionAndFieldsMapping.getServiceProviderId(), sectionAndFieldsMapping.getProjectId()); String sectionName = sectionMasterCustomizationRepo.findSectionName(sectionAndFieldsMapping.getSectionId()); Map responseMap = new HashMap<>(); responseMap.put("sectionId", sectionAndFieldsMapping.getSectionId()); responseMap.put("sectionName", sectionName); responseMap.put("serviceProviderId", sectionAndFieldsMapping.getServiceProviderId()); - + responseMap.put("projectId", sectionAndFieldsMapping.getProjectId()); List> fieldsList = new ArrayList<>(); for (SectionAndFieldsMapping field : resultSet) { Map fieldMap = new HashMap<>(); @@ -372,6 +376,11 @@ public String updateSectionAndFields(String request, String Authorization) throw if (sectionAndFieldsMapping.getId() != null) { SectionAndFieldsMapping response = sectionAndFieldsMappingRepo.getById(sectionAndFieldsMapping.getId()); if (response != null) { + if(sectionAndFieldsMapping.getProjectId() != null) { + ProjectCustomization project = projectCustomizationRepo.findById(sectionAndFieldsMapping.getProjectId()) + .orElseThrow(() -> new IllegalArgumentException("Invalid projectId")); + response.setProjectId(sectionAndFieldsMapping.getProjectId()); + } if (sectionAndFieldsMapping.getFieldName() != null) response.setFieldName(sectionAndFieldsMapping.getFieldName()); if (sectionAndFieldsMapping.getIsRequired() != null)