Skip to content

Commit

Permalink
#181: Updated the implementation of rendering region, district and su…
Browse files Browse the repository at this point in the history
…b district at hospitalization for Food Borne. Removed unncesscary code at Locationeditform.
  • Loading branch information
Flava177 committed Nov 27, 2024
1 parent 086e3fc commit 3c81060
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions sormas-api/src/main/resources/captions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions sormas-backend/src/main/resources/sql/sormas_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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. ***
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public class HospitalizationForm extends AbstractEditForm<HospitalizationDto> {
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 =
Expand Down Expand Up @@ -152,6 +156,7 @@ public class HospitalizationForm extends AbstractEditForm<HospitalizationDto> {
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) +
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -400,7 +405,7 @@ else if (healthFacility1 != null){

initializeVisibilitiesAndAllowedVisibilities();
initializeAccessAndAllowedAccesses();
// addressForm.hideForHospitalizationForm();
addressForm.hideForHospitalizationForm();

if (isVisibleAllowed(HospitalizationDto.ISOLATION_DATE)) {
FieldHelper.setVisibleWhen(
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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<FacilityReferenceDto> 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);
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 3c81060

Please sign in to comment.