Example #1
0
def main():
    st.set_option("deprecation.showfileUploaderEncoding", False)

    uploaded_file_buffer_list = st.file_uploader(
        "Files to pseudonymise, refresh page after downloading zip(s)",
        ["dcm"],
        accept_multiple_files=True,
    )

    if st.button("Pseudonymise", key="PseudonymiseButton"):
        pseudonymise_buffer_list(uploaded_file_buffer_list)
        uploaded_file_buffer_list.clear()
Example #2
0
def main():
    st.write("## Parameters")

    number_of_images = st.number_input("Number of Images", 10)

    width = st.number_input("Width (mm)", 20)
    length = st.number_input("Length (mm)", 24)
    edge_lengths = [width, length]

    # initial_rotation = 0
    bb_diameter = st.number_input("BB Diameter (mm)", 8)
    penumbra = st.number_input("Penumbra (mm)", 2)

    # files = sorted(IMAGES_DIR.glob("*.jpg"), key=lambda t: -os.stat(t).st_mtime)
    # most_recent = files[0:5]

    # most_recent

    files = get_file_list()
    most_recent = sorted(
        files, key=lambda t: -os.stat(t).st_mtime)[0:number_of_images]

    image_path = st.radio("Image to select", options=most_recent)

    plt.imshow(read_image(image_path))
    st.pyplot()

    if st.button("Calculate"):
        img = read_image(image_path)
        x, y, img = iview.iview_image_transform(img)
        field = imginterp.create_interpolated_field(x, y, img)
        initial_centre = findfield.get_centre_of_mass(x, y, img)
        (field_centre,
         field_rotation) = findfield.field_centre_and_rotation_refining(
             field, edge_lengths, penumbra, initial_centre, fixed_rotation=0)

        bb_centre = findbb.optimise_bb_centre(field, bb_diameter, edge_lengths,
                                              penumbra, field_centre,
                                              field_rotation)
        fig = reporting.image_analysis_figure(
            x,
            y,
            img,
            bb_centre,
            field_centre,
            field_rotation,
            bb_diameter,
            edge_lengths,
            penumbra,
        )

        st.write(fig)
        st.pyplot()
Example #3
0
def main():
    config = get_config()

    st.sidebar.markdown("""
        # Overview
        """)

    st.sidebar.markdown("""
        ## Reference
        """)

    set_reference_overview = sidebar_overview()

    st.sidebar.markdown("""
        ## Evaluation
        """)

    set_evaluation_overview = sidebar_overview()

    overview_updater_map = {
        "reference": set_reference_overview,
        "evaluation": set_evaluation_overview,
    }

    st.sidebar.markdown("""
        # Status indicators
        """)

    show_status_indicators()

    st.sidebar.markdown("""
        # Advanced options

        Enable advanced functionality by ticking the below.
        """)
    advanced_mode = st.sidebar.checkbox("Run in Advanced Mode")

    gamma_options = get_gamma_options(advanced_mode)

    data_option_functions = {
        "monaco": monaco_input_method,
        "dicom": dicom_input_method,
        "icom": icom_input_method,
        "trf": trf_input_method,
        "mosaiq": mosaiq_input_method,
    }

    default_reference_id = config["data_methods"]["default_reference"]
    default_evaluation_id = config["data_methods"]["default_evaluation"]
    available_data_methods = config["data_methods"]["available"]

    default_reference = DATA_OPTION_LABELS[default_reference_id]
    default_evaluation = DATA_OPTION_LABELS[default_evaluation_id]

    data_method_map = {}
    for method in available_data_methods:
        data_method_map[
            DATA_OPTION_LABELS[method]] = data_option_functions[method]
    """
    ### Reference
    """

    reference_results = get_input_data_ui(
        overview_updater_map,
        data_method_map,
        default_reference,
        "reference",
        advanced_mode,
    )
    """
    ### Evaluation
    """

    evaluation_results = get_input_data_ui(
        overview_updater_map,
        data_method_map,
        default_evaluation,
        "evaluation",
        advanced_mode,
        **reference_results,
    )
    """
    ## Output Locations
    """
    """
    ### eSCAN Directory

    The location to save the produced pdf report.
    """

    site_directories = get_site_directories()

    site_options = list(site_directories.keys())
    escan_site = st.radio("eScan Site", site_options)
    escan_directory = site_directories[escan_site]["escan"]

    if advanced_mode:
        st.write(escan_directory.resolve())

    default_png_output_directory = config["output"]["png_directory"]

    if advanced_mode:
        """
        ### Image record

        Path to save the image of the results for posterity
        """

        png_output_directory = pathlib.Path(
            st.text_input("png output directory",
                          default_png_output_directory))
        st.write(png_output_directory.resolve())

    else:
        png_output_directory = pathlib.Path(default_png_output_directory)
    """
    ## Calculation
    """

    if st.button("Run Calculation"):
        run_calculation(
            reference_results,
            evaluation_results,
            gamma_options,
            escan_directory,
            png_output_directory,
        )

    if advanced_mode:
        advanced_debugging()
Example #4
0
def main():
    st.write("# Anonymise Monaco Files")

    st.write("## Select Patient")

    (
        monaco_site,
        _,
        patient_id,
        _,
        patient_directory,
    ) = st_monaco.monaco_patient_directory_picker(advanced_mode_local=True)

    st.write(f"Directory to anonymise: `{patient_directory}`")

    st.write("## Select Export Location")

    _, export_directory = st_misc.get_site_and_directory(
        "Site to save anonymised zip file",
        "anonymised_monaco",
        default=monaco_site,
        key="export_site",
    )

    st.write(f"Export directory: `{export_directory}`")

    zip_path = pathlib.Path(export_directory).joinpath(f"{patient_id}.zip")

    st.write(f"Zip file to be created: `{zip_path}`")

    if zip_path.exists():
        st.write(FileExistsError("This zip file already exists."))
        if st.button("Delete zip file"):
            zip_path.unlink()
            st_rerun.rerun()

        st.stop()

    if st.button("Copy and Anonymise"):
        with tempfile.TemporaryDirectory() as temp_dir:
            pl_temp_dir = pathlib.Path(temp_dir)
            new_temp_location = pl_temp_dir.joinpath(patient_directory.name)

            st.write("Copying to temp directory, skipping DICOM files...")

            shutil.copytree(
                patient_directory,
                new_temp_location,
                ignore=shutil.ignore_patterns("*.DCM", "demographic.*"),
            )

            st.write("Creating anonymised demographic file...")

            new_demographic_file = new_temp_location.joinpath(
                f"demographic.{patient_id}"
            )

            shutil.copy2(ANON_DEMOGRAPHIC_FILE, new_demographic_file)
            with open(new_demographic_file, "r") as f:
                demographic_data = f.readlines()

            demographic_data[3] = demographic_data[3].replace("000000", patient_id)

            with open(new_demographic_file, "w") as f:
                f.writelines(demographic_data)

            st.write("Creating zip file...")

            shutil.make_archive(
                str(zip_path.with_suffix("")),
                "zip",
                root_dir=str(pl_temp_dir.resolve()),
                base_dir=f"{patient_directory.name}",
            )

            st.write("Complete!")
Example #5
0
def main():
    st.write("""
        # MU Density comparison tool

        Tool to compare the MU Density between planned and delivery.
        """)

    config = st_config.get_config()

    st.sidebar.markdown("""
        # MU Density Overview
        """)

    st.sidebar.markdown("""
        ## Reference
        """)

    set_reference_overview = sidebar_overview()

    st.sidebar.markdown("""
        ## Evaluation
        """)

    set_evaluation_overview = sidebar_overview()

    overview_updater_map = {
        "reference": set_reference_overview,
        "evaluation": set_evaluation_overview,
    }

    st.sidebar.markdown("""
        # Status indicators
        """)

    show_status_indicators()

    st.sidebar.markdown("""
        # Advanced options

        Enable advanced functionality by ticking the below.
        """)
    advanced_mode = st.sidebar.checkbox("Run in Advanced Mode")

    gamma_options = _config.get_gamma_options(advanced_mode)

    data_option_functions = {
        "monaco": _monaco.monaco_input_method,
        "dicom": _dicom.dicom_input_method,
        "icom": _icom.icom_input_method,
        "trf": _trf.trf_input_method,
        "mosaiq": _mosaiq.mosaiq_input_method,
    }

    default_reference_id = config["data_methods"]["default_reference"]
    default_evaluation_id = config["data_methods"]["default_evaluation"]
    available_data_methods = config["data_methods"]["available"]

    default_reference = DATA_OPTION_LABELS[default_reference_id]
    default_evaluation = DATA_OPTION_LABELS[default_evaluation_id]

    data_method_map = {}
    for method in available_data_methods:
        data_method_map[
            DATA_OPTION_LABELS[method]] = data_option_functions[method]

    st.write("""
        ## Selection of data to compare
        """)

    st.write("""
        ### Reference
        """)

    reference_results = get_input_data_ui(
        overview_updater_map,
        data_method_map,
        default_reference,
        "reference",
        advanced_mode,
    )

    st.write("""
        ### Evaluation
        """)

    evaluation_results = get_input_data_ui(
        overview_updater_map,
        data_method_map,
        default_evaluation,
        "evaluation",
        advanced_mode,
        **reference_results,
    )

    st.write("""
        ## Output Locations
        """)

    st.write("""
        ### eSCAN Directory

        The location to save the produced pdf report.
        """)

    default_site = evaluation_results.get("site", None)
    if default_site is None:
        default_site = reference_results.get("site", None)

    _, escan_directory = st_misc.get_site_and_directory(
        "eScan Site",
        "escan",
        default=default_site,
        key="escan_export_site_picker")

    escan_directory = pathlib.Path(
        os.path.expanduser(escan_directory)).resolve()

    if advanced_mode:
        st.write(escan_directory)

    default_png_output_directory = config["output"]["png_directory"]

    if advanced_mode:
        st.write("""
            ### Image record

            Path to save the image of the results for posterity
            """)

        png_output_directory = pathlib.Path(
            st.text_input("png output directory",
                          default_png_output_directory))
        st.write(png_output_directory.resolve())

    else:
        png_output_directory = pathlib.Path(default_png_output_directory)

    png_output_directory = pathlib.Path(
        os.path.expanduser(png_output_directory)).resolve()

    st.write("""
        ## Calculation
        """)

    if st.button("Run Calculation"):

        st.write("""
            ### MU Density usage warning
            """)

        st.warning(pymedphys.mudensity.WARNING_MESSAGE)

        st.write("""
            ### Calculation status
            """)

        run_calculation(
            reference_results,
            evaluation_results,
            gamma_options,
            escan_directory,
            png_output_directory,
        )

    if advanced_mode:
        advanced_debugging()
Example #6
0
def main():
    centres = ["rccc", "nbcc", "sash"]
    servers = {
        "rccc": "msqsql",
        "nbcc": "physics-server:31433",
        "sash": "physics-server",
    }
    physics_locations = {
        "rccc": "Physics_Check",
        "nbcc": "Physics",
        "sash": "Physics_Check",
    }

    cursors = {
        centre: st_mosaiq.get_mosaiq_cursor_in_bucket(servers[centre])
        for centre in centres
    }

    st.write("# Mosaiq QCLs")

    if st.button("Refresh"):
        st.experimental_rerun()

    for centre in centres:
        st.write(f"## {centre.upper()}")

        cursor_bucket = cursors[centre]
        physics_location = physics_locations[centre]

        try:
            table = msq_helpers.get_incomplete_qcls(cursor_bucket["cursor"],
                                                    physics_location)
        except (pymssql.InterfaceError, pymssql.OperationalError) as e:
            st.write(e)
            cursor_bucket["cursor"] = st_mosaiq.uncached_get_mosaiq_cursor(
                servers[centre])
            table = msq_helpers.get_incomplete_qcls(cursor_bucket["cursor"],
                                                    physics_location)

        table_dict = collections.OrderedDict()

        for index, row in table.iterrows():
            patient_name = f"{str(row.last_name).upper()}, {str(row.first_name).lower().capitalize()}"

            table_dict[index] = collections.OrderedDict({
                "Due":
                row.due.strftime("%Y-%m-%d"),
                "Patient":
                f"{row.patient_id} {patient_name}",
                "Instructions":
                row.instructions,
                "Comment":
                row.comment,
                "Task":
                row.task,
            })

        formated_table = pd.DataFrame.from_dict(table_dict).T
        formated_table = formated_table.reindex(
            ["Due", "Patient", "Instructions", "Comment", "Task"], axis=1)

        st.write(formated_table)