def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[ *expand_args.get("date_columns", []), "authoredOn", "dispenseRequest.validityPeriod.start", "dispenseRequest.validityPeriod.end", ], code_columns=[ *expand_args.get("code_columns", []), "medicationCodeableConcept", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("context"), Frame.codeable_like_column_expander("note"), ( "dispenseRequest", lambda r: pd.json_normalize(r).add_prefix( "dispenseRequest."), ), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[ *expand_args.get("date_columns", []), "period.start", "period.end", ], code_columns=[ *expand_args.get("code_columns", []), "class", "priority", "participant", "length", "hospitalization", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("period"), Frame.codeable_like_column_expander("reason"), Frame.codeable_like_column_expander("location"), Frame.codeable_like_column_expander("serviceProvider"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("presentedForm"), Frame.codeable_like_column_expander("result"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[*expand_args.get("date_columns", []), "dateTime"], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("sourceReference"), Frame.codeable_like_column_expander("actor"), Frame.codeable_like_column_expander("patient"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[*expand_args.get("date_columns", []), "date"], code_columns=[*expand_args.get("code_columns", []), "vaccineCode"], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("patient"), Frame.codeable_like_column_expander("encounter"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, code_columns=[ *expand_args.get("code_columns", []), "procedureCode", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("patient"), Frame.codeable_like_column_expander("context"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, code_columns=[*expand_args.get("code_columns", []), "type"], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("context"), ( "requester", lambda r: pd.json_normalize(r).add_prefix("requester."), ), ], )
def transform_results(data_frame: pd.DataFrame, **expand_args): args = { **expand_args, "code_columns": [ *expand_args.get("code_columns", []), "specimen", "repository", ], "custom_columns": [ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("patient"), Frame.codeable_like_column_expander("referenceSeq"), ], } return Frame.expand(data_frame, **args)
def transform_results(data_frame: pd.DataFrame, params={}, **expand_args): def expand_id(id_column: pd.Series): return pd.concat( [ id_column, id_column.str.split(":", expand=True).rename(columns={ 0: "variant_set_id", 2: "gene" })[["variant_set_id", "gene"]], ], axis=1, ) args = { **expand_args, "custom_columns": [ *expand_args.get("custom_columns", []), *[ Frame.codeable_like_column_expander(k) for k in [ "clinvar", "cosmic", "vcf", "ensemblCanon", "dbnsfp", ] ], ("id", expand_id), ], } return Frame.expand(data_frame, **args)
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[*expand_args.get("date_columns", []), "date"], code_columns=[ *expand_args.get("code_columns", []), "type", "author", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("text"), Frame.codeable_like_column_expander("relatesTo"), ], )
def transform_results(data_frame: pd.DataFrame, **expand_args): args = { **expand_args, "code_columns": [ *expand_args.get("code_columns", []), "component", "interpretation", ], "custom_columns": [ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("related"), Frame.codeable_like_column_expander("performer"), Frame.codeable_like_column_expander("context"), ], } return Frame.expand(data_frame, **args)
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[ *expand_args.get("date_columns", []), "occurrencePeriod.start", "occurrencePeriod.end", "occurrenceDateTime", "authoredOn", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("context"), Frame.codeable_like_column_expander("occurrencePeriod"), Frame.codeable_like_column_expander("note"), ], )
def transform_results(data_frame: pd.DataFrame, **expand_args): args = { **expand_args, "date_columns": [ *expand_args.get("date_columns", []), "performedPeriod.start", "performedPeriod.end", ], "custom_columns": [ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("performedPeriod"), Frame.codeable_like_column_expander("context"), Frame.codeable_like_column_expander("managingOrganization"), ], } return Frame.expand(data_frame, **args)
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[ *expand_args.get("date_columns", []), "effectiveDateTime", ], code_columns=[ *expand_args.get("code_columns", []), "type", "subtype", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("agent"), Frame.codeable_like_column_expander("source"), Frame.codeable_like_column_expander("entity"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[ *expand_args.get("date_columns", []), "effectivePeriod.start", "effectivePeriod.end", ], code_columns=[ *expand_args.get("code_columns", []), "medicationCodeableConcept", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("context"), Frame.codeable_like_column_expander("prescription"), Frame.codeable_like_column_expander("dosage"), Frame.codeable_like_column_expander("effectivePeriod"), ], )
def transform_results(data_frame: pd.DataFrame, **expand_args): args = { **expand_args, "date_columns": [*expand_args.get("date_columns", []), "startDate"], "custom_columns": [ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), ], } return Frame.expand(data_frame, **args)
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[ *expand_args.get("date_columns", []), "onsetDateTime", "assertedDate", "onsetPeriod.start", "onsetPeriod.end", ], code_columns=[ *expand_args.get("code_columns", []), "bodySite", "stage", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), Frame.codeable_like_column_expander("onsetPeriod"), Frame.codeable_like_column_expander("context"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, code_columns=[ *expand_args.get("code_columns", []), "collection", "type", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, code_columns=[ *expand_args.get("code_columns", []), "medicationCodeableConcept", "quantity", "dosageInstruction", "daysSupply", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[ *expand_args.get("date_columns", []), "effectiveDateTime", ], code_columns=[ *expand_args.get("code_columns", []), "medicationCodeableConcept", ], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), ], )
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, code_columns=[*expand_args.get("code_columns", []), "type"], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), # TODO: Properly parse content column # # Example: # [{'attachment': {'contentType': 'application/gzip', # 'url': 'https://api.us.lifeomic.com/v1/files/<uuid>', # 'size': 182539, # 'title': 'helix-source-files/normalized/<filename>.vcf.gz'}}] ], )
def transform_results(data_frame: pd.DataFrame, **expand_args): args = { **expand_args, "code_columns": [ *expand_args.get("code_columns", []), "contained", "maritalStatus", ], "custom_columns": [ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("managingOrganization"), ("address", expand_address_column), ("name", expand_name_column), ], } return Frame.expand(data_frame, **args)
def transform_results(df: pd.DataFrame, **expand_args): return Frame.expand( df, date_columns=[ *expand_args.get("date_columns", []), "occurrenceDateTime", ], code_columns=[*expand_args.get("code_columns", []), "bodySite"], custom_columns=[ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("subject"), ( "content", lambda r: pd.json_normalize(r).add_prefix("content."), ), ], )
def transform_results( data_frame: pd.DataFrame, params: dict, **expand_args ): args = { **expand_args, "code_columns": [ *expand_args.get("code_columns", []), "bodySite", "patient", ], "custom_columns": [ *expand_args.get("custom_columns", []), Frame.codeable_like_column_expander("sourceFile"), ], } df = Frame.expand(data_frame, **args) if "sets" in df.columns: df = ( pd.concat( data_frame.apply( lambda x: pd.DataFrame( [{"index": x.name, **s} for s in x.sets] ), axis=1, ).values ) .join(df.drop(["sets"], axis=1), on="index", rsuffix=".test") .drop(["index"], axis=1) .reset_index(drop=True) ) test_type = params.get("type", None) if test_type and len(df) > 0: # TODO: Remove when API fixed # NOTE: The API does not filter the returned sets because it is a # nested structure. Since it's not a boatload of information, we opt # to filter client-side for now. return df[df.setType == test_type].reset_index(drop=True) return df
def get_data_frame(document_id: str, raw: bool = False, auth_args: Auth = Auth.shared()): auth = Auth(auth_args) document = Document.get(document_id, auth_args=auth_args) file_id = pipe( document.get("content", []), c.filter(lambda c: c.get("format", {}).get("code") == "ocr-text-file-id"), c.first, c.get("attachment", default={}), c.get("url"), iffy(isa(str), lambda url: url.split("/")[-1]), ) if file_id is None: raise ValueError( f"No block file found for document: '{document_id}'") files = Files(auth.session()) filename = files.download(file_id, "/tmp/") frame = pd.read_json(filename, lines=True) os.remove(filename) if raw or len(frame) == 0: return frame return Block.sort( frame.drop(["Geometry"], axis=1).join( pd.json_normalize(frame.Geometry)).pipe( partial( Frame.expand, custom_columns=[ Frame.codeable_like_column_expander("Polygon") ], )).set_index("Id"))