Skip to content

Commit

Permalink
#182: Implemented the feature updates for Food borne at hospitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Flava177 committed Nov 27, 2024
1 parent 3c81060 commit 92621e6
Show file tree
Hide file tree
Showing 5 changed files with 516 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {

// public static final int DATABASE_VERSION = 307;
//public static final int DATABASE_VERSION = 343;
public static final int DATABASE_VERSION = 406;
public static final int DATABASE_VERSION = 407;

private static DatabaseHelper instance = null;

Expand Down Expand Up @@ -3983,6 +3983,29 @@ public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int
getDao(EpiData.class).executeRaw("ALTER TABLE epidata ADD COLUMN contactDate DATE ;");
getDao(EpiData.class).executeRaw("ALTER TABLE epidata ADD COLUMN specifyIllness varchar(255) ;");

case 406:
currentVersion = 406;
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN requestedSymptomsSelectedString varchar(512);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN otherSymptomSelected varchar(512);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN onsetOfSymptomDatetime DATE;");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN symptomsOngoing varchar(16);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN durationHours varchar(16);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN soughtMedicalAttention varchar(16);");

getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN soughtRegion_id bigint REFERENCES region(id);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN soughtDistrict_id bigint REFERENCES district(id);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN soughtCommunity_id bigint REFERENCES community(id);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN nameOfFacility_id bigint REFERENCES facility(id);");

getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN dateOfVisitHospital DATE;");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN hospitalizationYesNo varchar(16);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN physicianName varchar(255);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN physicianNumber varchar(255);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN labTestConducted varchar(16);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN typeOfSample varchar(255);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN agentIdentified varchar(255);");



// ATTENTION: break should only be done after last version
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,47 @@
package de.symeda.sormas.app.backend.hospitalization;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

import de.symeda.sormas.api.hospitalization.AccommodationType;
import de.symeda.sormas.api.hospitalization.SymptomsList;
import de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto;
import de.symeda.sormas.api.utils.DurationHours;
import de.symeda.sormas.api.utils.InpatOutpat;
import de.symeda.sormas.api.utils.MildModerateSevereCritical;
import de.symeda.sormas.api.hospitalization.HospitalizationReasonType;
import de.symeda.sormas.api.utils.YesNo;
import de.symeda.sormas.api.utils.YesNoUnknown;
import de.symeda.sormas.app.backend.common.AbstractDomainObject;
import de.symeda.sormas.app.backend.common.EmbeddedAdo;
import de.symeda.sormas.app.backend.facility.Facility;
import de.symeda.sormas.app.backend.region.Community;
import de.symeda.sormas.app.backend.region.District;
import de.symeda.sormas.app.backend.region.Region;

import static de.symeda.sormas.api.utils.FieldConstraints.CHARACTER_LIMIT_BIG;
import static de.symeda.sormas.api.utils.FieldConstraints.CHARACTER_LIMIT_DEFAULT;

import org.apache.commons.lang3.StringUtils;

@Entity(name = Hospitalization.TABLE_NAME)
@DatabaseTable(tableName = Hospitalization.TABLE_NAME)
Expand Down Expand Up @@ -116,6 +135,42 @@ public class Hospitalization extends AbstractDomainObject {
private YesNoUnknown wasPatientAdmitted;
@DatabaseField(dataType = DataType.DATE_LONG)
private Date terminationDateHospitalStay;
@Transient
private Set<SymptomsList> symptomsSelected;
@Column(length = CHARACTER_LIMIT_DEFAULT)
private String requestedSymptomsSelectedString;
@Column(columnDefinition = "text")
private String otherSymptomSelected;
@DatabaseField(dataType = DataType.DATE_LONG)
private Date onsetOfSymptomDatetime;
@Enumerated(EnumType.STRING)
private YesNo symptomsOngoing;
@Enumerated(EnumType.STRING)
private DurationHours durationHours;
@Enumerated(EnumType.STRING)
private YesNo soughtMedicalAttention;
@DatabaseField(foreign = true, foreignAutoRefresh = true, maxForeignAutoRefreshLevel = 3)
private Region soughtRegion;
@DatabaseField(foreign = true, foreignAutoRefresh = true, maxForeignAutoRefreshLevel = 3)
private District soughtDistrict;
@DatabaseField(foreign = true, foreignAutoRefresh = true, maxForeignAutoRefreshLevel = 3)
private Community soughtCommunity;
@DatabaseField(foreign = true, foreignAutoRefresh = true, maxForeignAutoRefreshLevel = 3)
private Facility nameOfFacility;
@DatabaseField(dataType = DataType.DATE_LONG)
private Date dateOfVisitHospital;
@Enumerated(EnumType.STRING)
private YesNo hospitalizationYesNo;
@Column(columnDefinition = "text")
private String physicianName;
@Column(columnDefinition = "text")
private String physicianNumber;
@Enumerated(EnumType.STRING)
private YesNo labTestConducted;
@Column(columnDefinition = "text")
private String typeOfSample;
@Column(columnDefinition = "text")
private String agentIdentified;


public Date getAdmissionDate() {
Expand Down Expand Up @@ -363,4 +418,173 @@ public Date getTerminationDateHospitalStay() {
public void setTerminationDateHospitalStay(Date terminationDateHospitalStay) {
this.terminationDateHospitalStay = terminationDateHospitalStay;
}

@Transient
public Set<SymptomsList> getSymptomsSelected() {
if (symptomsSelected == null) {
if (StringUtils.isEmpty(requestedSymptomsSelectedString)) {
symptomsSelected = new HashSet<>();
} else {
symptomsSelected =
Arrays.stream(requestedSymptomsSelectedString.split(",")).map(SymptomsList::valueOf).collect(Collectors.toSet());
}
}
return symptomsSelected;
}

public void setSymptomsSelected(Set<SymptomsList> symptomsSelected) {
this.symptomsSelected = symptomsSelected;

if (this.symptomsSelected == null) {
return;
}

StringBuilder sb = new StringBuilder();
symptomsSelected.stream().forEach(t -> {
sb.append(t.name());
sb.append(",");
});
if (sb.length() > 0) {
sb.substring(0, sb.lastIndexOf(","));
}
requestedSymptomsSelectedString = sb.toString();
}
public String getRequestedSymptomsSelectedString() {
return requestedSymptomsSelectedString;
}

public void setRequestedSymptomsSelectedString(String requestedSymptomsSelectedString) {
this.requestedSymptomsSelectedString = requestedSymptomsSelectedString;
symptomsSelected = null;
}

public String getOtherSymptomSelected() {
return otherSymptomSelected;
}

public void setOtherSymptomSelected(String otherSymptomSelected) {
this.otherSymptomSelected = otherSymptomSelected;
}

public Date getOnsetOfSymptomDatetime() {
return onsetOfSymptomDatetime;
}

public void setOnsetOfSymptomDatetime(Date onsetOfSymptomDatetime) {
this.onsetOfSymptomDatetime = onsetOfSymptomDatetime;
}
public YesNo getSymptomsOngoing() {
return symptomsOngoing;
}

public void setSymptomsOngoing(YesNo symptomsOngoing) {
this.symptomsOngoing = symptomsOngoing;
}

public DurationHours getDurationHours() {
return durationHours;
}

public void setDurationHours(DurationHours durationHours) {
this.durationHours = durationHours;
}

public YesNo getSoughtMedicalAttention() {
return soughtMedicalAttention;
}

public void setSoughtMedicalAttention(YesNo soughtMedicalAttention) {
this.soughtMedicalAttention = soughtMedicalAttention;
}

@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;
}

public Facility getNameOfFacility() {
return nameOfFacility;
}

public void setNameOfFacility(Facility nameOfFacility) {
this.nameOfFacility = nameOfFacility;
}

public Date getDateOfVisitHospital() {
return dateOfVisitHospital;
}

public void setDateOfVisitHospital(Date dateOfVisitHospital) {
this.dateOfVisitHospital = dateOfVisitHospital;
}

public YesNo getHospitalizationYesNo() {
return hospitalizationYesNo;
}

public void setHospitalizationYesNo(YesNo hospitalizationYesNo) {
this.hospitalizationYesNo = hospitalizationYesNo;
}

public String getPhysicianName() {
return physicianName;
}

public void setPhysicianName(String physicianName) {
this.physicianName = physicianName;
}

public String getPhysicianNumber() {
return physicianNumber;
}

public void setPhysicianNumber(String physicianNumber) {
this.physicianNumber = physicianNumber;
}

public YesNo getLabTestConducted() {
return labTestConducted;
}

public void setLabTestConducted(YesNo labTestConducted) {
this.labTestConducted = labTestConducted;
}

public String getTypeOfSample() {
return typeOfSample;
}

public void setTypeOfSample(String typeOfSample) {
this.typeOfSample = typeOfSample;
}

public String getAgentIdentified() {
return agentIdentified;
}

public void setAgentIdentified(String agentIdentified) {
this.agentIdentified = agentIdentified;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
import de.symeda.sormas.api.hospitalization.HospitalizationDto;
import de.symeda.sormas.api.hospitalization.PreviousHospitalizationDto;
import de.symeda.sormas.app.backend.common.AdoDtoHelper;
import de.symeda.sormas.app.backend.common.DatabaseHelper;
import de.symeda.sormas.app.backend.facility.Facility;
import de.symeda.sormas.app.backend.facility.FacilityDtoHelper;
import de.symeda.sormas.app.backend.region.Community;
import de.symeda.sormas.app.backend.region.CommunityDtoHelper;
import de.symeda.sormas.app.backend.region.District;
import de.symeda.sormas.app.backend.region.DistrictDtoHelper;
import de.symeda.sormas.app.backend.region.Region;
import de.symeda.sormas.app.backend.region.RegionDtoHelper;
import de.symeda.sormas.app.rest.NoConnectionException;
import retrofit2.Call;

Expand Down Expand Up @@ -101,6 +110,26 @@ public void fillInnerFromDto(Hospitalization a, HospitalizationDto b) {
a.setDateFormSentToDistrict(b.getDateFormSentToDistrict());
a.setSeenAtAHealthFacility(b.getSeenAtAHealthFacility());
a.setWasPatientAdmitted(b.getWasPatientAdmitted());

a.setTerminationDateHospitalStay(b.getTerminationDateHospitalStay());
a.setSymptomsSelected(b.getSymptomsSelected());
a.setOtherSymptomSelected(b.getOtherSymptomSelected());
a.setOnsetOfSymptomDatetime(b.getOnsetOfSymptomDatetime());
a.setSymptomsOngoing(b.getSymptomsOngoing());
a.setDurationHours(b.getDurationHours());
a.setSoughtMedicalAttention(b.getSoughtMedicalAttention());
a.setSoughtRegion(DatabaseHelper.getRegionDao().getByReferenceDto(b.getSoughtRegion()));
a.setSoughtDistrict(DatabaseHelper.getDistrictDao().getByReferenceDto(b.getSoughtDistrict()));
a.setSoughtCommunity(DatabaseHelper.getCommunityDao().getByReferenceDto(b.getSoughtCommunity()));
a.setNameOfFacility(DatabaseHelper.getFacilityDao().getByReferenceDto(b.getNameOfFacility()));
a.setDateOfVisitHospital(b.getDateOfVisitHospital());
a.setHospitalizationYesNo(b.getHospitalizationYesNo());
a.setPhysicianName(b.getPhysicianName());
a.setPhysicianNumber(b.getPhysicianNumber());
a.setLabTestConducted(b.getLabTestConducted());
a.setTypeOfSample(b.getTypeOfSample());
a.setAgentIdentified(b.getAgentIdentified());

}

@Override
Expand Down Expand Up @@ -141,6 +170,48 @@ public void fillInnerFromAdo(HospitalizationDto a, Hospitalization b) {
a.setDateFormSentToDistrict(b.getDateFormSentToDistrict());
a.setSeenAtAHealthFacility(b.getSeenAtAHealthFacility());
a.setWasPatientAdmitted(b.getWasPatientAdmitted());

a.setTerminationDateHospitalStay(b.getTerminationDateHospitalStay());
a.setSymptomsSelected(b.getSymptomsSelected());
a.setOtherSymptomSelected(b.getOtherSymptomSelected());
a.setOnsetOfSymptomDatetime(b.getOnsetOfSymptomDatetime());
a.setSymptomsOngoing(b.getSymptomsOngoing());
a.setDurationHours(b.getDurationHours());
a.setSoughtMedicalAttention(b.getSoughtMedicalAttention());
if (b.getSoughtRegion() != null) {
Region region = DatabaseHelper.getRegionDao().queryForId(b.getSoughtRegion().getId());
a.setSoughtRegion(RegionDtoHelper.toReferenceDto(region));
} else {
a.setSoughtRegion(null);
}

if (b.getSoughtDistrict() != null) {
District district = DatabaseHelper.getDistrictDao().queryForId(b.getSoughtDistrict().getId());
a.setSoughtDistrict(DistrictDtoHelper.toReferenceDto(district));
} else {
a.setSoughtDistrict(null);
}

if (b.getSoughtCommunity() != null) {
Community community = DatabaseHelper.getCommunityDao().queryForId(b.getSoughtCommunity().getId());
a.setSoughtCommunity(CommunityDtoHelper.toReferenceDto(community));
} else {
a.setSoughtCommunity(null);
}

if (b.getNameOfFacility() != null) {
Facility facility = DatabaseHelper.getFacilityDao().queryForId(b.getNameOfFacility().getId());
a.setNameOfFacility(FacilityDtoHelper.toReferenceDto(facility));
} else {
a.setNameOfFacility(null);
}
a.setDateOfVisitHospital(b.getDateOfVisitHospital());
a.setHospitalizationYesNo(b.getHospitalizationYesNo());
a.setPhysicianName(b.getPhysicianName());
a.setPhysicianNumber(b.getPhysicianNumber());
a.setLabTestConducted(b.getLabTestConducted());
a.setTypeOfSample(b.getTypeOfSample());
a.setAgentIdentified(b.getAgentIdentified());
}

@Override
Expand Down
Loading

0 comments on commit 92621e6

Please sign in to comment.