def update_phenomodel(model_id, user_form): """Update a phenotype model according to the user form Args: model_id(ObjectId): document ID of the model to be updated user_form(request.form): a POST request form object """ model_dict = store.phenomodel(model_id) update_model = False if model_dict is None: return if user_form.get( "update_model"): # update either model name of description update_model = True model_dict["name"] = user_form.get("model_name") model_dict["description"] = user_form.get("model_desc") if user_form.get( "subpanel_delete"): # Remove a phenotype submodel from phenomodel subpanels = model_dict["subpanels"] # remove panel from subpanels dictionary subpanels.pop(user_form.get("subpanel_delete"), None) model_dict["subpanels"] = subpanels update_model = True if user_form.get("add_subpanel"): # Add a new phenotype submodel update_model = _add_subpanel(model_id, model_dict, user_form) if user_form.get("model_save" ): # Save model according user preferences in the preview update_model = phenomodel_checkgroups_filter(model_dict, user_form) if update_model: store.update_phenomodel(model_id=model_id, model_obj=model_dict)
def phenomodel(institute_id, model_id): """View/Edit an advanced phenotype model""" institute_obj = institute_and_case(store, institute_id) pheno_form = PhenoModelForm(request.form) subpanel_form = PhenoSubPanelForm(request.form) hide_subpanel = True if request.method == "POST": # update an existing phenotype model controllers.update_phenomodel(model_id, request.form) phenomodel_obj = store.phenomodel(model_id) if phenomodel_obj is None: flash( f"Could not retrieve given phenotype model using the given key '{model_id}'", "warning", ) return redirect(request.referrer) pheno_form.model_name.data = phenomodel_obj["name"] pheno_form.model_desc.data = phenomodel_obj["description"] return dict( institute=institute_obj, pheno_form=pheno_form, phenomodel=phenomodel_obj, subpanel_form=subpanel_form, )
def lock_phenomodel(): """Lock or unlock a specific phenomodel for editing""" form = request.form model_id = form.get("model_id") phenomodel_obj = store.phenomodel(model_id) if phenomodel_obj is None: return redirect(request.referrer) phenomodel_obj["admins"] = [] if ( "lock" in form ): # lock phenomodel for all users except current user and specified collaborators phenomodel_obj["admins"] = [current_user.email ] + form.getlist("user_admins") # update phenomodels admins: store.update_phenomodel(model_id, phenomodel_obj) return redirect(request.referrer)
def edit_subpanel_checkbox(model_id, user_form): """Update checkboxes from one or more panels according to the user form Args: model_id(ObjectId): document ID of the model to be updated user_form(request.form): a POST request form object """ model_dict = store.phenomodel(model_id) update_model = False if model_dict is None: return if "add_hpo" in user_form: # add an HPO checkbox to subpanel update_model = _subpanel_hpo_checkgroup_add(model_dict, user_form) if "add_omim" in user_form: # add an OMIM checkbox to subpanel update_model = _subpanel_omim_checkbox_add(model_dict, user_form) if user_form.get("checkgroup_remove" ): # remove a checkbox of any type from subpanel update_model = _subpanel_checkgroup_remove_one(model_dict, user_form) if update_model: store.update_phenomodel(model_id=model_id, model_obj=model_dict)