3333import java .util .HashMap ;
3434import java .util .List ;
3535import java .util .Map ;
36- import java .util .function .BiConsumer ;
3736import java .util .function .Consumer ;
3837
3938import org .apache .commons .collections4 .CollectionUtils ;
@@ -170,6 +169,56 @@ public class PathogenTestForm extends AbstractEditForm<PathogenTestDto> {
170169 }
171170 });
172171
172+ public static final Map <Object , List <Object >> RIFAMPICIN_RESISTANT_VISIBILITY_CONDITIONS = Collections .unmodifiableMap (new HashMap <>() {
173+
174+ {
175+ put (PathogenTestDto .TESTED_DISEASE , Collections .unmodifiableList (Arrays .asList (Disease .LATENT_TUBERCULOSIS , Disease .TUBERCULOSIS )));
176+ put (PathogenTestDto .TEST_TYPE , Collections .unmodifiableList (Arrays .asList (PathogenTestType .PCR_RT_PCR )));
177+ put (PathogenTestDto .TEST_RESULT , Collections .unmodifiableList (Arrays .asList (PathogenTestResultType .POSITIVE )));
178+ }
179+ });
180+
181+ public static final Map <Object , List <Object >> TEST_SCALE_VISIBILITY_CONDITIONS = Collections .unmodifiableMap (new HashMap <>() {
182+
183+ {
184+ put (PathogenTestDto .TESTED_DISEASE , Collections .unmodifiableList (Arrays .asList (Disease .LATENT_TUBERCULOSIS , Disease .TUBERCULOSIS )));
185+ put (PathogenTestDto .TEST_TYPE , Collections .unmodifiableList (Arrays .asList (PathogenTestType .MICROSCOPY )));
186+ }
187+ });
188+
189+ public static final Map <Object , List <Object >> STRAIN_CALL_STATUS_VISIBILITY_CONDITIONS = Collections .unmodifiableMap (new HashMap <>() {
190+
191+ {
192+ put (PathogenTestDto .TESTED_DISEASE , Collections .unmodifiableList (Arrays .asList (Disease .LATENT_TUBERCULOSIS , Disease .TUBERCULOSIS )));
193+ put (PathogenTestDto .TEST_TYPE , Collections .unmodifiableList (Arrays .asList (PathogenTestType .BEIJINGGENOTYPING )));
194+ }
195+ });
196+
197+ public static final Map <Object , List <Object >> SPECIE_VISIBILITY_CONDITIONS = Collections .unmodifiableMap (new HashMap <>() {
198+
199+ {
200+ put (PathogenTestDto .TESTED_DISEASE , Collections .unmodifiableList (Arrays .asList (Disease .LATENT_TUBERCULOSIS , Disease .TUBERCULOSIS )));
201+ put (PathogenTestDto .TEST_TYPE , Collections .unmodifiableList (Arrays .asList (PathogenTestType .SPOLIGOTYPING )));
202+ put (PathogenTestDto .TEST_RESULT , Collections .unmodifiableList (Arrays .asList (PathogenTestResultType .POSITIVE )));
203+ }
204+ });
205+
206+ public static final Map <Object , List <Object >> PATTERN_PROFILE_VISIBILITY_CONDITIONS = Collections .unmodifiableMap (new HashMap <>() {
207+
208+ {
209+ put (PathogenTestDto .TESTED_DISEASE , Collections .unmodifiableList (Arrays .asList (Disease .LATENT_TUBERCULOSIS , Disease .TUBERCULOSIS )));
210+ put (PathogenTestDto .TEST_TYPE , Collections .unmodifiableList (Arrays .asList (PathogenTestType .MIRU_PATTERN_CODE )));
211+ }
212+ });
213+
214+ public static final Map <Object , List <Object >> PCR_TEST_SPECIFICATION_VISIBILITY_CONDITIONS = Collections .unmodifiableMap (new HashMap <>() {
215+
216+ {
217+ put (PathogenTestDto .TESTED_DISEASE , Collections .unmodifiableList (Arrays .asList (Disease .CORONAVIRUS )));
218+ put (PathogenTestDto .TEST_TYPE , Collections .unmodifiableList (Arrays .asList (PathogenTestType .PCR_RT_PCR )));
219+ }
220+ });
221+
173222 private SampleDto sample ;
174223 private EnvironmentSampleDto environmentSample ;
175224 private AbstractSampleForm sampleForm ;
@@ -265,63 +314,42 @@ private void updateDrugSusceptibilityFieldSpecifications(PathogenTestType testTy
265314 drugSusceptibilityField .updateFieldsVisibility (disease , testType );
266315 }
267316
268- if (disease != null ) {
269- if ((FacadeProvider .getConfigFacade ().isConfiguredCountry (CountryHelper .COUNTRY_CODE_LUXEMBOURG ))) {
270- boolean wasReadOnly = testResultField .isReadOnly ();
271-
272- if (List
273- .of (
274- Disease .TUBERCULOSIS ,
275- Disease .LATENT_TUBERCULOSIS ,
276- Disease .INVASIVE_MENINGOCOCCAL_INFECTION ,
277- Disease .INVASIVE_PNEUMOCOCCAL_INFECTION )
278- .contains (disease )
279- && testType != null ) {
280- if (List .of (Disease .TUBERCULOSIS , Disease .LATENT_TUBERCULOSIS ).contains (disease )) {
281- if (Arrays
282- .asList (
283- PathogenTestType .BEIJINGGENOTYPING ,
284- PathogenTestType .MIRU_PATTERN_CODE ,
285- PathogenTestType .ANTIBIOTIC_SUSCEPTIBILITY )
286- .contains (testType )) {
287- if (wasReadOnly ) {
288- testResultField .setReadOnly (false );
289- }
290- testResultField .setValue (PathogenTestResultType .NOT_APPLICABLE );
291- if (wasReadOnly ) {
292- testResultField .setReadOnly (true );
293- }
294- } else if (testType == PathogenTestType .SPOLIGOTYPING ) {
295- if (wasReadOnly ) {
296- testResultField .setReadOnly (false );
297- }
298- testResultField .setValue (PathogenTestResultType .POSITIVE );
299- if (wasReadOnly ) {
300- testResultField .setReadOnly (true );
301- }
302- } else if (wasReadOnly ) {
303- // Field was read-only but no longer meets conditions for auto-set values
304- testResultField .setReadOnly (false );
305- testResultField .setValue (null );
306- }
307- } else if (List .of (Disease .INVASIVE_MENINGOCOCCAL_INFECTION ).contains (disease )) {
308- if (Arrays .asList (PathogenTestType .ANTIBIOTIC_SUSCEPTIBILITY ).contains (testType )) {
309- if (wasReadOnly ) {
310- testResultField .setReadOnly (false );
311- }
312- testResultField .setValue (PathogenTestResultType .NOT_APPLICABLE );
313- if (wasReadOnly ) {
314- testResultField .setReadOnly (true );
315- }
316- }
317- }
318- } else if (wasReadOnly ) {
319- // Disease is not TB or testType is null, but field was read-only
320- testResultField .setReadOnly (false );
321- testResultField .setValue (null );
322- }
317+ // if the disease is null, means that we are dealing with a environment sample
318+ // and we don't need to update the result field
319+ if (disease == null ) {
320+ return ;
321+ }
322+
323+ // if the test type is null we just clear the result field
324+ if (testType == null ) {
325+ testResultField .setValue (null );
326+ return ;
327+ }
328+
329+ // FIXME: why was this here originally?
330+ // TODO: move this to another place, should be in listeners for disease/testType.
331+
332+ if ((FacadeProvider .getConfigFacade ().isConfiguredCountry (CountryHelper .COUNTRY_CODE_LUXEMBOURG ))) {
333+
334+ // testResult=NOT_APPLICABLE for Tuberculosis diseases, test types BEIJINGGENOTYPING,MIRU_PATTERN_CODE,ANTIBIOTIC_SUSCEPTIBILITY
335+ if ((disease == Disease .LATENT_TUBERCULOSIS || disease == Disease .TUBERCULOSIS )
336+ && (testType == PathogenTestType .BEIJINGGENOTYPING
337+ || testType == PathogenTestType .MIRU_PATTERN_CODE
338+ || testType == PathogenTestType .ANTIBIOTIC_SUSCEPTIBILITY )) {
339+ testResultField .setValue (PathogenTestResultType .NOT_APPLICABLE );
340+ }
341+
342+ // testResult=POSITIVE for Tuberculosis diseases, test type SPOLIGOTYPING
343+ if ((disease == Disease .LATENT_TUBERCULOSIS || disease == Disease .TUBERCULOSIS ) && (testType == PathogenTestType .SPOLIGOTYPING )) {
344+ testResultField .setValue (PathogenTestResultType .POSITIVE );
345+ }
346+
347+ // testResult=NOT_APPLICABLE for IMI, test type ANTIBIOTIC_SUSCEPTIBILITY
348+ if (disease == Disease .INVASIVE_MENINGOCOCCAL_INFECTION && testType == PathogenTestType .ANTIBIOTIC_SUSCEPTIBILITY ) {
349+ testResultField .setValue (PathogenTestResultType .NOT_APPLICABLE );
323350 }
324351 }
352+
325353 }
326354
327355 private Date getSampleDate () {
@@ -526,49 +554,16 @@ protected void addFields() {
526554
527555 if (FacadeProvider .getConfigFacade ().isConfiguredCountry (CountryHelper .COUNTRY_CODE_LUXEMBOURG )) {
528556 //tuberculosis-pcr test specification
529- Map <Object , List <Object >> tuberculosisPcrDependencies = new HashMap <>() {
530-
531- {
532- put (PathogenTestDto .TESTED_DISEASE , Arrays .asList (Disease .TUBERCULOSIS , Disease .LATENT_TUBERCULOSIS ));
533- put (PathogenTestDto .TEST_TYPE , Arrays .asList (PathogenTestType .PCR_RT_PCR ));
534- put (PathogenTestDto .TEST_RESULT , Arrays .asList (PathogenTestResultType .POSITIVE ));
535- }
536- };
537- FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .RIFAMPICIN_RESISTANT , tuberculosisPcrDependencies , true );
557+ FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .RIFAMPICIN_RESISTANT , RIFAMPICIN_RESISTANT_VISIBILITY_CONDITIONS , true );
538558
539559 //tuberculosis-microscopy test specification
540- Map <Object , List <Object >> tuberculosisMicroscopyDependencies = new HashMap <>() {
541-
542- {
543- put (PathogenTestDto .TESTED_DISEASE , Arrays .asList (Disease .TUBERCULOSIS , Disease .LATENT_TUBERCULOSIS ));
544- put (PathogenTestDto .TEST_TYPE , Arrays .asList (PathogenTestType .MICROSCOPY ));
545- }
546- };
547- FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .TEST_SCALE , tuberculosisMicroscopyDependencies , true );
548- //FieldHelper.setRequiredWhen(getFieldGroup(), PathogenTestDto.TEST_SCALE, tuberculosisMicroscopyDependencies);
560+ FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .TEST_SCALE , TEST_SCALE_VISIBILITY_CONDITIONS , true );
549561
550562 //tuberculosis-beijinggenotyping test specification
551- Map <Object , List <Object >> tuberculosisBeijingDependencies = new HashMap <>() {
552-
553- {
554- put (PathogenTestDto .TESTED_DISEASE , Arrays .asList (Disease .TUBERCULOSIS , Disease .LATENT_TUBERCULOSIS ));
555- put (PathogenTestDto .TEST_TYPE , Arrays .asList (PathogenTestType .BEIJINGGENOTYPING ));
556- }
557- };
558- FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .STRAIN_CALL_STATUS , tuberculosisBeijingDependencies , true );
559- //FieldHelper.setRequiredWhen(getFieldGroup(), PathogenTestDto.STRAIN_CALL_STATUS, tuberculosisBeijingDependencies);
563+ FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .STRAIN_CALL_STATUS , STRAIN_CALL_STATUS_VISIBILITY_CONDITIONS , true );
560564
561565 //tuberculosis-spoligotyping test specification
562- Map <Object , List <Object >> tuberculosisSpoligotypingDependencies = new HashMap <>() {
563-
564- {
565- put (PathogenTestDto .TESTED_DISEASE , Arrays .asList (Disease .TUBERCULOSIS , Disease .LATENT_TUBERCULOSIS ));
566- put (PathogenTestDto .TEST_TYPE , Arrays .asList (PathogenTestType .SPOLIGOTYPING ));
567- put (PathogenTestDto .TEST_RESULT , Arrays .asList (PathogenTestResultType .POSITIVE ));
568- }
569- };
570- FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .SPECIE , tuberculosisSpoligotypingDependencies , true );
571- //FieldHelper.setRequiredWhen(getFieldGroup(), PathogenTestDto.SPECIE, tuberculosisSpoligotypingDependencies);
566+ FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .SPECIE , SPECIE_VISIBILITY_CONDITIONS , true );
572567
573568 //tuberculosis-miru-code test specification
574569 Map <Object , List <Object >> tuberculosisMiruCodeDependencies = new HashMap <>() {
@@ -580,28 +575,6 @@ protected void addFields() {
580575 };
581576 FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .PATTERN_PROFILE , tuberculosisMiruCodeDependencies , true );
582577 //FieldHelper.setRequiredWhen(getFieldGroup(), PathogenTestDto.PATTERN_PROFILE, tuberculosisMiruCodeDependencies);
583-
584- //test result - read only
585- Map <Object , List <Object >> tuberculosisTestResultReadOnlyDependencies = new HashMap <>() {
586-
587- {
588- put (
589- PathogenTestDto .TESTED_DISEASE ,
590- Arrays .asList (
591- Disease .TUBERCULOSIS ,
592- Disease .LATENT_TUBERCULOSIS ,
593- Disease .INVASIVE_MENINGOCOCCAL_INFECTION ,
594- Disease .INVASIVE_PNEUMOCOCCAL_INFECTION ));
595- put (
596- PathogenTestDto .TEST_TYPE ,
597- Arrays .asList (
598- PathogenTestType .BEIJINGGENOTYPING ,
599- PathogenTestType .SPOLIGOTYPING ,
600- PathogenTestType .MIRU_PATTERN_CODE ,
601- PathogenTestType .ANTIBIOTIC_SUSCEPTIBILITY ));
602- }
603- };
604- FieldHelper .setReadOnlyWhen (getFieldGroup (), PathogenTestDto .TEST_RESULT , tuberculosisTestResultReadOnlyDependencies , true , false );
605578 }
606579
607580 seroTypeTF .setVisible (false );
@@ -965,6 +938,7 @@ protected void addFields() {
965938 NullableOptionGroup testResultVerifiedField = addField (PathogenTestDto .TEST_RESULT_VERIFIED , NullableOptionGroup .class );
966939 testResultVerifiedField .setRequired (true );
967940 addField (PathogenTestDto .PRELIMINARY ).addStyleName (CssStyles .VSPACE_4 );
941+
968942 CheckBox fourFoldIncrease = addField (PathogenTestDto .FOUR_FOLD_INCREASE_ANTIBODY_TITER , CheckBox .class );
969943 CssStyles .style (fourFoldIncrease , VSPACE_3 , VSPACE_TOP_4 );
970944 fourFoldIncrease .setVisible (false );
@@ -990,14 +964,8 @@ protected void addFields() {
990964 Label prescriberHeadingLabel = new Label (I18nProperties .getCaption (Captions .PathogenTest_prescriber ));
991965 prescriberHeadingLabel .addStyleName (H3 );
992966 getContent ().addComponent (prescriberHeadingLabel , PRESCRIBER_HEADING_LOC );
993- Map <Object , List <Object >> pcrTestSpecificationVisibilityDependencies = new HashMap <>() {
994967
995- {
996- put (PathogenTestDto .TESTED_DISEASE , Arrays .asList (Disease .CORONAVIRUS ));
997- put (PathogenTestDto .TEST_TYPE , Arrays .asList (PathogenTestType .PCR_RT_PCR ));
998- }
999- };
1000- FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .PCR_TEST_SPECIFICATION , pcrTestSpecificationVisibilityDependencies , true );
968+ FieldHelper .setVisibleWhen (getFieldGroup (), PathogenTestDto .PCR_TEST_SPECIFICATION , PCR_TEST_SPECIFICATION_VISIBILITY_CONDITIONS , true );
1001969 FieldHelper .setVisibleWhen (
1002970 getFieldGroup (),
1003971 PathogenTestDto .TEST_TYPE_TEXT ,
@@ -1169,22 +1137,6 @@ protected void addFields() {
11691137 diseaseVariantDetailsField .setVisible (diseaseVariant != null && diseaseVariant .matchPropertyValue (DiseaseVariant .HAS_DETAILS , true ));
11701138 });
11711139
1172- BiConsumer <Disease , PathogenTestType > resultField = (disease , testType ) -> {
1173- final boolean testResultFieldReadOnly = testResultField .isReadOnly ();
1174- testResultField .setReadOnly (false );
1175-
1176- if (RESULT_FIELD_DECISION_MAP .containsKey (disease ) && RESULT_FIELD_DECISION_MAP .get (disease ).contains (testType )) {
1177- testResultField .setValue (PathogenTestResultType .POSITIVE );
1178- testResultField .setEnabled (false );
1179- } else {
1180- testResultField .clear ();
1181- testResultField .setEnabled (true );
1182- }
1183-
1184- testResultField .setReadOnly (testResultFieldReadOnly );
1185- updateDrugSusceptibilityFieldSpecifications (testType , (Disease ) diseaseField .getValue ());
1186- };
1187-
11881140 testTypeField .addValueChangeListener (e -> {
11891141 PathogenTestType testType = (PathogenTestType ) e .getProperty ().getValue ();
11901142 if (testType != null ) {
@@ -1249,9 +1201,19 @@ protected void addFields() {
12491201 testResultField .clear ();
12501202 testResultField .setEnabled (true );
12511203 }
1252- resultField .accept ((Disease ) diseaseField .getValue (), testType );
1204+
1205+ if (RESULT_FIELD_DECISION_MAP .containsKey (disease ) && RESULT_FIELD_DECISION_MAP .get (disease ).contains (testType )) {
1206+ testResultField .setValue (PathogenTestResultType .POSITIVE );
1207+ } else {
1208+ testResultField .clear ();
1209+ }
1210+
1211+ updateDrugSusceptibilityFieldSpecifications (testType , (Disease ) diseaseField .getValue ());
12531212 });
1254- lab .addValueChangeListener (event -> {
1213+
1214+ lab .addValueChangeListener (event ->
1215+
1216+ {
12551217 if (event .getProperty ().getValue () != null
12561218 && ((FacilityReferenceDto ) event .getProperty ().getValue ()).getUuid ().equals (FacilityDto .OTHER_FACILITY_UUID )) {
12571219 labDetails .setVisible (true );
@@ -1292,4 +1254,13 @@ protected void addFields() {
12921254 || isVisibleAllowed (PathogenTestDto .PRESCRIBER_CITY )
12931255 || isVisibleAllowed (PathogenTestDto .PRESCRIBER_COUNTRY ));
12941256 }
1257+
1258+ static class TestTypeValueChangeListener implements ValueChangeListener {
1259+
1260+ @ Override
1261+ public void valueChange (com .vaadin .v7 .data .Property .ValueChangeEvent event ) {
1262+ // TODO Auto-generated method stub
1263+
1264+ }
1265+ }
12951266}
0 commit comments