3636import com .vaadin .v7 .ui .ComboBox ;
3737import com .vaadin .v7 .ui .OptionGroup ;
3838import com .vaadin .v7 .ui .TextField ;
39+
3940import de .symeda .sormas .api .Disease ;
4041import de .symeda .sormas .api .FacadeProvider ;
4142import de .symeda .sormas .api .caze .CaseDataDto ;
@@ -283,40 +284,40 @@ protected void addFields() {
283284 });
284285 facilityTypeGroup .setValue (FacilityTypeGroup .MEDICAL_FACILITY ); // default value
285286
286- facilityType .addValueChangeListener (e -> {
287- FieldHelper .removeItems (facility );
288- if (facilityType .getValue () != null && district .getValue () != null ) {
289- if (community .getValue () != null ) {
290- FieldHelper .updateItems (
291- facility ,
292- FacadeProvider .getFacilityFacade ()
293- .getActiveFacilitiesByCommunityAndType (
294- (CommunityReferenceDto ) community .getValue (),
295- (FacilityType ) facilityType .getValue (),
296- true ,
297- false ));
298- } else {
299- FieldHelper .updateItems (
300- facility ,
301- FacadeProvider .getFacilityFacade ()
302- .getActiveFacilitiesByDistrictAndType (
303- (DistrictReferenceDto ) district .getValue (),
304- (FacilityType ) facilityType .getValue (),
305- true ,
306- false ));
307- }
308- }
309- });
310- warningLayout = VaadinUiUtil .createWarningComponent (I18nProperties .getString (Strings .pseudonymizedCasesSelectedWarning ));
311- facilityOrHome .addValueChangeListener (e -> {
312- FieldHelper .removeItems (facility );
313- if (TypeOfPlace .FACILITY .equals (facilityOrHome .getValue ())) {
314- if (facilityTypeGroup .getValue () == null ) {
315- facilityTypeGroup .setValue (FacilityTypeGroup .MEDICAL_FACILITY );
316- }
317- if (facilityType .getValue () == null && FacilityTypeGroup .MEDICAL_FACILITY .equals (facilityTypeGroup .getValue ())) {
318- facilityType .setValue (FacilityType .HOSPITAL );
319- }
287+ facilityType .addValueChangeListener (e -> {
288+ FieldHelper .removeItems (facility );
289+ if (facilityType .getValue () != null && district .getValue () != null ) {
290+ if (community .getValue () != null ) {
291+ FieldHelper .updateItems (
292+ facility ,
293+ FacadeProvider .getFacilityFacade ()
294+ .getActiveFacilitiesByCommunityAndType (
295+ (CommunityReferenceDto ) community .getValue (),
296+ (FacilityType ) facilityType .getValue (),
297+ true ,
298+ false ));
299+ } else {
300+ FieldHelper .updateItems (
301+ facility ,
302+ FacadeProvider .getFacilityFacade ()
303+ .getActiveFacilitiesByDistrictAndType (
304+ (DistrictReferenceDto ) district .getValue (),
305+ (FacilityType ) facilityType .getValue (),
306+ true ,
307+ false ));
308+ }
309+ }
310+ });
311+ warningLayout = VaadinUiUtil .createWarningComponent (I18nProperties .getString (Strings .pseudonymizedCasesSelectedWarning ));
312+ facilityOrHome .addValueChangeListener (e -> {
313+ FieldHelper .removeItems (facility );
314+ if (TypeOfPlace .FACILITY .equals (facilityOrHome .getValue ())) {
315+ if (facilityTypeGroup .getValue () == null ) {
316+ facilityTypeGroup .setValue (FacilityTypeGroup .MEDICAL_FACILITY );
317+ }
318+ if (facilityType .getValue () == null && FacilityTypeGroup .MEDICAL_FACILITY .equals (facilityTypeGroup .getValue ())) {
319+ facilityType .setValue (FacilityType .HOSPITAL );
320+ }
320321
321322 if (facilityType .getValue () != null ) {
322323 updateFacility ((DistrictReferenceDto ) district .getValue (), (CommunityReferenceDto ) community .getValue (), facility );
@@ -343,58 +344,63 @@ protected void addFields() {
343344
344345 region .addItems (FacadeProvider .getRegionFacade ().getAllActiveAsReference ());
345346
346- FieldHelper .setRequiredWhen (getFieldGroup (), diseaseCheckBox , Arrays .asList (CaseBulkEditData .DISEASE ), Arrays .asList (true ));
347- FieldHelper
348- .setRequiredWhen (getFieldGroup (), classificationCheckBox , Arrays .asList (CaseBulkEditData .CASE_CLASSIFICATION ), Arrays .asList (true ));
349- FieldHelper
350- .setRequiredWhen (getFieldGroup (), investigationStatusCheckBox , Arrays .asList (CaseBulkEditData .INVESTIGATION_STATUS ), Arrays .asList (true ));
351- FieldHelper .setRequiredWhen (getFieldGroup (), outcomeCheckBox , Arrays .asList (CaseBulkEditData .OUTCOME ), Arrays .asList (true ));
352- FieldHelper .setRequiredWhen (
353- getFieldGroup (),
354- healthFacilityCheckbox ,
355- Arrays .asList (CaseBulkEditData .REGION , CaseBulkEditData .DISTRICT , CaseBulkEditData .HEALTH_FACILITY ),
356- Arrays .asList (true ));
357- FieldHelper .setRequiredWhen (healthFacilityCheckbox , Arrays .asList (facilityTypeGroup , facilityType , facilityOrHome ), Arrays .asList (true ), false , null );
358- FieldHelper .setVisibleWhen (
359- facilityOrHome ,
360- Arrays .asList (facilityTypeGroup , facilityType , facility ),
361- Collections .singletonList (TypeOfPlace .FACILITY ),
362- false );
363- FieldHelper .setRequiredWhen (
364- facilityOrHome ,
365- Arrays .asList (facilityTypeGroup , facilityType , facility ),
366- Collections .singletonList (TypeOfPlace .FACILITY ),
367- false ,
368- null );
369- diseaseCheckBox .addValueChangeListener (e -> {
370- disease .setEnabled ((boolean ) e .getProperty ().getValue ());
371- });
372- classificationCheckBox .addValueChangeListener (e -> {
373- caseClassification .setEnabled ((boolean ) e .getProperty ().getValue ());
374- });
375- investigationStatusCheckBox .addValueChangeListener (e -> {
376- investigationStatus .setEnabled ((boolean ) e .getProperty ().getValue ());
377- });
378- outcomeCheckBox .addValueChangeListener (e -> {
379- outcome .setEnabled ((boolean ) e .getProperty ().getValue ());
380- });
381- healthFacilityCheckbox .addValueChangeListener (e -> {
382- region .setEnabled ((boolean ) e .getProperty ().getValue ());
383- district .setEnabled ((boolean ) e .getProperty ().getValue ());
384- community .setEnabled ((boolean ) e .getProperty ().getValue ());
385- facilityTypeGroup .setEnabled ((boolean ) e .getProperty ().getValue ());
386- facilityOrHome .setEnabled ((boolean ) e .getProperty ().getValue ());
387- facilityOrHome .setRequired ((boolean ) e .getProperty ().getValue ());
388- healthFacilityDetails .setEnabled ((boolean ) e .getProperty ().getValue ());
389- facilityType .setEnabled ((boolean ) e .getProperty ().getValue ());
390- facility .setEnabled ((boolean ) e .getProperty ().getValue ());
391- if ((boolean ) e .getProperty ().getValue ()) {
392- FieldHelper .addSoftRequiredStyle (community );
393- } else {
394- FieldHelper .removeSoftRequiredStyle (community );
395- }
396- });
397- }
347+ FieldHelper .setRequiredWhen (getFieldGroup (), diseaseCheckBox , Arrays .asList (CaseBulkEditData .DISEASE ), Arrays .asList (true ));
348+ FieldHelper
349+ .setRequiredWhen (getFieldGroup (), classificationCheckBox , Arrays .asList (CaseBulkEditData .CASE_CLASSIFICATION ), Arrays .asList (true ));
350+ FieldHelper
351+ .setRequiredWhen (getFieldGroup (), investigationStatusCheckBox , Arrays .asList (CaseBulkEditData .INVESTIGATION_STATUS ), Arrays .asList (true ));
352+ FieldHelper .setRequiredWhen (getFieldGroup (), outcomeCheckBox , Arrays .asList (CaseBulkEditData .OUTCOME ), Arrays .asList (true ));
353+ FieldHelper .setRequiredWhen (
354+ getFieldGroup (),
355+ healthFacilityCheckbox ,
356+ Arrays .asList (CaseBulkEditData .REGION , CaseBulkEditData .DISTRICT , CaseBulkEditData .HEALTH_FACILITY ),
357+ Arrays .asList (true ));
358+ FieldHelper .setRequiredWhen (
359+ healthFacilityCheckbox ,
360+ Arrays .asList (facilityTypeGroup , facilityType , facilityOrHome ),
361+ Arrays .asList (true ),
362+ false ,
363+ null );
364+ FieldHelper .setVisibleWhen (
365+ facilityOrHome ,
366+ Arrays .asList (facilityTypeGroup , facilityType , facility ),
367+ Collections .singletonList (TypeOfPlace .FACILITY ),
368+ false );
369+ FieldHelper .setRequiredWhen (
370+ facilityOrHome ,
371+ Arrays .asList (facilityTypeGroup , facilityType , facility ),
372+ Collections .singletonList (TypeOfPlace .FACILITY ),
373+ false ,
374+ null );
375+ diseaseCheckBox .addValueChangeListener (e -> {
376+ disease .setEnabled ((boolean ) e .getProperty ().getValue ());
377+ });
378+ classificationCheckBox .addValueChangeListener (e -> {
379+ caseClassification .setEnabled ((boolean ) e .getProperty ().getValue ());
380+ });
381+ investigationStatusCheckBox .addValueChangeListener (e -> {
382+ investigationStatus .setEnabled ((boolean ) e .getProperty ().getValue ());
383+ });
384+ outcomeCheckBox .addValueChangeListener (e -> {
385+ outcome .setEnabled ((boolean ) e .getProperty ().getValue ());
386+ });
387+ healthFacilityCheckbox .addValueChangeListener (e -> {
388+ region .setEnabled ((boolean ) e .getProperty ().getValue ());
389+ district .setEnabled ((boolean ) e .getProperty ().getValue ());
390+ community .setEnabled ((boolean ) e .getProperty ().getValue ());
391+ facilityTypeGroup .setEnabled ((boolean ) e .getProperty ().getValue ());
392+ facilityOrHome .setEnabled ((boolean ) e .getProperty ().getValue ());
393+ facilityOrHome .setRequired ((boolean ) e .getProperty ().getValue ());
394+ healthFacilityDetails .setEnabled ((boolean ) e .getProperty ().getValue ());
395+ facilityType .setEnabled ((boolean ) e .getProperty ().getValue ());
396+ facility .setEnabled ((boolean ) e .getProperty ().getValue ());
397+ if ((boolean ) e .getProperty ().getValue ()) {
398+ FieldHelper .addSoftRequiredStyle (community );
399+ } else {
400+ FieldHelper .removeSoftRequiredStyle (community );
401+ }
402+ });
403+ }
398404
399405 @ Override
400406 protected String createHtmlLayout () {
@@ -461,12 +467,10 @@ private void updateFacilityFields(ComboBox cbFacility, TextField tfFacilityDetai
461467 if (!visibleAndRequired ) {
462468 tfFacilityDetails .clear ();
463469 }
464- } else {
465- if (TypeOfPlace .FACILITY .equals (facilityOrHome .getValue ())) {
466- tfFacilityDetails .setVisible (false );
467- tfFacilityDetails .setRequired (false );
468- tfFacilityDetails .clear ();
469- }
470+ } else if (TypeOfPlace .FACILITY .equals (facilityOrHome .getValue ())) {
471+ tfFacilityDetails .setVisible (false );
472+ tfFacilityDetails .setRequired (false );
473+ tfFacilityDetails .clear ();
470474 }
471475 }
472476}
0 commit comments