Search in sources :

Example 1 with EventParticipant

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

the class EventNewActivity 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 Event eventToSave = (Event) getActiveFragment().getPrimaryData();
    EventEditFragment fragment = (EventEditFragment) getActiveFragment();
    if (caseUuid != null) {
        Case linkedCase = DatabaseHelper.getCaseDao().getByReferenceDto(new CaseReferenceDto(caseUuid));
        if (eventToSave.getDisease() != null && !eventToSave.getDisease().equals(linkedCase.getDisease())) {
            NotificationHelper.showNotification(this, WARNING, getString(R.string.message_Event_and_Case_disease_mismatch) + " " + linkedCase.getDisease());
            return;
        }
    }
    fragment.setLiveValidationDisabled(false);
    try {
        FragmentValidator.validate(getContext(), fragment.getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    saveTask = new SavingAsyncTask(getRootView(), eventToSave) {

        @Override
        protected void onPreExecute() {
            showPreloader();
        }

        @Override
        public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
            DatabaseHelper.getEventDao().saveAndSnapshot(eventToSave);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            hidePreloader();
            super.onPostExecute(taskResult);
            if (taskResult.getResultStatus().isSuccess()) {
                finish();
                if (caseUuid != null) {
                    EventParticipant eventParticipantToSave = DatabaseHelper.getEventParticipantDao().build();
                    Case linkedCase = DatabaseHelper.getCaseDao().getByReferenceDto(new CaseReferenceDto(caseUuid));
                    eventParticipantToSave.setPerson(linkedCase.getPerson());
                    eventParticipantToSave.setEvent(eventToSave);
                    eventParticipantToSave.setResultingCaseUuid(linkedCase.getUuid());
                    EventParticipantSaver eventParticipantSaver = new EventParticipantSaver(EventNewActivity.this);
                    eventParticipantSaver.saveEventParticipantLinkedToCase(eventParticipantToSave);
                } else {
                    EventEditActivity.startActivity(getContext(), eventToSave.getUuid(), EventSection.EVENT_PARTICIPANTS);
                }
            }
            saveTask = null;
        }
    }.executeOnThreadPool();
}
Also used : EventParticipantSaver(de.symeda.sormas.app.event.eventparticipant.EventParticipantSaver) ValidationException(de.symeda.sormas.api.utils.ValidationException) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) Event(de.symeda.sormas.app.backend.event.Event) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) Case(de.symeda.sormas.app.backend.caze.Case)

Example 2 with EventParticipant

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

the class EventParticipantEditActivity method saveData.

@Override
public void saveData() {
    if (saveTask != null) {
        // don't save multiple times
        NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
        return;
    }
    final EventParticipant eventParticipant = (EventParticipant) getActiveFragment().getPrimaryData();
    EventParticipantEditFragment fragment = (EventParticipantEditFragment) getActiveFragment();
    try {
        FragmentValidator.validate(getContext(), fragment.getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    saveTask = new SavingAsyncTask(getRootView(), eventParticipant) {

        @Override
        protected void onPreExecute() {
            showPreloader();
        }

        @Override
        public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
            DatabaseHelper.getPersonDao().saveAndSnapshot(eventParticipant.getPerson());
            DatabaseHelper.getEventParticipantDao().saveAndSnapshot(eventParticipant);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            hidePreloader();
            super.onPostExecute(taskResult);
            if (taskResult.getResultStatus().isSuccess()) {
                finish();
            } else {
                // reload data
                onResume();
            }
            saveTask = null;
        }
    }.executeOnThreadPool();
}
Also used : ValidationException(de.symeda.sormas.api.utils.ValidationException) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask)

Example 3 with EventParticipant

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

the class EventParticipantNewActivity 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 EventParticipant eventParticipantToSave = (EventParticipant) getActiveFragment().getPrimaryData();
    EventParticipantNewFragment fragment = (EventParticipantNewFragment) getActiveFragment();
    fragment.setLiveValidationDisabled(false);
    try {
        FragmentValidator.validate(getContext(), fragment.getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    SelectOrCreatePersonDialog.selectOrCreatePerson(eventParticipantToSave.getPerson(), new Consumer<Person>() {

        @Override
        public void accept(Person person) {
            eventParticipantToSave.setPerson(person);
            saveTask = new SavingAsyncTask(getRootView(), eventParticipantToSave) {

                @Override
                protected void onPreExecute() {
                    showPreloader();
                }

                @Override
                protected void doInBackground(TaskResultHolder resultHolder) throws Exception {
                    DatabaseHelper.getPersonDao().saveAndSnapshot(eventParticipantToSave.getPerson());
                    final Event event = DatabaseHelper.getEventDao().queryUuid(eventUuid);
                    eventParticipantToSave.setEvent(event);
                    DatabaseHelper.getEventParticipantDao().saveAndSnapshot(eventParticipantToSave);
                }

                @Override
                protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
                    hidePreloader();
                    super.onPostExecute(taskResult);
                    if (taskResult.getResultStatus().isSuccess()) {
                        EventParticipantEditActivity.startActivity(getContext(), getRootUuid(), eventUuid, EventParticipantSection.EVENT_PARTICIPANT_INFO);
                    }
                    saveTask = null;
                }
            }.executeOnThreadPool();
        }
    });
}
Also used : ValidationException(de.symeda.sormas.api.utils.ValidationException) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) Event(de.symeda.sormas.app.backend.event.Event) Person(de.symeda.sormas.app.backend.person.Person) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask) ValidationException(de.symeda.sormas.api.utils.ValidationException)

Example 4 with EventParticipant

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

the class EventReadPersonsInvolvedListFragment method onListItemClick.

@Override
public void onListItemClick(View view, int position, Object item) {
    EventParticipant participant = (EventParticipant) item;
    EventParticipantReadActivity.startActivity(getContext(), participant.getUuid(), getActivityRootData().getUuid());
}
Also used : EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant)

Example 5 with EventParticipant

use of de.symeda.sormas.app.backend.event.EventParticipant 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)

Aggregations

EventParticipant (de.symeda.sormas.app.backend.event.EventParticipant)20 Event (de.symeda.sormas.app.backend.event.Event)9 Case (de.symeda.sormas.app.backend.caze.Case)8 Contact (de.symeda.sormas.app.backend.contact.Contact)8 Person (de.symeda.sormas.app.backend.person.Person)7 SavingAsyncTask (de.symeda.sormas.app.core.async.SavingAsyncTask)4 TaskResultHolder (de.symeda.sormas.app.core.async.TaskResultHolder)4 ValidationException (de.symeda.sormas.api.utils.ValidationException)3 Immunization (de.symeda.sormas.app.backend.immunization.Immunization)3 Sample (de.symeda.sormas.app.backend.sample.Sample)3 AsyncTaskResult (de.symeda.sormas.app.core.async.AsyncTaskResult)3 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)2 MeansOfImmunization (de.symeda.sormas.api.immunization.MeansOfImmunization)2 ActivityAsCase (de.symeda.sormas.app.backend.activityascase.ActivityAsCase)2 CaseDao (de.symeda.sormas.app.backend.caze.CaseDao)2 ClinicalVisit (de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit)2 District (de.symeda.sormas.app.backend.region.District)2 Region (de.symeda.sormas.app.backend.region.Region)2 Visit (de.symeda.sormas.app.backend.visit.Visit)2 Test (org.junit.Test)2