Search in sources :

Example 1 with VaccinationStatus

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]);
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) AggregateReport(de.symeda.sormas.app.backend.report.AggregateReport) Vaccine(de.symeda.sormas.api.caze.Vaccine) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) Region(de.symeda.sormas.app.backend.region.Region) StringUtils(org.apache.commons.lang3.StringUtils) CampaignDao(de.symeda.sormas.app.backend.campaign.CampaignDao) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) YesNoUnknown(de.symeda.sormas.api.utils.YesNoUnknown) VaccineManufacturer(de.symeda.sormas.api.caze.VaccineManufacturer) ClinicalCourse(de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourse) RegionDao(de.symeda.sormas.app.backend.region.RegionDao) Map(java.util.Map) BigInteger(java.math.BigInteger) AnimalContactType(de.symeda.sormas.api.exposure.AnimalContactType) TreatmentDao(de.symeda.sormas.app.backend.therapy.TreatmentDao) Vaccination(de.symeda.sormas.app.backend.vaccination.Vaccination) Log(android.util.Log) LbdsSync(de.symeda.sormas.app.backend.lbds.LbdsSync) SampleDao(de.symeda.sormas.app.backend.sample.SampleDao) WeeklyReportDao(de.symeda.sormas.app.backend.report.WeeklyReportDao) Campaign(de.symeda.sormas.app.backend.campaign.Campaign) Hospitalization(de.symeda.sormas.app.backend.hospitalization.Hospitalization) PersonDao(de.symeda.sormas.app.backend.person.PersonDao) HospitalizationDao(de.symeda.sormas.app.backend.hospitalization.HospitalizationDao) ConfigDao(de.symeda.sormas.app.backend.config.ConfigDao) Dao(com.j256.ormlite.dao.Dao) DataType(com.j256.ormlite.field.DataType) AreaDao(de.symeda.sormas.app.backend.region.AreaDao) Country(de.symeda.sormas.app.backend.region.Country) Stream(java.util.stream.Stream) DiseaseClassificationCriteria(de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteria) District(de.symeda.sormas.app.backend.region.District) Visit(de.symeda.sormas.app.backend.visit.Visit) HealthConditionsDao(de.symeda.sormas.app.backend.clinicalcourse.HealthConditionsDao) LbdsSyncDao(de.symeda.sormas.app.backend.lbds.LbdsSyncDao) SubcontinentDao(de.symeda.sormas.app.backend.region.SubcontinentDao) Location(de.symeda.sormas.app.backend.location.Location) TypeOfAnimal(de.symeda.sormas.api.exposure.TypeOfAnimal) SyncLogDao(de.symeda.sormas.app.backend.synclog.SyncLogDao) FeatureConfiguration(de.symeda.sormas.app.backend.feature.FeatureConfiguration) CountryDao(de.symeda.sormas.app.backend.region.CountryDao) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) CampaignFormMetaDao(de.symeda.sormas.app.backend.campaign.form.CampaignFormMetaDao) EpiData(de.symeda.sormas.app.backend.epidata.EpiData) ArrayList(java.util.ArrayList) WeeklyReportEntry(de.symeda.sormas.app.backend.report.WeeklyReportEntry) SQLException(java.sql.SQLException) ConnectionSource(com.j256.ormlite.support.ConnectionSource) Contact(de.symeda.sormas.app.backend.contact.Contact) Therapy(de.symeda.sormas.app.backend.therapy.Therapy) AnimalCondition(de.symeda.sormas.api.epidata.AnimalCondition) PersonContactDetailDao(de.symeda.sormas.app.backend.person.PersonContactDetailDao) Event(de.symeda.sormas.app.backend.event.Event) Symptoms(de.symeda.sormas.app.backend.symptoms.Symptoms) SormasToSormasOriginInfoDao(de.symeda.sormas.app.backend.sormastosormas.SormasToSormasOriginInfoDao) ClinicalCourseDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourseDao) PointOfEntryDao(de.symeda.sormas.app.backend.infrastructure.PointOfEntryDao) DataHelper(de.symeda.sormas.api.utils.DataHelper) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) Continent(de.symeda.sormas.app.backend.region.Continent) ActivityAsCaseDao(de.symeda.sormas.app.backend.activityascase.ActivityAsCaseDao) TextUtils(android.text.TextUtils) PersonContactDetail(de.symeda.sormas.app.backend.person.PersonContactDetail) Outbreak(de.symeda.sormas.app.backend.outbreak.Outbreak) Disease(de.symeda.sormas.api.Disease) Immunization(de.symeda.sormas.app.backend.immunization.Immunization) ClinicalVisitDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisitDao) PreviousHospitalizationDao(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalizationDao) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) SymptomsDao(de.symeda.sormas.app.backend.symptoms.SymptomsDao) HealthConditions(de.symeda.sormas.app.backend.clinicalcourse.HealthConditions) PrescriptionDao(de.symeda.sormas.app.backend.therapy.PrescriptionDao) ClinicalVisit(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit) ContactDao(de.symeda.sormas.app.backend.contact.ContactDao) FeatureConfigurationDao(de.symeda.sormas.app.backend.feature.FeatureConfigurationDao) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) ActivityAsCase(de.symeda.sormas.app.backend.activityascase.ActivityAsCase) MaternalHistory(de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistory) Array(java.lang.reflect.Array) Community(de.symeda.sormas.app.backend.region.Community) Date(java.util.Date) ExposureDao(de.symeda.sormas.app.backend.exposure.ExposureDao) AggregateReportDao(de.symeda.sormas.app.backend.report.AggregateReportDao) ExposureType(de.symeda.sormas.api.exposure.ExposureType) Exposure(de.symeda.sormas.app.backend.exposure.Exposure) Facility(de.symeda.sormas.app.backend.facility.Facility) FacilityDao(de.symeda.sormas.app.backend.facility.FacilityDao) ContinentDao(de.symeda.sormas.app.backend.region.ContinentDao) UserRoleConfig(de.symeda.sormas.app.backend.user.UserRoleConfig) WeeklyReport(de.symeda.sormas.app.backend.report.WeeklyReport) VisitDao(de.symeda.sormas.app.backend.visit.VisitDao) GenericRawResults(com.j256.ormlite.dao.GenericRawResults) ConfigProvider(de.symeda.sormas.app.backend.config.ConfigProvider) TableUtils(com.j256.ormlite.table.TableUtils) SyncLog(de.symeda.sormas.app.backend.synclog.SyncLog) Task(de.symeda.sormas.app.backend.task.Task) DiseaseClassificationCriteriaDao(de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteriaDao) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus) EventDao(de.symeda.sormas.app.backend.event.EventDao) Case(de.symeda.sormas.app.backend.caze.Case) OutbreakDao(de.symeda.sormas.app.backend.outbreak.OutbreakDao) TaskDao(de.symeda.sormas.app.backend.task.TaskDao) AdditionalTest(de.symeda.sormas.app.backend.sample.AdditionalTest) Collectors(java.util.stream.Collectors) CampaignFormMeta(de.symeda.sormas.app.backend.campaign.form.CampaignFormMeta) Objects(java.util.Objects) ImmunizationDao(de.symeda.sormas.app.backend.immunization.ImmunizationDao) List(java.util.List) DiseaseConfigurationDao(de.symeda.sormas.app.backend.disease.DiseaseConfigurationDao) OrmLiteSqliteOpenHelper(com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper) PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) LocationDao(de.symeda.sormas.app.backend.location.LocationDao) DiseaseConfiguration(de.symeda.sormas.app.backend.disease.DiseaseConfiguration) Context(android.content.Context) PointOfEntry(de.symeda.sormas.app.backend.infrastructure.PointOfEntry) PreviousHospitalization(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalization) AdditionalTestDao(de.symeda.sormas.app.backend.sample.AdditionalTestDao) VaccinationDao(de.symeda.sormas.app.backend.vaccination.VaccinationDao) HashMap(java.util.HashMap) HabitationType(de.symeda.sormas.api.exposure.HabitationType) Treatment(de.symeda.sormas.app.backend.therapy.Treatment) Function(java.util.function.Function) User(de.symeda.sormas.app.backend.user.User) WeeklyReportEntryDao(de.symeda.sormas.app.backend.report.WeeklyReportEntryDao) EventParticipantDao(de.symeda.sormas.app.backend.event.EventParticipantDao) CampaignFormData(de.symeda.sormas.app.backend.campaign.data.CampaignFormData) Area(de.symeda.sormas.app.backend.region.Area) CustomizableEnumValueDao(de.symeda.sormas.app.backend.customizableenum.CustomizableEnumValueDao) Subcontinent(de.symeda.sormas.app.backend.region.Subcontinent) Cursor(android.database.Cursor) CampaignFormDataDao(de.symeda.sormas.app.backend.campaign.data.CampaignFormDataDao) UserRoleConfigDao(de.symeda.sormas.app.backend.user.UserRoleConfigDao) PortHealthInfoDao(de.symeda.sormas.app.backend.caze.porthealthinfo.PortHealthInfoDao) Person(de.symeda.sormas.app.backend.person.Person) CustomizableEnumValue(de.symeda.sormas.app.backend.customizableenum.CustomizableEnumValue) Config(de.symeda.sormas.app.backend.config.Config) SormasToSormasOriginInfo(de.symeda.sormas.app.backend.sormastosormas.SormasToSormasOriginInfo) CommunityDao(de.symeda.sormas.app.backend.region.CommunityDao) UserDao(de.symeda.sormas.app.backend.user.UserDao) Sample(de.symeda.sormas.app.backend.sample.Sample) EpiDataDao(de.symeda.sormas.app.backend.epidata.EpiDataDao) DistrictDao(de.symeda.sormas.app.backend.region.DistrictDao) PortHealthInfo(de.symeda.sormas.app.backend.caze.porthealthinfo.PortHealthInfo) Prescription(de.symeda.sormas.app.backend.therapy.Prescription) PathogenTestDao(de.symeda.sormas.app.backend.sample.PathogenTestDao) TherapyDao(de.symeda.sormas.app.backend.therapy.TherapyDao) Comparator(java.util.Comparator) MaternalHistoryDao(de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistoryDao) Disease(de.symeda.sormas.api.Disease) ArrayList(java.util.ArrayList) Date(java.util.Date) ActivityAsCase(de.symeda.sormas.app.backend.activityascase.ActivityAsCase) Case(de.symeda.sormas.app.backend.caze.Case) BigInteger(java.math.BigInteger) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with VaccinationStatus

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;");
}
Also used : Exposure(de.symeda.sormas.app.backend.exposure.Exposure) EpiData(de.symeda.sormas.app.backend.epidata.EpiData) VaccinationStatus(de.symeda.sormas.api.caze.VaccinationStatus)

Aggregations

VaccinationStatus (de.symeda.sormas.api.caze.VaccinationStatus)2 EpiData (de.symeda.sormas.app.backend.epidata.EpiData)2 Exposure (de.symeda.sormas.app.backend.exposure.Exposure)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 OrmLiteSqliteOpenHelper (com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper)1 Dao (com.j256.ormlite.dao.Dao)1 GenericRawResults (com.j256.ormlite.dao.GenericRawResults)1 DataType (com.j256.ormlite.field.DataType)1 ConnectionSource (com.j256.ormlite.support.ConnectionSource)1 TableUtils (com.j256.ormlite.table.TableUtils)1 Disease (de.symeda.sormas.api.Disease)1 Vaccine (de.symeda.sormas.api.caze.Vaccine)1 VaccineManufacturer (de.symeda.sormas.api.caze.VaccineManufacturer)1 AnimalCondition (de.symeda.sormas.api.epidata.AnimalCondition)1 AnimalContactType (de.symeda.sormas.api.exposure.AnimalContactType)1 ExposureType (de.symeda.sormas.api.exposure.ExposureType)1