2323import static de .symeda .sormas .ui .utils .LayoutUtil .fluidRowLocs ;
2424import static de .symeda .sormas .ui .utils .LayoutUtil .loc ;
2525
26+ import java .util .ArrayList ;
2627import java .util .Arrays ;
2728import java .util .Date ;
2829import 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