import fire
import pandas as pd


def run(
    inpath="data/PMC-Patients/meta_data/PMC-Patients.json",
    outpath="data/PMC-Patients/pmc_patients.parquet",
):
    df = pd.read_json(inpath)

    # age column is in a weird format of list in list, e.g. [[60.0, year]]
    # this causes issues in the parquet format so convert to separate columns
    df["age_value"] = pd.Series([i[0][0] for i in df["age"]]).astype(int)
    df["age_units"] = [i[0][1] for i in df["age"]]
    df.drop(columns=["age"], inplace=True)

    df.to_parquet(outpath)


if __name__ == "__main__":
    fire.Fire(run)
