Skip to content

Commit

Permalink
#182: Implemented a new feature: Investigation Notes entity with it's…
Browse files Browse the repository at this point in the history
… fields: investigationNotesData, suspectedDiagnosis, confirmedDiagnosis, investigatedBy, investigatorSignature, investigatorDate
  • Loading branch information
Flava177 committed Dec 3, 2024
1 parent 9f34c4c commit 9839ff9
Show file tree
Hide file tree
Showing 13 changed files with 484 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
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.investigationnotes.InvestigationNotes;
import de.symeda.sormas.app.backend.person.Person;
import de.symeda.sormas.app.backend.region.Community;
import de.symeda.sormas.app.backend.region.District;
Expand Down Expand Up @@ -118,6 +119,7 @@ public class Case extends PseudonymizableAdo {
public static final String HEALTH_CONDITIONS = "healthConditions";
public static final String RISK_FACTOR = "riskFactor";
public static final String FOOD_HISTORY = "foodHistory";
public static final String INVESTIGATION_NOTES = "investigationNotes";

@DatabaseField(foreign = true, foreignAutoRefresh = true, canBeNull = false, maxForeignAutoRefreshLevel = 3)
private Person person;
Expand Down Expand Up @@ -291,6 +293,9 @@ public class Case extends PseudonymizableAdo {
@DatabaseField(foreign = true, foreignAutoRefresh = true)
private FoodHistory foodHistory;

@DatabaseField(foreign = true, foreignAutoRefresh = true)
private InvestigationNotes investigationNotes;

@Deprecated
@Column
private Long contactOfficer_id;
Expand Down Expand Up @@ -968,6 +973,12 @@ public FoodHistory getFoodHistory() {
public void setFoodHistory(FoodHistory foodHistory) {
this.foodHistory = foodHistory;
}
public InvestigationNotes getInvestigationNotes(){
return investigationNotes;
}

public void setInvestigationNotes(InvestigationNotes investigationNotes) {this.investigationNotes = investigationNotes; }


public Double getReportLat() {
return reportLat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
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.investigationnotes.InvestigationNotes;
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 @@ -220,6 +221,11 @@ public Date getLatestChangeDate() {
date = affectedPersonDate;
}

Date investigationNotesDate = getLatestChangeDateJoin(InvestigationNotes.TABLE_NAME, Case.INVESTIGATION_NOTES);
if (investigationNotesDate != null && investigationNotesDate.after(date)) {
date = investigationNotesDate;
}

return date;
}

Expand Down Expand Up @@ -302,6 +308,8 @@ public Case build(Person person) {
// food history
caze.setFoodHistory(DatabaseHelper.getFoodHistoryDao().build());

caze.setInvestigationNotes(DatabaseHelper.getInvestigationNotesDao().build());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import de.symeda.sormas.app.backend.hospitalization.HospitalizationDtoHelper;
import de.symeda.sormas.app.backend.infrastructure.PointOfEntry;
import de.symeda.sormas.app.backend.infrastructure.PointOfEntryDtoHelper;
import de.symeda.sormas.app.backend.investigationnotes.InvestigationNotesDtoHelper;
import de.symeda.sormas.app.backend.person.Person;
import de.symeda.sormas.app.backend.person.PersonDependentDtoHelper;
import de.symeda.sormas.app.backend.person.PersonDtoHelper;
Expand Down Expand Up @@ -73,6 +74,7 @@ public class CaseDtoHelper extends PersonDependentDtoHelper<Case, CaseDataDto> {
private HealthConditionsDtoHelper healthConditionsDtoHelper = new HealthConditionsDtoHelper();
private RiskFactorDtoHelper riskFactorDtoHelper = new RiskFactorDtoHelper();
private FoodHistoryDtoHelper foodHistoryDtoHelper = new FoodHistoryDtoHelper();
private InvestigationNotesDtoHelper investigationNotesDtoHelper = new InvestigationNotesDtoHelper();

@Override
protected Class<Case> getAdoClass() {
Expand Down Expand Up @@ -152,6 +154,7 @@ public void fillInnerFromDto(Case target, CaseDataDto source) {
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.setInvestigationNotes(investigationNotesDtoHelper.fillOrCreateFromDto(target.getInvestigationNotes(), source.getInvestigationNotes()));

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

if (source.getInvestigationNotes() != null) {
target.setInvestigationNotes(
investigationNotesDtoHelper.adoToDto(DatabaseHelper.getInvestigationNotesDao().queryForId(source.getInvestigationNotes().getId())));
} else {
target.setInvestigationNotes(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 @@ -142,6 +142,8 @@
import de.symeda.sormas.app.backend.immunization.ImmunizationDao;
import de.symeda.sormas.app.backend.infrastructure.PointOfEntry;
import de.symeda.sormas.app.backend.infrastructure.PointOfEntryDao;
import de.symeda.sormas.app.backend.investigationnotes.InvestigationNotes;
import de.symeda.sormas.app.backend.investigationnotes.InvestigationNotesDao;
import de.symeda.sormas.app.backend.lbds.LbdsSync;
import de.symeda.sormas.app.backend.lbds.LbdsSyncDao;
import de.symeda.sormas.app.backend.location.Location;
Expand Down Expand Up @@ -224,7 +226,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 = 409;
public static final int DATABASE_VERSION = 410;

private static DatabaseHelper instance = null;

Expand Down Expand Up @@ -313,6 +315,7 @@ public static void clearTables(boolean clearInfrastructure) {
TableUtils.clearTable(connectionSource, RiskFactor.class);
TableUtils.clearTable(connectionSource, FoodHistory.class);
TableUtils.clearTable(connectionSource, AffectedPerson.class);
TableUtils.clearTable(connectionSource, InvestigationNotes.class);

if (clearInfrastructure) {
TableUtils.clearTable(connectionSource, UserUserRole.class);
Expand Down Expand Up @@ -433,8 +436,10 @@ public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
TableUtils.createTable(connectionSource, PersonTravelHistory.class);
TableUtils.createTable(connectionSource, ContaminationSource.class);
TableUtils.createTable(connectionSource, ContainmentMeasure.class);
TableUtils.createTable(connectionSource, AffectedPerson.class);
TableUtils.createTable(connectionSource, RiskFactor.class);
TableUtils.createTable(connectionSource, FoodHistory.class);
TableUtils.createTable(connectionSource, InvestigationNotes.class);
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't build database", e);
throw new RuntimeException(e);
Expand Down Expand Up @@ -4122,6 +4127,30 @@ public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int
+ ");"
);

case 409:
currentVersion = 409;
getDao(InvestigationNotes.class).executeRaw(
"CREATE TABLE investigationnotes ("
+ " id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ " investigationNotesData VARCHAR(255),"
+ " suspectedDiagnosis VARCHAR(255),"
+ " confirmedDiagnosis VARCHAR(255),"
+ " investigatedBy VARCHAR(255),"
+ " investigatorSignature VARCHAR(255),"
+ " investigatorDate DATE,"
+ " changedate BIGINT,"
+ " changeUserId BIGINT,"
+ " creationDate DATE,"
+ " uuid VARCHAR(512),"
+ " pseudonymized SMALLINT,"
+ " lastOpenedDate BIGINT,"
+ " localChangeDate BIGINT NOT NULL,"
+ " modified SMALLINT,"
+ " snapshot SMALLINT,"
+ " UNIQUE (snapshot ASC, uuid ASC)"
+ ");"
);
getDao(Case.class).executeRaw("ALTER TABLE cases ADD COLUMN investigationnotes_id BIGINT;");

// ATTENTION: break should only be done after last version
break;
Expand Down Expand Up @@ -5102,6 +5131,8 @@ else if (type.equals(FormField.class)) {
dao = (AbstractAdoDao<ADO>) new FoodHistoryDao((Dao<FoodHistory, Long>) innerDao);
} else if (type.equals(AffectedPerson.class)) {
dao = (AbstractAdoDao<ADO>) new AffectedPersonDao((Dao<AffectedPerson, Long>) innerDao);
} else if (type.equals(InvestigationNotes.class)) {
dao = (AbstractAdoDao<ADO>) new InvestigationNotesDao((Dao<InvestigationNotes, Long>) innerDao);
} else {
throw new UnsupportedOperationException(type.toString());
}
Expand Down Expand Up @@ -5226,6 +5257,9 @@ public static FoodHistoryDao getFoodHistoryDao() {
return (FoodHistoryDao) getAdoDao(FoodHistory.class);
}

public static InvestigationNotesDao getInvestigationNotesDao() {
return (InvestigationNotesDao) getAdoDao(InvestigationNotes.class);
}

public static PersonDao getPersonDao() {
return (PersonDao) getAdoDao(Person.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package de.symeda.sormas.app.backend.investigationnotes;

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

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

import javax.persistence.Entity;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

import de.symeda.sormas.app.backend.common.EmbeddedAdo;
import de.symeda.sormas.app.backend.common.PseudonymizableAdo;

@Entity(name = InvestigationNotes.TABLE_NAME)
@DatabaseTable(tableName = InvestigationNotes.TABLE_NAME)
@EmbeddedAdo
public class InvestigationNotes extends PseudonymizableAdo {

private static final long serialVersionUID = -8294812479501735785L;
public static final String TABLE_NAME = "investigationnotes";
public static final String I18N_PREFIX = "InvestigationNotes";

@Column(length = CHARACTER_LIMIT_DEFAULT)
private String investigationNotesData;
@Column(length = CHARACTER_LIMIT_DEFAULT)
private String suspectedDiagnosis;
@Column(length = CHARACTER_LIMIT_DEFAULT)
private String confirmedDiagnosis;
@Column(length = CHARACTER_LIMIT_DEFAULT)
private String investigatedBy;
@Column(length = CHARACTER_LIMIT_DEFAULT)
private String investigatorSignature;
@DatabaseField(dataType = DataType.DATE_LONG)
private Date investigatorDate;

public String getInvestigationNotesData() {
return investigationNotesData;
}

public void setInvestigationNotesData(String investigationNotesData) {
this.investigationNotesData = investigationNotesData;
}

public String getSuspectedDiagnosis() {
return suspectedDiagnosis;
}

public void setSuspectedDiagnosis(String suspectedDiagnosis) {
this.suspectedDiagnosis = suspectedDiagnosis;
}

public String getConfirmedDiagnosis() {
return confirmedDiagnosis;
}

public void setConfirmedDiagnosis(String confirmedDiagnosis) {
this.confirmedDiagnosis = confirmedDiagnosis;
}

public String getInvestigatedBy() {
return investigatedBy;
}

public void setInvestigatedBy(String investigatedBy) {
this.investigatedBy = investigatedBy;
}

public String getInvestigatorSignature() {
return investigatorSignature;
}

public void setInvestigatorSignature(String investigatorSignature) {
this.investigatorSignature = investigatorSignature;
}
public Date getInvestigatorDate() {
return investigatorDate;
}

public void setInvestigatorDate(Date investigatorDate) {
this.investigatorDate = investigatorDate;
}

@Override
public String getI18nPrefix() {
return I18N_PREFIX;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package de.symeda.sormas.app.backend.investigationnotes;

import com.j256.ormlite.dao.Dao;

import java.util.Date;

import de.symeda.sormas.app.backend.common.AbstractAdoDao;
import de.symeda.sormas.app.backend.common.DaoException;

public class InvestigationNotesDao extends AbstractAdoDao<InvestigationNotes> {

public InvestigationNotesDao(Dao<InvestigationNotes, Long> innerDao) {
super(innerDao);
}

@Override
protected Class<InvestigationNotes> getAdoClass() {
return InvestigationNotes.class;
}

@Override
public String getTableName() {
return InvestigationNotes.TABLE_NAME;
}

@Override
public InvestigationNotes queryUuid(String uuid) {
InvestigationNotes data = super.queryUuid(uuid);
if (data != null) {
initLazyData(data);
}
return data;
}

@Override
public InvestigationNotes querySnapshotByUuid(String uuid) {
InvestigationNotes data = super.querySnapshotByUuid(uuid);
if (data != null) {
initLazyData(data);
}
return data;
}

@Override
public InvestigationNotes queryForId(Long id) {
InvestigationNotes data = super.queryForId(id);
if (data != null) {
initLazyData(data);
}
return data;
}

private InvestigationNotes initLazyData(InvestigationNotes foodHistory) {
return foodHistory;
}

@Override
public InvestigationNotes saveAndSnapshot(InvestigationNotes ado) throws DaoException {
InvestigationNotes snapshot = super.saveAndSnapshot(ado);
return snapshot;
}

@Override
public Date getLatestChangeDate() {
Date date = super.getLatestChangeDate();
if (date == null) {
return null;
}
return date;
}
}
Loading

0 comments on commit 9839ff9

Please sign in to comment.