Code Monkey home page Code Monkey logo

Comments (5)

ycq091044 avatar ycq091044 commented on May 22, 2024

Yes, I'd like to help. Could you share with us what functions you have called?

from pyhealth.

azusakou avatar azusakou commented on May 22, 2024

Yes, I'd like to help. Could you share with us what functions you have called?

Thanks for your reply.

from pyhealth.datasets import eICUDataset

base_dataset = eICUDataset(
    root="./eicu-crd/2.0",
    tables=["diagnosis", "medication", "physicalExam"],
    dev=True,
    refresh_cache=False,
)
sample_dataset = base_dataset.set_task(task_fn=drug_recommendation_eicu_fn)
sample_dataset.stat()
print(sample_dataset.available_keys)

the error is from:
sample_dataset = base_dataset.set_task(task_fn=drug_recommendation_eicu_fn)

from pyhealth.

ycq091044 avatar ycq091044 commented on May 22, 2024

Thanks for your patience. I just found the issue. We have a typo in drug_recommendation_eicu_fn in the current package version. Could you please use the following function to replace (not import from pyhealth.tasks, but directly define the function and use it):

def drug_recommendation_eicu_fn(patient):
    samples = []
    for i in range(len(patient)):
        visit = patient[i]
        conditions = visit.get_code_list(table="diagnosis")
        procedures = visit.get_code_list(table="physicalExam")
        drugs = visit.get_code_list(table="medication")
        # exclude: visits without condition, procedure, or drug code
        if len(conditions) * len(procedures) * len(drugs) == 0:
            continue
        # TODO: should also exclude visit with age < 18
        samples.append(
            {
                "visit_id": visit.visit_id,
                "patient_id": patient.patient_id,
                "conditions": conditions,
                "procedures": procedures,
                "drugs": drugs,
                "drugs_all": drugs,
            }
        )
    # exclude: patients with less than 2 visit
    if len(samples) < 2:
        return []
    # add history
    samples[0]["conditions"] = [samples[0]["conditions"]]
    samples[0]["procedures"] = [samples[0]["procedures"]]
    samples[0]["drugs_all"] = [samples[0]["drugs_all"]]

    for i in range(1, len(samples)):
        samples[i]["conditions"] = samples[i - 1]["conditions"] + [
            samples[i]["conditions"]
        ]
        samples[i]["procedures"] = samples[i - 1]["procedures"] + [
            samples[i]["procedures"]
        ]
        samples[i]["drugs_all"] = samples[i - 1]["drugs_all"] + [
            samples[i]["drugs_all"]
        ]

    return samples

So, this new function is almost the same as the one that you have imported. The only difference is that in the second to last line:

samples[i]["drugs"] = samples[i - 1]["drugs_all"] + [
            samples[i]["drugs_all"]
        ]

is changed into

samples[i]["drugs_all"] = samples[i - 1]["drugs_all"] + [
            samples[i]["drugs_all"]
        ]

from pyhealth.

ycq091044 avatar ycq091044 commented on May 22, 2024

BTW, the task function is really just an example of how we define healthcare tasks. You can follow the pattern and modify for your own purpose.

from pyhealth.

azusakou avatar azusakou commented on May 22, 2024

BTW, the task function is really just an example of how we define healthcare tasks. You can follow the pattern and modify for your own purpose.

It works! Many thanks!!!

from pyhealth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.