use of de.symeda.sormas.api.immunization.ImmunizationStatus in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationEditFragment method updateImmunizationStatus.
private void updateImmunizationStatus(FragmentImmunizationEditLayoutBinding contentBinding) {
if (Boolean.TRUE.equals(contentBinding.overwriteImmunizationManagementStatusCheckBox.getValue())) {
return;
}
MeansOfImmunization meansOfImmunizationValue = (MeansOfImmunization) contentBinding.immunizationMeansOfImmunization.getValue();
if (meansOfImmunizationValue == MeansOfImmunization.OTHER || meansOfImmunizationValue == MeansOfImmunization.RECOVERY) {
contentBinding.immunizationImmunizationManagementStatus.setValue(ImmunizationManagementStatus.COMPLETED);
contentBinding.overwriteImmunizationManagementStatusCheckBox.setValue(false);
contentBinding.immunizationImmunizationManagementStatus.setEnabled(false);
}
if (MeansOfImmunization.isVaccination(meansOfImmunizationValue)) {
ImmunizationStatus immunizationStatus = (ImmunizationStatus) contentBinding.immunizationImmunizationStatus.getValue();
if (immunizationStatus != ImmunizationStatus.NOT_ACQUIRED && immunizationStatus != ImmunizationStatus.EXPIRED) {
Integer numberOfDoses = null;
try {
numberOfDoses = Integer.valueOf(contentBinding.immunizationNumberOfDoses.getValue());
} catch (Exception e) {
numberOfDoses = null;
}
if (numberOfDoses != null && CollectionUtils.isNotEmpty(record.getVaccinations())) {
if (record.getVaccinations().size() >= numberOfDoses) {
contentBinding.immunizationImmunizationManagementStatus.setValue(ImmunizationManagementStatus.COMPLETED);
} else {
contentBinding.immunizationImmunizationManagementStatus.setValue(ImmunizationManagementStatus.ONGOING);
}
}
}
}
}
use of de.symeda.sormas.api.immunization.ImmunizationStatus 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.immunization.ImmunizationStatus in project SORMAS-Project by hzi-braunschweig.
the class ImmunizationService method updateImmunizationStatusBasedOnVaccinations.
public void updateImmunizationStatusBasedOnVaccinations(Immunization immunization) {
ImmunizationStatus immunizationStatus = immunization.getImmunizationStatus();
if (immunizationStatus != ImmunizationStatus.NOT_ACQUIRED && immunizationStatus != ImmunizationStatus.EXPIRED) {
final Integer numberOfDoses = immunization.getNumberOfDoses();
final int vaccinationCount = immunization.getVaccinations().size();
if (numberOfDoses != null) {
final Date startDate = immunization.getStartDate();
if ((startDate == null || System.currentTimeMillis() > startDate.getTime()) && vaccinationCount >= 1 && vaccinationCount < numberOfDoses) {
immunization.setImmunizationManagementStatus(ImmunizationManagementStatus.ONGOING);
immunization.setImmunizationStatus(ImmunizationStatus.PENDING);
} else if (vaccinationCount >= numberOfDoses) {
immunization.setImmunizationManagementStatus(ImmunizationManagementStatus.COMPLETED);
immunization.setImmunizationStatus(ImmunizationStatus.ACQUIRED);
}
}
}
}
Aggregations