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());
}
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());
}
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());
}
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());
}
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));
}
Aggregations