Search in sources :

Example 16 with Task

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

the class TaskListFragment method onListItemClick.

@Override
public void onListItemClick(View view, int position, Object item) {
    Task t = (Task) item;
    TaskEditActivity.startActivity(getContext(), t.getUuid());
}
Also used : Task(de.symeda.sormas.app.backend.task.Task)

Example 17 with Task

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

the class TaskNewActivity method buildRootEntity.

@Override
protected Task buildRootEntity() {
    Task _task;
    if (!DataHelper.isNullOrEmpty(caseUuid)) {
        Case _case = DatabaseHelper.getCaseDao().queryUuidBasic(caseUuid);
        _task = DatabaseHelper.getTaskDao().build(_case);
    } else if (!DataHelper.isNullOrEmpty(contactUuid)) {
        Contact _contact = DatabaseHelper.getContactDao().queryUuid(contactUuid);
        _task = DatabaseHelper.getTaskDao().build(_contact);
    } else if (!DataHelper.isNullOrEmpty(eventUuid)) {
        Event _event = DatabaseHelper.getEventDao().queryUuid(eventUuid);
        _task = DatabaseHelper.getTaskDao().build(_event);
    } else {
        _task = DatabaseHelper.getTaskDao().build();
    }
    return _task;
}
Also used : Task(de.symeda.sormas.app.backend.task.Task) AsyncTask(android.os.AsyncTask) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask) Event(de.symeda.sormas.app.backend.event.Event) Case(de.symeda.sormas.app.backend.caze.Case) Contact(de.symeda.sormas.app.backend.contact.Contact)

Example 18 with Task

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

the class TaskNewActivity method saveData.

@Override
public void saveData() {
    if (saveTask != null) {
        NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
        // don't save multiple times
        return;
    }
    final Task taskToSave = getStoredRootEntity();
    TaskEditFragment fragment = (TaskEditFragment) getActiveFragment();
    fragment.setLiveValidationDisabled(false);
    try {
        FragmentValidator.validate(getContext(), fragment.getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    saveDataInner(taskToSave);
}
Also used : Task(de.symeda.sormas.app.backend.task.Task) AsyncTask(android.os.AsyncTask) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask) ValidationException(de.symeda.sormas.api.utils.ValidationException)

Example 19 with Task

use of de.symeda.sormas.app.backend.task.Task 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 20 with Task

use of de.symeda.sormas.app.backend.task.Task 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

Task (de.symeda.sormas.app.backend.task.Task)23 Case (de.symeda.sormas.app.backend.caze.Case)7 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)6 TaskDao (de.symeda.sormas.app.backend.task.TaskDao)6 User (de.symeda.sormas.app.backend.user.User)6 Contact (de.symeda.sormas.app.backend.contact.Contact)5 Event (de.symeda.sormas.app.backend.event.Event)4 Community (de.symeda.sormas.app.backend.region.Community)4 District (de.symeda.sormas.app.backend.region.District)4 AsyncTask (android.os.AsyncTask)3 UserRole (de.symeda.sormas.api.user.UserRole)3 SavingAsyncTask (de.symeda.sormas.app.core.async.SavingAsyncTask)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 TaskDto (de.symeda.sormas.api.task.TaskDto)2 ValidationException (de.symeda.sormas.api.utils.ValidationException)2 ActivityAsCase (de.symeda.sormas.app.backend.activityascase.ActivityAsCase)2 ClinicalVisit (de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit)2 DaoException (de.symeda.sormas.app.backend.common.DaoException)2