Abstract
Medication recommendation aims to generate treatment regimens that balance efficacy and safety based on patients' historical medical records. Recent studies leveraging longitudinal Electronic Health Records (EHR) sequence modeling have significantly improved recommendation accuracy. However, existing methods still face two main limitations: on the encoder side, most approaches rely solely on sequence models to learn patient representations, failing to adequately mine the structured medical knowledge implicit in EHR; on the decoder side, methods employing a "copy-and-add" recommendation strategy attempt to simulate clinical decision-making but generally lack explicit modeling of long-tail drug distributions and temporal dynamics. To address these issues, we propose HeteroMed, a medication recommendation model enhanced by heterogeneous graph knowledge. The model constructs a multi-relational medical heterogeneous graph covering diagnosis, procedure, and drug entities to effectively integrate the structured cross-entity medical knowledge from EHR. It employs a gating mechanism to achieve dynamic knowledge fusion, thereby mitigating risks from noise and distribution shift. In the decoding stage, HeteroMed incorporates temporal factors and proposes a collaborative drug expansion and inheritance framework to model the increases and decreases in patient medication usage, achieving the appropriate introduction of potentially effective new drugs while retaining suitable existing ones. Furthermore, the model introduces an expected Drug-Drug Interaction (DDI) regularizer to enhance the safety of the recommended drug combination. Experimental results on two public datasets demonstrate that HeteroMed outperforms multiple representative baseline models on various metrics, and exhibits a stronger balancing capability between prescription efficacy and safety.