When a patient arrives bleeding from the upper gut, faster endoscopy is not always better. A territory-wide Hong Kong cohort found that scoping within 6 hours carried a 43% higher adjusted 30-day mortality than scoping at 6–24 hours, and that waiting past 24 hours was also worse, giving a U-shaped risk curve (Guo et al.). The benefit of waiting is attributed to resuscitation, acid suppression, and correction of clotting during the delay. How long that delay should be, though, plausibly depends on what the patient is already taking. Someone on a short-acting reversible anticoagulant, someone on an irreversible antiplatelet, and someone on no antithrombotic at all are in different pharmacological states. Ten other co-medications that affect clearance, bleeding, or blood pressure complicate the picture further. Current timing studies ignore this: they use three fixed time bins and a binary "received pharmacotherapy" flag.
We propose to estimate patient-specific curves of outcome versus endoscopy delay from electronic health records. The model is a sequential causal estimator that adjusts for vitals and labs as they change over time. The patient's full medication list enters it through a graph neural network that reads each drug's chemical structure. A graph neural network here means a model that passes information between bonded atoms to produce a vector for each molecule. The molecular part is not assumed to help; it is put to a specific test. Drug structure should matter only where a simple drug-identity code cannot generalize: the long tail of rarely prescribed co-medications, and drugs absent from training. The central experiment is therefore a held-out-drug evaluation against pharmacology lookup tables and hand-crafted chemical descriptors, not a comparison on random splits.
Core Claim
The claim has two parts, and they can succeed or fail independently. First, replacing fixed time bins with continuous-time g-computation will produce individualized timing recommendations. G-computation estimates outcomes by simulating each patient's trajectory forward under a hypothetical decision rule. These recommendations should reproduce the aggregate U-shape of Guo et al. yet diverge from the "6–24 hours for everyone" rule for identifiable subgroups. Second, encoding the co-medication list through molecular structure will improve outcome prediction and effect-modification estimates for patients whose medication lists contain drugs that were rare or unseen in training. It should give no gain where drugs are common. If the second part fails against pharmacology tables or descriptors, we will say so and ship the timing model with the simpler encoding.
In this design the molecule is a covariate and possible effect modifier, not the treatment being timed. The treatment is when to scope. This departs from the obvious combination, which would feed drug structure into the treatment slot of a counterfactual model. That version would only help if the timed interventions themselves were many and structurally diverse, which in acute care they are not.
Relation to Prior Work
Three lines of work motivate the proposal, and each supplies one piece. The clinical timing literature shows that a stabilization window exists but can only describe it through bins. Guo et al. and its abstract version (Guo et al.) use inverse probability of treatment weighting over three bins. Inverse probability weighting reweights patients so the timing groups look alike on baseline covariates. Kotani et al. delayed a craniotomy 6 hours until D-dimer and fibrinogen normalized, which is a case-level instance of letting the patient's clotting state set the timing. The authors of Guo et al. concede that crashing patients who deteriorate early are handled poorly by their design. That concession is the gap we target: baseline weighting cannot handle a patient who is scoped urgently because they worsened at hour 5.
Sequential counterfactual models supply the causal method. The Counterfactual Recurrent Network (Bica et al.) learns a patient-history representation that cannot predict treatment assignment. It reported a 48.1% improvement in counterfactual error over a standard recurrent network on a simulated tumor model under strong selection bias. G-Net (Li et al.) implements g-computation with recurrent networks and can evaluate dynamic rules such as "treat once pressure exceeds a threshold." Its ablations show that models seeing only the current snapshot underperform those using full history. We reuse G-Net's structure, because timing policies are naturally dynamic rules. Both methods treat drugs as one-hot indices, and we change only that input.
Molecular graph work supplies the encoder and also constrains our expectations. MPNP-DDI (Yan et al.) operates on line graphs, in which bonds become nodes and bond angles become edges, and adds cross-drug attention. It reports 99.35% AUROC on DrugBank and 98.94% on Twosides, against 90.07% for GMPNN-CS. Its encoder, pretrained on pairwise interactions, is our candidate for embedding each co-medication with interaction-awareness built in.
Therapeutics Data Commons (Huang et al.) is the key constraining result. On realistic out-of-distribution splits, graph models often fail to beat RDKit 2D descriptors, and drug–target correlation falls from about 0.7 to about 0.4 under temporal splits. This is why descriptors are a first-class baseline here rather than a straw man.
Finally, BernGraph (Piao et al.) builds graphs over electronic health record codes to fight the more than 99% sparsity of binary code vectors. It reports F1 of 0.846 for medication recommendation on MIMIC-III, but it contains no chemistry and no timing. We borrow its point that sparse drug codes starve neural models. We then ask whether chemistry, rather than code co-occurrence, is the better way to densify them.
Research Program
The cohort is adult upper-gastrointestinal-bleeding admissions in MIMIC-IV, with index time at emergency presentation. Time runs in hourly steps up to 48 hours or until endoscopy. At each hour the model sees vitals, hemoglobin, platelets, INR, creatinine, transfusions, vasopressors, and proton pump inhibitor infusion. It also sees the active medication list, which includes pre-admission antithrombotics recorded in medication reconciliation and all inpatient administrations.
A feasibility gate comes first. Some MIMIC-IV hospital procedure records carry only a date. We will keep only patients whose endoscopy has an hour-resolution timestamp from ICU or procedure-event tables, and report how many remain. If fewer than roughly a thousand qualify, the study becomes a methods paper validated semi-synthetically. The same code would then be offered for CDARS-style registries.
Each drug is converted from its structure into a molecular graph and embedded by a line-graph encoder initialized from DDI pretraining in the style of MPNP-DDI. Heparins and other polydisperse biologics have no single graph. They receive a learned class token instead, and this exception is reported. The per-hour medication set is pooled with attention to form a pharmacological-state vector.
The causal estimator is G-Net-style g-computation with three learned components: a model for how covariates evolve, a model for the hourly hazard of endoscopy, and a model for the outcome. Rollouts are run under dynamic policies of the form "scope at the first hour after $h_{\min}$ at which mean arterial pressure and hemoglobin are stable, and no fewer than $k$ hours after the last anticoagulant dose." The result is a per-patient curve of predicted outcome risk against delay. The outcome is Guo's composite of 30-day mortality, repeat endoscopy, and ICU admission, because mortality alone is too rare in a single-center cohort to rank policies with any power. The composite is also reported split into its components.
Two confounding problems are handled explicitly. Immortal time is addressed with a clone-and-censor emulation of each policy, and positivity is checked by plotting the estimated treatment hazard. Positivity means every patient type must have some realistic chance of each timing. Where hourly scoping probability falls near zero or one, no recommendation is issued.
Baselines
The naive reference is the population rule implied by Guo et al.: scope everyone in the 6–24 hour window. We will re-estimate it on our cohort with the same bins and inverse probability weighting. The published figures from their cohort are aHR 1.43 for urgent versus early and 1.25 for late versus early. Reproducing a U-shape of similar direction is our first sanity check. A second reference is observed care, meaning the timing each patient actually received.
The strongest existing method for timing under time-varying confounding is G-Net (Li et al.) with medications as multi-hot drug indices. CRN (Bica et al.) is run alongside it. The file reports no raw error value for G-Net on CVSim or on the tumor simulator, so there is no reported result found on Lacuna for G-Net's absolute error. The only quantitative anchor is CRN's 48.1% gain over a standard recurrent network. We will therefore re-run both ourselves on the tumor simulator to confirm our implementations before touching real data.
Two pharmacology-aware encodings are the serious competitors to the graph encoder, and all variants share the identical G-Net backbone. The first uses curated features: Anatomical Therapeutic Chemical class, reversibility, and tabulated half-life and renal clearance fraction. The second uses pooled RDKit 2D descriptors and Morgan fingerprints, which Huang et al. found hard to beat. A BernGraph-style Bernoulli code densification (Piao et al.) tests whether co-occurrence rather than chemistry explains any gain.
Two ablations isolate the key ingredient. One uses the same graph encoder with random initialization. The other randomly permutes structures across drugs, keeping a learned vector per drug while destroying chemical meaning. Every variant gets the same data splits, the same number of hyperparameter trials, the same compute, and five seeds.
Beating G-Net-multi-hot means lower Brier score on the held-out-drug split, with a paired bootstrap confidence interval excluding zero. It also means no loss on the common-drug split. Beating the curated-pharmacology baseline on that same held-out split is the bar for claiming that molecular structure matters.
Why not just…?
Why not just use drug class and known half-life instead of molecular graphs? This is the most serious threat. For approved antithrombotics, clearance and reversibility are tabulated and probably carry most of the timing-relevant signal. The graph encoder can only earn its place where tables are missing or coarse: the hundreds of low-frequency co-medications with unrecorded interaction-relevant properties, and drugs unseen in training. The held-out-drug split, which holds out whole drugs and whole scaffolds, decides this. If curated features tie the graph encoder there, we adopt them and report a negative result for structure.
Why not just refine Guo's analysis with finer bins or a spline in delay under baseline weighting? A spline removes bin boundaries but still weights on baseline covariates. It therefore mishandles patients whose deterioration causes early scoping, the feedback that Bica et al. and Li et al. show biases static methods. We run the spline model as a baseline. In a semi-synthetic version of our cohort, real covariates drive simulated outcomes and a simulated deterioration-triggered scoping rule. There the spline's policy-value error should grow with feedback strength while g-computation's should not. If it does not grow, the simpler model suffices.
Why not just use RDKit descriptors, since they match graph models on realistic splits? Huang et al. make exactly this point, so descriptors are a full baseline rather than a straw man. Pairwise interaction-aware pretraining (Yan et al.) is what descriptors lack. Whether that pretraining matters in polypharmacy is tested by the pretrained-versus-random-initialization ablation and by a subgroup analysis of patients on five or more co-medications.
Why not just predict from a current-hour snapshot? G-Net's own ablations show that snapshot models underperform history-based ones (Li et al.). We include a snapshot network, mainly to confirm this on real data.
Proposed Experiments
The first check is the semi-synthetic benchmark. Real MIMIC-IV trajectories and medication lists are paired with simulated outcomes. In these simulations the benefit of delay depends on hidden drug properties that no model is given directly. In one arm the relevant property is derived from structure; in another it is a structure-independent property assigned per drug. Held-out drugs are evaluated. Molecular encoding should win only in the first arm. This guards against a gain that comes merely from extra parameters.
The second check is on real outcomes. We measure factual prediction of the composite outcome, using Brier score and calibration, on three splits: random patients, patients exposed to drugs rare in training, and a scaffold-held-out drug split. The expected pattern is no gain on the random split and a gain on the rare and held-out splits. A gain on the random split alone would suggest leakage or overfitting rather than chemistry.
The third check is policy evaluation. We estimate the value of the learned individualized policy against the 6–24 hour rule with a doubly robust off-policy estimator, restricted to regions with adequate overlap. We also report whether the aggregate delay–risk curve reproduces the U-shape.
Residual confounding by shock severity is probed with a negative-control outcome that endoscopy timing cannot plausibly affect, such as pre-endoscopy transfusion volume in the first two hours. We also report a sensitivity analysis that asks how strong an unmeasured confounder would need to be to erase the recommended subgroup differences.
The result that would most change clinical practice is a subgroup-level finding, such as patients on recently dosed factor Xa inhibitors, whose recommended delay differs from 6–24 hours. That finding must survive the held-out-drug split, the negative control, and the overlap restriction. Only then do we report it as a hypothesis for prospective testing.
References
- Timing of endoscopy for acute upper gastrointestinal bleeding: a territory-wide cohort study
- IDDF2020-ABS-0194 Timing of endoscopy for acute upper gastrointestinal bleeding: a territory-wide cohort study
- Acute epidural vertex hematoma with good hemostasis using delayed surgery after monitoring of coagulation and fibrinolytic parameters: A case report
- Estimating counterfactual treatment outcomes over time through adversarially balanced representations
- G-Net: a Recurrent Network Approach to G-Computation for Counterfactual Prediction Under a Dynamic Treatment Regime
- A Multi-Scale Graph Neural Process with Cross-Drug Co-Attention for Drug-Drug Interactions Prediction
- Therapeutics Data Commons: Machine Learning Datasets and Tasks for Drug Discovery and Development
- BernGraph: Probabilistic Graph Neural Networks for EHR-based Medication Recommendations