Skip to content

Commit 8c9169f

Browse files
Merge pull request #13522 from SORMAS-Foundation/bugfix-13521-pathogen-test-failure-for-environment-samples
Environment sample pathogen test failure bug fix
2 parents 5666162 + 8ad370b commit 8c9169f

File tree

5 files changed

+82
-58
lines changed

5 files changed

+82
-58
lines changed

sormas-api/src/main/java/de/symeda/sormas/api/sample/PathogenTestDto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ public static PathogenTestDto build(EnvironmentSampleDto environmentSample, User
267267
PathogenTestDto pathogenTest = new PathogenTestDto();
268268
pathogenTest.setUuid(DataHelper.createUuid());
269269
pathogenTest.setEnvironmentSample(environmentSample.toReference());
270-
270+
// Initialize with an empty drug susceptibility to avoid multiple unnecessary conditional addFields ana checks of the drug susceptibility field in the form
271+
pathogenTest.setDrugSusceptibility(DrugSusceptibilityDto.build());
271272
pathogenTest.setLab(currentUser.getLaboratory());
272273
if (pathogenTest.getLab() == null) {
273274
pathogenTest.setLab(environmentSample.getLaboratory());

sormas-api/src/main/java/de/symeda/sormas/api/utils/AnnotationFieldHelper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,32 @@ public static List<String> getFieldNamesWithMatchingDiseaseAndTestAnnotations(
4141
Field[] fields = clazz.getDeclaredFields();
4242

4343
for (Field field : fields) {
44-
boolean matches = false;
44+
boolean diseaseMatches = false;
45+
boolean pathogenTestMatches = false;
4546

4647
// Check @Diseases annotation
4748
if (diseases != null && !diseases.isEmpty()) {
4849
Diseases diseasesAnnotation = field.getAnnotation(Diseases.class);
4950
if (diseasesAnnotation != null) {
5051
List<Disease> fieldDiseases = Arrays.asList(diseasesAnnotation.value());
5152
if (fieldDiseases.stream().anyMatch(diseases::contains)) {
52-
matches = true;
53+
diseaseMatches = true;
5354
}
5455
}
5556
}
5657

5758
// Check @ApplicableToPathogenTests annotation
58-
if (matches && pathogenTestTypes != null && !pathogenTestTypes.isEmpty()) {
59+
if (diseaseMatches && pathogenTestTypes != null && !pathogenTestTypes.isEmpty()) {
5960
ApplicableToPathogenTests pathogenTestsAnnotation = field.getAnnotation(ApplicableToPathogenTests.class);
6061
if (pathogenTestsAnnotation != null) {
6162
List<PathogenTestType> fieldTestTypes = Arrays.asList(pathogenTestsAnnotation.value());
6263
if (fieldTestTypes.stream().anyMatch(pathogenTestTypes::contains)) {
63-
matches = true;
64+
pathogenTestMatches = true;
6465
}
6566
}
6667
}
6768

68-
if (matches) {
69+
if (diseaseMatches && pathogenTestMatches) {
6970
matchingFieldNames.add(field.getName());
7071
}
7172
}

sormas-backend/src/main/java/de/symeda/sormas/backend/sample/PathogenTestFacadeEjb.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public static PathogenTestDto toDto(PathogenTest source) {
320320
target.setPatternProfile(source.getPatternProfile());
321321
target.setStrainCallStatus(source.getStrainCallStatus());
322322
target.setTestScale(source.getTestScale());
323-
target.setDrugSusceptibility(DrugSusceptibilityMapper.toDto(source.getDrugSusceptibility()));
323+
target.setDrugSusceptibility(DrugSusceptibilityMapper.toDto(source.getDrugSusceptibility()));
324324

325325
target.setSeroTypingMethod(source.getSeroTypingMethod());
326326
target.setSeroTypingMethodText(source.getSeroTypingMethodText());
@@ -469,8 +469,9 @@ public void validate(PathogenTestDto pathogenTest) throws ValidationRuntimeExcep
469469
Validations.required,
470470
I18nProperties.getPrefixCaption(PathogenTestDto.I18N_PREFIX, PathogenTestDto.TEST_RESULT_VERIFIED)));
471471
}
472-
if (pathogenTest.getTestType() == PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY
473-
&& !DrugSusceptibilityMapper.hasData(pathogenTest.getDrugSusceptibility())) {
472+
// susceptibility is applicable for only LUX TB and all counties of IMI and IPI
473+
if (pathogenTest.getDrugSusceptibility() != null && pathogenTest.getTestType() == PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY
474+
&& !DrugSusceptibilityMapper.hasData(pathogenTest.getDrugSusceptibility())) {
474475
throw new ValidationRuntimeException(I18nProperties.getValidationError(Validations.pathogenTestValidDrugSusceptibility));
475476
}
476477
}
@@ -583,7 +584,7 @@ public PathogenTest fillOrBuildEntity(@NotNull PathogenTestDto source, PathogenT
583584
target.setPatternProfile(source.getPatternProfile());
584585
target.setStrainCallStatus(source.getStrainCallStatus());
585586
target.setTestScale(source.getTestScale());
586-
if (source.getTestType() == PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY) {
587+
if (source.getDrugSusceptibility() !=null && source.getTestType() == PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY) {
587588
target.setDrugSusceptibility(
588589
drugSusceptibilityMapper.fillOrBuildEntity(source.getDrugSusceptibility(), target.getDrugSusceptibility(), checkChangeDate));
589590
}

sormas-ui/src/main/java/de/symeda/sormas/ui/samples/PathogenTestController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.function.Consumer;
2929
import java.util.stream.Collectors;
3030

31+
import de.symeda.sormas.api.DiseaseHelper;
32+
import de.symeda.sormas.api.sample.PathogenTestType;
3133
import org.apache.commons.collections4.CollectionUtils;
3234

3335
import com.vaadin.ui.Label;
@@ -299,6 +301,12 @@ public void savePathogenTests(List<PathogenTestDto> pathogenTests, SampleReferen
299301

300302
pathogenTests.forEach(p -> {
301303
p.setSample(sampleRef);
304+
boolean luxTB = FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG) && Disease.TUBERCULOSIS == p.getTestedDisease();
305+
boolean invasiveDisease = DiseaseHelper.checkDiseaseIsInvasiveBacterialDiseases(p.getTestedDisease());
306+
//the susceptibility test is applicable only for LUX TB and all-countries invasive disease
307+
if(PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY == p.getTestType() && !luxTB && !invasiveDisease) {
308+
p.setDrugSusceptibility(null);
309+
}
302310
facade.savePathogenTest(p);
303311
});
304312
if (associatedContact != null) {

sormas-ui/src/main/java/de/symeda/sormas/ui/samples/PathogenTestForm.java

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs;
2424
import static de.symeda.sormas.ui.utils.LayoutUtil.loc;
2525

26+
import java.util.ArrayList;
2627
import java.util.Arrays;
2728
import java.util.Date;
2829
import java.util.HashMap;
@@ -206,46 +207,51 @@ private static void setCqValueVisibility(TextField cqValueField, PathogenTestTyp
206207
}
207208
}
208209

209-
private void updateTuberculosisFieldSpecifications(PathogenTestType testType, Disease disease) {
210-
if ((FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG))) {
211-
boolean wasReadOnly = testResultField.isReadOnly();
212-
213-
if (disease == Disease.TUBERCULOSIS && testType != null) {
214-
if (Arrays.asList(PathogenTestType.BEIJINGGENOTYPING, PathogenTestType.MIRU_PATTERN_CODE, PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY)
215-
.contains(testType)) {
216-
if (wasReadOnly) {
210+
private void updateDrugSusceptibilityFieldSpecifications(PathogenTestType testType, Disease disease) {
211+
if (disease != null) { // Drug susceptibility is applicable only diseass not for environment
212+
if ((FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG))) {
213+
boolean wasReadOnly = testResultField.isReadOnly();
214+
215+
if (disease == Disease.TUBERCULOSIS && testType != null) {
216+
if (Arrays.asList(PathogenTestType.BEIJINGGENOTYPING, PathogenTestType.MIRU_PATTERN_CODE, PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY).contains(testType)) {
217+
if (wasReadOnly) {
218+
testResultField.setReadOnly(false);
219+
}
220+
testResultField.setValue(PathogenTestResultType.NOT_APPLICABLE);
221+
if (wasReadOnly) {
222+
testResultField.setReadOnly(true);
223+
}
224+
} else if (testType == PathogenTestType.SPOLIGOTYPING) {
225+
if (wasReadOnly) {
226+
testResultField.setReadOnly(false);
227+
}
228+
testResultField.setValue(PathogenTestResultType.POSITIVE);
229+
if (wasReadOnly) {
230+
testResultField.setReadOnly(true);
231+
}
232+
} else if (wasReadOnly) {
233+
// Field was read-only but no longer meets conditions for auto-set values
217234
testResultField.setReadOnly(false);
218-
}
219-
testResultField.setValue(PathogenTestResultType.NOT_APPLICABLE);
220-
if (wasReadOnly) {
221-
testResultField.setReadOnly(true);
222-
}
223-
} else if (testType == PathogenTestType.SPOLIGOTYPING) {
224-
if (wasReadOnly) {
225-
testResultField.setReadOnly(false);
226-
}
227-
testResultField.setValue(PathogenTestResultType.POSITIVE);
228-
if (wasReadOnly) {
229-
testResultField.setReadOnly(true);
235+
testResultField.setValue(null);
230236
}
231237
} else if (wasReadOnly) {
232-
// Field was read-only but no longer meets conditions for auto-set values
238+
// Disease is not TB or testType is null, but field was read-only
233239
testResultField.setReadOnly(false);
234240
testResultField.setValue(null);
235241
}
236-
} else if (wasReadOnly) {
237-
// Disease is not TB or testType is null, but field was read-only
238-
testResultField.setReadOnly(false);
239-
testResultField.setValue(null);
240-
}
241242

242-
drugSusceptibilityField.updateFieldsVisibility(disease, testType);
243-
}else if (!FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG) && DiseaseHelper.checkDiseaseIsInvasiveBacterialDiseases(disease)){
244-
drugSusceptibilityField.updateFieldsVisibility(disease, testType);
245-
}else{
246-
testResultField.setReadOnly(false);
247-
testResultField.setValue(null);
248-
testResultField.setEnabled(true);
243+
drugSusceptibilityField.updateFieldsVisibility(disease, testType);
244+
} else {
245+
if (disease != Disease.TUBERCULOSIS && (DiseaseHelper.checkDiseaseIsInvasiveBacterialDiseases(disease) && testType == PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY)) { // for non lux tb no drug susceptibility
246+
drugSusceptibilityField.updateFieldsVisibility(disease, testType);
247+
drugSusceptibilityField.setVisible(true);
248+
} else {
249+
if (drugSusceptibilityField != null) {
250+
drugSusceptibilityField.setVisible(false);
251+
drugSusceptibilityField.updateFieldsVisibility(disease, testType);
252+
}
253+
}
254+
}
249255
}
250256
}
251257

@@ -391,13 +397,13 @@ protected void addFields() {
391397
TextField patternProfileField = addField(PathogenTestDto.PATTERN_PROFILE, TextField.class);
392398
patternProfileField.setVisible(false);
393399

394-
drugSusceptibilityField = (DrugSusceptibilityForm) addField(
395-
PathogenTestDto.DRUG_SUSCEPTIBILITY,
396-
new DrugSusceptibilityForm(
397-
FieldVisibilityCheckers.withCountry(FacadeProvider.getConfigFacade().getCountryLocale()),
398-
UiFieldAccessCheckers.getDefault(true, FacadeProvider.getConfigFacade().getCountryLocale())));
399-
drugSusceptibilityField.setCaption(null);
400-
drugSusceptibilityField.setVisible(false);
400+
drugSusceptibilityField = (DrugSusceptibilityForm) addField(
401+
PathogenTestDto.DRUG_SUSCEPTIBILITY,
402+
new DrugSusceptibilityForm(
403+
FieldVisibilityCheckers.withCountry(FacadeProvider.getConfigFacade().getCountryLocale()),
404+
UiFieldAccessCheckers.getDefault(true, FacadeProvider.getConfigFacade().getCountryLocale())));
405+
drugSusceptibilityField.setCaption(null);
406+
drugSusceptibilityField.setVisible(false);
401407

402408
if (FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG)) {
403409
//tuberculosis-pcr test specification
@@ -640,7 +646,7 @@ protected void addFields() {
640646
FieldVisibilityCheckers.withDisease(disease),
641647
PathogenStrainCallStatus.class);
642648

643-
updateTuberculosisFieldSpecifications((PathogenTestType) testTypeField.getValue(), disease);
649+
updateDrugSusceptibilityFieldSpecifications((PathogenTestType) testTypeField.getValue(), disease);
644650
}
645651
});
646652
diseaseVariantField.addValueChangeListener(e -> {
@@ -664,18 +670,21 @@ protected void addFields() {
664670
} else {
665671
testResultField.clear();
666672
}
673+
674+
updateDrugSusceptibilityFieldSpecifications(testType, (Disease) diseaseField.getValue());
675+
667676
seroTypeMetCB.setVisible(disease == Disease.INVASIVE_PNEUMOCOCCAL_INFECTION && PathogenTestType.SEROGROUPING.equals(testType));
668677
seroTypeTF.setVisible(disease == Disease.INVASIVE_PNEUMOCOCCAL_INFECTION && seroGrpTests.contains(testType));
669678
seroGrpSepcCB.setVisible(disease == Disease.INVASIVE_MENINGOCOCCAL_INFECTION && seroGrpTests.contains(testType));
670679
// for enabling the test result, finding configured country and disease
671680
boolean isLuxTbAntiSus = FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG)
672681
&& Disease.TUBERCULOSIS.equals((Disease) diseaseField.getValue()) && PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY.equals(testType);
673682
if(isLuxTbAntiSus){
674-
testResultField.setEnabled(true);
675-
}else {
676-
testResultField.setEnabled(!seroGrpTests.contains(testType) && !PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY.equals(testType));
683+
seroGrpTests = new ArrayList<>(seroGrpTests);
684+
seroGrpTests.add(testType);
677685
}
678-
drugSusceptibilityField.setVisible(isLuxTbAntiSus || DiseaseHelper.checkDiseaseIsInvasiveBacterialDiseases((Disease)diseaseField.getValue()) && PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY.equals(testType));
686+
// for all serogrouping tests and isLuxTbAntiSus the test result field should be disabled
687+
testResultField.setEnabled(!seroGrpTests.contains(testType));
679688
setVisibleClear(
680689
PathogenTestType.PCR_RT_PCR == testType,
681690
PathogenTestDto.CQ_VALUE,
@@ -685,6 +694,13 @@ protected void addFields() {
685694
PathogenTestDto.CT_VALUE_S,
686695
PathogenTestDto.CT_VALUE_ORF_1,
687696
PathogenTestDto.CT_VALUE_RDRP_S);
697+
// If the disease is IMI or IPI and the test type is antibiotic susceptibility,
698+
// then a test result is set to positive and disabled
699+
if (DiseaseHelper.checkDiseaseIsInvasiveBacterialDiseases((Disease) diseaseField.getValue()) && testType == PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY) {
700+
testResultField.setValue(PathogenTestResultType.POSITIVE);
701+
testResultField.setEnabled(false);
702+
}
703+
688704
} else {
689705
setVisibleClear(
690706
testTypeField.getValue() != null,
@@ -695,14 +711,11 @@ protected void addFields() {
695711
testResultField.setEnabled(true);
696712
}
697713

698-
// if (FacadeProvider.getConfigFacade().isConfiguredCountry(CountryHelper.COUNTRY_CODE_LUXEMBOURG)) {
699-
updateTuberculosisFieldSpecifications(testType, (Disease) diseaseField.getValue());
700714
// If disease is IMI or IPI and test type is antibiotic susceptibility, then test result is set to positive
701715
if ((diseaseField.getValue() == Disease.INVASIVE_PNEUMOCOCCAL_INFECTION || diseaseField.getValue() == Disease.INVASIVE_MENINGOCOCCAL_INFECTION)
702716
&& testType == PathogenTestType.ANTIBIOTIC_SUSCEPTIBILITY) {
703717
testResultField.setValue(PathogenTestResultType.POSITIVE);
704718
}
705-
// }
706719
});
707720
lab.addValueChangeListener(event -> {
708721
if (event.getProperty().getValue() != null

0 commit comments

Comments
 (0)