Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public class ContactDataForm extends AbstractEditForm<ContactDto> {

private final ViewMode viewMode;
private final Disease disease;
private final boolean diseaseHasFollowUp;
private NullableOptionGroup contactProximity;
private ComboBox region;
private ComboBox district;
Expand Down Expand Up @@ -212,6 +213,7 @@ public ContactDataForm(Disease disease, ViewMode viewMode, boolean isPseudonymiz

this.viewMode = viewMode;
this.disease = disease;
this.diseaseHasFollowUp = FacadeProvider.getDiseaseConfigurationFacade().hasFollowUp(disease);
addFields();
}

Expand All @@ -234,12 +236,12 @@ protected void addFields() {
Label followUpStausHeadingLabel = new Label(I18nProperties.getString(Strings.headingFollowUpStatus));
followUpStausHeadingLabel.addStyleName(H3);
getContent().addComponent(followUpStausHeadingLabel, FOLLOW_UP_STATUS_HEADING_LOC);
followUpStausHeadingLabel.setVisible(Disease.INVASIVE_MENINGOCOCCAL_INFECTION !=disease);
followUpStausHeadingLabel.setVisible(diseaseHasFollowUp);

Label prophylaxisLabel = new Label(I18nProperties.getString(Strings.headingProphylaxisLoc));
prophylaxisLabel.addStyleName(H3);
getContent().addComponent(prophylaxisLabel, PROPHYLAXIS_LOC);
prophylaxisLabel.setVisible(Disease.INVASIVE_MENINGOCOCCAL_INFECTION ==disease);
prophylaxisLabel.setVisible(Disease.INVASIVE_MENINGOCOCCAL_INFECTION == disease);

addField(ContactDto.CONTACT_CLASSIFICATION, NullableOptionGroup.class);
addField(ContactDto.CONTACT_STATUS, NullableOptionGroup.class);
Expand Down Expand Up @@ -272,12 +274,12 @@ protected void addFields() {
addField(ContactDto.CONTACT_IDENTIFICATION_SOURCE, ComboBox.class);
TextField contactIdentificationSourceDetails = addField(ContactDto.CONTACT_IDENTIFICATION_SOURCE_DETAILS, TextField.class);
contactIdentificationSourceDetails.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));
// contactIdentificationSourceDetails.setVisible(false);
// contactIdentificationSourceDetails.setVisible(false);
ComboBox tracingApp = addField(ContactDto.TRACING_APP, ComboBox.class);
TextField tracingAppDetails = addField(ContactDto.TRACING_APP_DETAILS, TextField.class);
tracingAppDetails.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));
// tracingApp.setVisible(false);
// tracingAppDetails.setVisible(false);
// tracingApp.setVisible(false);
// tracingAppDetails.setVisible(false);
if (isConfiguredServer(CountryHelper.COUNTRY_CODE_GERMANY)) {
FieldHelper.setVisibleWhen(
getFieldGroup(),
Expand Down Expand Up @@ -468,6 +470,7 @@ protected void addFields() {
cbOverwriteFollowUpUntil.addValueChangeListener(e -> {
updateOverwriteFollowUpUntil();
});

dfQuarantineTo.addValueChangeListener(e -> onQuarantineEndChange());
addValueChangeListener(e -> {
ValidationUtils.initComponentErrorValidator(
Expand Down Expand Up @@ -711,13 +714,27 @@ public String getFormattedHtmlMessage() {
// Prophylaxis details for IMI
CheckBox prophylaxisPrescribed = addField(ContactDto.PROPHYLAXIS_PRESCRIBED, CheckBox.class);
prophylaxisPrescribed.setCaption(I18nProperties.getCaption(Captions.Contact_prophylaxisPrescribed));
// prophylaxisPrescribed.removeStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
// prophylaxisPrescribed.removeStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
addField(ContactDto.PRESCRIBED_DRUG, ComboBox.class);
addField(ContactDto.PRESCRIBED_DRUG_TEXT, TextField.class);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.PRESCRIBED_DRUG, ContactDto.PROPHYLAXIS_PRESCRIBED, Collections.singletonList(Boolean.TRUE), true);
FieldHelper.setVisibleWhen(
getFieldGroup(),
ContactDto.PRESCRIBED_DRUG,
ContactDto.PROPHYLAXIS_PRESCRIBED,
Collections.singletonList(Boolean.TRUE),
true);
FieldHelper.setRequiredWhenNotNull(getFieldGroup(), ContactDto.PROPHYLAXIS_PRESCRIBED, ContactDto.PRESCRIBED_DRUG);
FieldHelper.setVisibleWhen(getFieldGroup(), ContactDto.PRESCRIBED_DRUG_TEXT, ContactDto.PRESCRIBED_DRUG, Collections.singletonList(PrescribedDrug.OTHER), true);
FieldHelper.setRequiredWhen(getFieldGroup(), ContactDto.PRESCRIBED_DRUG, Arrays.asList(ContactDto.PRESCRIBED_DRUG_TEXT), Arrays.asList(PrescribedDrug.OTHER));
FieldHelper.setVisibleWhen(
getFieldGroup(),
ContactDto.PRESCRIBED_DRUG_TEXT,
ContactDto.PRESCRIBED_DRUG,
Collections.singletonList(PrescribedDrug.OTHER),
true);
FieldHelper.setRequiredWhen(
getFieldGroup(),
ContactDto.PRESCRIBED_DRUG,
Arrays.asList(ContactDto.PRESCRIBED_DRUG_TEXT),
Arrays.asList(PrescribedDrug.OTHER));
}

private void updateContactOfficers() {
Expand Down Expand Up @@ -846,6 +863,21 @@ private void updateDiseaseConfiguration(Disease disease) {
|| (propertyId.equals(ContactDto.CONTACT_CATEGORY) && isVisibleAllowed((String) propertyId))));
}

final boolean diseaseHasFollowUp = FacadeProvider.getDiseaseConfigurationFacade().hasFollowUp(disease);
// Hide follow-up if disease does not have it enabled
//followUpStausHeadingLabel.setVisible(this.diseaseHasFollowUp);
FieldHelper.setMultipleVisible(
getFieldGroup(),
Arrays.asList(
ContactDto.FOLLOW_UP_STATUS,
ContactDto.FOLLOW_UP_STATUS_CHANGE_DATE,
ContactDto.FOLLOW_UP_STATUS_CHANGE_USER,
ContactDto.FOLLOW_UP_COMMENT,
ContactDto.FOLLOW_UP_UNTIL,
ContactDto.OVERWRITE_FOLLOW_UP_UNTIL),
field -> diseaseHasFollowUp,
field -> false);

FieldHelper.updateEnumData(
contactProximity,
Arrays.asList(ContactProximity.getValues(disease, FacadeProvider.getConfigFacade().getCountryLocale())));
Expand Down
17 changes: 17 additions & 0 deletions sormas-ui/src/main/java/de/symeda/sormas/ui/utils/FieldHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,23 @@ public static void setVisibleWhen(
}
}

@SuppressWarnings("rawtypes")
public static void setMultipleVisible(
final FieldGroup fieldGroup,
List<String> targetPropertyIds,
Function<Field, Boolean> isVisibleFunction,
Function<Field, Boolean> isClearedOnHidden) {
final List<? extends Field<?>> targetFields = targetPropertyIds.stream().map(id -> fieldGroup.getField(id)).collect(Collectors.toList());
targetFields.forEach(targetField -> {
final boolean visible = isVisibleFunction.apply(targetField);
final boolean clearOnHidden = isClearedOnHidden.apply(targetField);
targetField.setVisible(visible);
if (!visible && clearOnHidden && targetField.getValue() != null) {
targetField.clear();
}
});
}

public static void setCaptionWhen(Field<?> sourceField, Field<?> targetField, Object sourceValue, String matchCaption, String noMatchCaption) {
if (sourceField != null) {
// initialize
Expand Down
Loading