Search in sources :

Example 1 with TaskResultHolder

use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.

the class BaseReportFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    if (getActivity() instanceof BaseReportActivity) {
        this.baseReportActivity = (BaseReportActivity) this.getActivity();
    } else {
        throw new NotImplementedException("The list activity for fragment must implement BaseReportActivity");
    }
    if (getActivity() instanceof IUpdateSubHeadingTitle) {
        this.subHeadingHandler = (IUpdateSubHeadingTitle) this.getActivity();
    } else {
        throw new NotImplementedException("Activity for fragment does not support updateSubHeadingTitle; " + "implement IUpdateSubHeadingTitle");
    }
    if (!(getActivity() instanceof NotificationContext)) {
        throw new NotImplementedException("Activity for fragment does not support showErrorNotification; " + "implement NotificationContext");
    }
    // Inflate Root
    rootBinding = DataBindingUtil.inflate(inflater, getRootLayoutResId(), container, false);
    View rootView = rootBinding.getRoot();
    final ViewStub vsChildFragmentFrame = rootView.findViewById(R.id.vsChildFragmentFrame);
    vsChildFragmentFrame.setOnInflateListener(new ViewStub.OnInflateListener() {

        @Override
        public void onInflate(ViewStub stub, View inflated) {
            contentViewStubBinding = DataBindingUtil.bind(inflated);
            contentViewStubBinding.addOnRebindCallback(new OnRebindCallback() {

                @Override
                public void onBound(ViewDataBinding binding) {
                    super.onBound(binding);
                    if (!skipAfterLayoutBinding)
                        onAfterLayoutBinding(contentViewStubBinding);
                    skipAfterLayoutBinding = true;
                    getSubHeadingHandler().updateSubHeadingTitle(getSubHeadingTitle());
                }
            });
            onLayoutBinding(contentViewStubBinding);
        }
    });
    vsChildFragmentFrame.setLayoutResource(getReportLayout());
    jobTask = new DefaultAsyncTask(getContext()) {

        @Override
        public void onPreExecute() {
            getBaseActivity().showPreloader();
        }

        @Override
        public void doInBackground(final TaskResultHolder resultHolder) {
            prepareFragmentData(savedInstanceState);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            getBaseActivity().hidePreloader();
            if (taskResult.getResultStatus().isFailed())
                return;
            vsChildFragmentFrame.inflate();
        }
    }.executeOnThreadPool();
    return rootView;
}
Also used : OnRebindCallback(androidx.databinding.OnRebindCallback) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) NotImplementedException(de.symeda.sormas.app.core.NotImplementedException) ViewDataBinding(androidx.databinding.ViewDataBinding) View(android.view.View) NotificationContext(de.symeda.sormas.app.core.NotificationContext) DefaultAsyncTask(de.symeda.sormas.app.core.async.DefaultAsyncTask) ViewStub(android.view.ViewStub) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) IUpdateSubHeadingTitle(de.symeda.sormas.app.core.IUpdateSubHeadingTitle)

Example 2 with TaskResultHolder

use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.

the class PrescriptionEditActivity method saveData.

@Override
public void saveData() {
    if (saveTask != null) {
        NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
        return;
    }
    final Prescription prescription = (Prescription) getActiveFragment().getPrimaryData();
    PrescriptionEditFragment fragment = (PrescriptionEditFragment) getActiveFragment();
    try {
        FragmentValidator.validate(getContext(), fragment.getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    saveTask = new SavingAsyncTask(getRootView(), prescription) {

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

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

        @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 : Prescription(de.symeda.sormas.app.backend.therapy.Prescription) 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)

Example 3 with TaskResultHolder

use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.

the class TreatmentEditActivity method saveData.

@Override
public void saveData() {
    if (saveTask != null) {
        NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
        return;
    }
    final Treatment treatment = (Treatment) getActiveFragment().getPrimaryData();
    TreatmentEditFragment fragment = (TreatmentEditFragment) getActiveFragment();
    try {
        FragmentValidator.validate(getContext(), fragment.getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    saveTask = new SavingAsyncTask(getRootView(), treatment) {

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

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

        @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 : Treatment(de.symeda.sormas.app.backend.therapy.Treatment) 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)

Example 4 with TaskResultHolder

use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.

the class TreatmentNewActivity method saveData.

@Override
public void saveData() {
    if (saveTask != null) {
        NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
        return;
    }
    final Treatment treatment = getStoredRootEntity();
    TreatmentEditFragment fragment = (TreatmentEditFragment) getActiveFragment();
    fragment.setLiveValidationDisabled(false);
    try {
        FragmentValidator.validate(getContext(), fragment.getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    saveTask = new SavingAsyncTask(getRootView(), treatment) {

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

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

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            hidePreloader();
            super.onPostExecute(taskResult);
            if (taskResult.getResultStatus().isSuccess()) {
                finish();
            }
            saveTask = null;
        }
    }.executeOnThreadPool();
}
Also used : Treatment(de.symeda.sormas.app.backend.therapy.Treatment) 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)

Example 5 with TaskResultHolder

use of de.symeda.sormas.app.core.async.TaskResultHolder in project SORMAS-Project by hzi-braunschweig.

the class CaseNewActivity method saveDataInner.

private void saveDataInner(final Case caseToSave) {
    if (saveTask != null) {
        NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
        // don't save multiple times
        return;
    }
    saveTask = new SavingAsyncTask(getRootView(), caseToSave) {

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

        @Override
        protected void doInBackground(TaskResultHolder resultHolder) throws Exception {
            DatabaseHelper.getPersonDao().saveAndSnapshot(caseToSave.getPerson());
            // epid number
            if (StringUtils.isBlank(caseToSave.getEpidNumber())) {
                Calendar calendar = Calendar.getInstance();
                String year = String.valueOf(calendar.get(Calendar.YEAR)).substring(2);
                caseToSave.setEpidNumber(caseToSave.getResponsibleRegion().getEpidCode() != null ? caseToSave.getResponsibleRegion().getEpidCode() : "" + "-" + caseToSave.getResponsibleDistrict().getEpidCode() != null ? caseToSave.getResponsibleDistrict().getEpidCode() : "" + "-" + year + "-");
            }
            DatabaseHelper.getCaseDao().saveAndSnapshot(caseToSave);
            if (!DataHelper.isNullOrEmpty(contactUuid)) {
                Contact sourceContact = DatabaseHelper.getContactDao().queryUuid(contactUuid);
                sourceContact.setResultingCaseUuid(caseToSave.getUuid());
                sourceContact.setResultingCaseUser(ConfigProvider.getUser());
                sourceContact.setContactStatus(ContactStatus.CONVERTED);
                DatabaseHelper.getContactDao().saveAndSnapshot(sourceContact);
            }
            if (!DataHelper.isNullOrEmpty(eventParticipantUuid)) {
                EventParticipant eventParticipant = DatabaseHelper.getEventParticipantDao().queryUuid(eventParticipantUuid);
                eventParticipant.setResultingCaseUuid(caseToSave.getUuid());
                DatabaseHelper.getEventParticipantDao().saveAndSnapshot(eventParticipant);
            }
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            hidePreloader();
            if (taskResult.getResultStatus().isSuccess()) {
                CaseNewFragment fragment = (CaseNewFragment) getActiveFragment();
                if (lineListingDiseases.contains(caseToSave.getDisease()) && Boolean.TRUE.equals(fragment.getContentBinding().rapidCaseEntryCheckBox.getValue())) {
                    setStoredRootEntity(buildRootEntity());
                    fragment.setActivityRootData(getStoredRootEntity());
                    fragment.updateForRapidCaseEntry(caseToSave);
                    setNewSubHeading(caseToSave.getPerson());
                } else {
                    finish();
                    CaseEditActivity.startActivity(getContext(), caseToSave.getUuid(), CaseSection.CASE_INFO);
                }
            }
            // do after clearing, because we want to show a success notification that would otherwise be hidden immediately
            super.onPostExecute(taskResult);
            saveTask = null;
        }
    }.executeOnThreadPool();
}
Also used : TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) Calendar(java.util.Calendar) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask) EventParticipant(de.symeda.sormas.app.backend.event.EventParticipant) Contact(de.symeda.sormas.app.backend.contact.Contact)

Aggregations

TaskResultHolder (de.symeda.sormas.app.core.async.TaskResultHolder)30 AsyncTaskResult (de.symeda.sormas.app.core.async.AsyncTaskResult)28 SavingAsyncTask (de.symeda.sormas.app.core.async.SavingAsyncTask)24 ValidationException (de.symeda.sormas.api.utils.ValidationException)23 DefaultAsyncTask (de.symeda.sormas.app.core.async.DefaultAsyncTask)6 ArrayList (java.util.ArrayList)5 EventParticipant (de.symeda.sormas.app.backend.event.EventParticipant)4 Case (de.symeda.sormas.app.backend.caze.Case)3 Contact (de.symeda.sormas.app.backend.contact.Contact)3 Event (de.symeda.sormas.app.backend.event.Event)3 WeeklyReport (de.symeda.sormas.app.backend.report.WeeklyReport)3 WeeklyReportEntry (de.symeda.sormas.app.backend.report.WeeklyReportEntry)3 ConfirmationDialog (de.symeda.sormas.app.component.dialog.ConfirmationDialog)3 ITaskResultHolderIterator (de.symeda.sormas.app.core.async.ITaskResultHolderIterator)3 Intent (android.content.Intent)2 CampaignFormDataEntry (de.symeda.sormas.api.campaign.data.CampaignFormDataEntry)2 CampaignFormData (de.symeda.sormas.app.backend.campaign.data.CampaignFormData)2 ClinicalVisit (de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit)2 Immunization (de.symeda.sormas.app.backend.immunization.Immunization)2 Person (de.symeda.sormas.app.backend.person.Person)2