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());
}
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));
}
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()));
}
}
}
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);
}
}
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);
}
}
}
Aggregations