Search in sources :

Example 1 with CaseDao

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

the class AbstractAdoDaoTest method testQueryForNew.

@Test
public void testQueryForNew() throws DaoException {
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    // Case with change date 0 should be included
    Case caseChangeDate0 = TestEntityCreator.createCase();
    List<Case> newCases = caseDao.queryForNew();
    assertEquals(1, newCases.size());
    // Case with newer change date should not be included
    Case caseNewChangeDate = TestEntityCreator.createCase();
    caseNewChangeDate.setChangeDate(new Date());
    caseDao.saveAndSnapshot(caseNewChangeDate);
    newCases = caseDao.queryForNew();
    assertEquals(1, newCases.size());
    // Additional tests for other entities
    Contact contact = TestEntityCreator.createContact(caseChangeDate0);
    Visit visit = TestEntityCreator.createVisit(contact);
    Sample sample = TestEntityCreator.createSample(caseChangeDate0);
    Event event = TestEntityCreator.createEvent();
    EventParticipant eventParticipant = TestEntityCreator.createEventParticipant(event);
    assertEquals(1, DatabaseHelper.getContactDao().queryForNew().size());
    assertEquals(1, DatabaseHelper.getVisitDao().queryForNew().size());
    assertEquals(1, DatabaseHelper.getSampleDao().queryForNew().size());
    assertEquals(1, DatabaseHelper.getEventDao().queryForNew().size());
    assertEquals(1, DatabaseHelper.getEventParticipantDao().queryForNew().size());
}
Also used : Visit(de.symeda.sormas.app.backend.visit.Visit) Sample(de.symeda.sormas.app.backend.sample.Sample) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) Event(de.symeda.sormas.app.backend.event.Event) Date(java.util.Date) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) Case(de.symeda.sormas.app.backend.caze.Case) TestCase(junit.framework.TestCase) Contact(de.symeda.sormas.app.backend.contact.Contact) Test(org.junit.Test)

Example 2 with CaseDao

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

the class AbstractAdoDaoTest method testQueryForModified.

@Test
public void testQueryForModified() throws DaoException {
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    // Modified cases with change date 0 should be included
    Case caseChangeDate0 = TestEntityCreator.createCase();
    // Modification is necessary because TestEntityCreator automatically accepts the case
    caseChangeDate0.setAdditionalDetails("...");
    caseDao.saveAndSnapshot(caseChangeDate0);
    List<Case> newCases = caseDao.queryForModified();
    assertEquals(1, newCases.size());
    // Modified cases with newer change date should also be included
    Case caseNewChangeDate = TestEntityCreator.createCase();
    caseNewChangeDate.setChangeDate(new Date());
    caseDao.saveAndSnapshot(caseNewChangeDate);
    newCases = caseDao.queryForModified();
    assertEquals(2, newCases.size());
}
Also used : CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) Date(java.util.Date) Case(de.symeda.sormas.app.backend.caze.Case) TestCase(junit.framework.TestCase) Test(org.junit.Test)

Example 3 with CaseDao

use of de.symeda.sormas.app.backend.caze.CaseDao 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 4 with CaseDao

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

the class CaseBackendTest method shouldeMergeCollectionAsExpected.

@Test
public void shouldeMergeCollectionAsExpected() throws DaoException {
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    CaseDtoHelper caseDtoHelper = new CaseDtoHelper();
    // create existing data for app
    Case caze = TestEntityCreator.createCase();
    TestEntityCreator.addPreviousHospitalization(caze);
    caseDao.saveAndSnapshot(caze);
    caseDao.accept(caze);
    caze = caseDao.queryForIdWithEmbedded(caze.getId());
    // add previous hospitalization on "server-side"
    CaseDataDto serverCaseDto = caseDtoHelper.adoToDto(caze);
    serverCaseDto.getHospitalization().getPreviousHospitalizations().get(0).setDescription("Server-side change");
    PreviousHospitalizationDto previousHospitalizationDto = new PreviousHospitalizationDto();
    previousHospitalizationDto.setUuid(DataHelper.createUuid());
    // now
    previousHospitalizationDto.setCreationDate(new Date());
    previousHospitalizationDto.setChangeDate(new Date());
    serverCaseDto.getHospitalization().getPreviousHospitalizations().add(previousHospitalizationDto);
    // add previous hospitalization on app-side
    caze.getHospitalization().getPreviousHospitalizations().get(0).setDescription("App-side change");
    TestEntityCreator.addPreviousHospitalization(caze);
    caseDao.saveAndSnapshot(caze);
    // merge server case
    Case serverCase = caseDtoHelper.fillOrCreateFromDto(null, serverCaseDto);
    DatabaseHelper.getCaseDao().mergeOrCreate(serverCase);
    Case mergedCase = DatabaseHelper.getCaseDao().queryUuidWithEmbedded(serverCase.getUuid());
    assertEquals(3, mergedCase.getHospitalization().getPreviousHospitalizations().size());
    caseDao.accept(mergedCase);
    mergedCase = DatabaseHelper.getCaseDao().queryUuidWithEmbedded(mergedCase.getUuid());
    assertFalse(mergedCase.isModifiedOrChildModified());
}
Also used : CaseDtoHelper(de.symeda.sormas.app.backend.caze.CaseDtoHelper) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) PreviousHospitalizationDto(de.symeda.sormas.api.hospitalization.PreviousHospitalizationDto) Date(java.util.Date) Case(de.symeda.sormas.app.backend.caze.Case) Test(org.junit.Test)

Example 5 with CaseDao

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

the class CaseBackendTest method shouldCreateSyncLogEntry.

// TODO #704
// @Test
// public void shouldUpdateUnreadStatus() throws DaoException {
// CaseDao caseDao = DatabaseHelper.getCaseDao();
// Case caze = TestEntityCreator.createCase();
// EpiDataBurial burial = TestEntityCreator.createEpiDataBurial(caze);
// 
// caze.setLocalChangeDate(DateHelper.addSeconds(caze.getLocalChangeDate(), 6));
// 
// // Updated case should be unread
// assertThat(caze.isUnreadOrChildUnread(), is(true));
// 
// caseDao.markAsRead(caze);
// caze = DatabaseHelper.getCaseDao().queryUuidWithEmbedded(caze.getUuid());
// // Case shouldn't be marked as unread after markAsRead has been called
// assertThat(caze.isUnreadOrChildUnread(), is(false));
// // UUID of embedded object should still be the same
// EpiDataBurial burialFromDB = DatabaseHelper.getEpiDataBurialDao().queryUuid(burial.getUuid());
// assertEquals(burial.getUuid(), burialFromDB.getUuid());
// }
@Test
public void shouldCreateSyncLogEntry() throws DaoException {
    SyncLogDao syncLogDao = DatabaseHelper.getSyncLogDao();
    assertThat(syncLogDao.countOf(), is(0L));
    CaseDao caseDao = DatabaseHelper.getCaseDao();
    Case caze = TestEntityCreator.createCase();
    caze.setEpidNumber("AppEpidNumber");
    DatabaseHelper.getCaseDao().saveAndSnapshot(caze);
    DatabaseHelper.getPersonDao().saveAndSnapshot(caze.getPerson());
    Case mergeCase = (Case) caze.clone();
    mergeCase.setPerson((Person) caze.getPerson().clone());
    mergeCase.getPerson().setAddress((Location) caze.getPerson().getAddress().clone());
    mergeCase.setSymptoms((Symptoms) caze.getSymptoms().clone());
    mergeCase.setHospitalization((Hospitalization) caze.getHospitalization().clone());
    mergeCase.setEpiData((EpiData) caze.getEpiData().clone());
    mergeCase.setId(null);
    mergeCase.getPerson().setId(null);
    mergeCase.getPerson().getAddress().setId(null);
    mergeCase.getSymptoms().setId(null);
    mergeCase.getHospitalization().setId(null);
    mergeCase.getEpiData().setId(null);
    mergeCase.getClinicalCourse().setId(null);
    mergeCase.getPortHealthInfo().setId(null);
    mergeCase.getTherapy().setId(null);
    mergeCase.getHealthConditions().setId(null);
    mergeCase.getMaternalHistory().setId(null);
    mergeCase.setEpidNumber("ServerEpidNumber");
    caseDao.mergeOrCreate(mergeCase);
    DatabaseHelper.getPersonDao().mergeOrCreate(mergeCase.getPerson());
    assertThat(syncLogDao.countOf(), is(1L));
}
Also used : SyncLogDao(de.symeda.sormas.app.backend.synclog.SyncLogDao) CaseDao(de.symeda.sormas.app.backend.caze.CaseDao) Case(de.symeda.sormas.app.backend.caze.Case) Test(org.junit.Test)

Aggregations

Case (de.symeda.sormas.app.backend.caze.Case)11 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)11 Test (org.junit.Test)8 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 Date (java.util.Date)4 UserRole (de.symeda.sormas.api.user.UserRole)3 Contact (de.symeda.sormas.app.backend.contact.Contact)3 HashSet (java.util.HashSet)3 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 CaseDtoHelper (de.symeda.sormas.app.backend.caze.CaseDtoHelper)2 ContactDao (de.symeda.sormas.app.backend.contact.ContactDao)2 Event (de.symeda.sormas.app.backend.event.Event)2 PreviousHospitalization (de.symeda.sormas.app.backend.hospitalization.PreviousHospitalization)2 TestCase (junit.framework.TestCase)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1