Search in sources :

Example 1 with ValidationException

use of de.symeda.sormas.api.utils.ValidationException in project SORMAS-Project by hzi-braunschweig.

the class ClinicalVisitEditActivity 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 ClinicalVisit clinicalVisit = getStoredRootEntity();
    try {
        FragmentValidator.validate(getContext(), getActiveFragment().getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    saveTask = new SavingAsyncTask(getRootView(), clinicalVisit) {

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

        @Override
        public void doInBackground(TaskResultHolder resultHolder) throws Exception {
            DatabaseHelper.getClinicalVisitDao().saveAndSnapshot(clinicalVisit);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            hidePreloader();
            super.onPostExecute(taskResult);
            if (taskResult.getResultStatus().isSuccess()) {
                goToNextPage();
            } 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) ClinicalVisit(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask)

Example 2 with ValidationException

use of de.symeda.sormas.api.utils.ValidationException in project SORMAS-Project by hzi-braunschweig.

the class ClinicalVisitNewActivity 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 ClinicalVisit clinicalVisit = getStoredRootEntity();
    ClinicalVisitEditFragment fragment = (ClinicalVisitEditFragment) getActiveFragment();
    fragment.setLiveValidationDisabled(false);
    try {
        FragmentValidator.validate(getContext(), getActiveFragment().getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    saveTask = new SavingAsyncTask(getRootView(), clinicalVisit) {

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

        @Override
        public void doInBackground(TaskResultHolder resultHolder) throws Exception {
            DatabaseHelper.getClinicalVisitDao().saveAndSnapshot(clinicalVisit);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            hidePreloader();
            super.onPostExecute(taskResult);
            if (taskResult.getResultStatus().isSuccess()) {
                finish();
                ClinicalVisitEditActivity.startActivity(getContext(), clinicalVisit.getUuid(), caseUuid, ClinicalVisitSection.CLINICAL_MEASUREMENTS);
            }
            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) ClinicalVisit(de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask)

Example 3 with ValidationException

use of de.symeda.sormas.api.utils.ValidationException in project SORMAS-Project by hzi-braunschweig.

the class ContactEditActivity 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 Contact contactToSave = getStoredRootEntity();
    if (ContactEditAuthorization.isContactEditAllowed(contactToSave)) {
        try {
            FragmentValidator.validate(getContext(), getActiveFragment().getContentBinding());
        } catch (ValidationException e) {
            NotificationHelper.showNotification(this, ERROR, e.getMessage());
            return;
        }
        saveTask = new SavingAsyncTask(getRootView(), contactToSave) {

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

            @Override
            protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
                super.onPostExecute(taskResult);
                if (taskResult.getResultStatus().isSuccess()) {
                    if (getActivePage().getPosition() == ContactSection.PERSON_INFO.ordinal()) {
                        finish();
                    } else {
                        goToNextPage();
                    }
                } else {
                    // reload data
                    onResume();
                }
                saveTask = null;
            }
        }.executeOnThreadPool();
    } else {
        NotificationHelper.showNotification(this, WARNING, getString(R.string.message_edit_forbidden));
    }
}
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) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask) Contact(de.symeda.sormas.app.backend.contact.Contact)

Example 4 with ValidationException

use of de.symeda.sormas.api.utils.ValidationException in project SORMAS-Project by hzi-braunschweig.

the class EventEditActivity 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();
    try {
        FragmentValidator.validate(getContext(), fragment.getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    if (eventToSave.getTypeOfPlace() == TypeOfPlace.OTHER) {
        eventToSave.getEventLocation().setFacility(null);
        eventToSave.getEventLocation().setFacilityDetails(null);
        eventToSave.getEventLocation().setFacilityType(null);
    }
    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()) {
                goToNextPage();
            } else {
                // reload data
                onResume();
            }
            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) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask)

Example 5 with ValidationException

use of de.symeda.sormas.api.utils.ValidationException 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)

Aggregations

ValidationException (de.symeda.sormas.api.utils.ValidationException)31 SavingAsyncTask (de.symeda.sormas.app.core.async.SavingAsyncTask)24 TaskResultHolder (de.symeda.sormas.app.core.async.TaskResultHolder)23 AsyncTaskResult (de.symeda.sormas.app.core.async.AsyncTaskResult)21 Case (de.symeda.sormas.app.backend.caze.Case)6 Event (de.symeda.sormas.app.backend.event.Event)3 EventParticipant (de.symeda.sormas.app.backend.event.EventParticipant)3 Immunization (de.symeda.sormas.app.backend.immunization.Immunization)3 AsyncTask (android.os.AsyncTask)2 CampaignFormDataEntry (de.symeda.sormas.api.campaign.data.CampaignFormDataEntry)2 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 CampaignFormData (de.symeda.sormas.app.backend.campaign.data.CampaignFormData)2 ClinicalVisit (de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit)2 DaoException (de.symeda.sormas.app.backend.common.DaoException)2 Contact (de.symeda.sormas.app.backend.contact.Contact)2 Person (de.symeda.sormas.app.backend.person.Person)2 Sample (de.symeda.sormas.app.backend.sample.Sample)2 Task (de.symeda.sormas.app.backend.task.Task)2 Prescription (de.symeda.sormas.app.backend.therapy.Prescription)2 Treatment (de.symeda.sormas.app.backend.therapy.Treatment)2