Search in sources :

Example 1 with TaskDao

use of de.symeda.sormas.app.backend.task.TaskDao in project SORMAS-Project by hzi-braunschweig.

the class CaseBackendTest method testTaskReassignmentAfterChangedCaseDistrict.

@Test
public void testTaskReassignmentAfterChangedCaseDistrict() throws DaoException {
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    Case caze = TestEntityCreator.createCase();
    caze.setRegion(caze.getResponsibleRegion());
    caze.setDistrict(caze.getResponsibleDistrict());
    caze.setCommunity(caze.getResponsibleCommunity());
    caseDao.saveAndSnapshot(caze);
    User user = ConfigProvider.getUser();
    UserRole userRole = UserRole.SURVEILLANCE_OFFICER;
    Set<UserRole> userRoles = new HashSet<>();
    userRoles.add(userRole);
    user.setUserRoles(userRoles);
    DatabaseHelper.getUserDao().saveAndSnapshot(user);
    TaskDao taskDao = DatabaseHelper.getTaskDao();
    Task task = TestEntityCreator.createCaseTask(caze, TaskStatus.PENDING, user);
    assertEquals(caze.getResponsibleRegion().getUuid(), TestHelper.REGION_UUID);
    assertEquals(caze.getResponsibleDistrict().getUuid(), TestHelper.DISTRICT_UUID);
    assertEquals(caze.getResponsibleCommunity().getUuid(), TestHelper.COMMUNITY_UUID);
    assertEquals(caze.getRegion().getUuid(), TestHelper.REGION_UUID);
    assertEquals(caze.getDistrict().getUuid(), TestHelper.DISTRICT_UUID);
    assertEquals(caze.getCommunity().getUuid(), TestHelper.COMMUNITY_UUID);
    assertEquals(caze.getHealthFacility().getUuid(), TestHelper.FACILITY_UUID);
    task = taskDao.queryUuid(task.getUuid());
    assertEquals(TestHelper.USER_UUID, task.getAssigneeUser().getUuid());
    // ResponsibleDistrict changed, but District still in user's jurisdiction
    District secondDistrict = DatabaseHelper.getDistrictDao().queryUuid(TestHelper.SECOND_DISTRICT_UUID);
    Community secondCommunity = DatabaseHelper.getCommunityDao().queryUuid(TestHelper.SECOND_COMMUNITY_UUID);
    caze.setResponsibleDistrict(secondDistrict);
    caze.setResponsibleCommunity(secondCommunity);
    caseDao.saveAndSnapshot(caze);
    task = taskDao.queryUuid(task.getUuid());
    assertEquals(TestHelper.USER_UUID, task.getAssigneeUser().getUuid());
    // Case not in user's jurisdiction anymore
    caze.setDistrict(secondDistrict);
    caze.setCommunity(null);
    caseDao.saveAndSnapshot(caze);
    task = taskDao.queryUuid(task.getUuid());
    assertEquals(TestHelper.SECOND_USER_UUID, task.getAssigneeUser().getUuid());
}
Also used : Task(de.symeda.sormas.app.backend.task.Task) User(de.symeda.sormas.app.backend.user.User) UserRole(de.symeda.sormas.api.user.UserRole) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) TaskDao(de.symeda.sormas.app.backend.task.TaskDao) District(de.symeda.sormas.app.backend.region.District) Community(de.symeda.sormas.app.backend.region.Community) Case(de.symeda.sormas.app.backend.caze.Case) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with TaskDao

use of de.symeda.sormas.app.backend.task.TaskDao in project SORMAS-Project by hzi-braunschweig.

the class TaskNotificationService method doTaskNotification.

public static void doTaskNotification(Context context) {
    if (!DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_GENERATION_GENERAL) || !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_GENERATION_CASE_SURVEILLANCE) || !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_GENERATION_CONTACT_TRACING) || !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_GENERATION_EVENT_SURVEILLANCE)) {
        Date notificationRangeStart = ConfigProvider.getLastNotificationDate();
        if (notificationRangeStart == null) {
            notificationRangeStart = new DateTime().minusDays(1).toDate();
        }
        Date notificationRangeEnd = new Date();
        TaskDao taskDao = DatabaseHelper.getTaskDao();
        List<Task> taskList = taskDao.queryMyPendingForNotification(notificationRangeStart, notificationRangeEnd);
        CaseDao caseDAO = DatabaseHelper.getCaseDao();
        ContactDao contactDAO = DatabaseHelper.getContactDao();
        EventDao eventDAO = DatabaseHelper.getEventDao();
        for (Task task : taskList) {
            Case caze = null;
            Contact contact = null;
            Event event = null;
            StringBuilder content = new StringBuilder();
            switch(task.getTaskContext()) {
                case CASE:
                    if (task.getCaze() != null && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_GENERATION_CASE_SURVEILLANCE)) {
                        caze = caseDAO.queryForId(task.getCaze().getId());
                        content.append("<b>").append(caze.toString()).append("</b><br/>");
                    }
                    break;
                case CONTACT:
                    if (task.getContact() != null && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_GENERATION_CONTACT_TRACING)) {
                        contact = contactDAO.queryForId(task.getContact().getId());
                        content.append("<b>").append(contact.toString()).append("</b><br/>");
                    }
                    break;
                case EVENT:
                    if (task.getEvent() != null && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_GENERATION_EVENT_SURVEILLANCE)) {
                        event = eventDAO.queryForId(task.getEvent().getId());
                        content.append("<b>").append(event.toString()).append("</b><br/>");
                    }
                    break;
                case GENERAL:
                    break;
                default:
                    continue;
            }
            Intent notificationIntent = new Intent(context, TaskEditActivity.class);
            notificationIntent.putExtras(TaskEditActivity.buildBundle(task.getUuid()).get());
            // Just for your information: The issue here was that the second argument of the getActivity call
            // was set to 0, which leads to previous intents to be recycled; passing the task's ID instead
            // makes sure that a new intent with the right task behind it is created
            PendingIntent pi = PendingIntent.getActivity(context, task.getId().intValue(), notificationIntent, 0);
            Resources r = context.getResources();
            if (!TextUtils.isEmpty(task.getCreatorComment())) {
                content.append(task.getCreatorComment());
            }
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, NotificationHelper.NOTIFICATION_CHANNEL_TASKS_ID).setTicker(r.getString(R.string.heading_task_notification)).setSmallIcon(R.mipmap.ic_launcher_foreground).setContentTitle(task.getTaskType().toString() + (caze != null ? " (" + caze.getDisease().toShortString() + ")" : contact != null ? " (" + contact.getDisease().toShortString() + ")" : "")).setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(content.toString()))).setContentIntent(pi).setAutoCancel(true).setContentIntent(pi);
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
            int notificationId = task.getId().intValue();
            notificationManager.notify(notificationId, notificationBuilder.build());
            // @TODO implement notification grouping
            break;
        }
        doWeeklyReportNotification(context, notificationRangeStart, notificationRangeEnd);
        ConfigProvider.setLastNotificationDate(notificationRangeEnd);
    }
}
Also used : Task(de.symeda.sormas.app.backend.task.Task) NotificationManager(android.app.NotificationManager) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Date(java.util.Date) DateTime(org.joda.time.DateTime) Case(de.symeda.sormas.app.backend.caze.Case) Contact(de.symeda.sormas.app.backend.contact.Contact) ContactDao(de.symeda.sormas.app.backend.contact.ContactDao) EventDao(de.symeda.sormas.app.backend.event.EventDao) Event(de.symeda.sormas.app.backend.event.Event) NotificationCompat(androidx.core.app.NotificationCompat) TaskDao(de.symeda.sormas.app.backend.task.TaskDao) PendingIntent(android.app.PendingIntent) Resources(android.content.res.Resources)

Example 3 with TaskDao

use of de.symeda.sormas.app.backend.task.TaskDao in project SORMAS-Project by hzi-braunschweig.

the class DatabaseHelper method getAdoDaoInner.

public <ADO extends AbstractDomainObject> AbstractAdoDao<ADO> getAdoDaoInner(Class<ADO> type) {
    if (!adoDaos.containsKey(type)) {
        // build dao
        AbstractAdoDao<ADO> dao;
        Dao<ADO, Long> innerDao;
        try {
            innerDao = super.getDao(type);
            if (type.equals(Case.class)) {
                dao = (AbstractAdoDao<ADO>) new CaseDao((Dao<Case, Long>) innerDao);
            } else if (type.equals(Immunization.class)) {
                dao = (AbstractAdoDao<ADO>) new ImmunizationDao((Dao<Immunization, Long>) innerDao);
            } else if (type.equals(Vaccination.class)) {
                dao = (AbstractAdoDao<ADO>) new VaccinationDao((Dao<Vaccination, Long>) innerDao);
            } else if (type.equals(Therapy.class)) {
                dao = (AbstractAdoDao<ADO>) new TherapyDao((Dao<Therapy, Long>) innerDao);
            } else if (type.equals(Prescription.class)) {
                dao = (AbstractAdoDao<ADO>) new PrescriptionDao((Dao<Prescription, Long>) innerDao);
            } else if (type.equals(Treatment.class)) {
                dao = (AbstractAdoDao<ADO>) new TreatmentDao((Dao<Treatment, Long>) innerDao);
            } else if (type.equals(Person.class)) {
                dao = (AbstractAdoDao<ADO>) new PersonDao((Dao<Person, Long>) innerDao);
            } else if (type.equals(PersonContactDetail.class)) {
                dao = (AbstractAdoDao<ADO>) new PersonContactDetailDao((Dao<PersonContactDetail, Long>) innerDao);
            } else if (type.equals(Location.class)) {
                dao = (AbstractAdoDao<ADO>) new LocationDao((Dao<Location, Long>) innerDao);
            } else if (type.equals(PointOfEntry.class)) {
                dao = (AbstractAdoDao<ADO>) new PointOfEntryDao((Dao<PointOfEntry, Long>) innerDao);
            } else if (type.equals(Facility.class)) {
                dao = (AbstractAdoDao<ADO>) new FacilityDao((Dao<Facility, Long>) innerDao);
            } else if (type.equals(Continent.class)) {
                dao = (AbstractAdoDao<ADO>) new ContinentDao((Dao<Continent, Long>) innerDao);
            } else if (type.equals(Subcontinent.class)) {
                dao = (AbstractAdoDao<ADO>) new SubcontinentDao((Dao<Subcontinent, Long>) innerDao);
            } else if (type.equals(Country.class)) {
                dao = (AbstractAdoDao<ADO>) new CountryDao((Dao<Country, Long>) innerDao);
            } else if (type.equals(Area.class)) {
                dao = (AbstractAdoDao<ADO>) new AreaDao((Dao<Area, Long>) innerDao);
            } else if (type.equals(Region.class)) {
                dao = (AbstractAdoDao<ADO>) new RegionDao((Dao<Region, Long>) innerDao);
            } else if (type.equals(District.class)) {
                dao = (AbstractAdoDao<ADO>) new DistrictDao((Dao<District, Long>) innerDao);
            } else if (type.equals(Community.class)) {
                dao = (AbstractAdoDao<ADO>) new CommunityDao((Dao<Community, Long>) innerDao);
            } else if (type.equals(User.class)) {
                dao = (AbstractAdoDao<ADO>) new UserDao((Dao<User, Long>) innerDao);
            } else if (type.equals(UserRoleConfig.class)) {
                dao = (AbstractAdoDao<ADO>) new UserRoleConfigDao((Dao<UserRoleConfig, Long>) innerDao);
            } else if (type.equals(DiseaseConfiguration.class)) {
                dao = (AbstractAdoDao<ADO>) new DiseaseConfigurationDao((Dao<DiseaseConfiguration, Long>) innerDao);
            } else if (type.equals(CustomizableEnumValue.class)) {
                dao = (AbstractAdoDao<ADO>) new CustomizableEnumValueDao((Dao<CustomizableEnumValue, Long>) innerDao);
            } else if (type.equals(FeatureConfiguration.class)) {
                dao = (AbstractAdoDao<ADO>) new FeatureConfigurationDao((Dao<FeatureConfiguration, Long>) innerDao);
            } else if (type.equals(Symptoms.class)) {
                dao = (AbstractAdoDao<ADO>) new SymptomsDao((Dao<Symptoms, Long>) innerDao);
            } else if (type.equals(HealthConditions.class)) {
                dao = (AbstractAdoDao<ADO>) new HealthConditionsDao((Dao<HealthConditions, Long>) innerDao);
            } else if (type.equals(ClinicalCourse.class)) {
                dao = (AbstractAdoDao<ADO>) new ClinicalCourseDao((Dao<ClinicalCourse, Long>) innerDao);
            } else if (type.equals(ClinicalVisit.class)) {
                dao = (AbstractAdoDao<ADO>) new ClinicalVisitDao((Dao<ClinicalVisit, Long>) innerDao);
            } else if (type.equals(MaternalHistory.class)) {
                dao = (AbstractAdoDao<ADO>) new MaternalHistoryDao((Dao<MaternalHistory, Long>) innerDao);
            } else if (type.equals(PortHealthInfo.class)) {
                dao = (AbstractAdoDao<ADO>) new PortHealthInfoDao((Dao<PortHealthInfo, Long>) innerDao);
            } else if (type.equals(Task.class)) {
                dao = (AbstractAdoDao<ADO>) new TaskDao((Dao<Task, Long>) innerDao);
            } else if (type.equals(Contact.class)) {
                dao = (AbstractAdoDao<ADO>) new ContactDao((Dao<Contact, Long>) innerDao);
            } else if (type.equals(Visit.class)) {
                dao = (AbstractAdoDao<ADO>) new VisitDao((Dao<Visit, Long>) innerDao);
            } else if (type.equals(Event.class)) {
                dao = (AbstractAdoDao<ADO>) new EventDao((Dao<Event, Long>) innerDao);
            } else if (type.equals(EventParticipant.class)) {
                dao = (AbstractAdoDao<ADO>) new EventParticipantDao((Dao<EventParticipant, Long>) innerDao);
            } else if (type.equals(Sample.class)) {
                dao = (AbstractAdoDao<ADO>) new SampleDao((Dao<Sample, Long>) innerDao);
            } else if (type.equals(PathogenTest.class)) {
                dao = (AbstractAdoDao<ADO>) new PathogenTestDao((Dao<PathogenTest, Long>) innerDao);
            } else if (type.equals(AdditionalTest.class)) {
                dao = (AbstractAdoDao<ADO>) new AdditionalTestDao((Dao<AdditionalTest, Long>) innerDao);
            } else if (type.equals(Hospitalization.class)) {
                dao = (AbstractAdoDao<ADO>) new HospitalizationDao((Dao<Hospitalization, Long>) innerDao);
            } else if (type.equals(PreviousHospitalization.class)) {
                dao = (AbstractAdoDao<ADO>) new PreviousHospitalizationDao((Dao<PreviousHospitalization, Long>) innerDao);
            } else if (type.equals(EpiData.class)) {
                dao = (AbstractAdoDao<ADO>) new EpiDataDao((Dao<EpiData, Long>) innerDao);
            } else if (type.equals(Exposure.class)) {
                dao = (AbstractAdoDao<ADO>) new ExposureDao((Dao<Exposure, Long>) innerDao);
            } else if (type.equals(ActivityAsCase.class)) {
                dao = (AbstractAdoDao<ADO>) new ActivityAsCaseDao((Dao<ActivityAsCase, Long>) innerDao);
            } else if (type.equals(WeeklyReport.class)) {
                dao = (AbstractAdoDao<ADO>) new WeeklyReportDao((Dao<WeeklyReport, Long>) innerDao);
            } else if (type.equals(WeeklyReportEntry.class)) {
                dao = (AbstractAdoDao<ADO>) new WeeklyReportEntryDao((Dao<WeeklyReportEntry, Long>) innerDao);
            } else if (type.equals(AggregateReport.class)) {
                dao = (AbstractAdoDao<ADO>) new AggregateReportDao((Dao<AggregateReport, Long>) innerDao);
            } else if (type.equals(Outbreak.class)) {
                dao = (AbstractAdoDao<ADO>) new OutbreakDao((Dao<Outbreak, Long>) innerDao);
            } else if (type.equals(DiseaseClassificationCriteria.class)) {
                dao = (AbstractAdoDao<ADO>) new DiseaseClassificationCriteriaDao((Dao<DiseaseClassificationCriteria, Long>) innerDao);
            } else if (type.equals(SormasToSormasOriginInfo.class)) {
                dao = (AbstractAdoDao<ADO>) new SormasToSormasOriginInfoDao((Dao<SormasToSormasOriginInfo, Long>) innerDao);
            } else if (type.equals(Campaign.class)) {
                dao = (AbstractAdoDao<ADO>) new CampaignDao((Dao<Campaign, Long>) innerDao);
            } else if (type.equals(CampaignFormMeta.class)) {
                dao = (AbstractAdoDao<ADO>) new CampaignFormMetaDao((Dao<CampaignFormMeta, Long>) innerDao);
            } else if (type.equals(CampaignFormData.class)) {
                dao = (AbstractAdoDao<ADO>) new CampaignFormDataDao((Dao<CampaignFormData, Long>) innerDao);
            } else {
                throw new UnsupportedOperationException(type.toString());
            }
            adoDaos.put(type, dao);
        } catch (SQLException e) {
            Log.e(DatabaseHelper.class.getName(), "Can't build dao", e);
            throw new RuntimeException(e);
        }
    }
    return (AbstractAdoDao<ADO>) adoDaos.get(type);
}
Also used : Prescription(de.symeda.sormas.app.backend.therapy.Prescription) PersonContactDetailDao(de.symeda.sormas.app.backend.person.PersonContactDetailDao) DistrictDao(de.symeda.sormas.app.backend.region.DistrictDao) ClinicalCourse(de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourse) ImmunizationDao(de.symeda.sormas.app.backend.immunization.ImmunizationDao) CampaignFormMeta(de.symeda.sormas.app.backend.campaign.form.CampaignFormMeta) CountryDao(de.symeda.sormas.app.backend.region.CountryDao) EventParticipantDao(de.symeda.sormas.app.backend.event.EventParticipantDao) SormasToSormasOriginInfo(de.symeda.sormas.app.backend.sormastosormas.SormasToSormasOriginInfo) ActivityAsCaseDao(de.symeda.sormas.app.backend.activityascase.ActivityAsCaseDao) PointOfEntry(de.symeda.sormas.app.backend.infrastructure.PointOfEntry) AreaDao(de.symeda.sormas.app.backend.region.AreaDao) PortHealthInfoDao(de.symeda.sormas.app.backend.caze.porthealthinfo.PortHealthInfoDao) LocationDao(de.symeda.sormas.app.backend.location.LocationDao) ClinicalVisitDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisitDao) VisitDao(de.symeda.sormas.app.backend.visit.VisitDao) Exposure(de.symeda.sormas.app.backend.exposure.Exposure) PointOfEntryDao(de.symeda.sormas.app.backend.infrastructure.PointOfEntryDao) WeeklyReportEntry(de.symeda.sormas.app.backend.report.WeeklyReportEntry) PreviousHospitalization(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalization) Country(de.symeda.sormas.app.backend.region.Country) TaskDao(de.symeda.sormas.app.backend.task.TaskDao) Person(de.symeda.sormas.app.backend.person.Person) RegionDao(de.symeda.sormas.app.backend.region.RegionDao) ContinentDao(de.symeda.sormas.app.backend.region.ContinentDao) AdditionalTestDao(de.symeda.sormas.app.backend.sample.AdditionalTestDao) AdditionalTest(de.symeda.sormas.app.backend.sample.AdditionalTest) ActivityAsCase(de.symeda.sormas.app.backend.activityascase.ActivityAsCase) Case(de.symeda.sormas.app.backend.caze.Case) MaternalHistoryDao(de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistoryDao) ContactDao(de.symeda.sormas.app.backend.contact.ContactDao) HospitalizationDao(de.symeda.sormas.app.backend.hospitalization.HospitalizationDao) PreviousHospitalizationDao(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalizationDao) CustomizableEnumValueDao(de.symeda.sormas.app.backend.customizableenum.CustomizableEnumValueDao) ActivityAsCaseDao(de.symeda.sormas.app.backend.activityascase.ActivityAsCaseDao) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) Hospitalization(de.symeda.sormas.app.backend.hospitalization.Hospitalization) PreviousHospitalization(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalization) DiseaseConfiguration(de.symeda.sormas.app.backend.disease.DiseaseConfiguration) PortHealthInfo(de.symeda.sormas.app.backend.caze.porthealthinfo.PortHealthInfo) DiseaseClassificationCriteria(de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteria) PathogenTestDao(de.symeda.sormas.app.backend.sample.PathogenTestDao) CampaignDao(de.symeda.sormas.app.backend.campaign.CampaignDao) RegionDao(de.symeda.sormas.app.backend.region.RegionDao) TreatmentDao(de.symeda.sormas.app.backend.therapy.TreatmentDao) SampleDao(de.symeda.sormas.app.backend.sample.SampleDao) WeeklyReportDao(de.symeda.sormas.app.backend.report.WeeklyReportDao) 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) AreaDao(de.symeda.sormas.app.backend.region.AreaDao) HealthConditionsDao(de.symeda.sormas.app.backend.clinicalcourse.HealthConditionsDao) LbdsSyncDao(de.symeda.sormas.app.backend.lbds.LbdsSyncDao) SubcontinentDao(de.symeda.sormas.app.backend.region.SubcontinentDao) SyncLogDao(de.symeda.sormas.app.backend.synclog.SyncLogDao) CountryDao(de.symeda.sormas.app.backend.region.CountryDao) CampaignFormMetaDao(de.symeda.sormas.app.backend.campaign.form.CampaignFormMetaDao) PersonContactDetailDao(de.symeda.sormas.app.backend.person.PersonContactDetailDao) SormasToSormasOriginInfoDao(de.symeda.sormas.app.backend.sormastosormas.SormasToSormasOriginInfoDao) ClinicalCourseDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourseDao) PointOfEntryDao(de.symeda.sormas.app.backend.infrastructure.PointOfEntryDao) ActivityAsCaseDao(de.symeda.sormas.app.backend.activityascase.ActivityAsCaseDao) ClinicalVisitDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisitDao) PreviousHospitalizationDao(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalizationDao) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) SymptomsDao(de.symeda.sormas.app.backend.symptoms.SymptomsDao) PrescriptionDao(de.symeda.sormas.app.backend.therapy.PrescriptionDao) ContactDao(de.symeda.sormas.app.backend.contact.ContactDao) FeatureConfigurationDao(de.symeda.sormas.app.backend.feature.FeatureConfigurationDao) ExposureDao(de.symeda.sormas.app.backend.exposure.ExposureDao) AggregateReportDao(de.symeda.sormas.app.backend.report.AggregateReportDao) FacilityDao(de.symeda.sormas.app.backend.facility.FacilityDao) ContinentDao(de.symeda.sormas.app.backend.region.ContinentDao) VisitDao(de.symeda.sormas.app.backend.visit.VisitDao) DiseaseClassificationCriteriaDao(de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteriaDao) EventDao(de.symeda.sormas.app.backend.event.EventDao) OutbreakDao(de.symeda.sormas.app.backend.outbreak.OutbreakDao) TaskDao(de.symeda.sormas.app.backend.task.TaskDao) ImmunizationDao(de.symeda.sormas.app.backend.immunization.ImmunizationDao) DiseaseConfigurationDao(de.symeda.sormas.app.backend.disease.DiseaseConfigurationDao) LocationDao(de.symeda.sormas.app.backend.location.LocationDao) AdditionalTestDao(de.symeda.sormas.app.backend.sample.AdditionalTestDao) VaccinationDao(de.symeda.sormas.app.backend.vaccination.VaccinationDao) WeeklyReportEntryDao(de.symeda.sormas.app.backend.report.WeeklyReportEntryDao) EventParticipantDao(de.symeda.sormas.app.backend.event.EventParticipantDao) CustomizableEnumValueDao(de.symeda.sormas.app.backend.customizableenum.CustomizableEnumValueDao) 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) CommunityDao(de.symeda.sormas.app.backend.region.CommunityDao) UserDao(de.symeda.sormas.app.backend.user.UserDao) EpiDataDao(de.symeda.sormas.app.backend.epidata.EpiDataDao) DistrictDao(de.symeda.sormas.app.backend.region.DistrictDao) PathogenTestDao(de.symeda.sormas.app.backend.sample.PathogenTestDao) TherapyDao(de.symeda.sormas.app.backend.therapy.TherapyDao) MaternalHistoryDao(de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistoryDao) PersonContactDetail(de.symeda.sormas.app.backend.person.PersonContactDetail) Event(de.symeda.sormas.app.backend.event.Event) PreviousHospitalizationDao(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalizationDao) Facility(de.symeda.sormas.app.backend.facility.Facility) WeeklyReportEntryDao(de.symeda.sormas.app.backend.report.WeeklyReportEntryDao) OutbreakDao(de.symeda.sormas.app.backend.outbreak.OutbreakDao) Therapy(de.symeda.sormas.app.backend.therapy.Therapy) Task(de.symeda.sormas.app.backend.task.Task) SormasToSormasOriginInfoDao(de.symeda.sormas.app.backend.sormastosormas.SormasToSormasOriginInfoDao) WeeklyReportDao(de.symeda.sormas.app.backend.report.WeeklyReportDao) PersonDao(de.symeda.sormas.app.backend.person.PersonDao) AggregateReportDao(de.symeda.sormas.app.backend.report.AggregateReportDao) CampaignFormMetaDao(de.symeda.sormas.app.backend.campaign.form.CampaignFormMetaDao) WeeklyReport(de.symeda.sormas.app.backend.report.WeeklyReport) SampleDao(de.symeda.sormas.app.backend.sample.SampleDao) MaternalHistory(de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistory) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) Immunization(de.symeda.sormas.app.backend.immunization.Immunization) TherapyDao(de.symeda.sormas.app.backend.therapy.TherapyDao) SubcontinentDao(de.symeda.sormas.app.backend.region.SubcontinentDao) PrescriptionDao(de.symeda.sormas.app.backend.therapy.PrescriptionDao) CommunityDao(de.symeda.sormas.app.backend.region.CommunityDao) ClinicalCourseDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourseDao) FeatureConfiguration(de.symeda.sormas.app.backend.feature.FeatureConfiguration) TreatmentDao(de.symeda.sormas.app.backend.therapy.TreatmentDao) Area(de.symeda.sormas.app.backend.region.Area) Campaign(de.symeda.sormas.app.backend.campaign.Campaign) DiseaseConfigurationDao(de.symeda.sormas.app.backend.disease.DiseaseConfigurationDao) Region(de.symeda.sormas.app.backend.region.Region) AggregateReport(de.symeda.sormas.app.backend.report.AggregateReport) Subcontinent(de.symeda.sormas.app.backend.region.Subcontinent) UserRoleConfig(de.symeda.sormas.app.backend.user.UserRoleConfig) District(de.symeda.sormas.app.backend.region.District) Symptoms(de.symeda.sormas.app.backend.symptoms.Symptoms) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) DiseaseClassificationCriteriaDao(de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteriaDao) User(de.symeda.sormas.app.backend.user.User) SQLException(java.sql.SQLException) Vaccination(de.symeda.sormas.app.backend.vaccination.Vaccination) Visit(de.symeda.sormas.app.backend.visit.Visit) ClinicalVisit(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit) ExposureDao(de.symeda.sormas.app.backend.exposure.ExposureDao) ClinicalVisitDao(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisitDao) Outbreak(de.symeda.sormas.app.backend.outbreak.Outbreak) UserDao(de.symeda.sormas.app.backend.user.UserDao) EventDao(de.symeda.sormas.app.backend.event.EventDao) FacilityDao(de.symeda.sormas.app.backend.facility.FacilityDao) UserRoleConfigDao(de.symeda.sormas.app.backend.user.UserRoleConfigDao) EpiData(de.symeda.sormas.app.backend.epidata.EpiData) SymptomsDao(de.symeda.sormas.app.backend.symptoms.SymptomsDao) VaccinationDao(de.symeda.sormas.app.backend.vaccination.VaccinationDao) CampaignDao(de.symeda.sormas.app.backend.campaign.CampaignDao) FeatureConfigurationDao(de.symeda.sormas.app.backend.feature.FeatureConfigurationDao) Sample(de.symeda.sormas.app.backend.sample.Sample) ClinicalVisit(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) CampaignFormData(de.symeda.sormas.app.backend.campaign.data.CampaignFormData) Contact(de.symeda.sormas.app.backend.contact.Contact) HealthConditions(de.symeda.sormas.app.backend.clinicalcourse.HealthConditions) Continent(de.symeda.sormas.app.backend.region.Continent) Treatment(de.symeda.sormas.app.backend.therapy.Treatment) CampaignFormDataDao(de.symeda.sormas.app.backend.campaign.data.CampaignFormDataDao) CustomizableEnumValue(de.symeda.sormas.app.backend.customizableenum.CustomizableEnumValue) HealthConditionsDao(de.symeda.sormas.app.backend.clinicalcourse.HealthConditionsDao) ActivityAsCase(de.symeda.sormas.app.backend.activityascase.ActivityAsCase) Community(de.symeda.sormas.app.backend.region.Community) Location(de.symeda.sormas.app.backend.location.Location) EpiDataDao(de.symeda.sormas.app.backend.epidata.EpiDataDao)

Example 4 with TaskDao

use of de.symeda.sormas.app.backend.task.TaskDao in project SORMAS-Project by hzi-braunschweig.

the class CaseBackendTest method shouldUpdateCaseAndAssociatedEntitiesOnMove.

@Test
public void shouldUpdateCaseAndAssociatedEntitiesOnMove() throws DaoException {
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    Case caze = TestEntityCreator.createCase();
    User user = DatabaseHelper.getUserDao().queryUuid(TestHelper.USER_UUID);
    TaskDao taskDao = DatabaseHelper.getTaskDao();
    Task pendingTask = TestEntityCreator.createCaseTask(caze, TaskStatus.PENDING, user);
    Task doneTask = TestEntityCreator.createCaseTask(caze, TaskStatus.DONE, user);
    Case existingCase = caseDao.queryUuidWithEmbedded(caze.getUuid());
    District secondDistrict = DatabaseHelper.getDistrictDao().queryUuid(TestHelper.SECOND_DISTRICT_UUID);
    caze.setResponsibleDistrict(secondDistrict);
    Community secondCommunity = DatabaseHelper.getCommunityDao().queryUuid(TestHelper.SECOND_COMMUNITY_UUID);
    caze.setResponsibleCommunity(secondCommunity);
    caze.setHealthFacility(DatabaseHelper.getFacilityDao().queryUuid(TestHelper.SECOND_FACILITY_UUID));
    caseDao.createPreviousHospitalizationAndUpdateHospitalization(caze, existingCase);
    caseDao.saveAndSnapshot(caze);
    caze = caseDao.queryUuidWithEmbedded(caze.getUuid());
    pendingTask = taskDao.queryUuid(pendingTask.getUuid());
    doneTask = taskDao.queryUuid(doneTask.getUuid());
    // Case should have the new region, district, community and facility set
    assertEquals(caze.getResponsibleRegion().getUuid(), TestHelper.REGION_UUID);
    assertEquals(caze.getResponsibleDistrict().getUuid(), TestHelper.SECOND_DISTRICT_UUID);
    assertEquals(caze.getResponsibleCommunity().getUuid(), TestHelper.SECOND_COMMUNITY_UUID);
    assertEquals(caze.getHealthFacility().getUuid(), TestHelper.SECOND_FACILITY_UUID);
    // The case officer should have changed
    assertEquals(caze.getSurveillanceOfficer().getUuid(), TestHelper.SECOND_USER_UUID);
    // Pending task should have been reassigned to the second user, done task should still be assigned to the first one
    assertEquals(pendingTask.getAssigneeUser().getUuid(), TestHelper.SECOND_USER_UUID);
    assertEquals(doneTask.getAssigneeUser().getUuid(), TestHelper.USER_UUID);
    // A previous hospitalization with the former facility should have been created
    List<PreviousHospitalization> previousHospitalizations = caze.getHospitalization().getPreviousHospitalizations();
    assertEquals(1, previousHospitalizations.size());
}
Also used : Task(de.symeda.sormas.app.backend.task.Task) User(de.symeda.sormas.app.backend.user.User) PreviousHospitalization(de.symeda.sormas.app.backend.hospitalization.PreviousHospitalization) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) TaskDao(de.symeda.sormas.app.backend.task.TaskDao) District(de.symeda.sormas.app.backend.region.District) Community(de.symeda.sormas.app.backend.region.Community) Case(de.symeda.sormas.app.backend.caze.Case) Test(org.junit.Test)

Example 5 with TaskDao

use of de.symeda.sormas.app.backend.task.TaskDao in project SORMAS-Project by hzi-braunschweig.

the class CaseBackendTest method testTaskReassignmentAfterChangedCaseCommunity.

@Test
public void testTaskReassignmentAfterChangedCaseCommunity() throws DaoException {
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    Case caze = TestEntityCreator.createCase();
    caze.setRegion(caze.getResponsibleRegion());
    caze.setDistrict(caze.getResponsibleDistrict());
    caze.setCommunity(caze.getResponsibleCommunity());
    caseDao.saveAndSnapshot(caze);
    User user = ConfigProvider.getUser();
    user.setCommunity(caze.getCommunity());
    UserRole userRole = UserRole.COMMUNITY_OFFICER;
    Set<UserRole> userRoles = new HashSet<>();
    userRoles.add(userRole);
    user.setUserRoles(userRoles);
    DatabaseHelper.getUserDao().saveAndSnapshot(user);
    TaskDao taskDao = DatabaseHelper.getTaskDao();
    Task task = TestEntityCreator.createCaseTask(caze, TaskStatus.PENDING, user);
    caze = caseDao.queryUuidBasic(caze.getUuid());
    assertEquals(TestHelper.USER_UUID, caze.getSurveillanceOfficer().getUuid());
    assertEquals(caze.getResponsibleRegion().getUuid(), TestHelper.REGION_UUID);
    assertEquals(caze.getResponsibleDistrict().getUuid(), TestHelper.DISTRICT_UUID);
    assertEquals(caze.getResponsibleCommunity().getUuid(), TestHelper.COMMUNITY_UUID);
    assertEquals(caze.getRegion().getUuid(), TestHelper.REGION_UUID);
    assertEquals(caze.getDistrict().getUuid(), TestHelper.DISTRICT_UUID);
    assertEquals(caze.getCommunity().getUuid(), TestHelper.COMMUNITY_UUID);
    assertEquals(caze.getHealthFacility().getUuid(), TestHelper.FACILITY_UUID);
    task = taskDao.queryUuid(task.getUuid());
    assertEquals(TestHelper.USER_UUID, task.getAssigneeUser().getUuid());
    // ResponsibleDistrict and ResponsibleCommunity changed,
    // but District and Community still in user's jurisdiction
    District secondDistrict = DatabaseHelper.getDistrictDao().queryUuid(TestHelper.SECOND_DISTRICT_UUID);
    Community secondCommunity = DatabaseHelper.getCommunityDao().queryUuid(TestHelper.SECOND_COMMUNITY_UUID);
    caze.setResponsibleDistrict(secondDistrict);
    caze.setResponsibleCommunity(secondCommunity);
    caze.setDistrict(secondDistrict);
    caseDao.saveAndSnapshot(caze);
    task = taskDao.queryUuid(task.getUuid());
    assertEquals(TestHelper.USER_UUID, task.getAssigneeUser().getUuid());
    caze = caseDao.queryUuidBasic(caze.getUuid());
    assertEquals(TestHelper.SECOND_USER_UUID, caze.getSurveillanceOfficer().getUuid());
    // Case not in user's jurisdiction anymore
    caze.setCommunity(null);
    caseDao.saveAndSnapshot(caze);
    task = taskDao.queryUuid(task.getUuid());
    assertEquals(TestHelper.SECOND_USER_UUID, task.getAssigneeUser().getUuid());
}
Also used : Task(de.symeda.sormas.app.backend.task.Task) User(de.symeda.sormas.app.backend.user.User) UserRole(de.symeda.sormas.api.user.UserRole) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) TaskDao(de.symeda.sormas.app.backend.task.TaskDao) District(de.symeda.sormas.app.backend.region.District) Community(de.symeda.sormas.app.backend.region.Community) Case(de.symeda.sormas.app.backend.caze.Case) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Case (de.symeda.sormas.app.backend.caze.Case)6 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)6 Task (de.symeda.sormas.app.backend.task.Task)6 TaskDao (de.symeda.sormas.app.backend.task.TaskDao)6 User (de.symeda.sormas.app.backend.user.User)5 Community (de.symeda.sormas.app.backend.region.Community)4 District (de.symeda.sormas.app.backend.region.District)4 Test (org.junit.Test)4 UserRole (de.symeda.sormas.api.user.UserRole)3 HashSet (java.util.HashSet)3 Contact (de.symeda.sormas.app.backend.contact.Contact)2 ContactDao (de.symeda.sormas.app.backend.contact.ContactDao)2 PreviousHospitalization (de.symeda.sormas.app.backend.hospitalization.PreviousHospitalization)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 NotificationCompat (androidx.core.app.NotificationCompat)1 Dao (com.j256.ormlite.dao.Dao)1 MeansOfImmunization (de.symeda.sormas.api.immunization.MeansOfImmunization)1