Skip to content

Commit

Permalink
Merge branch 'refs/heads/gh-release-1.87.0-disease-lab-linkage' into …
Browse files Browse the repository at this point in the history
…gh-release-1.87.0
  • Loading branch information
douglasderrick committed Jan 15, 2025
2 parents b2331b6 + b6745d0 commit c9421f2
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
import de.symeda.sormas.app.backend.vaccination.VaccinationDao;
import de.symeda.sormas.app.backend.visit.Visit;
import de.symeda.sormas.app.backend.visit.VisitDao;
import de.symeda.sormas.app.backend.disease.DiseaseFacility;

/**
* Database helper class used to manage the creation and upgrading of your database. This class also usually provides
Expand All @@ -228,7 +229,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 = 410;
public static final int DATABASE_VERSION = 428;
public static final int DATABASE_VERSION = 429;

private static DatabaseHelper instance = null;
private final Context context;
Expand Down Expand Up @@ -339,6 +340,7 @@ public static void clearTables(boolean clearInfrastructure) {
TableUtils.clearTable(connectionSource, FormField.class);
TableUtils.clearTable(connectionSource, FormBuilder.class);
TableUtils.clearTable(connectionSource, FormBuilderFormField.class);
TableUtils.clearTable(connectionSource, DiseaseFacility.class);

ConfigProvider.init(instance.context);
}
Expand Down Expand Up @@ -794,6 +796,8 @@ public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
TableUtils.createTable(connectionSource, AfpImmunization.class);
TableUtils.createTable(connectionSource, SixtyDay.class);
TableUtils.createTable(connectionSource, PatientSymptomsPrecedence.class);
TableUtils.createTable(connectionSource, DiseaseFacility.class);

} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't build database", e);
throw new RuntimeException(e);
Expand Down Expand Up @@ -4452,7 +4456,9 @@ public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int
currentVersion = 427;
getDao(Facility.class).executeRaw(
"UPDATE facility SET type = 'HOSPITAL' WHERE type = null AND uuid NOT IN ('SORMAS-CONSTID-NOTBASED-FACILITY','SORMAS-CONSTID-NOTSET-FACILITY');");

case 428:
currentVersion = 428;
getDao(DiseaseConfiguration.class).executeRaw("CREATE TABLE IF NOT EXISTS facility_diseaseconfiguration(diseaseConfiguration_id integer, facility_id integer);");
// ATTENTION: break should only be done after last version
break;
default:
Expand Down Expand Up @@ -5337,7 +5343,7 @@ public <ADO extends AbstractDomainObject> AbstractAdoDao<ADO> getAdoDaoInner(Cla
} else if (type.equals(UserRole.class)) {
dao = (AbstractAdoDao<ADO>) new UserRoleDao((Dao<UserRole, Long>) innerDao);
} else if (type.equals(DiseaseConfiguration.class)) {
dao = (AbstractAdoDao<ADO>) new DiseaseConfigurationDao((Dao<DiseaseConfiguration, Long>) innerDao);
dao = (AbstractAdoDao<ADO>) new DiseaseConfigurationDao((Dao<DiseaseConfiguration, Long>) innerDao, super.getDao(DiseaseFacility.class));
} else if (type.equals(CustomizableEnumValue.class)) {
dao = (AbstractAdoDao<ADO>) new CustomizableEnumValueDao((Dao<CustomizableEnumValue, Long>) innerDao);
} else if (type.equals(FeatureConfiguration.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package de.symeda.sormas.app.backend.disease;

import java.sql.SQLException;

import java.util.List;
import java.util.stream.Collectors;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.DeleteBuilder;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.Where;

Expand All @@ -26,11 +28,17 @@
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.app.backend.common.AbstractAdoDao;
import de.symeda.sormas.app.util.DiseaseConfigurationCache;
import de.symeda.sormas.app.backend.common.DatabaseHelper;
import de.symeda.sormas.app.backend.facility.Facility;

public class DiseaseConfigurationDao extends AbstractAdoDao<DiseaseConfiguration> {

public DiseaseConfigurationDao(Dao<DiseaseConfiguration, Long> innerDao) {
private Dao<DiseaseFacility, Long> diseaseFacilityDao;


public DiseaseConfigurationDao(Dao<DiseaseConfiguration, Long> innerDao, Dao<DiseaseFacility, Long> diseaseFacilityDao) {
super(innerDao);
this.diseaseFacilityDao = diseaseFacilityDao;
}

@Override
Expand All @@ -57,13 +65,60 @@ public DiseaseConfiguration getDiseaseConfiguration(Disease disease) {

@Override
public void create(DiseaseConfiguration data) throws SQLException {
if (data == null)
return;
super.create(data);
DiseaseConfigurationCache.reset();
if (data.getFacilities() != null) {
for (Facility facility : data.getFacilities()) {
int resultRowCount = diseaseFacilityDao.create(new DiseaseFacility(data, facility));
if (resultRowCount < 1)
throw new SQLException(
"Database entry was not created - go back and try again.\n" + "Type: " + DiseaseFacility.class.getSimpleName() + ", Facility-UUID: "
+ data.getUuid());
}
}
}

@Override
protected void update(DiseaseConfiguration data) throws SQLException {
if (data == null)
return;
super.update(data);
DiseaseConfigurationCache.reset();
// 1. Delete existing DiseaseFacility
DeleteBuilder<DiseaseFacility, Long> diseaseFacilityLongDeleteBuilder = diseaseFacilityDao.deleteBuilder();
diseaseFacilityLongDeleteBuilder.where().eq(DiseaseFacility.DISEASE_CONFIGURATION + "_id", data);
diseaseFacilityLongDeleteBuilder.delete();
// 2. Create new DiseaseFacility
if (data.getFacilities() != null) {
for (Facility facility : data.getFacilities()) {
int resultRowCount = diseaseFacilityDao.create(new DiseaseFacility(data, facility));
if (resultRowCount < 1)
throw new SQLException(
"Database entry was not created - go back and try again.\n" + "Type: " + DiseaseFacility.class.getSimpleName() + ", Facility-UUID: "
+ data.getUuid());
}
}
}

public List<Facility> getDiseaseFacilities(DiseaseConfiguration diseaseConfiguration) {
diseaseConfiguration.setFacilities(
loadDiseaseFacility(diseaseConfiguration.getId()).stream()
.map(diseaseFacility -> DatabaseHelper.getFacilityDao().queryForId(diseaseFacility.getFacility().getId()))
.collect(Collectors.toList()));
List<Facility> facilities = diseaseConfiguration.getFacilities();
return facilities;
}
private List<DiseaseFacility> loadDiseaseFacility(Long diseaseId) {
try {
QueryBuilder builder = diseaseFacilityDao.queryBuilder();
Where where = builder.where();
where.eq(DiseaseConfiguration.TABLE_NAME + "_id", diseaseId);
return (List<DiseaseFacility>) builder.query();
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform loadUserRoles");
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
import com.j256.ormlite.stmt.Where;

import android.util.Log;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.infrastructure.facility.FacilityDto;
import de.symeda.sormas.api.infrastructure.facility.FacilityType;
import de.symeda.sormas.app.backend.common.AbstractDomainObject;
import de.symeda.sormas.app.backend.common.AbstractInfrastructureAdoDao;
import de.symeda.sormas.app.backend.common.DatabaseHelper;
import de.symeda.sormas.app.backend.common.InfrastructureAdo;
import de.symeda.sormas.app.backend.disease.DiseaseConfiguration;
import de.symeda.sormas.app.backend.region.Community;
import de.symeda.sormas.app.backend.region.District;
import de.symeda.sormas.app.backend.region.Region;
Expand Down Expand Up @@ -198,6 +202,16 @@ public List<Facility> getActiveLaboratories(boolean includeOtherFacility) {
}
}

public List<Facility> getActiveLaboratoriesByDisease(Disease disease, boolean includeOtherFacility) {
DiseaseConfiguration diseaseConfiguration = DatabaseHelper.getDiseaseConfigurationDao().getDiseaseConfiguration(disease);
List<Facility> facilities = DatabaseHelper.getDiseaseConfigurationDao().getDiseaseFacilities(diseaseConfiguration);
if (facilities.size() < 1) {
facilities = getActiveLaboratories(includeOtherFacility);
}
return facilities;
}


@Override
public Facility saveAndSnapshot(Facility facility) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ record = getActivityRootData();
sample = record.getSample();
testTypeList = DataUtils.getEnumItems(PathogenTestType.class, true, getFieldVisibilityCheckers());
pcrTestSpecificationList = DataUtils.getEnumItems(PCRTestSpecification.class, true);
labList = DatabaseHelper.getFacilityDao().getActiveLaboratories(true);
Disease incomingDisease = record.getSample().getAssociatedCase().getDisease();
Disease incomingTestedDisease = record.getTestedDisease();
testResultVariationList = DataUtils.getEnumItems(PathogenTestResultVariant.class, true);
Expand Down Expand Up @@ -140,7 +141,6 @@ record = getActivityRootData();
testResultList = DataUtils.toItems(
Arrays.stream(PathogenTestResultType.values()).filter(type -> type != PathogenTestResultType.NOT_DONE).collect(Collectors.toList()),
true);
labList = DatabaseHelper.getFacilityDao().getActiveLaboratories(true);

finalClassificationList = DataUtils.toItems(Arrays.asList(FinalClassification.values()));
}
Expand Down Expand Up @@ -178,6 +178,10 @@ public void onLayoutBinding(FragmentPathogenTestEditLayoutBinding contentBinding
contentBinding.pathogenTestLaboratoryDatePcrPerformed.initializeDateField(getFragmentManager());
contentBinding.pathogenTestLaboratoryDateResultsSentDSD.initializeDateTimeField(getFragmentManager());
contentBinding.pathogenTestDateSampleSentRegLab.initializeDateField(getFragmentManager());
if (contentBinding.pathogenTestTestedDisease.getValue() != null) {
labList = DatabaseHelper.getFacilityDao().getActiveLaboratoriesByDisease((Disease) contentBinding.pathogenTestTestedDisease.getValue(), true);
contentBinding.pathogenTestLab.setSpinnerData(DataUtils.toItems(labList));
}

}

Expand Down Expand Up @@ -223,6 +227,13 @@ public void onChange(ControlPropertyField field) {
}

updateDiseaseVariantsField(contentBinding);
if (contentBinding.pathogenTestTestedDisease.getValue() != null) {
labList = DatabaseHelper.getFacilityDao().getActiveLaboratoriesByDisease((Disease) contentBinding.pathogenTestTestedDisease.getValue(), true);
contentBinding.pathogenTestLab.setSpinnerData(DataUtils.toItems(labList));
}
if (this.currentDisease == null || contentBinding.pathogenTestTestedDisease.getValue() != currentDisease) {
updateDiseaseVariantsField(contentBinding);
}
if(caseDisease != Disease.NEW_INFLUENZA){
testTypeList = DataUtils.toItems(
Arrays.asList(PathogenTestType.values()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ record = getActivityRootData();
}

sampleMaterialList = DataUtils.getEnumItems(SampleMaterial.class, true, getFieldVisibilityCheckers());
sampleSourceList = DataUtils.getEnumItems(SampleSource.class, true);
labList = DatabaseHelper.getFacilityDao().getActiveLaboratories(true);
labList = DatabaseHelper.getFacilityDao().getActiveLaboratoriesByDisease(getDiseaseOfAssociatedEntity(record), true);
samplePurposeList = DataUtils.getEnumItems(SamplePurpose.class, true);
samplingReasonList = DataUtils.getEnumItems(SamplingReason.class, true, getFieldVisibilityCheckers());
csfReasonList = DataUtils.getEnumItems(CsfReason.class, true, getFieldVisibilityCheckers());
Expand Down

0 comments on commit c9421f2

Please sign in to comment.