Skip to content

Fix drug recommandation drug code and padding. #1138

Merged
jhnwu3 merged 4 commits intosunlabuiuc:masterfrom
Logiquo:fix/dr
Apr 25, 2026
Merged

Fix drug recommandation drug code and padding. #1138
jhnwu3 merged 4 commits intosunlabuiuc:masterfrom
Logiquo:fix/dr

Conversation

@Logiquo
Copy link
Copy Markdown
Collaborator

@Logiquo Logiquo commented Apr 25, 2026

Fix #1137

@Logiquo Logiquo requested a review from jhnwu3 April 25, 2026 14:16
Copy link
Copy Markdown
Collaborator

@jhnwu3 jhnwu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tldr; Would be good to just delete the .codex file.

I'm curious about the logic wit the test casing with the FakeLegacyPatient class here, but not too concerned at the moment.

Comment thread .codex Outdated
Comment thread tests/core/test_drug_recommendation_atc3.py Outdated
_NDC_TO_ATC3_CACHE: Dict[str, List[str]] = {}


def _get_ndc_to_atc3_mapper():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention, sequence processor can also handle the code mappings now too. Don't think it matters that much here, but worth sharing.

class SequenceProcessor(FeatureProcessor, TokenProcessorInterface):
    """Feature processor for encoding categorical sequences.

    Encodes medical codes (e.g., diagnoses, procedures) into numerical
    indices. Supports single or multiple tokens and can build vocabulary
    on the fly if not provided.

    Args:
        code_mapping: optional tuple of (source_vocabulary, target_vocabulary)
            to map raw codes to a grouped vocabulary before tokenizing.
            Uses ``pyhealth.medcode.CrossMap`` internally. For example,
            ``("ICD9CM", "CCSCM")`` maps ~128K ICD-9 diagnosis codes to
            ~280 CCS categories, and ``("NDC", "ATC")`` maps ~940K drug
            codes to ~5K ATC categories. When None (default), codes are
            used as-is with no change to existing behavior.

    Examples:
        >>> proc = SequenceProcessor()  # no mapping, same as before
        >>> proc = SequenceProcessor(code_mapping=("ICD9CM", "CCSCM"))
    """

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit tricky because NestedSequence & MultiLabel does not yet support this. May be better to left this into a future PR.

Copy link
Copy Markdown
Collaborator

@jhnwu3 jhnwu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new changes lgtm

@jhnwu3 jhnwu3 merged commit 1262a76 into sunlabuiuc:master Apr 25, 2026
1 check passed
@Logiquo Logiquo deleted the fix/dr branch April 26, 2026 03:38
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

Successfully merging this pull request may close these issues.

PyHealth 2.0 cannot reproduce previous MIMIC-III drug recommendation / SafeDrug performance

2 participants