use of de.symeda.sormas.api.caze.VaccinationStatus in project SORMAS-Project by hzi-braunschweig.
the class DatabaseHelper method migrateVaccinationInfo.
private void migrateVaccinationInfo() throws SQLException {
// Retrieve all new unsynchronized cases with vaccinationStatus == VACCINATED from the database
GenericRawResults<Object[]> caseInfoResult = getDao(Case.class).queryRaw("SELECT cases.id, person_id, disease, diseaseDetails, reportDate, reportingUser_id, responsibleRegion_id, responsibleDistrict_id, " + "responsibleCommunity_id, COALESCE(symptoms.onsetDate, cases.reportDate), firstVaccinationDate, vaccinationDate, vaccinationDoses, vaccineName, otherVaccineName, vaccine, " + "vaccineManufacturer, otherVaccineManufacturer, vaccinationInfoSource, vaccineInn, vaccineBatchNumber, vaccineUniiCode, vaccineAtcCode," + "pregnant, trimester, healthConditions_id FROM cases LEFT JOIN clinicalCourse ON cases.clinicalCourse_id = clinicalCourse.id " + "LEFT JOIN symptoms ON cases.symptoms_id = symptoms.id WHERE cases.snapshot = 0 AND cases.changeDate = 0 AND vaccination = 'VACCINATED';", new DataType[] { // 0: cases.id
DataType.BIG_INTEGER, // 1: person_id
DataType.BIG_INTEGER, // 2: disease
DataType.ENUM_STRING, // 3: diseaseDetails
DataType.STRING, // 4: reportDate
DataType.DATE_LONG, // 5: reportingUser_id
DataType.BIG_INTEGER, // 6: responsibleRegion_id
DataType.BIG_INTEGER, // 7: responsibleDistrict_id
DataType.BIG_INTEGER, // 8: responsibleCommunity_id
DataType.BIG_INTEGER, // 9: symptoms.onsetDate OR cases.reportDate
DataType.DATE_LONG, // 10: firstVaccinationDate
DataType.DATE_LONG, // 11: vaccinationDate
DataType.DATE_LONG, // 12: vaccinationDoses
DataType.STRING, // 13: vaccineName
DataType.ENUM_STRING, // 14: otherVaccineName
DataType.STRING, // 15: vaccine
DataType.STRING, // 16: vaccineManufacturer
DataType.ENUM_STRING, // 17: otherVaccineManufacturer
DataType.STRING, // 18: vaccinationInfoSource
DataType.ENUM_STRING, // 19: vaccineInn
DataType.STRING, // 20: vaccineBatchNumber
DataType.STRING, // 21: vaccineUniiCode
DataType.STRING, // 22: vaccineAtcCode
DataType.STRING, // 23: pregnant
DataType.ENUM_STRING, // 24: trimester
DataType.ENUM_STRING, // 25: healthConditions_id
DataType.BIG_INTEGER });
List<Object[]> caseInfoList = caseInfoResult.getResults();
for (Object[] caseInfo : caseInfoList) {
doNullCheckOnString(caseInfo, 3);
doNullCheckOnString(caseInfo, 14);
doNullCheckOnString(caseInfo, 15);
doNullCheckOnString(caseInfo, 17);
doNullCheckOnString(caseInfo, 19);
doNullCheckOnString(caseInfo, 20);
doNullCheckOnString(caseInfo, 21);
doNullCheckOnString(caseInfo, 22);
formatRawResultDate(caseInfo, 4);
formatRawResultDate(caseInfo, 9);
formatRawResultDate(caseInfo, 10);
formatRawResultDate(caseInfo, 11);
if (DataHelper.isNullOrEmpty((String) caseInfo[12])) {
Array.set(caseInfo, 12, null);
} else {
try {
Array.set(caseInfo, 12, new Integer((String) caseInfo[12]));
} catch (NumberFormatException e) {
Array.set(caseInfo, 12, 1);
}
}
}
// Retrieve earlier cases of each person for each disease
Comparator<Object[]> comparator = Comparator.comparing(c -> new Date((Long) c[9]));
List<Object[]> filteredCaseInfo = new ArrayList<>();
Map<Disease, List<Object[]>> caseInfoByDisease = caseInfoList.stream().collect(Collectors.groupingBy(c -> Disease.valueOf((String) c[2])));
caseInfoByDisease.keySet().forEach(d -> {
filteredCaseInfo.addAll(caseInfoByDisease.get(d).stream().sorted(comparator).collect(Collectors.collectingAndThen(Collectors.toMap(c -> ((BigInteger) c[1]), Function.identity(), (c1, c2) -> new Date((Long) c1[9]).after(new Date((Long) c2[9])) ? c1 : c2), r -> new ArrayList<>(r.values()))));
});
filteredCaseInfo.forEach(objects -> {
// Retrieve all cases of the case person with the respective disease
final Object caseId = objects[0];
final Object personId = objects[1];
final List<Object[]> objectList = caseInfoByDisease.get(Disease.valueOf((String) objects[2])).stream().filter(c -> ((BigInteger) c[0]).intValue() != ((BigInteger) caseId).intValue() && ((BigInteger) c[1]).intValue() == ((BigInteger) personId).intValue()).collect(Collectors.toList());
// set earliest report date
Comparator<Object[]> reportDateComparator = Comparator.comparing(c -> new Date((Long) c[4]));
objectList.stream().min(reportDateComparator).ifPresent(earliestObject -> {
objects[4] = earliestObject[4];
});
// set earliest first vaccination date
if (objects[10] == null) {
Comparator<Object[]> firstVacDateComparator = Comparator.comparing(c -> new Date((Long) c[10]));
objectList.stream().filter(c -> c[10] != null).max(firstVacDateComparator).ifPresent(earliestObject -> {
objects[10] = earliestObject[10];
});
}
// set latest last vaccination date
if (objects[11] == null) {
Comparator<Object[]> lastVacDateComparator = Comparator.comparing(c -> new Date((Long) c[11]));
objectList.stream().filter(c -> c[11] != null).min(lastVacDateComparator).ifPresent(earliestObject -> {
objects[11] = earliestObject[11];
});
}
// set latest available vaccine name
if (objects[13] == null) {
objectList.stream().filter(c -> c[13] != null).min(comparator).ifPresent(latestObject -> {
objects[13] = latestObject[13];
objects[14] = latestObject[14];
});
}
// set latest available vaccine
if (objects[15] == null) {
objectList.stream().filter(c -> c[15] != null).min(comparator).ifPresent(latestObject -> objects[15] = latestObject[15]);
}
// set latest available vaccine manufacturer
if (objects[16] == null) {
objectList.stream().filter(c -> c[16] != null).min(comparator).ifPresent(latestObject -> {
objects[16] = latestObject[16];
objects[17] = latestObject[17];
});
}
// set latest available vaccination info source
if (objects[18] == null) {
objectList.stream().filter(c -> c[18] != null).min(comparator).ifPresent(latestObject -> objects[18] = latestObject[18]);
}
// set latest available INN
if (objects[19] == null) {
objectList.stream().filter(c -> c[19] != null).min(comparator).ifPresent(latestObject -> objects[19] = latestObject[19]);
}
// set latest available batch number
if (objects[20] == null) {
objectList.stream().filter(c -> c[20] != null).min(comparator).ifPresent(latestObject -> objects[20] = latestObject[20]);
}
// set latest available UNII code
if (objects[21] == null) {
objectList.stream().filter(c -> c[21] != null).min(comparator).ifPresent(latestObject -> objects[21] = latestObject[21]);
}
// set latest available ATC code
if (objects[22] == null) {
objectList.stream().filter(c -> c[22] != null).min(comparator).ifPresent(latestObject -> objects[22] = latestObject[22]);
}
});
// Create immunizations and vaccinations for each case
for (Object[] caseInfo : filteredCaseInfo) {
// Create immunization
String immunizationInsertQuery = "INSERT INTO immunization " + "(" + " uuid, changeDate, localChangeDate, creationDate, person_id," + " disease, diseaseDetails, reportDate, reportingUser_id, immunizationStatus, meansOfImmunization, immunizationManagementStatus," + " responsibleRegion_id, responsibleDistrict_id, responsibleCommunity_id, startDate, endDate, numberOfDoses, pseudonymized," + " modified, snapshot" + ")" + "VALUES (?, ?, " + generateDateNowSQL() + ", " + generateDateNowSQL() + ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
executeRaw(Immunization.class, immunizationInsertQuery, DataHelper.createUuid(), 0, caseInfo[1], caseInfo[2], caseInfo[3], caseInfo[4], caseInfo[5], ImmunizationStatus.ACQUIRED.name(), MeansOfImmunization.VACCINATION.name(), ImmunizationManagementStatus.COMPLETED.name(), caseInfo[6], caseInfo[7], caseInfo[8], caseInfo[10], caseInfo[11], caseInfo[12], 0, 1, 0);
if (caseInfo[12] == null) {
// No vaccination doses specified
if (caseInfo[10] != null || caseInfo[11] == null) {
cloneHealthConditions(caseInfo[25]);
insertFirstVaccination(caseInfo, caseInfo[10]);
}
// Last vaccination
if (caseInfo[11] != null || ("ASTRA_ZENECA_COMIRNATY".equals(caseInfo[13]) || "ASTRA_ZENECA_MRNA_1273".equals(caseInfo[13]))) {
cloneHealthConditions(caseInfo[25]);
insertVaccination(caseInfo, caseInfo[11]);
}
} else {
// Vaccination doses specified
int vaccinationDoses = (int) caseInfo[12];
if (vaccinationDoses == 1) {
cloneHealthConditions(caseInfo[25]);
insertFirstVaccination(caseInfo, caseInfo[11] != null ? caseInfo[11] : caseInfo[10]);
} else {
cloneHealthConditions(caseInfo[25]);
insertFirstVaccination(caseInfo, caseInfo[10]);
for (int i = 2; i <= vaccinationDoses - 1; i++) {
cloneHealthConditions(caseInfo[25]);
insertVaccination(caseInfo, null);
}
cloneHealthConditions(caseInfo[25]);
insertVaccination(caseInfo, caseInfo[11]);
}
}
}
}
use of de.symeda.sormas.api.caze.VaccinationStatus in project SORMAS-Project by hzi-braunschweig.
the class DatabaseHelper method migrateEpiData.
private void migrateEpiData() throws SQLException {
getDao(EpiData.class).executeRaw("UPDATE epidata SET wildbirds = 'YES', poultryEat = 'YES' WHERE poultry = 'YES' AND changeDate = 0 AND snapshot = 0;");
// Epi data field names sometimes don't match the actual field names because the columns were renamed in the past
migrateEpiDataField("processingConfirmedCaseFluidUnsafe", Exposure.HANDLING_SAMPLES, YesNoUnknown.YES, ExposureType.WORK);
migrateEpiDataField("percutaneousCaseBlood", Exposure.PERCUTANEOUS, YesNoUnknown.YES, ExposureType.WORK);
migrateEpiDataField("wildbirdsLocation", Exposure.PHYSICAL_CONTACT_WITH_BODY, YesNoUnknown.YES, ExposureType.BURIAL);
migrateEpiDataField("wildbirdsDetails", Exposure.HANDLING_SAMPLES, YesNoUnknown.YES, ExposureType.WORK);
migrateEpiDataField("poultrySick", Exposure.ANIMAL_CONDITION, AnimalCondition.DEAD, ExposureType.ANIMAL_CONTACT, "poultryDate", "poultryDate", "poultrySickDetails", "poultryLocation");
migrateEpiDataField("poultryEat", Exposure.EATING_RAW_ANIMAL_PRODUCTS, YesNoUnknown.YES, ExposureType.ANIMAL_CONTACT, null, null, "poultryDetails", null);
migrateEpiDataField("rodents", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.RODENT, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("bats", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.BAT, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("primates", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.PRIMATE, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("swine", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.SWINE, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("birds", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.POULTRY, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("rabbits", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.RABBIT, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("cattle", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.CATTLE, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("dogs", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.DOG, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("cats", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.CAT, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("canidae", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.CANIDAE, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("camels", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.CAMEL, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("snakes", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.SNAKE, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("tickBite", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.TICK, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("fleaBite", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.FLEA, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("otherAnimals", Exposure.TYPE_OF_ANIMAL, TypeOfAnimal.OTHER, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("waterBody", Exposure.BODY_OF_WATER, YesNoUnknown.YES, ExposureType.OTHER, null, null, "waterBodyDetails", null);
migrateEpiDataField("visitedHealthFacility", Exposure.HABITATION_TYPE, HabitationType.MEDICAL, ExposureType.HABITATION);
migrateEpiDataField("visitedAnimalMarket", Exposure.ANIMAL_MARKET, YesNoUnknown.YES, ExposureType.OTHER);
migrateEpiDataField("areaConfirmedCases", Exposure.RISK_AREA, YesNoUnknown.YES, ExposureType.TRAVEL);
migrateEpiDataField("kindOfExposureBite", Exposure.ANIMAL_CONTACT_TYPE, AnimalContactType.BITE, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("kindOfExposureTouch", Exposure.ANIMAL_CONTACT_TYPE, AnimalContactType.TOUCH, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("kindOfExposureScratch", Exposure.ANIMAL_CONTACT_TYPE, AnimalContactType.SCRATCH, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("kindOfExposureLick", Exposure.ANIMAL_CONTACT_TYPE, AnimalContactType.LICK, ExposureType.ANIMAL_CONTACT);
migrateEpiDataField("kindOfExposureOther", Exposure.ANIMAL_CONTACT_TYPE, AnimalContactType.OTHER, ExposureType.ANIMAL_CONTACT);
GenericRawResults<Object[]> lastExposureInfo = getDao(EpiData.class).queryRaw("SELECT id, dateOfLastExposure, placeOfLastExposure, animalCondition, animalVaccinationStatus, prophylaxisStatus, dateOfProphylaxis" + " FROM epidata WHERE changeDate = 0 AND snapshot = 0 AND (dateOfLastExposure IS NOT NULL OR placeOfLastExposure IS NOT NULL" + " OR animalCondition IS NOT NULL OR animalVaccinationStatus IS NOT NULL OR prophylaxisStatus IS NOT NULL OR dateOfProphylaxis IS NOT NULL);", new DataType[] { DataType.BIG_INTEGER, DataType.DATE_LONG, DataType.STRING, DataType.ENUM_STRING, DataType.ENUM_STRING, DataType.ENUM_STRING, DataType.DATE_LONG });
for (Object[] result : lastExposureInfo) {
doNullCheckOnString(result, 2);
formatRawResultDate(result, 1);
formatRawResultDate(result, 6);
Long locationId = insertLocation((String) result[2]);
VaccinationStatus vaccinationStatus = result[4] != null ? VaccinationStatus.valueOf((String) result[4]) : null;
String exposureQuery = "INSERT INTO exposures" + "(" + " uuid, changeDate, localChangeDate, creationDate, epiData_id, location_id, exposureType, " + " startDate, endDate, animalCondition, animalVaccinated, prophylaxis, prophylaxisDate, description, pseudonymized, modified, snapshot" + ")" + "VALUES (?, ?, " + generateDateNowSQL() + ", " + generateDateNowSQL() + ", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
executeRaw(Exposure.class, exposureQuery, DataHelper.createUuid(), 0, result[0], locationId, ExposureType.ANIMAL_CONTACT.name(), result[1], result[1], result[3], (vaccinationStatus == VaccinationStatus.VACCINATED ? YesNoUnknown.YES.name() : vaccinationStatus == VaccinationStatus.UNVACCINATED ? YesNoUnknown.NO.name() : vaccinationStatus == VaccinationStatus.UNKNOWN ? YesNoUnknown.UNKNOWN.name() : null), result[5], result[6], "Automatic epi data migration based on last exposure details; this exposure may be merged with another exposure with animal contact", 0, 0, 0);
}
getDao(Exposure.class).executeRaw("UPDATE exposures SET typeOfAnimalDetails = (SELECT otherAnimalsDetails FROM epidata WHERE id = exposures.epidata_id AND exposures.typeOfAnimal = 'OTHER');");
getDao(Exposure.class).executeRaw("UPDATE exposures SET animalContactTypeDetails = (SELECT kindOfExposureDetails FROM epidata WHERE id = exposures.epidata_id AND exposures.animalContactType = 'OTHER');");
getDao(Exposure.class).executeRaw("UPDATE exposures SET waterSource = (SELECT waterSource FROM epidata WHERE id = exposures.epidata_id AND exposures.bodyOfWater = 'YES');");
getDao(Exposure.class).executeRaw("UPDATE exposures SET waterSourceDetails = (SELECT waterSourceOther FROM epidata WHERE id = exposures.epidata_id AND exposures.bodyOfWater = 'YES');");
getDao(Exposure.class).executeRaw("UPDATE exposures SET description = 'Automatic epi data migration based on selected kinds of exposure; this exposure may be merged with another exposure with animal contact' WHERE exposureType = 'ANIMAL_CONTACT' AND typeOfAnimal IS NULL;");
getDao(EpiData.class).executeRaw("UPDATE epidata SET contactWithSourceCaseKnown = 'YES' WHERE snapshot = 0 AND changeDate = 0 AND (directContactConfirmedCase = 'YES' OR directContactProbableCase = 'YES' OR closeContactProbableCase = 'YES' OR contactWithSourceRespiratoryCase = 'YES');");
getDao(EpiData.class).executeRaw("UPDATE epidata SET exposureDetailsKnown = 'YES' WHERE snapshot = 0 AND changeDate = 0 AND (exposureDetailsKnown IS NULL OR exposureDetailsKnown != 'YES') " + "AND (SELECT COUNT(id) FROM exposures WHERE exposures.epidata_id = epidata.id LIMIT 1) > 0;");
}
Aggregations