diff --git a/sormas-api/src/main/java/de/symeda/sormas/api/hospitalization/HospitalizationDto.java b/sormas-api/src/main/java/de/symeda/sormas/api/hospitalization/HospitalizationDto.java index 2474957c446..0ed1191706c 100644 --- a/sormas-api/src/main/java/de/symeda/sormas/api/hospitalization/HospitalizationDto.java +++ b/sormas-api/src/main/java/de/symeda/sormas/api/hospitalization/HospitalizationDto.java @@ -18,7 +18,10 @@ package de.symeda.sormas.api.hospitalization; import de.symeda.sormas.api.feature.FeatureType; +import de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto; +import de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto; import de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto; +import de.symeda.sormas.api.infrastructure.region.RegionReferenceDto; import de.symeda.sormas.api.location.LocationDto; import de.symeda.sormas.api.person.PersonContactDetailDto; import de.symeda.sormas.api.person.PersonDto; @@ -88,6 +91,9 @@ public class HospitalizationDto extends EntityDto { public static final String NAME_OF_FACILITY = "nameOfFacility"; public static final String LOCATION_ADDRESS = "locationAddress"; public static final String LOCATION_TYPE = "locationType"; + public static final String SOUGHT_REGION = "soughtRegion"; + public static final String SOUGHT_DISTRICT = "soughtDistrict"; + public static final String SOUGHT_COMMUNITY = "soughtCommunity"; public static final String DATE_OF_VISIT_HOSPITAL = "dateOfVisitHospital"; public static final String PHYSICIAN_NAME = "physicianName"; public static final String PHYSICIAN_NUMBER = "physicianNumber"; @@ -178,6 +184,9 @@ public class HospitalizationDto extends EntityDto { @EmbeddedSensitiveData @Valid private LocationDto locationType; + private RegionReferenceDto soughtRegion; + private DistrictReferenceDto soughtDistrict; + private CommunityReferenceDto soughtCommunity; public static HospitalizationDto build() { @@ -650,4 +659,28 @@ public YesNo getHospitalizationYesNo() { public void setHospitalizationYesNo(YesNo hospitalizationYesNo) { this.hospitalizationYesNo = hospitalizationYesNo; } + + public RegionReferenceDto getSoughtRegion() { + return soughtRegion; + } + + public void setSoughtRegion(RegionReferenceDto soughtRegion) { + this.soughtRegion = soughtRegion; + } + + public DistrictReferenceDto getSoughtDistrict() { + return soughtDistrict; + } + + public void setSoughtDistrict(DistrictReferenceDto soughtDistrict) { + this.soughtDistrict = soughtDistrict; + } + + public CommunityReferenceDto getSoughtCommunity() { + return soughtCommunity; + } + + public void setSoughtCommunity(CommunityReferenceDto soughtCommunity) { + this.soughtCommunity = soughtCommunity; + } } diff --git a/sormas-api/src/main/java/de/symeda/sormas/api/i18n/Captions.java b/sormas-api/src/main/java/de/symeda/sormas/api/i18n/Captions.java index 11a0813bacc..5279c1d8c19 100644 --- a/sormas-api/src/main/java/de/symeda/sormas/api/i18n/Captions.java +++ b/sormas-api/src/main/java/de/symeda/sormas/api/i18n/Captions.java @@ -684,6 +684,9 @@ public interface Captions { String CaseHospitalization_receptionDates = "CaseHospitalization.receptionDate"; String CaseHospitalization_memberFamilyHelpingPatient = "CaseHospitalization.memberFamilyHelpingPatient"; String CaseHospitalization_dateOfDeath = "CaseHospitalization.dateOfDeath"; + String CaseHospitalization_soughtRegion = "CaseHospitalization.soughtRegion"; + String CaseHospitalization_soughtDistrict = "CaseHospitalization.soughtDistrict"; + String CaseHospitalization_soughtCommunity = "CaseHospitalization.soughtCommunity"; String CaseHospitalization_previousHospitalizations = "CaseHospitalization.previousHospitalizations"; diff --git a/sormas-api/src/main/resources/captions.properties b/sormas-api/src/main/resources/captions.properties index bd6285890b1..f132bea8be3 100644 --- a/sormas-api/src/main/resources/captions.properties +++ b/sormas-api/src/main/resources/captions.properties @@ -3714,6 +3714,9 @@ CaseHospitalization.durationHours = If No, duration of Symptoms CaseHospitalization.receptionDate = Reception date CaseHospitalization.memberFamilyHelpingPatient = Member of family helping the patient (Name and Surname) CaseHospitalization.dateOfDeath = Date of death +CaseHospitalization.soughtRegion = Region +CaseHospitalization.soughtDistrict = District +CaseHospitalization.soughtCommunity = Sub District EpiData.nameOfVaccine=If Yes, Name of Vaccine EpiData.previouslyVaccinatedAgainstCovid=Previously vaccinated against Covid-19? diff --git a/sormas-backend/src/main/java/de/symeda/sormas/backend/hospitalization/Hospitalization.java b/sormas-backend/src/main/java/de/symeda/sormas/backend/hospitalization/Hospitalization.java index d017e983512..2931f22718f 100644 --- a/sormas-backend/src/main/java/de/symeda/sormas/backend/hospitalization/Hospitalization.java +++ b/sormas-backend/src/main/java/de/symeda/sormas/backend/hospitalization/Hospitalization.java @@ -26,6 +26,9 @@ import javax.validation.constraints.Size; import de.symeda.sormas.api.hospitalization.HospitalizationReasonType; +import de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto; +import de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto; +import de.symeda.sormas.api.infrastructure.region.RegionReferenceDto; import de.symeda.sormas.api.location.LocationDto; import de.symeda.sormas.api.utils.MildModerateSevereCritical; import de.symeda.sormas.api.hospitalization.SymptomsList; @@ -34,7 +37,10 @@ import de.symeda.sormas.api.sample.SampleMaterial; import de.symeda.sormas.api.utils.*; import de.symeda.sormas.backend.common.AbstractDomainObject; +import de.symeda.sormas.backend.infrastructure.community.Community; +import de.symeda.sormas.backend.infrastructure.district.District; import de.symeda.sormas.backend.infrastructure.facility.Facility; +import de.symeda.sormas.backend.infrastructure.region.Region; import de.symeda.sormas.backend.location.Location; import org.apache.commons.lang3.StringUtils; @@ -129,6 +135,9 @@ public class Hospitalization extends AbstractDomainObject { private Date dateOfDeath; private YesNo hospitalizationYesNo; private Location locationType; + private Region soughtRegion; + private District soughtDistrict; + private Community soughtCommunity; @Temporal(TemporalType.TIMESTAMP) public Date getAdmissionDate() { @@ -648,4 +657,31 @@ public Location getLocationType() { public void setLocationType(Location locationType) { this.locationType = locationType; } + + @ManyToOne(cascade = {}, fetch = FetchType.LAZY) + public Region getSoughtRegion() { + return soughtRegion; + } + + public void setSoughtRegion(Region soughtRegion) { + this.soughtRegion = soughtRegion; + } + + public void setSoughtDistrict(District soughtDistrict) { + this.soughtDistrict = soughtDistrict; + } + @ManyToOne(cascade = {}, fetch = FetchType.LAZY) + public District getSoughtDistrict() { + return soughtDistrict; + } + + @OneToOne(cascade = CascadeType.ALL) + + public Community getSoughtCommunity() { + return soughtCommunity; + } + + public void setSoughtCommunity(Community soughtCommunity) { + this.soughtCommunity = soughtCommunity; + } } diff --git a/sormas-backend/src/main/java/de/symeda/sormas/backend/hospitalization/HospitalizationFacadeEjb.java b/sormas-backend/src/main/java/de/symeda/sormas/backend/hospitalization/HospitalizationFacadeEjb.java index d142168d986..4a3e635c17c 100644 --- a/sormas-backend/src/main/java/de/symeda/sormas/backend/hospitalization/HospitalizationFacadeEjb.java +++ b/sormas-backend/src/main/java/de/symeda/sormas/backend/hospitalization/HospitalizationFacadeEjb.java @@ -164,6 +164,10 @@ public Hospitalization fillOrBuildEntity(HospitalizationDto source, Hospitalizat target.setHospitalizationYesNo(source.getHospitalizationYesNo()); target.setLocationType(locationFacade.fillOrBuildEntity(source.getLocationType(), target.getLocationType(), checkChangeDate)); + target.setSoughtRegion(regionService.getByReferenceDto(source.getSoughtRegion())); + target.setSoughtDistrict(districtService.getByReferenceDto(source.getSoughtDistrict())); + target.setSoughtCommunity(communityService.getByReferenceDto(source.getSoughtCommunity())); + return target; } @@ -278,8 +282,10 @@ public static HospitalizationDto toDto(Hospitalization hospitalization) { target.setMemberFamilyHelpingPatient(source.getMemberFamilyHelpingPatient()); target.setDateOfDeath(source.getDateOfDeath()); target.setHospitalizationYesNo(source.getHospitalizationYesNo()); - target.setLocationType(LocationFacadeEjb.toDto(source.getLocationType())); + target.setSoughtRegion(RegionFacadeEjb.toReferenceDto(source.getSoughtRegion())); + target.setSoughtDistrict(DistrictFacadeEjb.toReferenceDto(source.getSoughtDistrict())); + target.setSoughtCommunity(CommunityFacadeEjb.toReferenceDto(source.getSoughtCommunity())); return target; diff --git a/sormas-backend/src/main/resources/sql/sormas_schema.sql b/sormas-backend/src/main/resources/sql/sormas_schema.sql index fdbdfdebc87..0bf43d3b51e 100644 --- a/sormas-backend/src/main/resources/sql/sormas_schema.sql +++ b/sormas-backend/src/main/resources/sql/sormas_schema.sql @@ -15153,4 +15153,9 @@ ALTER TABLE forms_form_fields ALTER COLUMN displayOrder SET NOT NULL; CREATE INDEX idx_forms_form_fields_order ON forms_form_fields (form_id, displayOrder); INSERT INTO schema_version (version_number, comment) VALUES (713, 'Created index for displayorder on forms_form_fields table'); + +ALTER TABLE hospitalization ADD COLUMN soughtRegion_id BIGINT; +ALTER TABLE hospitalization ADD COLUMN soughtDistrict_id BIGINT; +ALTER TABLE hospitalization ADD COLUMN soughtCommunity_id BIGINT; +INSERT INTO schema_version (version_number, comment) VALUES (714, 'Created location module fields to reimplement region, district and community in hosp table'); -- *** Insert new sql commands BEFORE this line. Remember to always consider _history tables. *** diff --git a/sormas-ui/src/main/java/de/symeda/sormas/ui/hospitalization/HospitalizationForm.java b/sormas-ui/src/main/java/de/symeda/sormas/ui/hospitalization/HospitalizationForm.java index 67d07fb57f3..84a9326c7e0 100644 --- a/sormas-ui/src/main/java/de/symeda/sormas/ui/hospitalization/HospitalizationForm.java +++ b/sormas-ui/src/main/java/de/symeda/sormas/ui/hospitalization/HospitalizationForm.java @@ -107,6 +107,10 @@ public class HospitalizationForm extends AbstractEditForm { OptionGroup tickSymptomField; TextField physicianName; TextField physicianNumber; + private ComboBox soughtRegion; + private ComboBox soughtDistrict; + private ComboBox soughtCommunity; + private ComboBox nameOfFacilityField; private LocationEditForm addressForm; //@formatter:off private static final String HTML_LAYOUT = @@ -152,6 +156,7 @@ public class HospitalizationForm extends AbstractEditForm { fluidRowLocs(6, HospitalizationDto.DURATION_HOURS)+ fluidRowLocs(6, HospitalizationDto.SOUGHT_MEDICAL_ATTENTION)+ fluidRowLocs(HospitalizationDto.LOCATION_TYPE)+ + fluidRowLocs(HospitalizationDto.SOUGHT_REGION, HospitalizationDto.SOUGHT_DISTRICT, HospitalizationDto.SOUGHT_COMMUNITY)+ fluidRowLocs(6, HospitalizationDto.NAME_OF_FACILITY)+ fluidRowLocs(6,HospitalizationDto.DATE_OF_VISIT_HOSPITAL)+ fluidRowLocs(6,HospitalizationDto.HOSPITALIZATION_YES_NO) + @@ -316,6 +321,10 @@ else if (healthFacility1 != null){ addField(HospitalizationDto.PREVIOUS_HOSPITALIZATIONS, PreviousHospitalizationsField.class); NullableOptionGroup soughtMedicalAttentionField = addField(HospitalizationDto.SOUGHT_MEDICAL_ATTENTION, NullableOptionGroup.class); + soughtRegion = addInfrastructureField(HospitalizationDto.SOUGHT_REGION); + soughtDistrict = addInfrastructureField(HospitalizationDto.SOUGHT_DISTRICT); + soughtCommunity = addInfrastructureField(HospitalizationDto.SOUGHT_COMMUNITY); + setFieldsVisible(false, soughtRegion, soughtDistrict, soughtCommunity); if(caze.getDisease() == Disease.MONKEYPOX){ addressForm = new LocationEditForm( @@ -327,16 +336,12 @@ else if (healthFacility1 != null){ UiFieldAccessCheckers.getNoop(), disease); } - addField(HospitalizationDto.LOCATION_TYPE, addressForm); - addressForm.setCaption(null); - - ComboBox nameOfFacilityField = addInfrastructureField(HospitalizationDto.NAME_OF_FACILITY); + nameOfFacilityField = addInfrastructureField(HospitalizationDto.NAME_OF_FACILITY); nameOfFacilityField.setImmediate(true); addressForm.setNameOfFacilityField(nameOfFacilityField); addressForm.hideForHospitalizationForm(); nameOfFacilityField.setVisible(false); - setVisible(false, HospitalizationDto.LOCATION_TYPE); DateField dateOfVisitHospital = addField(HospitalizationDto.DATE_OF_VISIT_HOSPITAL, DateField.class); physicianName = addField(HospitalizationDto.PHYSICIAN_NAME, TextField.class); @@ -400,7 +405,7 @@ else if (healthFacility1 != null){ initializeVisibilitiesAndAllowedVisibilities(); initializeAccessAndAllowedAccesses(); -// addressForm.hideForHospitalizationForm(); + addressForm.hideForHospitalizationForm(); if (isVisibleAllowed(HospitalizationDto.ISOLATION_DATE)) { FieldHelper.setVisibleWhen( @@ -506,6 +511,13 @@ public String getFormattedHtmlMessage() { /*caseOutcome.addValueChangeListener(e -> addSequelaeValue()); sequelae.addValueChangeListener(e -> addSequelaeDetailsValue());*/ + addListenersToInfrastructureFields( + soughtRegion, + soughtDistrict, + soughtCommunity, + nameOfFacilityField); + soughtRegion.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry()); + setVisible(false, HospitalizationDto.RECEPTION_DATE, HospitalizationDto.DATE_OF_DEATH, HospitalizationDto.MEMBER_FAMILY_HELPING_PATIENT); hideFieldsForSelectedDisease(caze.getDisease()); @@ -610,20 +622,14 @@ public String getFormattedHtmlMessage() { FieldHelper.setVisibleWhen(hospitalizedYesNo, Arrays.asList(physicianName, physicianNumber), Arrays.asList(YesNo.YES), true); FieldHelper.setVisibleWhen(labTestConducted, Arrays.asList(typeOfSample, agentIdentified), Arrays.asList(YesNo.YES), true); - FieldHelper.setVisibleWhen( - getFieldGroup(), - Arrays.asList(HospitalizationDto.LOCATION_TYPE), - HospitalizationDto.SOUGHT_MEDICAL_ATTENTION, - Arrays.asList(YesNo.YES), - true - ); + FieldHelper.setVisibleWhen(soughtMedicalAttentionField, Arrays.asList(soughtRegion, soughtDistrict, soughtCommunity), Arrays.asList(YesNo.YES), true); } if(caze.getDisease() == Disease.MONKEYPOX){ + addField(HospitalizationDto.LOCATION_TYPE, addressForm); + addressForm.setCaption(null); setFieldsVisible(true, admittedToHealthFacilityNew); -// setVisible(true, HospitalizationDto.HOSPITAL_RECORD_NUMBER, HospitalizationDto.LOCATION_TYPE, HospitalizationDto.NAME_OF_FACILITY); - FieldHelper.setVisibleWhen( getFieldGroup(), Arrays.asList(HospitalizationDto.ADMISSION_DATE, HospitalizationDto.HOSPITAL_RECORD_NUMBER, HospitalizationDto.LOCATION_TYPE, HospitalizationDto.NAME_OF_FACILITY), @@ -833,4 +839,47 @@ public void setValue(HospitalizationDto newFieldValue) { // this hopefully resets everything to its correct value addressForm.discard(); } + + private void addListenersToInfrastructureFields( + ComboBox regionField, + ComboBox districtField, + ComboBox communityField, + ComboBox facilityField) { + regionField.addValueChangeListener(e -> { + RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue(); + FieldHelper + .updateItems(districtField, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null); + updateFacilities(); + }); + districtField.addValueChangeListener(e -> { + DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue(); + FieldHelper.updateItems( + communityField, + districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null); + updateFacilities(); + }); + FieldHelper.updateItems( + facilityField, + Collections.singletonList(FacadeProvider.getFacilityFacade().getReferenceByUuid(FacilityDto.NONE_FACILITY_UUID))); + + } + + private void updateFacilities() { + DistrictReferenceDto selectedDistrict = (DistrictReferenceDto) soughtDistrict.getValue(); + CommunityReferenceDto selectedCommunity = (CommunityReferenceDto) soughtCommunity.getValue(); + + List facilities = null; + if (selectedCommunity != null) { + facilities = FacadeProvider.getFacilityFacade().getActiveHospitalsByCommunity(selectedCommunity, true, true, true); + } else if (selectedDistrict != null) { + facilities = FacadeProvider.getFacilityFacade().getActiveHospitalsByDistrict(selectedDistrict, true, true, true); + } + + if (nameOfFacilityField!= null) { + FieldHelper.updateItems(nameOfFacilityField, facilities); + } + + + } + } diff --git a/sormas-ui/src/main/java/de/symeda/sormas/ui/location/LocationEditForm.java b/sormas-ui/src/main/java/de/symeda/sormas/ui/location/LocationEditForm.java index 9a8dc512f25..f0d0275f2f8 100644 --- a/sormas-ui/src/main/java/de/symeda/sormas/ui/location/LocationEditForm.java +++ b/sormas-ui/src/main/java/de/symeda/sormas/ui/location/LocationEditForm.java @@ -235,15 +235,6 @@ public void setSkipFacilityTypeUpdate(boolean skipFacilityTypeUpdate) { protected void addFields() { caseDisease = getCaseDisease(); - CaseDataDto newCazeData = getCaseData(); - if(newCazeData != null){ - RegionReferenceDto regionReferenceDto = newCazeData.getResponsibleRegion(); - DistrictReferenceDto districtReferenceDto = newCazeData.getResponsibleDistrict(); - CommunityReferenceDto communityReferenceDto = newCazeData.getResponsibleCommunity(); - } - - - addressType = addField(LocationDto.ADDRESS_TYPE, ComboBox.class); addressType.setVisible(false); final PersonAddressType[] personAddressTypeValues = PersonAddressType.getValues(FacadeProvider.getConfigFacade().getCountryCode());