use of de.symeda.sormas.app.backend.task.Task in project SORMAS-Project by hzi-braunschweig.
the class EventDao method deleteEventAndAllDependingEntities.
public void deleteEventAndAllDependingEntities(String eventUuid) throws SQLException {
Event event = queryUuidWithEmbedded(eventUuid);
// Cancel if not in local database
if (event == null) {
return;
}
// Delete event tasks
List<Task> tasks = DatabaseHelper.getTaskDao().queryByEvent(event);
for (Task task : tasks) {
DatabaseHelper.getTaskDao().deleteCascade(task);
}
// Delete event participants
List<EventParticipant> eventParticipants = DatabaseHelper.getEventParticipantDao().getByEvent(event);
for (EventParticipant eventParticipant : eventParticipants) {
DatabaseHelper.getEventParticipantDao().deleteCascade(eventParticipant);
}
// Delete event
deleteCascade(event);
}
use of de.symeda.sormas.app.backend.task.Task in project SORMAS-Project by hzi-braunschweig.
the class TestEntityCreator method createCaseTask.
public static Task createCaseTask(Case caze, TaskStatus taskStatus, User user) {
TaskDto taskDto = new TaskDto();
Task task = new TaskDtoHelper().fillOrCreateFromDto(null, taskDto);
task.setUuid(DataHelper.createUuid());
task.setCreationDate(new Date());
task.setChangeDate(new Date());
task.setTaskContext(TaskContext.CASE);
task.setTaskType(TaskType.CASE_INVESTIGATION);
task.setTaskStatus(taskStatus);
task.setCaze(caze);
task.setAssigneeUser(user);
try {
DatabaseHelper.getTaskDao().saveAndSnapshot(task);
DatabaseHelper.getTaskDao().accept(task);
} catch (DaoException e) {
throw new RuntimeException(e);
}
return DatabaseHelper.getTaskDao().queryForIdWithEmbedded(task.getId());
}
use of de.symeda.sormas.app.backend.task.Task 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.task.Task in project SORMAS-Project by hzi-braunschweig.
the class CaseDao method deleteCaseAndAllDependingEntities.
public void deleteCaseAndAllDependingEntities(String caseUuid) throws SQLException {
Case caze = queryUuidWithEmbedded(caseUuid);
// Cancel if not in local database
if (caze == null) {
return;
}
// Delete contacts, contact tasks and visits
List<Contact> contacts = DatabaseHelper.getContactDao().getByCase(caze);
for (Contact contact : contacts) {
DatabaseHelper.getContactDao().deleteContactAndAllDependingEntities(contact);
}
// Delete samples, pathogen tests and additional tests
List<Sample> samples = DatabaseHelper.getSampleDao().queryByCase(caze);
for (Sample sample : samples) {
DatabaseHelper.getSampleDao().deleteSampleAndAllDependingEntities(sample);
}
// Delete case tasks
List<Task> tasks = DatabaseHelper.getTaskDao().queryByCase(caze);
for (Task task : tasks) {
DatabaseHelper.getTaskDao().deleteCascade(task);
}
// Delete treatments and prescriptions
if (caze.getTherapy() != null) {
for (Treatment treatment : DatabaseHelper.getTreatmentDao().findBy(new TreatmentCriteria().therapy(caze.getTherapy()))) {
DatabaseHelper.getTreatmentDao().delete(treatment);
}
for (Prescription prescription : DatabaseHelper.getPrescriptionDao().findBy(new PrescriptionCriteria().therapy(caze.getTherapy()))) {
DatabaseHelper.getPrescriptionDao().delete(prescription);
}
}
// Delete clinical visits
if (caze.getClinicalCourse() != null) {
for (ClinicalVisit clinicalVisit : DatabaseHelper.getClinicalVisitDao().findBy(new ClinicalVisitCriteria().clinicalCourse(caze.getClinicalCourse()))) {
DatabaseHelper.getClinicalVisitDao().delete(clinicalVisit);
}
}
// Remove events linked to case by removing case_id from event participants - delete event participant and
List<EventParticipant> eventParticipants = DatabaseHelper.getEventParticipantDao().getByCase(caze);
for (EventParticipant eventParticipant : eventParticipants) {
DatabaseHelper.getEventParticipantDao().deleteEventParticipant(eventParticipant);
}
// Remove events outside jurisdiction which were pulled in due to linking with an accessible case
EventCriteria eventCriteria = new EventCriteria();
eventCriteria.caze(caze);
List<Event> eventList = DatabaseHelper.getEventDao().queryByCriteria(eventCriteria, 0, 0);
for (Event event : eventList) {
List<EventParticipant> eventParticipantByEventList = DatabaseHelper.getEventParticipantDao().getByEvent(event);
if (eventParticipantByEventList.isEmpty()) {
Boolean isEventInJurisdiction = EventEditAuthorization.isEventEditAllowed(event);
if (!isEventInJurisdiction) {
DatabaseHelper.getEventDao().delete(event);
}
}
}
// Delete case
deleteCascade(caze);
}
use of de.symeda.sormas.app.backend.task.Task in project SORMAS-Project by hzi-braunschweig.
the class CaseDao method onCaseChanged.
private void onCaseChanged(Case existingCase, Case changedCase) {
changedCase.setCompleteness(calculateCompleteness(changedCase));
if (existingCase == null) {
// If a new case is created, use the last available location to update its report latitude and longitude
Location location = LocationService.instance().getLocation();
if (location != null) {
changedCase.setReportLat(location.getLatitude());
changedCase.setReportLon(location.getLongitude());
changedCase.setReportLatLonAccuracy(location.getAccuracy());
}
} else {
// classification
if (changedCase.getCaseClassification() != existingCase.getCaseClassification()) {
changedCase.setClassificationDate(new Date());
changedCase.setClassificationUser(ConfigProvider.getUser());
}
// change the disease of all contacts if the case disease or disease details have changed
if (existingCase.getDisease() != changedCase.getDisease() || !StringUtils.equals(existingCase.getDiseaseDetails(), changedCase.getDiseaseDetails())) {
for (Contact contact : DatabaseHelper.getContactDao().getByCase(changedCase)) {
contact.setDisease(changedCase.getDisease());
contact.setDiseaseDetails(changedCase.getDiseaseDetails());
try {
DatabaseHelper.getContactDao().saveAndSnapshot(contact);
} catch (DaoException e) {
Log.e(getTableName(), "Failed to save an updated contact in onCaseChanged");
}
}
}
boolean responsibleRegionChanged = !DataHelper.isSame(changedCase.getResponsibleRegion(), existingCase.getResponsibleRegion());
boolean regionChanged = !DataHelper.isSame(changedCase.getRegion(), existingCase.getRegion());
boolean responsibleDistrictChanged = !DataHelper.isSame(changedCase.getResponsibleDistrict(), existingCase.getResponsibleDistrict());
boolean districtChanged = !DataHelper.isSame(changedCase.getDistrict(), existingCase.getDistrict());
boolean responsibleCommunityChanged = !DataHelper.isSame(changedCase.getResponsibleCommunity(), existingCase.getResponsibleCommunity());
boolean communityChanged = !DataHelper.isSame(changedCase.getCommunity(), existingCase.getCommunity());
boolean facilityChanged = !DataHelper.isSame(changedCase.getHealthFacility(), existingCase.getHealthFacility());
// If the case is moved from the surveillance officer's jurisdiction, assign a new surveillance officer
if (DatabaseHelper.getFeatureConfigurationDao().isPropertyValueTrue(FeatureType.CASE_SURVEILANCE, FeatureTypeProperty.AUTOMATIC_RESPONSIBILITY_ASSIGNMENT) && changedCase.getSurveillanceOfficer() == null || ((responsibleDistrictChanged || districtChanged) && !DataHelper.isSame(changedCase.getResponsibleDistrict(), changedCase.getSurveillanceOfficer().getDistrict()) && !DataHelper.isSame(changedCase.getDistrict(), changedCase.getSurveillanceOfficer().getDistrict()))) {
List<User> districtOfficers = DatabaseHelper.getUserDao().getByDistrictAndRole(changedCase.getResponsibleDistrict(), UserRole.SURVEILLANCE_OFFICER, User.UUID);
if (districtOfficers.size() == 0 && changedCase.getDistrict() != null) {
districtOfficers = DatabaseHelper.getUserDao().getByDistrictAndRole(changedCase.getDistrict(), UserRole.SURVEILLANCE_OFFICER, User.UUID);
}
changedCase.setSurveillanceOfficer(DataUtils.getRandomCandidate(districtOfficers));
}
// if the case's jurisdiction has changed, re-assign tasks
if (responsibleRegionChanged || responsibleDistrictChanged || responsibleCommunityChanged || regionChanged || districtChanged || communityChanged || facilityChanged) {
for (Task task : DatabaseHelper.getTaskDao().queryByCase(existingCase)) {
if (task.getTaskStatus() != TaskStatus.PENDING) {
continue;
}
User assigneeUser = task.getAssigneeUser();
if (assigneeUser != null && CaseJurisdictionBooleanValidator.of(JurisdictionHelper.createCaseJurisdictionDto(changedCase), JurisdictionHelper.createUserJurisdiction(assigneeUser)).isInJurisdiction()) {
continue;
}
assignOfficerOrSupervisorToTask(changedCase, task);
try {
DatabaseHelper.getTaskDao().saveAndSnapshot(task);
} catch (DaoException e) {
Log.e(getTableName(), "Failed to save an updated task in onCaseChanged");
}
}
}
}
}
Aggregations