11package de .symeda .sormas .ui .caze ;
22
3+ import static de .symeda .sormas .ui .utils .LayoutUtil .filterLocs ;
4+ import static de .symeda .sormas .ui .utils .LayoutUtil .filterLocsCss ;
5+ import static de .symeda .sormas .ui .utils .LayoutUtil .loc ;
6+
7+ import java .util .Date ;
8+ import java .util .stream .Stream ;
9+
310import com .vaadin .server .Page ;
411import com .vaadin .server .Sizeable ;
512import com .vaadin .ui .Button ;
1421import com .vaadin .v7 .ui .ComboBox ;
1522import com .vaadin .v7 .ui .Field ;
1623import com .vaadin .v7 .ui .TextField ;
24+
1725import de .symeda .sormas .api .FacadeProvider ;
1826import de .symeda .sormas .api .caze .CaseClassification ;
1927import de .symeda .sormas .api .caze .CaseCriteria ;
4755import de .symeda .sormas .ui .utils .FieldConfiguration ;
4856import de .symeda .sormas .ui .utils .FieldHelper ;
4957
50- import java .util .Date ;
51- import java .util .stream .Stream ;
52-
53- import static de .symeda .sormas .ui .utils .LayoutUtil .filterLocs ;
54- import static de .symeda .sormas .ui .utils .LayoutUtil .filterLocsCss ;
55- import static de .symeda .sormas .ui .utils .LayoutUtil .loc ;
56-
5758public class CaseFilterForm extends AbstractFilterForm <CaseCriteria > {
5859
5960 private static final long serialVersionUID = -8326451364091398731L ;
@@ -125,8 +126,9 @@ public void addMoreFilters(CustomLayout moreFiltersContainer) {
125126 presentConditionField .setInputPrompt (I18nProperties .getPrefixCaption (PersonDto .I18N_PREFIX , PersonDto .PRESENT_CONDITION ));
126127
127128 UserDto user = UserProvider .getCurrent ().getUser ();
129+ ComboBox regionField = null ;
128130 if (user .getRegion () == null ) {
129- ComboBox regionField = addField (moreFiltersContainer , FieldConfiguration .pixelSized (CaseDataDto .REGION , 140 ));
131+ regionField = addField (moreFiltersContainer , FieldConfiguration .pixelSized (CaseDataDto .REGION , 140 ));
130132 regionField .addItems (FacadeProvider .getRegionFacade ().getAllActiveAsReference ());
131133 }
132134
@@ -270,54 +272,157 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC
270272
271273 CaseCriteria criteria = getValue ();
272274
275+ ComboBox districtField = getField (CaseDataDto .DISTRICT );
276+ ComboBox communityField = getField (CaseDataDto .COMMUNITY );
277+ ComboBox facilityTypeField = getField (CaseCriteria .FACILITY_TYPE );
278+ ComboBox facilityField = getField (CaseDataDto .HEALTH_FACILITY );
279+ ComboBox pointOfEntryField = getField (CaseDataDto .POINT_OF_ENTRY );
280+
281+ UserDto user = UserProvider .getCurrent ().getUser ();
282+ DistrictReferenceDto currentDistrict = user .getDistrict () != null ? user .getDistrict () : (DistrictReferenceDto ) districtField .getValue ();
283+ CaseOrigin currentCaseOrigin = (CaseOrigin ) getField (CaseDataDto .CASE_ORIGIN ).getValue ();
284+
273285 switch (propertyId ) {
274286 case CaseDataDto .REGION : {
275- RegionReferenceDto region = (RegionReferenceDto ) event .getProperty ().getValue ();
287+ RegionReferenceDto region = user . getRegion () != null ? user . getRegion () : (RegionReferenceDto ) event .getProperty ().getValue ();
276288
277289 if (!DataHelper .equal (region , criteria .getRegion ())) {
278- getField (CaseDataDto .DISTRICT ).setValue (null );
279- getField (CaseDataDto .COMMUNITY ).setValue (null );
280- getField (CaseCriteria .FACILITY_TYPE_GROUP ).setValue (null );
281- getField (CaseCriteria .FACILITY_TYPE ).setValue (null );
282- getField (CaseDataDto .HEALTH_FACILITY ).setValue (null );
283- getField (CaseDataDto .POINT_OF_ENTRY ).setValue (null );
290+ if (region != null ) {
291+ enableFields (CaseDataDto .DISTRICT );
292+ districtField .addItems (FacadeProvider .getDistrictFacade ().getAllActiveByRegion (region .getUuid ()));
293+ } else {
294+ clearAndDisableFields (
295+ CaseDataDto .DISTRICT ,
296+ CaseDataDto .COMMUNITY ,
297+ CaseCriteria .FACILITY_TYPE_GROUP ,
298+ CaseCriteria .FACILITY_TYPE ,
299+ CaseDataDto .HEALTH_FACILITY );
300+
301+ if (pointOfEntryField != null ) {
302+ pointOfEntryField .setEnabled (false );
303+ }
304+ }
284305 }
285306
286307 break ;
287308 }
288309 case CaseDataDto .DISTRICT : {
289- DistrictReferenceDto district = (DistrictReferenceDto ) event .getProperty ().getValue ();
290-
291- if (!DataHelper .equal (district , criteria .getDistrict ())) {
292- getField (CaseDataDto .COMMUNITY ).setValue (null );
293- getField (CaseCriteria .FACILITY_TYPE_GROUP ).setValue (null );
294- getField (CaseCriteria .FACILITY_TYPE ).setValue (null );
295- getField (CaseDataDto .HEALTH_FACILITY ).setValue (null );
296- getField (CaseDataDto .POINT_OF_ENTRY ).setValue (null );
310+ DistrictReferenceDto newDistrict = (DistrictReferenceDto ) event .getProperty ().getValue ();
311+
312+ if (!DataHelper .equal (newDistrict , criteria .getDistrict ())) {
313+ if (newDistrict != null ) {
314+ enableFields (CaseDataDto .COMMUNITY , CaseCriteria .FACILITY_TYPE_GROUP );
315+ communityField .addItems (FacadeProvider .getCommunityFacade ().getAllActiveByDistrict (newDistrict .getUuid ()));
316+ if (pointOfEntryField != null && currentCaseOrigin == CaseOrigin .POINT_OF_ENTRY ) {
317+ pointOfEntryField .setEnabled (true );
318+ FieldHelper .updateItems (
319+ pointOfEntryField ,
320+ FacadeProvider .getPointOfEntryFacade ().getAllActiveByDistrict (newDistrict .getUuid (), true ));
321+
322+ }
323+ } else {
324+ clearAndDisableFields (
325+ CaseDataDto .COMMUNITY ,
326+ CaseCriteria .FACILITY_TYPE_GROUP ,
327+ CaseCriteria .FACILITY_TYPE ,
328+ CaseDataDto .HEALTH_FACILITY );
329+
330+ if (pointOfEntryField != null ) {
331+ clearAndDisableFields (CaseDataDto .POINT_OF_ENTRY );
332+ }
333+ }
297334 }
298335
299336 break ;
300337 }
301338 case CaseDataDto .COMMUNITY : {
302339 CommunityReferenceDto community = (CommunityReferenceDto ) event .getProperty ().getValue ();
303340 if (!DataHelper .equal (community , criteria .getCommunity ())) {
304- getField (CaseDataDto .HEALTH_FACILITY ).setValue (null );
341+ facilityField .setValue (null );
342+
343+ FacilityType facilityType = (FacilityType ) facilityTypeField .getValue ();
344+
345+ if (facilityType == null ) {
346+ facilityField .removeAllItems ();
347+ } else {
348+ if (community == null ) {
349+ FieldHelper .updateItems (
350+ facilityField ,
351+ FacadeProvider .getFacilityFacade ().getActiveFacilitiesByDistrictAndType (currentDistrict , facilityType , true , false ));
352+ } else {
353+ FieldHelper .updateItems (
354+ facilityField ,
355+ FacadeProvider .getFacilityFacade ().getActiveFacilitiesByCommunityAndType (community , facilityType , true , false ));
356+ }
357+ }
305358 }
306359 break ;
307360 }
308361 case CaseCriteria .FACILITY_TYPE_GROUP : {
309362 FacilityTypeGroup typeGroup = (FacilityTypeGroup ) event .getProperty ().getValue ();
310363 if (!DataHelper .equal (typeGroup , criteria .getFacilityTypeGroup ())) {
311- getField (CaseCriteria .FACILITY_TYPE ).setValue (null );
312- getField (CaseDataDto .HEALTH_FACILITY ).setValue (null );
364+ if (typeGroup != null ) {
365+ enableFields (CaseDataDto .FACILITY_TYPE );
366+ FieldHelper .updateEnumData (facilityTypeField , FacilityType .getAccommodationTypes (typeGroup ));
367+ facilityField .setValue (null );
368+ } else {
369+ clearAndDisableFields (CaseCriteria .FACILITY_TYPE , CaseDataDto .HEALTH_FACILITY );
370+ }
313371 }
372+
314373 break ;
315374 }
316- case CaseCriteria .FACILITY_TYPE :
317- FacilityType type = (FacilityType ) event .getProperty ().getValue ();
318- if (!DataHelper .equal (type , criteria .getFacilityType ())) {
319- getField (CaseDataDto .HEALTH_FACILITY ).setValue (null );
375+ case CaseCriteria .FACILITY_TYPE : {
376+ FacilityType facilityType = (FacilityType ) event .getProperty ().getValue ();
377+ if (!DataHelper .equal (facilityType , criteria .getFacilityType ())) {
378+ if (facilityType == null ) {
379+ clearAndDisableFields (CaseDataDto .HEALTH_FACILITY );
380+ } else {
381+ enableFields (CaseDataDto .HEALTH_FACILITY );
382+ facilityField .setValue (null );
383+
384+ CommunityReferenceDto community = (CommunityReferenceDto ) communityField .getValue ();
385+ if (community == null ) {
386+ FieldHelper .updateItems (
387+ facilityField ,
388+ FacadeProvider .getFacilityFacade ().getActiveFacilitiesByDistrictAndType (currentDistrict , facilityType , true , false ));
389+ } else {
390+ FieldHelper .updateItems (
391+ facilityField ,
392+ FacadeProvider .getFacilityFacade ().getActiveFacilitiesByCommunityAndType (community , facilityType , true , false ));
393+ }
394+ }
320395 }
396+ break ;
397+ }
398+ case CaseCriteria .BIRTHDATE_MM : {
399+ Integer birthMM = (Integer ) event .getProperty ().getValue ();
400+
401+ ComboBox birthDayDD = getField (CaseCriteria .BIRTHDATE_DD );
402+ birthDayDD .setEnabled (birthMM != null );
403+ FieldHelper .updateItems (
404+ birthDayDD ,
405+ DateHelper .getDaysInMonth (
406+ (Integer ) getField (CaseCriteria .BIRTHDATE_MM ).getValue (),
407+ (Integer ) getField (CaseCriteria .BIRTHDATE_YYYY ).getValue ()));
408+
409+ break ;
410+ }
411+ case CaseDataDto .CASE_ORIGIN : {
412+ if (pointOfEntryField != null ) {
413+ CaseOrigin caseOrigin = (CaseOrigin ) event .getProperty ().getValue ();
414+ if (caseOrigin == CaseOrigin .POINT_OF_ENTRY ) {
415+ pointOfEntryField .setEnabled (true );
416+ } else {
417+ clearAndDisableFields (CaseDataDto .POINT_OF_ENTRY );
418+ if (currentDistrict != null ) {
419+ FieldHelper .updateItems (
420+ pointOfEntryField ,
421+ FacadeProvider .getPointOfEntryFacade ().getAllActiveByDistrict (currentDistrict .getUuid (), true ));
422+ }
423+ }
424+ }
425+ }
321426 }
322427 }
323428
@@ -336,10 +441,10 @@ protected Stream<Field> streamFieldsForEmptyCheck(CustomLayout layout) {
336441 @ Override
337442 protected void applyDependenciesOnNewValue (CaseCriteria criteria ) {
338443
339- ComboBox districtField = ( ComboBox ) getField (CaseDataDto .DISTRICT );
444+ ComboBox districtField = getField (CaseDataDto .DISTRICT );
340445 districtField .setEnabled (false );
341446
342- ComboBox communityField = ( ComboBox ) getField (CaseDataDto .COMMUNITY );
447+ ComboBox communityField = getField (CaseDataDto .COMMUNITY );
343448 districtField .setEnabled (false );
344449
345450 UserDto user = UserProvider .getCurrent ().getUser ();
@@ -360,8 +465,8 @@ protected void applyDependenciesOnNewValue(CaseCriteria criteria) {
360465 }
361466 }
362467
363- ComboBox typeGroupField = ( ComboBox ) getField (CaseCriteria .FACILITY_TYPE_GROUP );
364- ComboBox typeField = ( ComboBox ) getField (CaseCriteria .FACILITY_TYPE );
468+ ComboBox typeGroupField = getField (CaseCriteria .FACILITY_TYPE_GROUP );
469+ ComboBox typeField = getField (CaseCriteria .FACILITY_TYPE );
365470
366471 if (user .getDistrict () != null && user .getCommunity () == null ) {
367472 communityField .addItems (FacadeProvider .getCommunityFacade ().getAllActiveByDistrict (user .getDistrict ().getUuid ()));
@@ -377,8 +482,8 @@ protected void applyDependenciesOnNewValue(CaseCriteria criteria) {
377482 typeField .setEnabled (false );
378483 }
379484
380- ComboBox facilityField = ( ComboBox ) getField (CaseDataDto .HEALTH_FACILITY );
381- ComboBox pointOfEntryField = ( ComboBox ) getField (CaseDataDto .POINT_OF_ENTRY );
485+ ComboBox facilityField = getField (CaseDataDto .HEALTH_FACILITY );
486+ ComboBox pointOfEntryField = getField (CaseDataDto .POINT_OF_ENTRY );
382487
383488 DistrictReferenceDto district = criteria .getDistrict ();
384489 FacilityTypeGroup typeGroup = criteria .getFacilityTypeGroup ();
@@ -456,7 +561,7 @@ protected void applyDependenciesOnNewValue(CaseCriteria criteria) {
456561 weekAndDateFilter .getDateToFilter ().setValue (criteria .getNewCaseDateTo ());
457562 }
458563 }
459- ComboBox birthDateDD = ( ComboBox ) getField (CaseCriteria .BIRTHDATE_DD );
564+ ComboBox birthDateDD = getField (CaseCriteria .BIRTHDATE_DD );
460565 if (getField (CaseCriteria .BIRTHDATE_YYYY ).getValue () != null && getField (CaseCriteria .BIRTHDATE_MM ).getValue () != null ) {
461566 birthDateDD .addItems (
462567 DateHelper .getDaysInMonth (
0 commit comments