Search in sources :

Example 1 with PathogenTest

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

the class TestEntityCreator method createSampleTest.

public static PathogenTest createSampleTest(Sample sample) {
    PathogenTestType pathogenTestType = PathogenTestType.RAPID_TEST;
    PathogenTestResultType pathogenTestResultType = PathogenTestResultType.NEGATIVE;
    Date sampleTestDateTime = new Date();
    PathogenTest pathogenTest = DatabaseHelper.getSampleTestDao().build(sample);
    pathogenTest.setTestType(pathogenTestType);
    pathogenTest.setTestResult(pathogenTestResultType);
    pathogenTest.setTestDateTime(sampleTestDateTime);
    try {
        DatabaseHelper.getSampleTestDao().saveAndSnapshot(pathogenTest);
        DatabaseHelper.getSampleTestDao().accept(pathogenTest);
    } catch (DaoException e) {
        throw new RuntimeException(e);
    }
    return DatabaseHelper.getSampleTestDao().queryForIdWithEmbedded(pathogenTest.getId());
}
Also used : PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) DaoException(de.symeda.sormas.app.backend.common.DaoException) Date(java.util.Date)

Example 2 with PathogenTest

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

the class SampleBackendTest method shouldMergeSamplesAsExpected.

@Test
public void shouldMergeSamplesAsExpected() throws DaoException {
    Sample sample = TestEntityCreator.createSample(null);
    PathogenTest pathogenTest = TestEntityCreator.createSampleTest(sample);
    sample.setComment("AppSampleComment");
    pathogenTest.setTestResult(PathogenTestResultType.NEGATIVE);
    DatabaseHelper.getSampleDao().saveAndSnapshot(sample);
    DatabaseHelper.getSampleDao().accept(sample);
    DatabaseHelper.getSampleTestDao().saveAndSnapshot(pathogenTest);
    DatabaseHelper.getSampleTestDao().accept(pathogenTest);
    Sample mergeSample = (Sample) sample.clone();
    mergeSample.setAssociatedCase((Case) sample.getAssociatedCase().clone());
    mergeSample.setId(null);
    mergeSample.setComment("ServerSampleComment");
    PathogenTest mergePathogenTest = (PathogenTest) pathogenTest.clone();
    mergePathogenTest.setId(null);
    mergePathogenTest.setTestResult(PathogenTestResultType.POSITIVE);
    DatabaseHelper.getSampleDao().mergeOrCreate(mergeSample);
    DatabaseHelper.getSampleTestDao().mergeOrCreate(mergePathogenTest);
    Sample updatedSample = DatabaseHelper.getSampleDao().queryUuid(sample.getUuid());
    assertThat(updatedSample.getComment(), is("ServerSampleComment"));
    PathogenTest updatedPathogenTest = DatabaseHelper.getSampleTestDao().queryUuid(pathogenTest.getUuid());
    assertThat(updatedPathogenTest.getTestResult(), is(PathogenTestResultType.POSITIVE));
}
Also used : Sample(de.symeda.sormas.app.backend.sample.Sample) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) Test(org.junit.Test)

Example 3 with PathogenTest

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

the class SampleEditFragment method prepareFragmentData.

@Override
protected void prepareFragmentData() {
    record = getActivityRootData();
    if (record.getId() != null) {
        mostRecentTest = DatabaseHelper.getSampleTestDao().queryMostRecentBySample(record);
        if (ConfigProvider.hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.ADDITIONAL_TESTS)) {
            mostRecentAdditionalTests = DatabaseHelper.getAdditionalTestDao().queryMostRecentBySample(record);
        }
    }
    if (!StringUtils.isEmpty(record.getReferredToUuid())) {
        referredSample = DatabaseHelper.getSampleDao().queryUuid(record.getReferredToUuid());
    } else {
        referredSample = null;
    }
    sampleMaterialList = DataUtils.getEnumItems(SampleMaterial.class, true, getFieldVisibilityCheckers());
    sampleSourceList = DataUtils.getEnumItems(SampleSource.class, true);
    labList = DatabaseHelper.getFacilityDao().getActiveLaboratories(true);
    samplePurposeList = DataUtils.getEnumItems(SamplePurpose.class, true);
    samplingReasonList = DataUtils.getEnumItems(SamplingReason.class, true, getFieldVisibilityCheckers());
    for (PathogenTestType pathogenTest : record.getRequestedPathogenTests()) {
        requestedPathogenTests.clear();
        if (pathogenTest != PathogenTestType.OTHER) {
            requestedPathogenTests.add(pathogenTest.toString());
        }
    }
    if (ConfigProvider.hasUserRight(UserRight.ADDITIONAL_TEST_VIEW) && !DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.ADDITIONAL_TESTS)) {
        requestedAdditionalTests.clear();
        for (AdditionalTestType additionalTest : record.getRequestedAdditionalTests()) {
            requestedAdditionalTests.add(additionalTest.toString());
        }
    }
    if (record.getId() != null) {
        if (DatabaseHelper.getSampleTestDao().queryBySample(record).stream().allMatch(pathogenTest -> pathogenTest.getTestResult() == PathogenTestResultType.PENDING)) {
            finalTestResults = DataUtils.toItems(Arrays.asList(PathogenTestResultType.values()));
        } else {
            finalTestResults = DataUtils.toItems(Arrays.stream(PathogenTestResultType.values()).filter(type -> type != PathogenTestResultType.NOT_DONE).collect(Collectors.toList()));
        }
    }
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) Arrays(java.util.Arrays) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DataUtils(de.symeda.sormas.app.util.DataUtils) SampleSource(de.symeda.sormas.api.sample.SampleSource) SpecimenCondition(de.symeda.sormas.api.sample.SpecimenCondition) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) Intent(android.content.Intent) Facility(de.symeda.sormas.app.backend.facility.Facility) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) BarcodeActivity(de.symeda.sormas.app.barcode.BarcodeActivity) ConfigProvider(de.symeda.sormas.app.backend.config.ConfigProvider) VISIBLE(android.view.View.VISIBLE) View(android.view.View) Item(de.symeda.sormas.app.component.Item) SampleReadActivity(de.symeda.sormas.app.sample.read.SampleReadActivity) AdditionalTest(de.symeda.sormas.app.backend.sample.AdditionalTest) Collectors(java.util.stream.Collectors) CommonStatusCodes(com.google.android.gms.common.api.CommonStatusCodes) R(de.symeda.sormas.app.R) Sample(de.symeda.sormas.app.backend.sample.Sample) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) UserRight(de.symeda.sormas.api.user.UserRight) List(java.util.List) Nullable(androidx.annotation.Nullable) Disease(de.symeda.sormas.api.Disease) GONE(android.view.View.GONE) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) SampleDto(de.symeda.sormas.api.sample.SampleDto) DatabaseHelper(de.symeda.sormas.app.backend.common.DatabaseHelper) FragmentSampleEditLayoutBinding(de.symeda.sormas.app.databinding.FragmentSampleEditLayoutBinding) BaseEditFragment(de.symeda.sormas.app.BaseEditFragment) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) AdditionalTestType(de.symeda.sormas.api.sample.AdditionalTestType) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) SamplingReason(de.symeda.sormas.api.sample.SamplingReason) SamplingReason(de.symeda.sormas.api.sample.SamplingReason) SamplePurpose(de.symeda.sormas.api.sample.SamplePurpose) SampleMaterial(de.symeda.sormas.api.sample.SampleMaterial) SampleSource(de.symeda.sormas.api.sample.SampleSource) AdditionalTestType(de.symeda.sormas.api.sample.AdditionalTestType) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType)

Example 4 with PathogenTest

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

the class TextViewBindingAdapters method setTestResultValue.

@BindingAdapter(value = { "testResultValue", "defaultValue" }, requireAll = false)
public static void setTestResultValue(TextView textField, Sample sample, String defaultValue) {
    if (sample == null) {
        textField.setText(defaultValue);
    } else {
        Resources resources = textField.getContext().getResources();
        String result = "";
        SpecimenCondition condition = sample.getSpecimenCondition();
        // TODO: Orson - Replace
        // PathogenTest mostRecentTest = DatabaseHelper.getSampleTestDao().queryMostRecentBySample(sample);
        PathogenTest mostRecentTest = null;
        if (condition == null) {
            textField.setText(defaultValue);
            return;
        }
        if (condition == SpecimenCondition.NOT_ADEQUATE) {
            result = resources.getString(R.string.value_inadequate_specimen_condition);
        } else if (mostRecentTest != null) {
            result = mostRecentTest.getTestResult().toString();
        } else {
            result = resources.getString(R.string.info_no_sample_test);
        }
        textField.setText(result);
    }
}
Also used : Resources(android.content.res.Resources) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) SpecimenCondition(de.symeda.sormas.api.sample.SpecimenCondition) BindingAdapter(androidx.databinding.BindingAdapter)

Example 5 with PathogenTest

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

the class PathogenTestEditActivity 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 PathogenTest pathogenTestToSave = getStoredRootEntity();
    final Case associatedCase = pathogenTestToSave.getSample().getAssociatedCase();
    if (associatedCase != null) {
        DiseaseVariant caseDiseaseVariant = associatedCase.getDiseaseVariant();
        DiseaseVariant newDiseaseVariant = pathogenTestToSave.getTestedDiseaseVariant();
        if (pathogenTestToSave.getTestResult() == PathogenTestResultType.POSITIVE && pathogenTestToSave.getTestResultVerified() && !DataHelper.equal(newDiseaseVariant, caseDiseaseVariant)) {
            String heading = I18nProperties.getString(Strings.headingUpdateCaseWithNewDiseaseVariant);
            String subHeading = I18nProperties.getString(Strings.messageUpdateCaseWithNewDiseaseVariant);
            int positiveButtonTextResId = R.string.yes;
            int negativeButtonTextResId = R.string.no;
            ConfirmationDialog dlg = new ConfirmationDialog(this, heading, subHeading, positiveButtonTextResId, negativeButtonTextResId);
            dlg.setCancelable(false);
            dlg.setNegativeCallback(() -> {
                save(pathogenTestToSave, associatedCase);
            });
            dlg.setPositiveCallback(() -> {
                associatedCase.setDiseaseVariant(newDiseaseVariant);
                try {
                    DatabaseHelper.getCaseDao().updateOrCreate(associatedCase);
                } catch (SQLException | java.sql.SQLException e) {
                    Log.e(getClass().getSimpleName(), "Could not update case: " + associatedCase.getUuid());
                    throw new RuntimeException(e);
                }
                save(pathogenTestToSave, associatedCase);
            });
            dlg.show();
        } else {
            save(pathogenTestToSave, associatedCase);
        }
    }
}
Also used : DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) SQLException(android.database.SQLException) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) Case(de.symeda.sormas.app.backend.caze.Case) ConfirmationDialog(de.symeda.sormas.app.component.dialog.ConfirmationDialog)

Aggregations

PathogenTest (de.symeda.sormas.app.backend.sample.PathogenTest)12 Case (de.symeda.sormas.app.backend.caze.Case)5 Sample (de.symeda.sormas.app.backend.sample.Sample)5 Facility (de.symeda.sormas.app.backend.facility.Facility)3 MeansOfImmunization (de.symeda.sormas.api.immunization.MeansOfImmunization)2 PathogenTestResultType (de.symeda.sormas.api.sample.PathogenTestResultType)2 PathogenTestType (de.symeda.sormas.api.sample.PathogenTestType)2 SpecimenCondition (de.symeda.sormas.api.sample.SpecimenCondition)2 ActivityAsCase (de.symeda.sormas.app.backend.activityascase.ActivityAsCase)2 Campaign (de.symeda.sormas.app.backend.campaign.Campaign)2 CampaignFormData (de.symeda.sormas.app.backend.campaign.data.CampaignFormData)2 CampaignFormMeta (de.symeda.sormas.app.backend.campaign.form.CampaignFormMeta)2 MaternalHistory (de.symeda.sormas.app.backend.caze.maternalhistory.MaternalHistory)2 PortHealthInfo (de.symeda.sormas.app.backend.caze.porthealthinfo.PortHealthInfo)2 DiseaseClassificationCriteria (de.symeda.sormas.app.backend.classification.DiseaseClassificationCriteria)2 ClinicalCourse (de.symeda.sormas.app.backend.clinicalcourse.ClinicalCourse)2 ClinicalVisit (de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisit)2 HealthConditions (de.symeda.sormas.app.backend.clinicalcourse.HealthConditions)2 Contact (de.symeda.sormas.app.backend.contact.Contact)2 CustomizableEnumValue (de.symeda.sormas.app.backend.customizableenum.CustomizableEnumValue)2