Skip to content

Commit

Permalink
"#182: Add Food History entity with fields and features - Implemented…
Browse files Browse the repository at this point in the history
… a new entity (FoodHistory) to track relevant data. - Added all necessary fields and features for the entity. - Ensured proper integration with existing components and workflows."
  • Loading branch information
Flava177 committed Nov 29, 2024
1 parent 9ef1e77 commit a530766
Show file tree
Hide file tree
Showing 12 changed files with 1,968 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import de.symeda.sormas.app.backend.common.PseudonymizableAdo;
import de.symeda.sormas.app.backend.epidata.EpiData;
import de.symeda.sormas.app.backend.facility.Facility;
import de.symeda.sormas.app.backend.foodhistory.FoodHistory;
import de.symeda.sormas.app.backend.hospitalization.Hospitalization;
import de.symeda.sormas.app.backend.infrastructure.PointOfEntry;
import de.symeda.sormas.app.backend.person.Person;
Expand Down Expand Up @@ -116,6 +117,7 @@ public class Case extends PseudonymizableAdo {
public static final String VACCINATION_STATUS = "vaccinationStatus";
public static final String HEALTH_CONDITIONS = "healthConditions";
public static final String RISK_FACTOR = "riskFactor";
public static final String FOOD_HISTORY = "foodHistory";

@DatabaseField(foreign = true, foreignAutoRefresh = true, canBeNull = false, maxForeignAutoRefreshLevel = 3)
private Person person;
Expand Down Expand Up @@ -286,6 +288,9 @@ public class Case extends PseudonymizableAdo {
@DatabaseField(foreign = true, foreignAutoRefresh = true)
private RiskFactor riskFactor;

@DatabaseField(foreign = true, foreignAutoRefresh = true)
private FoodHistory foodHistory;

@Deprecated
@Column
private Long contactOfficer_id;
Expand Down Expand Up @@ -956,6 +961,14 @@ public void setRiskFactor(RiskFactor riskFactor) {
this.riskFactor = riskFactor;
}

public FoodHistory getFoodHistory() {
return foodHistory;
}

public void setFoodHistory(FoodHistory foodHistory) {
this.foodHistory = foodHistory;
}

public Double getReportLat() {
return reportLat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import de.symeda.sormas.api.caze.InvestigationStatus;
import de.symeda.sormas.api.feature.FeatureType;
import de.symeda.sormas.api.feature.FeatureTypeProperty;
import de.symeda.sormas.api.foodhistory.FoodHistoryDto;
import de.symeda.sormas.api.infrastructure.facility.FacilityType;
import de.symeda.sormas.api.task.TaskStatus;
import de.symeda.sormas.api.user.JurisdictionLevel;
Expand Down Expand Up @@ -79,6 +80,7 @@
import de.symeda.sormas.app.backend.event.EventEditAuthorization;
import de.symeda.sormas.app.backend.event.EventParticipant;
import de.symeda.sormas.app.backend.exposure.Exposure;
import de.symeda.sormas.app.backend.foodhistory.FoodHistory;
import de.symeda.sormas.app.backend.person.Person;
import de.symeda.sormas.app.backend.persontravelhistory.PersonTravelHistory;
import de.symeda.sormas.app.backend.region.Community;
Expand Down Expand Up @@ -207,6 +209,11 @@ public Date getLatestChangeDate() {
date = riskFactorDate;
}

Date foodHistoryDate = getLatestChangeDateJoin(FoodHistory.TABLE_NAME, Case.FOOD_HISTORY);
if (foodHistoryDate != null && foodHistoryDate.after(date)) {
date = foodHistoryDate;
}

return date;
}

Expand Down Expand Up @@ -286,6 +293,9 @@ public Case build(Person person) {
// risk factor
caze.setRiskFactor(DatabaseHelper.getRiskFactorDao().build());

// food history
caze.setFoodHistory(DatabaseHelper.getFoodHistoryDao().build());

// Location
User currentUser = ConfigProvider.getUser();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import de.symeda.sormas.api.PostResponse;
import de.symeda.sormas.api.caze.CaseDataDto;
import de.symeda.sormas.api.caze.CaseReferenceDto;
import de.symeda.sormas.api.foodhistory.FoodHistoryDto;
import de.symeda.sormas.api.person.PersonReferenceDto;
import de.symeda.sormas.api.symptoms.SymptomsDto;
import de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistoryDtoHelper;
Expand All @@ -33,6 +34,7 @@
import de.symeda.sormas.app.backend.epidata.EpiDataDtoHelper;
import de.symeda.sormas.app.backend.facility.Facility;
import de.symeda.sormas.app.backend.facility.FacilityDtoHelper;
import de.symeda.sormas.app.backend.foodhistory.FoodHistoryDtoHelper;
import de.symeda.sormas.app.backend.hospitalization.Hospitalization;
import de.symeda.sormas.app.backend.hospitalization.HospitalizationDtoHelper;
import de.symeda.sormas.app.backend.infrastructure.PointOfEntry;
Expand Down Expand Up @@ -70,6 +72,7 @@ public class CaseDtoHelper extends PersonDependentDtoHelper<Case, CaseDataDto> {
private SormasToSormasOriginInfoDtoHelper sormasToSormasOriginInfoDtoHelper = new SormasToSormasOriginInfoDtoHelper();
private HealthConditionsDtoHelper healthConditionsDtoHelper = new HealthConditionsDtoHelper();
private RiskFactorDtoHelper riskFactorDtoHelper = new RiskFactorDtoHelper();
private FoodHistoryDtoHelper foodHistoryDtoHelper = new FoodHistoryDtoHelper();

@Override
protected Class<Case> getAdoClass() {
Expand Down Expand Up @@ -148,6 +151,7 @@ public void fillInnerFromDto(Case target, CaseDataDto source) {
target.setMaternalHistory(maternalHistoryDtoHelper.fillOrCreateFromDto(target.getMaternalHistory(), source.getMaternalHistory()));
target.setPortHealthInfo(portHealthInfoDtoHelper.fillOrCreateFromDto(target.getPortHealthInfo(), source.getPortHealthInfo()));
target.setRiskFactor(riskFactorDtoHelper.fillOrCreateFromDto(target.getRiskFactor(), source.getRiskFactor()));
target.setFoodHistory(foodHistoryDtoHelper.fillOrCreateFromDto(target.getFoodHistory(), source.getFoodHistory()));

target.setSurveillanceOfficer(DatabaseHelper.getUserDao().getByReferenceDto(source.getSurveillanceOfficer()));
target.setClinicianName(source.getClinicianName());
Expand Down Expand Up @@ -459,6 +463,13 @@ public void fillInnerFromAdo(CaseDataDto target, Case source) {
target.setRiskFactor(null);
}

if (source.getFoodHistory() != null) {
target.setFoodHistory(
foodHistoryDtoHelper.adoToDto(DatabaseHelper.getFoodHistoryDao().queryForId(source.getFoodHistory().getId())));
} else {
target.setFoodHistory(null);
}

target.setClinicianName(source.getClinicianName());
target.setClinicianPhone(source.getClinicianPhone());
target.setClinicianEmail(source.getClinicianEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import de.symeda.sormas.api.exposure.ExposureType;
import de.symeda.sormas.api.exposure.HabitationType;
import de.symeda.sormas.api.exposure.TypeOfAnimal;
import de.symeda.sormas.api.foodhistory.FoodHistoryDto;
import de.symeda.sormas.api.immunization.ImmunizationManagementStatus;
import de.symeda.sormas.api.immunization.ImmunizationStatus;
import de.symeda.sormas.api.immunization.MeansOfImmunization;
Expand Down Expand Up @@ -123,6 +124,8 @@
import de.symeda.sormas.app.backend.facility.FacilityDao;
import de.symeda.sormas.app.backend.feature.FeatureConfiguration;
import de.symeda.sormas.app.backend.feature.FeatureConfigurationDao;
import de.symeda.sormas.app.backend.foodhistory.FoodHistory;
import de.symeda.sormas.app.backend.foodhistory.FoodHistoryDao;
import de.symeda.sormas.app.backend.formbuilder.FormBuilder;
import de.symeda.sormas.app.backend.formbuilder.FormBuilderDao;
import de.symeda.sormas.app.backend.formbuilder.FormBuilderFormField;
Expand Down Expand Up @@ -218,7 +221,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 = 407;
public static final int DATABASE_VERSION = 408;

private static DatabaseHelper instance = null;

Expand Down Expand Up @@ -305,6 +308,7 @@ public static void clearTables(boolean clearInfrastructure) {
TableUtils.clearTable(connectionSource, ContaminationSource.class);
TableUtils.clearTable(connectionSource, ContainmentMeasure.class);
TableUtils.clearTable(connectionSource, RiskFactor.class);
TableUtils.clearTable(connectionSource, FoodHistory.class);

if (clearInfrastructure) {
TableUtils.clearTable(connectionSource, UserUserRole.class);
Expand Down Expand Up @@ -426,6 +430,7 @@ public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
TableUtils.createTable(connectionSource, ContaminationSource.class);
TableUtils.createTable(connectionSource, ContainmentMeasure.class);
TableUtils.createTable(connectionSource, RiskFactor.class);
TableUtils.createTable(connectionSource, FoodHistory.class);
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't build database", e);
throw new RuntimeException(e);
Expand Down Expand Up @@ -4005,6 +4010,92 @@ public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN typeOfSample varchar(255);");
getDao(Hospitalization.class).executeRaw("ALTER TABLE hospitalizations ADD COLUMN agentIdentified varchar(255);");

case 407:
currentVersion = 407;
getDao(FoodHistory.class).executeRaw(
"CREATE TABLE foodhistory ("
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ " suspectedFood VARCHAR(255),"
+ " dateConsumed DATE,"
+ " foodSource VARCHAR(255),"
+ " eventType VARCHAR(255),"
+ " eventOtherSpecify VARCHAR(255),"
+ " nameOfAffectedPerson VARCHAR(255),"
+ " nameOfAffectedPerson2 VARCHAR(255),"
+ " nameOfAffectedPerson3 VARCHAR(512),"
+ " nameOfAffectedPerson4 VARCHAR(255),"
+ " telNo VARCHAR(255),"
+ " telNo2 VARCHAR(255),"
+ " telNo3 VARCHAR(255),"
+ " telNo4 VARCHAR(255),"
+ " dateTime DATE,"
+ " dateTime2 DATE,"
+ " dateTime3 DATE,"
+ " dateTime4 DATE,"
+ " age VARCHAR(255),"
+ " age2 VARCHAR(255),"
+ " age3 VARCHAR(255),"
+ " age4 VARCHAR(255),"
+ " breakfast VARCHAR(3),"
+ " totalNoPersons VARCHAR(255),"
+ " foodConsumed VARCHAR(255),"
+ " sourceOfFood VARCHAR(255),"
+ " consumedAtPlace VARCHAR(3),"
+ " lunch VARCHAR(55),"
+ " totalNoPersonsL1 VARCHAR(255),"
+ " foodConsumedL1 VARCHAR(255),"
+ " sourceOfFoodL1 VARCHAR(255),"
+ " consumedAtPlaceL1 VARCHAR(3),"
+ " supper VARCHAR(55),"
+ " totalNoPersonsS1 VARCHAR(255),"
+ " foodConsumedS1 VARCHAR(255),"
+ " sourceOfFoodS1 VARCHAR(255),"
+ " consumedAtPlaceS1 VARCHAR(3),"
+ " breakfast2 VARCHAR(3),"
+ " totalNoPersons2 VARCHAR(255),"
+ " foodConsumed2 VARCHAR(255),"
+ " sourceOfFood2 VARCHAR(255),"
+ " consumedAtPlace2 VARCHAR(3),"
+ " lunchL2 VARCHAR(55),"
+ " totalNoPersonsL2 VARCHAR(255),"
+ " foodConsumedL2 VARCHAR(255),"
+ " sourceOfFoodL2 VARCHAR(255),"
+ " consumedAtPlaceL2 VARCHAR(3),"
+ " supperS2 VARCHAR(55),"
+ " totalNoPersonsS2 VARCHAR(255),"
+ " foodConsumedS2 VARCHAR(255),"
+ " sourceOfFoodS2 VARCHAR(255),"
+ " consumedAtPlaceS2 VARCHAR(3),"
+ " breakfast3 VARCHAR(55),"
+ " totalNoPersons3 VARCHAR(255),"
+ " foodConsumed3 VARCHAR(255),"
+ " sourceOfFood3 VARCHAR(255),"
+ " consumedAtPlace3 VARCHAR(3),"
+ " lunchL3 VARCHAR(55),"
+ " totalNoPersonsL3 VARCHAR(255),"
+ " foodConsumedL3 VARCHAR(255),"
+ " sourceOfFoodL3 VARCHAR(255),"
+ " consumedAtPlaceL3 VARCHAR(3),"
+ " supperS3 VARCHAR(55),"
+ " totalNoPersonsS3 VARCHAR(255),"
+ " foodConsumedS3 VARCHAR(255),"
+ " sourceOfFoodS3 VARCHAR(255),"
+ " consumedAtPlaceS3 VARCHAR(55),"
+ " numberOfPeopleAteImplicatedFood INTEGER,"
+ " numberAffected VARCHAR,"
+ " changeDate BIGINT,"
+ " changeUserId BIGINT,"
+ " creationDate DATE,"
+ " uuid VARCHAR(512),"
+ " lastOpenedDate BIGINT,"
+ " localChangeDate BIGINT NOT NULL,"
+ " modified SMALLINT,"
+ " snapshot SMALLINT,"
+ " UNIQUE (snapshot ASC, uuid ASC)"
+ ");"
);
getDao(Case.class).executeRaw("ALTER TABLE cases ADD COLUMN foodhistory_id BIGINT;");



// ATTENTION: break should only be done after last version
Expand Down Expand Up @@ -4981,6 +5072,8 @@ else if (type.equals(FormField.class)) {
dao = (AbstractAdoDao<ADO>) new ContainmentMeasureDao((Dao<ContainmentMeasure, Long>) innerDao);
} else if(type.equals(RiskFactor.class)) {
dao = (AbstractAdoDao<ADO>) new RiskFactorDao((Dao<RiskFactor, Long>) innerDao);
} else if(type.equals(FoodHistory.class)) {
dao = (AbstractAdoDao<ADO>) new FoodHistoryDao((Dao<FoodHistory, Long>) innerDao);
}else {
throw new UnsupportedOperationException(type.toString());
}
Expand Down Expand Up @@ -5101,6 +5194,10 @@ public static PortHealthInfoDao getPortHealthInfoDao() {
public static RiskFactorDao getRiskFactorDao() {
return (RiskFactorDao) getAdoDao(RiskFactor.class);
}
public static FoodHistoryDao getFoodHistoryDao() {
return (FoodHistoryDao) getAdoDao(FoodHistory.class);
}


public static PersonDao getPersonDao() {
return (PersonDao) getAdoDao(Person.class);
Expand Down
Loading

0 comments on commit a530766

Please sign in to comment.