Search in sources :

Example 1 with SamplePurpose

use of de.symeda.sormas.api.sample.SamplePurpose in project SORMAS-Project by hzi-braunschweig.

the class SampleEditFragment method onAfterLayoutBinding.

@Override
public void onAfterLayoutBinding(final FragmentSampleEditLayoutBinding contentBinding) {
    setFieldVisibilitiesAndAccesses(SampleDto.class, contentBinding.mainContent);
    setUpFieldVisibilities(contentBinding);
    // Initialize ControlSpinnerFields
    contentBinding.sampleSampleMaterial.initializeSpinner(sampleMaterialList);
    contentBinding.sampleSampleSource.initializeSpinner(sampleSourceList);
    contentBinding.samplePurpose.setEnabled(referredSample == null || record.getSamplePurpose() != SamplePurpose.EXTERNAL);
    contentBinding.sampleLab.initializeSpinner(DataUtils.toItems(labList), field -> {
        Facility laboratory = (Facility) field.getValue();
        if (laboratory != null && laboratory.getUuid().equals(FacilityDto.OTHER_FACILITY_UUID)) {
            contentBinding.sampleLabDetails.setVisibility(View.VISIBLE);
        } else {
            contentBinding.sampleLabDetails.hideField(true);
        }
    });
    if (finalTestResults != null) {
        contentBinding.samplePathogenTestResult.initializeSpinner(finalTestResults);
        if (contentBinding.samplePathogenTestResult.getValue() == null) {
            contentBinding.samplePathogenTestResult.setValue(PathogenTestResultType.PENDING);
        }
    }
    contentBinding.samplePurpose.initializeSpinner(samplePurposeList, field -> {
        SamplePurpose samplePurpose = (SamplePurpose) field.getValue();
        if (SamplePurpose.EXTERNAL == samplePurpose) {
            contentBinding.externalSampleFieldsLayout.setVisibility(VISIBLE);
            contentBinding.samplePathogenTestingRequested.setVisibility(ConfigProvider.getUser().equals(record.getReportingUser()) ? VISIBLE : GONE);
            contentBinding.sampleAdditionalTestingRequested.setVisibility(ConfigProvider.getUser().equals(record.getReportingUser()) ? VISIBLE : GONE);
        } else {
            contentBinding.sampleShipped.setValue(null);
            contentBinding.sampleShipmentDate.setValue(null);
            contentBinding.sampleShipmentDetails.setValue(null);
            contentBinding.externalSampleFieldsLayout.setVisibility(GONE);
            contentBinding.samplePathogenTestingRequested.setVisibility(GONE);
            contentBinding.sampleAdditionalTestingRequested.setVisibility(GONE);
        }
    });
    contentBinding.sampleSamplingReason.initializeSpinner(samplingReasonList);
    // Initialize ControlDateFields and ControlDateTimeFields
    contentBinding.sampleSampleDateTime.initializeDateTimeField(getFragmentManager());
    contentBinding.sampleShipmentDate.initializeDateField(getFragmentManager());
    // Initialize on clicks
    contentBinding.buttonScanFieldSampleId.setOnClickListener((View v) -> {
        Intent intent = new Intent(getContext(), BarcodeActivity.class);
        startActivityForResult(intent, BarcodeActivity.RC_BARCODE_CAPTURE);
    });
    // the user is not the one that originally reported the sample
    if (!ConfigProvider.getUser().equals(record.getReportingUser())) {
        contentBinding.sampleSampleDateTime.setEnabled(false);
        contentBinding.sampleSampleMaterial.setEnabled(false);
        contentBinding.sampleSampleMaterialText.setEnabled(false);
        contentBinding.sampleSampleSource.setEnabled(false);
        contentBinding.sampleLab.setEnabled(false);
        contentBinding.sampleLabDetails.setEnabled(false);
        contentBinding.sampleShipped.setEnabled(false);
        contentBinding.sampleShipmentDate.setEnabled(false);
        contentBinding.sampleShipmentDetails.setEnabled(false);
        contentBinding.samplePurpose.setEnabled(false);
        contentBinding.sampleReceived.setEnabled(false);
        contentBinding.sampleLabSampleID.setEnabled(false);
        contentBinding.sampleSpecimenCondition.setEnabled(false);
        contentBinding.samplePathogenTestingRequested.setVisibility(GONE);
        contentBinding.sampleRequestedPathogenTests.setVisibility(GONE);
        contentBinding.sampleAdditionalTestingRequested.setVisibility(GONE);
        contentBinding.sampleRequestedAdditionalTests.setVisibility(GONE);
        if (!requestedPathogenTests.isEmpty()) {
            contentBinding.sampleRequestedPathogenTestsTags.setTags(requestedPathogenTests);
            if (StringUtils.isEmpty(record.getRequestedOtherPathogenTests())) {
                contentBinding.sampleRequestedOtherPathogenTests.setVisibility(GONE);
            }
        } else {
            contentBinding.sampleRequestedPathogenTestsTags.setVisibility(GONE);
            contentBinding.sampleRequestedOtherPathogenTests.setVisibility(GONE);
        }
        if (ConfigProvider.hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.ADDITIONAL_TESTS)) {
            if (!requestedAdditionalTests.isEmpty()) {
                contentBinding.sampleRequestedAdditionalTestsTags.setTags(requestedAdditionalTests);
                if (StringUtils.isEmpty(record.getRequestedOtherAdditionalTests())) {
                    contentBinding.sampleRequestedOtherAdditionalTests.setVisibility(GONE);
                }
            } else {
                contentBinding.sampleRequestedAdditionalTestsTags.setVisibility(GONE);
                contentBinding.sampleRequestedOtherAdditionalTests.setVisibility(GONE);
            }
        }
        if (requestedPathogenTests.isEmpty() && requestedAdditionalTests.isEmpty()) {
            contentBinding.pathogenTestingDivider.setVisibility(GONE);
        }
    } else {
        contentBinding.sampleRequestedPathogenTestsTags.setVisibility(GONE);
        contentBinding.sampleRequestedPathogenTests.removeItem(PathogenTestType.OTHER);
        contentBinding.sampleRequestedAdditionalTestsTags.setVisibility(GONE);
    }
    if (!ConfigProvider.hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.ADDITIONAL_TESTS)) {
        contentBinding.additionalTestingLayout.setVisibility(GONE);
    }
}
Also used : SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) Intent(android.content.Intent) Facility(de.symeda.sormas.app.backend.facility.Facility) View(android.view.View)

Aggregations

Intent (android.content.Intent)1 View (android.view.View)1 SamplePurpose (de.symeda.sormas.api.sample.SamplePurpose)1 Facility (de.symeda.sormas.app.backend.facility.Facility)1