Exemple #1
0
def get_username_password(storage_name,
                          user_input=input,
                          password_input=getpass,
                          output=print):

    user = keyring.get_password("MosaiqSQL_username", storage_name)
    password = keyring.get_password("MosaiqSQL_password", storage_name)

    if user is None or user == "":
        output("Provide a user that only has `db_datareader` access to the "
               "Mosaiq database at `{}`".format(storage_name))
        user = user_input()
        if user == "":
            error_message = "Username should not be blank."
            output(error_message)
            raise ValueError(error_message)
        keyring.set_password("MosaiqSQL_username", storage_name, user)

    if password is None:
        output("Provide password for '{}' server and '{}' user".format(
            storage_name, user))
        password = password_input()
        keyring.set_password("MosaiqSQL_password", storage_name, password)

    return user, password
Exemple #2
0
def mosaiq_input_method(patient_id="", key_namespace="", site=None, **_):
    mosaiq_details = _config.get_mosaiq_details()

    mosaiq_site = st_misc.site_picker("Mosaiq Site",
                                      default=site,
                                      key=f"{key_namespace}_mosaiq_site")

    server = mosaiq_details[mosaiq_site]["server"]
    st.write(f"Mosaiq Hostname: `{server}`")

    sql_user = keyring.get_password("MosaiqSQL_username", server)
    st.write(f"Mosaiq SQL login being used: `{sql_user}`")

    patient_id = st.text_input("Patient ID",
                               patient_id,
                               key=f"{key_namespace}_patient_id")
    st.write(patient_id)

    cursor = st_mosaiq.get_mosaiq_cursor(server)

    if patient_id == "":
        return {}

    patient_name = get_patient_name(cursor, patient_id)

    st.write(f"Patient Name: `{patient_name}`")

    patient_fields = get_patient_fields(cursor, patient_id)

    st.write("""
        #### Mosaiq patient fields
        """)

    patient_fields = patient_fields[patient_fields["monitor_units"] != 0]
    st.write(patient_fields)

    field_ids = patient_fields["field_id"]
    field_ids = field_ids.values.tolist()

    selected_field_ids = st.multiselect("Select Mosaiq field id(s)",
                                        field_ids,
                                        key=f"{key_namespace}_mosaiq_field_id")

    cursor_and_field_ids = [(cursor, field_id)
                            for field_id in selected_field_ids]
    deliveries = _deliveries.cached_deliveries_loading(
        cursor_and_field_ids, _deliveries.delivery_from_mosaiq)
    identifier = f"{mosaiq_site} Mosaiq ({', '.join([str(field_id) for field_id in selected_field_ids])})"

    return {
        "site": mosaiq_site,
        "patient_id": patient_id,
        "patient_name": patient_name,
        "data_paths": [],
        "identifier": identifier,
        "deliveries": deliveries,
    }
def mosaiq_input_method(patient_id="", key_namespace="", **_):
    mosaiq_details = get_mosaiq_details()
    site_options = list(mosaiq_details.keys())

    mosaiq_site = st.radio("Mosaiq Site",
                           site_options,
                           key=f"{key_namespace}_mosaiq_site")
    server = mosaiq_details[mosaiq_site]["server"]
    f"Mosaiq Hostname: `{server}`"

    sql_user = keyring.get_password("MosaiqSQL_username", server)
    f"Mosaiq SQL login being used: `{sql_user}`"

    patient_id = st.text_input("Patient ID",
                               patient_id,
                               key=f"{key_namespace}_patient_id")
    patient_id

    cursor = get_mosaiq_cursor(server)

    if patient_id == "":
        return {}

    patient_name = get_patient_name(cursor, patient_id)

    f"Patient Name: `{patient_name}`"

    patient_fields = get_patient_fields(cursor, patient_id)
    """
    #### Mosaiq patient fields
    """

    patient_fields = patient_fields[patient_fields["monitor_units"] != 0]
    patient_fields

    field_ids = patient_fields["field_id"]
    field_ids = field_ids.values.tolist()

    selected_field_ids = st.multiselect("Select Mosaiq field id(s)",
                                        field_ids,
                                        key=f"{key_namespace}_mosaiq_field_id")

    cursor_and_field_ids = [(cursor, field_id)
                            for field_id in selected_field_ids]
    deliveries = cached_deliveries_loading(cursor_and_field_ids,
                                           delivery_from_mosaiq)
    identifier = (
        f"Mosaiq ({', '.join([str(field_id) for field_id in selected_field_ids])})"
    )

    return {
        "patient_id": patient_id,
        "patient_name": patient_name,
        "data_paths": selected_field_ids,
        "identifier": identifier,
        "deliveries": deliveries,
    }
def get_zenodo_access_token(hostname):
    access_token = keyring.get_password("Zenodo", hostname)

    if access_token is None or access_token == "":
        print(
            "To upload files to Zenodo you need to provide a Zenodo "
            "access token. Please go to "
            f"<https://{hostname}/account/settings/applications/tokens/new/>, "
            "login to Zenodo and create a new access token.\n"
            "When creating the access token use the scopes `deposit:actions`, `deposit:write`, "
            "and `user:email`. Once you have your token copy it into the prompt below "
            "to continue with the upload.")
        access_token = getpass.getpass()
        set_zenodo_access_token(access_token, hostname)

    return access_token