Пример #1
0
 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(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)
Пример #3
0
 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."),
             ),
         ],
     )
Пример #4
0
 def transform_results(df: pd.DataFrame, **expand_args):
     return Frame.expand(
         df,
         custom_columns=[
             *expand_args.get("custom_columns", []),
             ("name", expand_name_column),
         ],
     )
Пример #5
0
 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"),
         ],
     )
Пример #6
0
 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"),
         ],
     )
Пример #7
0
 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"),
         ],
     )
Пример #8
0
    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)
Пример #9
0
 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"),
         ],
     )
Пример #10
0
 def transform_results(df: pd.DataFrame, **expand_args):
     return Frame.expand(
         df,
         date_columns=[
             *expand_args.get("date_columns", []),
             "recorded",
             "signature.when",
         ],
         code_columns=[
             *expand_args.get("code_columns", []),
             "agent",
             "signature",
         ],
     )
Пример #11
0
 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."),
             ),
         ],
     )
Пример #12
0
 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"),
         ],
     )
Пример #13
0
    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(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"),
         ],
     )
Пример #15
0
 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'}}]
         ],
     )
Пример #16
0
    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)
Пример #17
0
 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."),
             ),
         ],
     )
Пример #18
0
def test_frame_expand_date_out_of_range():
    original = pd.DataFrame(
        [
            {"effectiveDateTime": "2020-09-15 12:31:00-0500", "id": "obs1"},
            {"effectiveDateTime": "0217-05-04 12:31:00-0500", "id": "obs2"},
        ]
    )

    expanded = Frame.expand(original)

    assert expanded.at[0, "effectiveDateTime.tz"] == -5.0
    assert expanded.at[0, "effectiveDateTime.local"] == pd.Timestamp(
        "2020-09-15 12:31:00", tz="utc"
    )

    assert math.isnan(expanded.at[1, "effectiveDateTime.tz"])
    assert pd.isna(expanded.at[1, "effectiveDateTime.local"])
Пример #19
0
    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)
Пример #20
0
    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)
Пример #21
0
 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"),
         ],
     )
Пример #22
0
def test_local_and_timezone_split():
    original = pd.DataFrame(
        [
            {"effectiveDateTime": "2020-08-08 11:00:00+0300", "id": "obs1"},
            {"effectiveDateTime": "2020-08-09 10:00:00-0400", "id": "obs2"},
        ]
    )

    expanded = Frame.expand(original)

    assert expanded.at[0, "effectiveDateTime.tz"] == 3.0
    assert expanded.at[0, "effectiveDateTime.local"] == pd.Timestamp(
        "2020-08-08 11:00:00", tz="utc"
    )

    assert expanded.at[1, "effectiveDateTime.tz"] == -4.0
    assert expanded.at[1, "effectiveDateTime.local"] == pd.Timestamp(
        "2020-08-09 10:00:00", tz="utc"
    )
Пример #23
0
 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"),
         ],
     )
Пример #24
0
    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
Пример #25
0
    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"})["variant_set_id"],
                ],
                axis=1,
            )

        args = {
            **expand_args,
            "custom_columns": [
                *expand_args.get("custom_columns", []),
                ("id", expand_id),
            ],
        }

        return Frame.expand(data_frame, **args)
Пример #26
0
 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"),
         ],
     )
Пример #27
0
 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"),
         ],
     )