3030
3131import java .util .ArrayList ;
3232import java .util .Arrays ;
33+ import java .util .Collections ;
3334import java .util .Comparator ;
3435import java .util .Date ;
3536import java .util .HashMap ;
37+ import java .util .HashSet ;
3638import java .util .List ;
3739import java .util .Map ;
3840import java .util .Optional ;
@@ -132,6 +134,9 @@ public class SymptomsForm extends AbstractEditForm<SymptomsDto> {
132134 private static final String TUBERCULOSIS_ONSET_DATE_LOC = "tuberculosisOnsetDateLoc" ;
133135 private static final String TUBERCULOSIS_CLINICAL_PRESENTATION_DETAILS_LOC = "tuberculosisClinicalPresentationDetailsLoc" ;
134136
137+ private static final List <String > YES_NO_UNKNOWN_SYMPTOM_FIELD_IDS =
138+ Collections .unmodifiableList (Arrays .asList (PARENT_TIME_OFF_WORK , JAUNDICE_WITHIN_24_HOURS_OF_BIRTH , DATE_OF_ONSET_KNOWN ));
139+
135140 private static Map <String , List <String >> symptomGroupMap = new HashMap <>();
136141 public static final String SKIN_RASH_ONSET_DATE_LAYOUT = fluidRowLocs (6 , "LBL_SKIN_RASH_ONSET_DATE" , 1 , "" , 5 , SKIN_RASH_ONSET_DATE );
137142
@@ -214,6 +219,7 @@ private static String createSymptomGroupLayout(SymptomGroup symptomGroup, String
214219 private final PersonDto person ;
215220 private final SymptomsContext symptomsContext ;
216221 private final ViewMode viewMode ;
222+
217223 private transient List <String > unconditionalSymptomFieldIds ;
218224 private List <String > conditionalBleedingSymptomFieldIds ;
219225 private List <String > lesionsFieldIds ;
@@ -678,6 +684,7 @@ public String getFormattedHtmlMessage() {
678684 COUGH_WITH_HEAMOPTYSIS ,
679685 RUNNY_NOSE ,
680686 DIFFICULTY_BREATHING ,
687+ DIFFICULTY_BREATHING_DURING_MEALS ,
681688 CHEST_PAIN ,
682689 CONJUNCTIVITIS ,
683690 EYE_PAIN_LIGHT_SENSITIVE ,
@@ -750,6 +757,7 @@ public String getFormattedHtmlMessage() {
750757 HYPERACTIVITY ,
751758 INSOMNIA ,
752759 OPISTHOTONUS ,
760+ PARADOXICAL_BREATHING ,
753761 PARALYSIS ,
754762 PARASTHESIA_AROUND_WOUND ,
755763 PARESIS ,
@@ -766,6 +774,7 @@ public String getFormattedHtmlMessage() {
766774 FEELING_ILL ,
767775 SHIVERING ,
768776 RESPIRATORY_DISEASE_VENTILATION ,
777+ RESPIRATORY_FATIGUE ,
769778 FAST_HEART_RATE ,
770779 OXYGEN_SATURATION_LOWER_94 ,
771780 FEVERISHFEELING ,
@@ -942,21 +951,12 @@ public String getFormattedHtmlMessage() {
942951 addListenerForOnsetFields (onsetSymptom , onsetDateField );
943952
944953 Button clearAllButton = ButtonHelper .createButton (Captions .actionClearAll , event -> {
945- for (Object symptomId : unconditionalSymptomFieldIds ) {
946- getFieldGroup ().getField (symptomId ).setValue (null );
947- }
948- for (Object symptomId : conditionalBleedingSymptomFieldIds ) {
949- getFieldGroup ().getField (symptomId ).setValue (null );
950- }
951- for (Object symptomId : lesionsFieldIds ) {
952- getFieldGroup ().getField (symptomId ).setValue (null );
953- }
954- for (Object symptomId : lesionsLocationFieldIds ) {
955- getFieldGroup ().getField (symptomId ).setValue (null );
956- }
957- for (Object symptomId : monkeypoxImageFieldIds ) {
958- getFieldGroup ().getField (symptomId ).setValue (null );
959- }
954+ unconditionalSymptomFieldIds .forEach (this ::safeClearField );
955+ conditionalBleedingSymptomFieldIds .forEach (this ::safeClearField );
956+ lesionsFieldIds .forEach (this ::safeClearField );
957+ lesionsLocationFieldIds .forEach (this ::safeClearField );
958+ monkeypoxImageFieldIds .forEach (this ::safeClearField );
959+ YES_NO_UNKNOWN_SYMPTOM_FIELD_IDS .forEach (this ::safeClearField );
960960 }, ValoTheme .BUTTON_LINK );
961961
962962 Button setEmptyToNoButton = createButtonSetClearedToSymptomState (Captions .symptomsSetClearedToNo , SymptomState .NO );
@@ -1420,6 +1420,56 @@ public Button createButtonSetClearedToSymptomState(String caption, SymptomState
14201420 }
14211421 }
14221422 }
1423+ // Clear YesNoUnknown fields - map SymptomState to YesNoUnknown
1424+ YesNoUnknown yesNoValue ;
1425+ switch (symptomState ) {
1426+ case YES :
1427+ yesNoValue = YesNoUnknown .YES ;
1428+ break ;
1429+ case NO :
1430+ yesNoValue = YesNoUnknown .NO ;
1431+ break ;
1432+ case UNKNOWN :
1433+ default :
1434+ yesNoValue = YesNoUnknown .UNKNOWN ;
1435+ break ;
1436+ }
1437+ YES_NO_UNKNOWN_SYMPTOM_FIELD_IDS .forEach (symptomId -> {
1438+ final Field <Object > field = (Field <Object >) getFieldGroup ().getField (symptomId );
1439+ // quit early if the field is not supposed to be set
1440+ if (field == null ) {
1441+ return ;
1442+ }
1443+ if (!field .isVisible ()) {
1444+ return ;
1445+ }
1446+ if (field .isReadOnly ()) {
1447+ return ;
1448+ }
1449+
1450+ final Object value = field .getValue ();
1451+ final Set <?> valueSet = value instanceof Set ? (Set <?>) value : null ;
1452+
1453+ // non empty value within a set
1454+ if (valueSet != null && !valueSet .isEmpty ()) {
1455+ return ;
1456+ }
1457+
1458+ // non empty raw value
1459+ if (valueSet == null && value != null ) {
1460+ return ;
1461+ }
1462+
1463+ // if we have a set as value, add the new value
1464+ if (valueSet != null ) {
1465+ safeSetFieldValue (field , Collections .singleton (yesNoValue ));
1466+ return ;
1467+ }
1468+
1469+ // we have a raw value, set it
1470+ safeSetFieldValue (field , yesNoValue );
1471+
1472+ });
14231473 }, ValoTheme .BUTTON_LINK );
14241474
14251475 return button ;
0 commit comments