Search in sources :

Example 1 with CampaignFormDataEntry

use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.

the class CampaignStatisticsService method getCampaignStatistics.

public List<CampaignStatisticsDto> getCampaignStatistics(CampaignStatisticsCriteria criteria) {
    Query campaignsStatisticsQuery = em.createNativeQuery(buildStatisticsQuery(criteria));
    final CampaignJurisdictionLevel groupingLevel = criteria.getGroupingLevel();
    Map<CampaignStatisticsGroupingDto, CampaignStatisticsDto> results = new LinkedHashMap<>();
    ((Stream<Object[]>) campaignsStatisticsQuery.getResultStream()).forEach(result -> {
        CampaignStatisticsGroupingDto campaignStatisticsGroupingDto = new CampaignStatisticsGroupingDto((String) result[1], (String) result[2], (String) result[3], shouldIncludeRegion(groupingLevel) ? (String) result[4] : "", shouldIncludeDistrict(groupingLevel) ? (String) result[5] : "", shouldIncludeCommunity(groupingLevel) ? (String) result[6] : "");
        if (!results.containsKey(campaignStatisticsGroupingDto)) {
            CampaignStatisticsDto campaignStatisticsDto = new CampaignStatisticsDto(campaignStatisticsGroupingDto, result[0] != null ? ((Number) result[0]).intValue() : null);
            results.put(campaignStatisticsGroupingDto, campaignStatisticsDto);
        }
        int length = result.length;
        CampaignFormDataEntry campaignFormDataEntry = new CampaignFormDataEntry((String) result[length - 2], result[length - 1]);
        results.get(campaignStatisticsGroupingDto).addStatisticsData(campaignFormDataEntry);
    });
    return results.values().stream().collect(Collectors.toList());
}
Also used : Query(javax.persistence.Query) CampaignStatisticsDto(de.symeda.sormas.api.campaign.statistics.CampaignStatisticsDto) Stream(java.util.stream.Stream) CampaignFormDataEntry(de.symeda.sormas.api.campaign.data.CampaignFormDataEntry) CampaignJurisdictionLevel(de.symeda.sormas.api.campaign.CampaignJurisdictionLevel) CampaignStatisticsGroupingDto(de.symeda.sormas.api.campaign.statistics.CampaignStatisticsGroupingDto) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with CampaignFormDataEntry

use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.

the class CampaignFormDataEditActivity 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 CampaignFormData campaignFormDataToSave = getStoredRootEntity();
    try {
        FragmentValidator.validate(getContext(), getActiveFragment().getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    final List<CampaignFormDataEntry> formValues = campaignFormDataToSave.getFormValues();
    final List<CampaignFormDataEntry> filledFormValues = new ArrayList<>();
    formValues.forEach(campaignFormDataEntry -> {
        if (campaignFormDataEntry.getId() != null && campaignFormDataEntry.getValue() != null) {
            filledFormValues.add(campaignFormDataEntry);
        }
    });
    campaignFormDataToSave.setFormValues(filledFormValues);
    saveTask = new SavingAsyncTask(getRootView(), campaignFormDataToSave) {

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

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            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) ArrayList(java.util.ArrayList) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) CampaignFormDataEntry(de.symeda.sormas.api.campaign.data.CampaignFormDataEntry) CampaignFormData(de.symeda.sormas.app.backend.campaign.data.CampaignFormData) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask)

Example 3 with CampaignFormDataEntry

use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.

the class CampaignFormDataNewActivity 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 CampaignFormData campaignFormDataToSave = getStoredRootEntity();
    try {
        FragmentValidator.validate(getContext(), getActiveFragment().getContentBinding());
    } catch (ValidationException e) {
        NotificationHelper.showNotification(this, ERROR, e.getMessage());
        return;
    }
    final List<CampaignFormDataEntry> formValues = campaignFormDataToSave.getFormValues();
    final List<CampaignFormDataEntry> filledFormValues = new ArrayList<>();
    formValues.forEach(campaignFormDataEntry -> {
        if (campaignFormDataEntry.getId() != null && campaignFormDataEntry.getValue() != null) {
            filledFormValues.add(campaignFormDataEntry);
        }
    });
    campaignFormDataToSave.setFormValues(filledFormValues);
    CampaignFormDataNewFragment activeFragment = (CampaignFormDataNewFragment) getActiveFragment();
    activeFragment.setLiveValidationDisabled(true);
    saveTask = new SavingAsyncTask(getRootView(), campaignFormDataToSave) {

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

        @Override
        protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
            hidePreloader();
            super.onPostExecute(taskResult);
            if (taskResult.getResultStatus().isSuccess()) {
                finish();
                CampaignFormDataEditActivity.startActivity(getContext(), campaignFormDataToSave.getUuid());
            }
            saveTask = null;
        }
    }.executeOnThreadPool();
}
Also used : ValidationException(de.symeda.sormas.api.utils.ValidationException) TaskResultHolder(de.symeda.sormas.app.core.async.TaskResultHolder) ArrayList(java.util.ArrayList) AsyncTaskResult(de.symeda.sormas.app.core.async.AsyncTaskResult) CampaignFormDataEntry(de.symeda.sormas.api.campaign.data.CampaignFormDataEntry) CampaignFormData(de.symeda.sormas.app.backend.campaign.data.CampaignFormData) SavingAsyncTask(de.symeda.sormas.app.core.async.SavingAsyncTask)

Example 4 with CampaignFormDataEntry

use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.

the class ExpressionProcessorTest method setup.

@Before
public void setup() throws IOException {
    GridLayout campaignFormLayout = new GridLayout(12, 1);
    ObjectMapper objectMapper = new ObjectMapper();
    List<CampaignFormElement> campaignFormElements = createData(objectMapper, this.getClass().getResourceAsStream("/campaign/expressions/formelements.json"), CampaignFormElement.class);
    List<CampaignFormDataEntry> campaignFormDataEntries = createData(objectMapper, this.getClass().getResourceAsStream("/campaign/expressions/formvalues.json"), CampaignFormDataEntry.class);
    campaignFormBuilder = new CampaignFormBuilder(campaignFormElements, campaignFormDataEntries, campaignFormLayout, Collections.emptyList());
    campaignFormBuilder.buildForm();
    expressionProcessor = new ExpressionProcessor(campaignFormBuilder);
}
Also used : GridLayout(com.vaadin.ui.GridLayout) CampaignFormBuilder(de.symeda.sormas.ui.campaign.campaigndata.CampaignFormBuilder) CampaignFormElement(de.symeda.sormas.api.campaign.form.CampaignFormElement) CampaignFormDataEntry(de.symeda.sormas.api.campaign.data.CampaignFormDataEntry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 5 with CampaignFormDataEntry

use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.

the class CampaignFormDataFragmentUtils method getOrCreateCampaignFormDataEntry.

public static CampaignFormDataEntry getOrCreateCampaignFormDataEntry(List<CampaignFormDataEntry> formValues, CampaignFormElement campaignFormElement) {
    for (CampaignFormDataEntry campaignFormDataEntry : formValues) {
        if (campaignFormDataEntry.getId().equals(campaignFormElement.getId())) {
            return campaignFormDataEntry;
        }
    }
    final CampaignFormDataEntry newCampaignFomDataEntry = new CampaignFormDataEntry(campaignFormElement.getId(), null);
    formValues.add(newCampaignFomDataEntry);
    return newCampaignFomDataEntry;
}
Also used : CampaignFormDataEntry(de.symeda.sormas.api.campaign.data.CampaignFormDataEntry)

Aggregations

CampaignFormDataEntry (de.symeda.sormas.api.campaign.data.CampaignFormDataEntry)10 CampaignFormElement (de.symeda.sormas.api.campaign.form.CampaignFormElement)5 CampaignFormElementType (de.symeda.sormas.api.campaign.form.CampaignFormElementType)4 View (android.view.View)3 ImageView (android.widget.ImageView)3 LinearLayout (android.widget.LinearLayout)3 TextView (android.widget.TextView)3 CampaignFormMeta (de.symeda.sormas.app.backend.campaign.form.CampaignFormMeta)3 ControlPropertyField (de.symeda.sormas.app.component.controls.ControlPropertyField)3 HashMap (java.util.HashMap)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CampaignReferenceDto (de.symeda.sormas.api.campaign.CampaignReferenceDto)2 CampaignFormDataDto (de.symeda.sormas.api.campaign.data.CampaignFormDataDto)2 CampaignFormMetaReferenceDto (de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto)2 ValidationException (de.symeda.sormas.api.utils.ValidationException)2 CampaignFormData (de.symeda.sormas.app.backend.campaign.data.CampaignFormData)2 CampaignFormDataFragmentUtils.getOrCreateCampaignFormDataEntry (de.symeda.sormas.app.campaign.CampaignFormDataFragmentUtils.getOrCreateCampaignFormDataEntry)2 AsyncTaskResult (de.symeda.sormas.app.core.async.AsyncTaskResult)2 SavingAsyncTask (de.symeda.sormas.app.core.async.SavingAsyncTask)2 TaskResultHolder (de.symeda.sormas.app.core.async.TaskResultHolder)2