@@ -254,7 +254,13 @@ public static void initializeFacilityFields(
254254 if (initialCommunity != null && selectedDistrict .equals (initialCommunity .getDistrict ()) && !newCommunities .contains (communityItem )) {
255255 newCommunities .add (communityItem );
256256 }
257- if (typeField .getValue () != null ) {
257+ if (typeField == null ) {
258+ List <Item > newFacilities = loadFacilities (selectedDistrict , null , FacilityType .HOSPITAL );
259+ if (initialFacility != null && selectedDistrict .equals (initialFacility .getDistrict ()) && !newFacilities .contains (facilityItem )) {
260+ newFacilities .add (facilityItem );
261+ }
262+ facilityField .setSpinnerData (newFacilities , facilityField .getValue ());
263+ } else if (typeField .getValue () != null ) {
258264 List <Item > newFacilities = loadFacilities (selectedDistrict , null , (FacilityType ) typeField .getValue ());
259265 if (initialFacility != null && selectedDistrict .equals (initialFacility .getDistrict ()) && !newFacilities .contains (facilityItem )) {
260266 newFacilities .add (facilityItem );
@@ -284,12 +290,26 @@ public static void initializeFacilityFields(
284290
285291 communityField .initializeSpinner (communities , field -> {
286292 Community selectedCommunity = (Community ) field .getValue ();
287- if (selectedCommunity != null && typeField .getValue () != null ) {
293+ if (selectedCommunity != null && typeField == null ) {
294+ List <Item > newFacilities = loadFacilities (null , selectedCommunity , FacilityType .HOSPITAL );
295+ if (initialFacility != null && selectedCommunity .equals (initialFacility .getCommunity ()) && !newFacilities .contains (facilityItem )) {
296+ newFacilities .add (facilityItem );
297+ }
298+ facilityField .setSpinnerData (newFacilities );
299+ } else if (selectedCommunity != null && typeField .getValue () != null ) {
288300 List <Item > newFacilities = loadFacilities (null , selectedCommunity , (FacilityType ) typeField .getValue ());
289301 if (initialFacility != null && selectedCommunity .equals (initialFacility .getCommunity ()) && !newFacilities .contains (facilityItem )) {
290302 newFacilities .add (facilityItem );
291303 }
292304 facilityField .setSpinnerData (newFacilities );
305+ } else if (districtField .getValue () != null && typeField == null ) {
306+ List <Item > newFacilities = loadFacilities ((District ) districtField .getValue (), null , FacilityType .HOSPITAL );
307+ if (initialFacility != null
308+ && districtField .getValue ().equals (initialFacility .getDistrict ())
309+ && !newFacilities .contains (facilityItem )) {
310+ newFacilities .add (facilityItem );
311+ }
312+ facilityField .setSpinnerData (newFacilities );
293313 } else if (districtField .getValue () != null && typeField .getValue () != null ) {
294314 List <Item > newFacilities = loadFacilities ((District ) districtField .getValue (), null , (FacilityType ) typeField .getValue ());
295315 if (initialFacility != null
@@ -337,15 +357,17 @@ public static void initializeFacilityFields(
337357 });
338358 }
339359
340- typeField .initializeSpinner (types , field -> {
341- FacilityType selectedType = (FacilityType ) field .getValue ();
342- if (selectedType != null ) {
343- facilityField
344- .setSpinnerData (loadFacilities ((District ) districtField .getValue (), (Community ) communityField .getValue (), selectedType ));
345- } else {
346- facilityField .setSpinnerData (null );
347- }
348- });
360+ if (typeField != null ) {
361+ typeField .initializeSpinner (types , field -> {
362+ FacilityType selectedType = (FacilityType ) field .getValue ();
363+ if (selectedType != null ) {
364+ facilityField
365+ .setSpinnerData (loadFacilities ((District ) districtField .getValue (), (Community ) communityField .getValue (), selectedType ));
366+ } else {
367+ facilityField .setSpinnerData (null );
368+ }
369+ });
370+ }
349371
350372 facilityField .setSpinnerData (facilities );
351373
0 commit comments