Exemplo n.º 1
0
def _get_records(ptid, fhir_plugin_id, timestamp):
    url_patient = f"{pds_url_base}/{fhir_plugin_id}/Patient/{ptid}"
    url_condition = f"{pds_url_base}/{fhir_plugin_id}/Condition?patient={ptid}"
    url_observation = f"{pds_url_base}/{fhir_plugin_id}/Observation?patient={ptid}"

    return get(url_patient).bind(lambda patient: get(url_condition).bind(lambda condition: get(url_observation).bind(lambda observation: unbundle(condition).bind(lambda condition_unbundled: unbundle(observation).map(lambda observation_unbundled: bundle([
        patient,
        *condition_unbundled,
        *observation_unbundled
    ]))))))
def get_patient(patient_id, plugin):
    resp = get(pdsdpi_url_base(plugin) + f"/Patient/{patient_id}")
    if isinstance(resp, Left) and isinstance(
            resp.value[0], dict) and resp.value[0].get("status_code") == 404:
        return Right(None)
    else:
        return resp
Exemplo n.º 3
0
def _get_records(ptids, fhir_plugin_id, timestamp):
    pt_records = []
    for ptid in ptids:
        url_patient = f"{pds_url_base}/{fhir_plugin_id}/Patient/{ptid}"
        url_condition = f"{pds_url_base}/{fhir_plugin_id}/Condition?patient={ptid}"
        url_observation = f"{pds_url_base}/{fhir_plugin_id}/Observation?patient={ptid}"

        val = get(url_patient).bind(lambda patient: get(url_condition).bind(
            lambda condition: get(url_observation).
            bind(lambda observation: unbundle(condition).bind(
                lambda condition_unbundled: unbundle(observation).map(
                    lambda observation_unbundled: bundle([
                        patient, *condition_unbundled, *observation_unbundled
                    ]))))))
        pt_records.append(val)
    return list_traversable_either_applicative.sequence(pt_records)
Exemplo n.º 4
0
def _get_config(piid=None):
    url = f"{pds_url_base}/{pds_config}/config"
    if piid is not None:
        url += f"/{piid}"

    return error_code(
        get(url)).map(lambda config: config if piid is None else [config])
Exemplo n.º 5
0
def _get_plugin_config_factory_default(piid):
    config = get(pdsdpi_url_base(piid) + "/config")
    config = config.value
    config["piid"] = piid
    if "enabled" not in config:
        config["enabled"] = True
    return config
Exemplo n.º 6
0
def _get_config(piid=None):
    url = f"{pds_url_base}/{pds_config}/config"
    resp = get(url)
    if isinstance(resp, Left):
        return resp
    else:
        if piid is not None:
            l = list(filter(lambda x : x["piid"] == piid, resp.value))
            if len(l) == 0:
                return Left(("not found", 404))
            else:
                return Right(l)
        else:
            return resp
Exemplo n.º 7
0
def profile(patient_id, model_plugin_id, timestamp, body):
    phenotype_mapping_plugin_id = body["phenotype_mapping_plugin_id"]
    data_provider_plugin_id = body["data_provider_plugin_id"]
    custom_units = body.get("custom_units")
    url = f"{pds_url_base}/{model_plugin_id}/clinical_feature_variables"
    resp1 = get(url, schema=cfv_schema)
    if isinstance(resp1, Left):
        return resp1.value
    clinical_feature_variable_objects = resp1.value

    def cfvo_to_cfvo2(cfvo):
        cfv = cfvo["clinical_feature_variable"]
        cfvo2 = {
            "clinical_feature_variable": cfv
        }
        unit = cfvo.get("unit")
        if unit is not None:
            cfvo2["unit"] = unit
        elif custom_units is not None:
            cus = [a for a in custom_units if a["clinical_feature_variable"] == cfv]
            if len(cus) > 0:
                cfvo2["unit"] = cus[0]["unit"]
        return cfvo2
    
    cfvos2 = list(map(cfvo_to_cfvo2, clinical_feature_variable_objects))

    url = f"{pds_url_base}/{phenotype_mapping_plugin_id}/mapping?patient_id={patient_id}&data_provider_plugin_id={data_provider_plugin_id}&timestamp={timestamp}"
    print(f"url = {url}")
    resp2 = post(url, json=cfvos2)
    if isinstance(resp2, Left):
        return resp2.value
    value_objects = resp2.value
    print(f"value_objects = {value_objects}")
    sys.stdout.flush()

    profile = [{
        **clinical_feature_variable_object, **value_object
    } for value_object, clinical_feature_variable_object in zip(value_objects, clinical_feature_variable_objects)]

    return profile
            
        
def get_condition(patient_id, plugin):
    resp = get(pdsdpi_url_base(plugin) + f"/Condition?patient={patient_id}")
    return resp.bind(unbundle)
Exemplo n.º 9
0
def get_selectors(piid=None):
    url = f"{pds_url_base}/{pds_config}/selectors"
    resp = get(url)
    return resp.value
Exemplo n.º 10
0
def _get_selector_config():
    url = f"{pds_url_base}/{pds_config}/selectorConfig"

    return error_code(get(url))
Exemplo n.º 11
0
def _get_custom_units():
    url = f"{pds_url_base}/{pds_config}/custom_units"
    return get(url)