Skip to content

Commit

Permalink
feat: Implement dynamic menu management for case-specific forms #185
Browse files Browse the repository at this point in the history
- Added functionality to dynamically manage menu items based on the selected disease and case.
- Updated `FormBuilderDao` to retrieve available forms for the selected disease.
- Modified `CaseEditActivity` and `CaseReadActivity` to remove irrelevant menu items based on available forms.

This ensures that only relevant menus are displayed for a given case, improving user experience and accuracy.
  • Loading branch information
douglasderrick committed Nov 25, 2024
1 parent dfb9ceb commit 4226345
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,18 @@ protected void update(FormBuilder data) throws SQLException {
}
}
}

//get all forms for Disease
public List<FormBuilder> getFormBuilders(Disease disease) {
try {
QueryBuilder builder = queryBuilder();
Where where = builder.where();
where.eq(FormBuilder.DISEASE, disease);
return builder.query();
} catch (SQLException e) {
Log.e(getTableName(), "Could not perform getFormBuilders");
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.view.Menu;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.FormType;
import de.symeda.sormas.api.caze.CaseClassification;
import de.symeda.sormas.api.caze.CaseOrigin;
import de.symeda.sormas.api.caze.CaseReferenceDto;
Expand All @@ -45,6 +46,7 @@
import de.symeda.sormas.app.backend.event.Event;
import de.symeda.sormas.app.backend.event.EventCriteria;
import de.symeda.sormas.app.backend.event.EventParticipant;
import de.symeda.sormas.app.backend.formbuilder.FormBuilder;
import de.symeda.sormas.app.backend.user.UserRole;
import de.symeda.sormas.app.caze.CaseSection;
import de.symeda.sormas.app.clinicalcourse.edit.ClinicalVisitNewActivity;
Expand All @@ -71,6 +73,7 @@
import de.symeda.sormas.app.util.Bundler;
import de.symeda.sormas.app.util.Consumer;
import de.symeda.sormas.app.util.DiseaseConfigurationCache;
import de.symeda.sormas.app.util.DiseaseFieldHandler;

public class CaseEditActivity extends BaseEditActivity<Case> {

Expand Down Expand Up @@ -105,7 +108,11 @@ public CaseClassification getPageStatus() {
public List<PageMenuItem> getPageMenuData() {
List<PageMenuItem> menuItems = PageMenuItem.fromEnum(CaseSection.values(), getContext());
Case caze = getStoredRootEntity();
// Sections must be removed in reverse order

Disease disease = caze != null ? caze.getDisease() : null;
if (disease != null) {
menuItems = DiseaseFieldHandler.handleMenuDataForDisease(menuItems, disease);
}
if (DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_MANAGEMENT)) {
menuItems.set(CaseSection.TASKS.ordinal(), null);
}
Expand Down Expand Up @@ -164,6 +171,69 @@ public List<PageMenuItem> getPageMenuData() {
return menuItems;
}


// public List<PageMenuItem> getPageMenuData() {
// List<PageMenuItem> menuItems = PageMenuItem.fromEnum(CaseSection.values(), getContext());
// Case caze = getStoredRootEntity();
// // Sections must be removed in reverse order
// if (DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_MANAGEMENT)) {
// menuItems.set(CaseSection.TASKS.ordinal(), null);
// }
// if (!ConfigProvider.hasUserRight(UserRight.CLINICAL_COURSE_VIEW)
// || DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.VIEW_TAB_CASES_CLINICAL_COURSE)
// || (caze != null && caze.isUnreferredPortHealthCase())
// || (caze != null && caze.getClinicalCourse() == null)
// || DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.CLINICAL_MANAGEMENT)) {
// menuItems.set(CaseSection.CLINICAL_VISITS.ordinal(), null);
// menuItems.set(CaseSection.HEALTH_CONDITIONS.ordinal(), null);
// }
// if (!ConfigProvider.hasUserRight(UserRight.THERAPY_VIEW)
// || DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.VIEW_TAB_CASES_THERAPY)
// || (caze != null && caze.isUnreferredPortHealthCase())
// || (caze != null && caze.getTherapy() == null)
// || DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.CLINICAL_MANAGEMENT)) {
// menuItems.set(CaseSection.TREATMENTS.ordinal(), null);
// menuItems.set(CaseSection.PRESCRIPTIONS.ordinal(), null);
// }
// if (caze != null && caze.isUnreferredPortHealthCase()) {
// menuItems.set(CaseSection.SAMPLES.ordinal(), null);
// }
// if (!ConfigProvider.hasUserRight(UserRight.IMMUNIZATION_VIEW)
// || DatabaseHelper.getFeatureConfigurationDao().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
// menuItems.set(CaseSection.IMMUNIZATIONS.ordinal(), null);
// }
// if (!ConfigProvider.hasUserRight(UserRight.IMMUNIZATION_VIEW)
// || !DatabaseHelper.getFeatureConfigurationDao().isPropertyValueTrue(FeatureType.IMMUNIZATION_MANAGEMENT, FeatureTypeProperty.REDUCED)) {
// menuItems.set(CaseSection.VACCINATIONS.ordinal(), null);
// }
// if (!ConfigProvider.hasUserRight(UserRight.CONTACT_VIEW)
// || (caze != null && caze.isUnreferredPortHealthCase())
// || (caze != null && !DiseaseConfigurationCache.getInstance().hasFollowUp(caze.getDisease()))) {
// menuItems.set(CaseSection.CONTACTS.ordinal(), null);
// }
// if (caze != null && caze.getDisease() == Disease.CONGENITAL_RUBELLA
// || DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.VIEW_TAB_CASES_EPIDEMIOLOGICAL_DATA)) {
// menuItems.set(CaseSection.EPIDEMIOLOGICAL_DATA.ordinal(), null);
// }
// if (caze != null && (caze.getCaseOrigin() != CaseOrigin.POINT_OF_ENTRY || !ConfigProvider.hasUserRight(UserRight.PORT_HEALTH_INFO_EDIT))) {
// menuItems.set(CaseSection.PORT_HEALTH_INFO.ordinal(), null);
// }
// if (caze != null
// && (caze.isUnreferredPortHealthCase()
// || UserRole.isPortHealthUser(ConfigProvider.getUser().getUserRoles())
// || DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.VIEW_TAB_CASES_HOSPITALIZATION))) {
// menuItems.set(CaseSection.HOSPITALIZATION.ordinal(), null);
// }
// if (caze != null && caze.getDisease() != Disease.CONGENITAL_RUBELLA) {
// menuItems.set(CaseSection.MATERNAL_HISTORY.ordinal(), null);
// }
// if (DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.VIEW_TAB_CASES_SYMPTOMS)) {
// menuItems.set(CaseSection.SYMPTOMS.ordinal(), null);
// }
//
// return menuItems;
// }

@Override
protected BaseEditFragment buildEditFragment(PageMenuItem menuItem, Case activityRootData) {
CaseSection section = CaseSection.fromOrdinal(menuItem.getPosition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import de.symeda.sormas.app.symptoms.SymptomsReadFragment;
import de.symeda.sormas.app.util.Bundler;
import de.symeda.sormas.app.util.DiseaseConfigurationCache;
import de.symeda.sormas.app.util.DiseaseFieldHandler;

public class CaseReadActivity extends BaseReadActivity<Case> {

Expand Down Expand Up @@ -72,6 +73,11 @@ protected Case queryRootEntity(String recordUuid) {
public List<PageMenuItem> getPageMenuData() {
List<PageMenuItem> menuItems = PageMenuItem.fromEnum(CaseSection.values(), getContext());
Case caze = getStoredRootEntity();

Disease disease = caze != null ? caze.getDisease() : null;
if (disease != null) {
menuItems = DiseaseFieldHandler.handleMenuDataForDisease(menuItems, disease);
}
// Sections must be removed in reverse order
if (DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.TASK_MANAGEMENT)) {
menuItems.set(CaseSection.TASKS.ordinal(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
import de.symeda.sormas.app.backend.common.DatabaseHelper;
import de.symeda.sormas.app.backend.formbuilder.FormBuilder;
import de.symeda.sormas.app.backend.formfield.FormField;
import de.symeda.sormas.app.caze.CaseSection;
import de.symeda.sormas.app.component.controls.ControlButton;
import de.symeda.sormas.app.component.controls.ControlCheckBoxField;
import de.symeda.sormas.app.component.controls.ControlDateField;
import de.symeda.sormas.app.component.controls.ControlPropertyField;
import de.symeda.sormas.app.component.controls.ControlSwitchField;
import de.symeda.sormas.app.component.controls.ControlTextReadField;
import de.symeda.sormas.app.component.menu.PageMenuItem;

public class DiseaseFieldHandler {
private static String TAG = DiseaseFieldHandler.class.getSimpleName();

private Context context;
private static List<FormBuilder> diseaseForms;

public DiseaseFieldHandler(Context context) {
this.context = context;
Expand Down Expand Up @@ -236,6 +239,69 @@ public List<FormField> getFieldsForDisease(Disease diseaseName, FormType formTyp
return new ArrayList<>();
}

/**
* Check if a form exists for a given disease and form type.
*
* @param formType The form type (e.g., "ClinicalVisits").
* @return true if the form exists, false otherwise.
*/
private static boolean isFormNotAvailableForDisease(FormType formType) {
if (diseaseForms.isEmpty()) {
return false;
}

for (FormBuilder formBuilder : diseaseForms) {
if (formBuilder.getFormType().name() == formType.name()) {
return false;
}
}

return true;
}

/**
* Remove menu items if a form is available for a given disease.
*
* @param menuItems The list of menu items.
*/
public static List<PageMenuItem> handleMenuDataForDisease(List<PageMenuItem> menuItems, Disease disease) {
diseaseForms = DatabaseHelper.getFormBuilderDao().getFormBuilders(disease);

removeMenuItemIfFormAvailable(menuItems, FormType.PERSON_EDIT, CaseSection.PERSON_INFO);
removeMenuItemIfFormAvailable(menuItems, FormType.MATERNAL_HISTORY_EDIT, CaseSection.MATERNAL_HISTORY);
removeMenuItemIfFormAvailable(menuItems, FormType.HOSPITALIZATION_EDIT, CaseSection.HOSPITALIZATION);
removeMenuItemIfFormAvailable(menuItems, FormType.PORT_HEALTH_INFO_EDIT, CaseSection.PORT_HEALTH_INFO);
removeMenuItemIfFormAvailable(menuItems, FormType.SYMPTOMS_EDIT, CaseSection.SYMPTOMS);
removeMenuItemIfFormAvailable(menuItems, FormType.HEALTH_CONDITION_EDIT, CaseSection.HEALTH_CONDITIONS);
removeMenuItemIfFormAvailable(menuItems, FormType.EPIDEMIOLOGICAL_EDIT, CaseSection.EPIDEMIOLOGICAL_DATA);
removeMenuItemIfFormAvailable(menuItems, FormType.SAMPLE_EDIT, CaseSection.SAMPLES);
removeMenuItemIfFormAvailable(menuItems, FormType.CONTACT_EDIT, CaseSection.CONTACTS);
removeMenuItemIfFormAvailable(menuItems, FormType.PRESCRIPTION_EDIT, CaseSection.PRESCRIPTIONS);
removeMenuItemIfFormAvailable(menuItems, FormType.TREATMENT_EDIT, CaseSection.TREATMENTS);
removeMenuItemIfFormAvailable(menuItems, FormType.CLINICAL_VISIT_EDIT, CaseSection.CLINICAL_VISITS);
removeMenuItemIfFormAvailable(menuItems, FormType.TASK_EDIT, CaseSection.TASKS);
removeMenuItemIfFormAvailable(menuItems, FormType.EVENT_EDIT, CaseSection.EVENTS);
removeMenuItemIfFormAvailable(menuItems, FormType.IMMUNIZATION_EDIT, CaseSection.IMMUNIZATIONS);
removeMenuItemIfFormAvailable(menuItems, FormType.VACCINATION_EDIT, CaseSection.VACCINATIONS);
removeMenuItemIfFormAvailable(menuItems, FormType.RISK_FACTOR_EDIT, CaseSection.RISK_FACTORS);

return menuItems;
}

/**
* Remove a menu item if a form is available for a given disease and form type.
*
* @param menuItems The list of menu items.
* @param formType The form type to check.
* @param section The section to remove if the form is available.
*/
private static void removeMenuItemIfFormAvailable(List<PageMenuItem> menuItems, FormType formType, CaseSection section) {
boolean isFormAvailable = isFormNotAvailableForDisease(formType);
if (isFormAvailable) {
menuItems.set(section.ordinal(), null);
}
}


}

0 comments on commit 4226345

Please sign in to comment.