Esempio n. 1
0
def ena_description(auto_fields):
    # get current stage, output next stage
    stage_dict = {}
    datafile_id = auto_fields["datafile"]
    current_stage = auto_fields["current_stage"]
    static_list = d_utils.json_to_pytype(lkup.WIZARD_FILES["ena"])["properties"]
    unified_list = static_list

    # get stages from db if exist. stages (both static and dynamic) are held in the db,
    # to provide a single or unified point of reference

    d = DataFile()
    description = d.GET(datafile_id)["description"]
    description_stages = description["stages"]

    if len(description_stages) > 0:
        unified_list = description_stages
    else:
        description["stages"] = unified_list
        fields = {"description": description}
        d.edit_datafile(datafile_id, fields)

    # generate and merge dynamic stages with static if not already generated
    if unified_list == static_list:  # only static stages exist, generate dynamic

        dynamic_elements = get_dynamic_elements_ena(datafile_id)  # ENA dynamic stages, contingent upon study_type

        if dynamic_elements:
            unified_list = unified_list + dynamic_elements  # merge and save stages

            description["stages"] = unified_list
            fields = {"description": description}
            d.edit_datafile(datafile_id, fields)

    # now, resolve stages for the wizard
    next_stage_indx = 0
    listed_stage = [indx for indx, elem in enumerate(unified_list) if elem["ref"] == current_stage]
    if listed_stage:
        next_stage_indx = listed_stage[0] + 1

    try:
        elem = unified_list[next_stage_indx]
        if not is_stage_present(datafile_id, elem["ref"]):
            stage_dict = get_stage_display(elem, datafile_id)
    except:
        pass

    if not stage_dict and current_stage == unified_list[-1]["ref"]:  # reached last stage of wizard, 'review' now
        # stage_dict = wtags.get_review_html(get_stages_display(datafile_id))
        pass

    return stage_dict