use of de.symeda.sormas.api.caze.Vaccine in project SORMAS-Project by hzi-braunschweig.
the class DatabaseHelper method insertVaccination.
private void insertVaccination(Object[] caseInfo, Object vaccinationDate) throws SQLException {
Vaccine vaccineName = caseInfo[13] != null ? (caseInfo[13].equals("ASTRA_ZENECA_COMIRNATY") ? Vaccine.COMIRNATY : (caseInfo[13].equals("ASTRA_ZENECA_MRNA_1273")) ? Vaccine.MRNA_1273 : Vaccine.valueOf((String) caseInfo[13])) : (caseInfo[15] != null ? Vaccine.OTHER : null);
String otherVaccineName = vaccineName == Vaccine.OTHER && caseInfo[15] == null ? (String) caseInfo[14] : (String) caseInfo[15];
VaccineManufacturer vaccineManufacturer = "ASTRA_ZENECA_COMIRNATY".equals(caseInfo[13]) ? VaccineManufacturer.BIONTECH_PFIZER : ("ASTRA_ZENECA_MRNA_1273".equals(caseInfo[13])) ? VaccineManufacturer.MODERNA : (caseInfo[16] != null ? VaccineManufacturer.valueOf((String) caseInfo[16]) : null);
insertVaccination(caseInfo, vaccineName, otherVaccineName, vaccineManufacturer, vaccinationDate);
}
use of de.symeda.sormas.api.caze.Vaccine in project SORMAS-Project by hzi-braunschweig.
the class VaccinationEditForm method addFields.
@Override
protected void addFields() {
addField(VaccinationDto.REPORT_DATE).setRequired(true);
addField(VaccinationDto.REPORTING_USER).setReadOnly(true);
addField(VaccinationDto.VACCINATION_DATE);
Field vaccineName = addField(VaccinationDto.VACCINE_NAME);
addField(VaccinationDto.OTHER_VACCINE_NAME);
Field vaccineManufacturer = addField(VaccinationDto.VACCINE_MANUFACTURER);
addField(VaccinationDto.OTHER_VACCINE_MANUFACTURER);
vaccineName.addValueChangeListener(e -> {
Vaccine vaccine = (Vaccine) e.getProperty().getValue();
if (vaccine != null) {
vaccineManufacturer.setValue(vaccine.getManufacturer());
}
});
addField(VaccinationDto.VACCINE_TYPE);
addField(VaccinationDto.VACCINATION_INFO_SOURCE);
addField(VaccinationDto.VACCINE_DOSE);
addField(VaccinationDto.VACCINE_INN);
addField(VaccinationDto.VACCINE_UNII_CODE);
addField(VaccinationDto.VACCINE_BATCH_NUMBER);
addField(VaccinationDto.VACCINE_ATC_CODE);
FieldHelper.setVisibleWhen(getFieldGroup(), VaccinationDto.OTHER_VACCINE_NAME, VaccinationDto.VACCINE_NAME, Collections.singletonList(Vaccine.OTHER), true);
FieldHelper.setVisibleWhen(getFieldGroup(), VaccinationDto.OTHER_VACCINE_MANUFACTURER, VaccinationDto.VACCINE_MANUFACTURER, Collections.singletonList(VaccineManufacturer.OTHER), true);
if (!FacadeProvider.getFeatureConfigurationFacade().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
addField(VaccinationDto.PREGNANT);
addField(VaccinationDto.TRIMESTER);
addField(VaccinationDto.HEALTH_CONDITIONS, HealthConditionsForm.class).setCaption(null);
FieldHelper.setVisibleWhen(getFieldGroup(), VaccinationDto.TRIMESTER, VaccinationDto.PREGNANT, Collections.singletonList(YesNoUnknown.YES), true);
}
}
use of de.symeda.sormas.api.caze.Vaccine in project SORMAS-Project by hzi-braunschweig.
the class VaccinationEditFragment method onLayoutBinding.
@Override
public void onLayoutBinding(FragmentVaccinationEditLayoutBinding contentBinding) {
contentBinding.setData(record);
contentBinding.setTrimesterClass(Trimester.class);
if (ConfigProvider.hasUserRight(UserRight.IMMUNIZATION_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
contentBinding.vaccinationPregnant.setVisibility(View.VISIBLE);
} else {
contentBinding.vaccinationPregnant.setVisibility(View.GONE);
}
contentBinding.vaccinationVaccineName.addValueChangedListener(new ValueChangeListener() {
private Vaccine currentVaccine = record.getVaccineName();
@Override
public void onChange(ControlPropertyField e) {
Vaccine vaccine = (Vaccine) e.getValue();
if (currentVaccine != vaccine) {
contentBinding.vaccinationVaccineManufacturer.setValue(vaccine != null ? vaccine.getManufacturer() : null);
currentVaccine = vaccine;
}
}
});
}
use of de.symeda.sormas.api.caze.Vaccine in project SORMAS-Project by hzi-braunschweig.
the class DatabaseHelper method insertFirstVaccination.
private void insertFirstVaccination(Object[] caseInfo, Object vaccinationDate) throws SQLException {
Vaccine vaccineName = caseInfo[13] != null ? (caseInfo[13].equals("ASTRA_ZENECA_COMIRNATY") || caseInfo[13].equals("ASTRA_ZENECA_MRNA_1273")) ? Vaccine.OXFORD_ASTRA_ZENECA : Vaccine.valueOf((String) caseInfo[13]) : (caseInfo[15] != null ? Vaccine.OTHER : null);
String otherVaccineName = vaccineName == Vaccine.OTHER && caseInfo[15] == null ? (String) caseInfo[14] : (String) caseInfo[15];
VaccineManufacturer vaccineManufacturer = ("ASTRA_ZENECA_COMIRNATY".equals(caseInfo[13]) || "ASTRA_ZENECA_MRNA_1273".equals(caseInfo[13])) ? VaccineManufacturer.ASTRA_ZENECA : (caseInfo[16] != null ? VaccineManufacturer.valueOf((String) caseInfo[16]) : null);
insertVaccination(caseInfo, vaccineName, otherVaccineName, vaccineManufacturer, vaccinationDate);
}
use of de.symeda.sormas.api.caze.Vaccine 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]);
}
}
}
}
Aggregations