Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sequential_drug_recommendation #55

Closed
bbb801 opened this issue Dec 28, 2022 · 4 comments
Closed

sequential_drug_recommendation #55

bbb801 opened this issue Dec 28, 2022 · 4 comments

Comments

@bbb801
Copy link

bbb801 commented Dec 28, 2022

Dear sir/Madam,

In 'Advanced Case 2: Work on customized healthcare task' , I have questions about 'sequential_drugs' and 'drugs' (see following codes). It seems 'sequential_drugs' is always empty. What ' sequential_drugs[-1] = drugs' is used for at the final row?

def sequential_drug_recommendation(patient):
samples = []

sequential_conditions = []
sequential_procedures = []
sequential_drugs = [] # not include the drugs now
for visit in patient:

    # step 1: obtain feature information
    conditions = visit.get_code_list(table="DIAGNOSES_ICD")
    procedures = visit.get_code_list(table="PROCEDURES_ICD")
    drugs = visit.get_code_list(table="PRESCRIPTIONS")

    sequential_conditions.append(conditions)
    sequential_procedures.append(drugs)
    sequential_drugs.append([])

    # step 2: exclusion criteria: visits without drug
    if len(drugs) == 0: 
        sequential_drugs[-1] = drugs
        continue

    # step 3: assemble the samples
    samples.append(
        {
            "visit_id": visit.visit_id,
            "patient_id": patient.patient_id,
            # the following keys can be the "feature_keys" or "label_key" for initializing downstream ML model
            "sequential_conditions": sequential_drugs.copy(),
            "sequential_procedures": sequential_procedures.copy(),
            "sequential_drugs": sequential_drugs.copy(),
            "label": drugs,
        }
    )
    sequential_drugs[-1] = drugs

return samples
@ycq091044
Copy link
Collaborator

Thanks for the question. sequential_drug_recommendation works as an example to show how to define a healthcare task in pyhealth. By definition:

Sequential drug recommendation aims at predicting the drug set of the current visit given the history of diagnosis and procedure information as well as past drug information.

We want to use the diagnosis and procedures of visit-1 up to visit-N and the drug information from visit-1 up to visit-(N-1) to predict the drug in visit-N. A sample in this task looks like this:

{
   "patient_id": xxx,
   "visit_id": xxx,
   "sequential_conditions": [diagnoses-visit-1, diagnosis-visit-2, ..., diagnosis-visit-N],
   "sequential_procedures": [procedure-visit-1, procedure-visit-2, ..., procedure-visit-N],
   "sequential_drugs": [drug-visit-1, drug-visit-2, ..., drug-visit-(N-1)],
   "label": [drug-visit-N],
}

Some explanations for the task:

  1. The current drugs are what we want to predict, so they cannot be included in the feature lists. Thus, we use
sequential_conditions.append(conditions)
sequential_procedures.append(drugs)
sequential_drugs.append([])
  1. If the current drugs (i.e., predicted targets are empty, we ignore this visit).
if len(drugs) == 0: 
    sequential_drugs[-1] = drugs
    continue
  1. After we obtain the sample for the current visit, we will have to add the drugs back for the next visit. Thus we have the following line in the end.
sequential_drugs[-1] = drugs
  1. For the question "It seems 'sequential_drugs' is always empty." Because many patients only have one visit.

@bbb801
Copy link
Author

bbb801 commented Dec 29, 2022 via email

@bbb801
Copy link
Author

bbb801 commented Dec 30, 2022

Thank you. I still have a question about the following codes. May I know why 'drug' is in 'sequential_procedures.append(drugs)' instead of ' procedures'?

"""
Some explanations for the task:

The current drugs are what we want to predict, so they cannot be included in the feature lists. Thus, we use
sequential_conditions.append(conditions)
sequential_procedures.append(drugs)
sequential_drugs.append([])
"""

@ycq091044
Copy link
Collaborator

Good findings. This is a typo, just corrected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants