marmar-context / src / domain / checks / sources.ts
sources.ts
Raw
/**
 * Named references a finding can cite. Every rule points at one or more of
 * these ids, and the writing layer may only cite ids that a finding carries.
 *
 * DRAFT: the rule tables that use these sources need a clinical pharmacist's
 * sign-off before CHECK_V2_ENABLED is turned on (see docs/api/medicine-checks.md).
 * Labels are cited by product, not by section number, because section
 * numbering differs between the FDA label and the UK SmPC.
 */
export interface CheckSource {
  id: string;
  name: string;
  kind: 'label' | 'guideline' | 'criteria' | 'public_health' | 'reference';
  url: string | null;
}

const sources = [
  { id: 'label-warfarin', name: 'Warfarin product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=warfarin' },
  { id: 'label-nsaid', name: 'NSAID product labels (ibuprofen, diclofenac, naproxen)', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=ibuprofen' },
  { id: 'label-rivaroxaban', name: 'Rivaroxaban product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=rivaroxaban' },
  { id: 'label-apixaban', name: 'Apixaban product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=apixaban' },
  { id: 'label-paracetamol', name: 'Paracetamol (acetaminophen) product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=acetaminophen' },
  { id: 'label-amlodipine', name: 'Amlodipine product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=amlodipine' },
  { id: 'label-rosuvastatin', name: 'Rosuvastatin product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=rosuvastatin' },
  // Where no source of its own is listed for a medicine's maximum: its own label, never another medicine's (M3). The pharmacist may name one.
  { id: 'label-product', name: 'The medicine\'s own product label (UK SmPC or patient leaflet)', kind: 'label', url: null },
  { id: 'label-simvastatin', name: 'Simvastatin product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=simvastatin' },
  { id: 'label-atorvastatin', name: 'Atorvastatin product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=atorvastatin' },
  { id: 'label-tramadol', name: 'Tramadol product label (serotonin syndrome and seizure warnings)', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=tramadol' },
  { id: 'label-sulfonylurea', name: 'Sulfonylurea product labels (glimepiride, glipizide, glyburide)', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=glimepiride' },
  { id: 'label-artemether-lumefantrine', name: 'Artemether and lumefantrine (Coartem) product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=coartem' },
  { id: 'liverpool-efavirenz-artemether-lumefantrine', name: 'University of Liverpool HIV drug interactions: efavirenz with artemether/lumefantrine', kind: 'reference', url: 'https://www.hiv-druginteractions.org/interactions/69284' },
  { id: 'label-metformin', name: 'Metformin product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=metformin' },
  // The catalogue's 3,000 mg a day is the UK maximum ("3 g daily, taken as 3 divided doses"); US labels allow 2,550 mg.
  { id: 'smpc-metformin', name: 'Glucophage (metformin) 500 mg film-coated tablets: UK SmPC', kind: 'label', url: 'https://www.medicines.org.uk/emc/product/987/smpc' },
  { id: 'label-clopidogrel', name: 'Clopidogrel product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=clopidogrel' },
  { id: 'label-methotrexate', name: 'Methotrexate product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=methotrexate' },
  { id: 'label-azathioprine', name: 'Azathioprine product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=azathioprine' },
  { id: 'label-sildenafil', name: 'PDE5 inhibitor labels (sildenafil, tadalafil)', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=sildenafil' },
  { id: 'label-dolutegravir', name: 'Dolutegravir product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=dolutegravir' },
  { id: 'label-nevirapine', name: 'Nevirapine product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=nevirapine' },
  { id: 'who-malaria-guidelines', name: 'WHO guidelines for malaria (artesunate-amodiaquine with efavirenz: avoid)', kind: 'guideline', url: 'https://www.who.int/publications/i/item/guidelines-for-malaria' },
  { id: 'label-digoxin', name: 'Digoxin product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=digoxin' },
  { id: 'label-lithium', name: 'Lithium product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=lithium' },
  { id: 'label-fluoroquinolone', name: 'Ciprofloxacin and levofloxacin labels', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=ciprofloxacin' },
  { id: 'label-levothyroxine', name: 'Levothyroxine product label', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=levothyroxine' },
  { id: 'fda-opioid-benzodiazepine-2016', name: 'FDA boxed warning: opioids with benzodiazepines (2016)', kind: 'public_health', url: 'https://www.fda.gov/drugs/drug-safety-and-availability/fda-drug-safety-communication-fda-warns-about-serious-risks-and-death-when-combining-opioid-pain-or' },
  { id: 'nhs-warfarin', name: 'NHS: Warfarin', kind: 'public_health', url: 'https://www.nhs.uk/medicines/warfarin/' },
  { id: 'nhs-ibuprofen', name: 'NHS: Ibuprofen for adults', kind: 'public_health', url: 'https://www.nhs.uk/medicines/ibuprofen-for-adults/' },
  { id: 'nhs-paracetamol', name: 'NHS: Paracetamol for adults', kind: 'public_health', url: 'https://www.nhs.uk/medicines/paracetamol-for-adults/' },
  // UK maximums of 240 mg a day (US codeine labels allow 360 mg): pharmacist to confirm each page states it.
  { id: 'nhs-codeine', name: 'NHS: Codeine', kind: 'public_health', url: 'https://www.nhs.uk/medicines/codeine/' },
  { id: 'nhs-dihydrocodeine', name: 'NHS: Dihydrocodeine', kind: 'public_health', url: 'https://www.nhs.uk/medicines/dihydrocodeine/' },
  { id: 'nhs-aspirin', name: 'NHS: Aspirin for pain relief', kind: 'public_health', url: 'https://www.nhs.uk/medicines/aspirin-for-pain-relief/' },
  { id: 'nhs-anaphylaxis', name: 'NHS: Anaphylaxis', kind: 'public_health', url: 'https://www.nhs.uk/conditions/anaphylaxis/' },
  { id: 'nhs-aspirin-children', name: 'NHS: Who can and cannot take aspirin (not for children under 16)', kind: 'public_health', url: 'https://www.nhs.uk/medicines/aspirin-for-pain-relief/who-can-and-cannot-take-aspirin-for-pain-relief/' },
  // The 2003 label warning has no current page of its own; the pharmacist should attach the reference they use.
  { id: 'mhra-aspirin-children', name: 'MHRA: aspirin label warning, "Do not give to children aged under 16 years, unless on the advice of a doctor" (2003)', kind: 'public_health', url: null },
  { id: 'mhra-codeine-children', name: 'MHRA Drug Safety Update: codeine for pain only in children older than 12 (2013)', kind: 'public_health', url: 'https://www.gov.uk/drug-safety-update/codeine-for-analgesia-restricted-use-in-children-because-of-reports-of-morphine-toxicity' },
  { id: 'mhra-codeine-cough-children', name: 'MHRA Drug Safety Update: codeine for cough and cold not for children under 12 (2015)', kind: 'public_health', url: 'https://www.gov.uk/drug-safety-update/codeine-for-cough-and-cold-restricted-use-in-children' },
  { id: 'label-promethazine', name: 'Promethazine product label (not for children under 2)', kind: 'label', url: 'https://dailymed.nlm.nih.gov/dailymed/search.cfm?query=promethazine' },
  { id: 'mhra-cough-cold-children', name: 'MHRA Drug Safety Update: over-the-counter cough and cold medicines for children (2009)', kind: 'public_health', url: 'https://www.gov.uk/drug-safety-update/over-the-counter-cough-and-cold-medicines-for-children' },
  { id: 'label-night-nurse', name: 'Night Nurse patient leaflet (not for children under 16)', kind: 'label', url: 'https://assets.hpra.ie/products/Human/19454/9eaefa82-543f-40a7-92a2-03ff801e2b73.pdf' },
  { id: 'ema-codeine-children', name: 'European Medicines Agency: codeine-containing medicines referral (children under 12)', kind: 'public_health', url: 'https://www.ema.europa.eu/en/medicines/human/referrals/codeine-containing-medicines' },
  { id: 'nhs-st-johns-wort', name: 'NHS: herbal medicines and St John\'s wort', kind: 'public_health', url: 'https://www.nhs.uk/conditions/herbal-medicines/' },
  { id: 'beers-2023', name: 'American Geriatrics Society Beers Criteria (2023)', kind: 'criteria', url: 'https://doi.org/10.1111/jgs.18372' },
  { id: 'stopp-start-v3', name: 'STOPP/START criteria, version 3 (2023)', kind: 'criteria', url: 'https://doi.org/10.1007/s41999-023-00777-y' },
  { id: 'chest-2012', name: 'CHEST guideline: oral anticoagulant therapy (2012)', kind: 'guideline', url: 'https://doi.org/10.1378/chest.11-2292' },
  { id: 'nice-ng136', name: 'NICE NG136: Hypertension in adults', kind: 'guideline', url: 'https://www.nice.org.uk/guidance/ng136' },
  { id: 'nice-ng28', name: 'NICE NG28: Type 2 diabetes in adults', kind: 'guideline', url: 'https://www.nice.org.uk/guidance/ng28' },
  { id: 'ada-standards', name: 'American Diabetes Association Standards of Care', kind: 'guideline', url: 'https://diabetesjournals.org/care/issue' },
  { id: 'nice-lipids', name: 'NICE guidance on lipid modification', kind: 'guideline', url: 'https://www.nice.org.uk/guidance/ng238' },
  { id: 'nice-cks-ace', name: 'NICE CKS: ACE inhibitors and angiotensin receptor blockers (monitoring)', kind: 'guideline', url: 'https://cks.nice.org.uk/' },
  { id: 'nice-cks-hyperkalaemia', name: 'NICE CKS: Hyperkalaemia', kind: 'guideline', url: 'https://cks.nice.org.uk/topics/hyperkalaemia/' },
  { id: 'marmar-unknown-product', name: 'MARMAR: product we could not identify', kind: 'reference', url: null },
  // Added for MARMAR Context's specific references (FND-2), each checked on 30 October 2026. Cited by no table rule.
  { id: 'smpc-amoxicillin', name: 'Amoxicillin 500mg Capsules: UK SmPC (Aurobindo Pharma - Milpharm Ltd)', kind: 'label', url: 'https://www.medicines.org.uk/emc/product/526/smpc' },
  { id: 'nice-cg183', name: 'NICE CG183: Drug allergy: diagnosis and management (2014)', kind: 'guideline', url: 'https://www.nice.org.uk/guidance/cg183/chapter/Recommendations' },
  // No DOAC label covers these herbs; the rule is "expected from how the medicines work" and needs the pharmacist's source.
  { id: 'marmar-herbal-doac', name: 'MARMAR: garlic, ginger, turmeric and ginkgo with DOACs; no label covers this, expected from how these herbs affect clotting (to confirm)', kind: 'reference', url: null },
] as const satisfies readonly CheckSource[];

export type CheckSourceId = (typeof sources)[number]['id'];
export const CHECK_SOURCES: Record<CheckSourceId, CheckSource> = Object.fromEntries(sources.map((source) => [source.id, source])) as Record<CheckSourceId, CheckSource>;

/**
 * FND-2: the specific place a rule's basis is written, with its date, for MARMAR Context's "Why this finding". An
 * additional field: no rule's `sources` change, so no sign-off hash changes. Only references someone has opened and
 * read are listed (checked on 30 October 2026); the rest wait for the clinical safety lead (SPECIFIC_REFERENCE_TODO).
 */
export interface SpecificReference {
  sourceId: CheckSourceId;
  document: string;
  section: string;
  /** The version of the document read. */
  version: string;
  url: string;
  checkedOn: string;
  /** What that section says, in brief. */
  says: string;
  /** Only for these ingredients (catalogue keys), when the document is one product's label. */
  appliesTo?: string[];
}

const GLUCOPHAGE = { sourceId: 'smpc-metformin', document: 'Glucophage 500 mg film-coated tablets: UK SmPC (Merck)',
  version: 'Date of revision of the text: November 2025 (emc, updated 22 December 2025)', url: 'https://www.medicines.org.uk/emc/product/987/smpc',
  checkedOn: '2026-10-30' } as const;
const CG183 = { sourceId: 'nice-cg183', document: 'NICE clinical guideline CG183: Drug allergy: diagnosis and management',
  version: 'Published 3 September 2014', url: 'https://www.nice.org.uk/guidance/cg183/chapter/Recommendations', checkedOn: '2026-10-30' } as const;

export const SPECIFIC_REFERENCES: Readonly<Record<string, readonly SpecificReference[]>> = {
  'lab-metformin-egfr-45': [{ ...GLUCOPHAGE, section: '4.2 Posology and method of administration: renal impairment table',
    says: 'GFR 30-44 mL/min: total maximum daily dose 1000 mg, divided into 2-3 doses. GFR 45-59 mL/min: 2000 mg.' }],
  'lab-metformin-egfr-30': [{ ...GLUCOPHAGE, section: '4.2 Posology (renal impairment table) and 4.3 Contraindications',
    says: 'GFR under 30 mL/min: metformin is contraindicated (severe renal failure).' }],
  'kidney-dose-metformin': [{ ...GLUCOPHAGE, section: '4.2 Posology and method of administration: renal impairment table',
    says: 'Total maximum daily dose by GFR: 60-89 mL/min 3000 mg; 45-59 mL/min 2000 mg; 30-44 mL/min 1000 mg; under 30 mL/min contraindicated.' }],
  'allergy-penicillin': [
    { sourceId: 'smpc-amoxicillin', document: 'Amoxicillin 500mg Capsules: UK SmPC (Aurobindo Pharma - Milpharm Ltd)', section: '4.3 Contraindications',
      version: 'emc, updated 1 April 2025', url: 'https://www.medicines.org.uk/emc/product/526/smpc', checkedOn: '2026-10-30',
      says: 'Contraindicated with hypersensitivity to the active substance or to any of the penicillins, or a history of a severe '
        + 'immediate hypersensitivity reaction (for example anaphylaxis) to another beta-lactam.', appliesTo: ['amoxicillin'] },
    { ...CG183, section: 'Recommendations 1.2.2 and 1.2.6',
      says: 'Record the drug, the signs, symptoms and severity of the reaction and its date; check and confirm drug allergy status before prescribing.' },
  ],
};

/** Rules shown in Context whose specific reference is still to be added, and what is missing. For the clinical safety lead. */
export const SPECIFIC_REFERENCE_TODO: Readonly<Record<string, string>> = {
  'allergy-penicillin': 'TODO(clinical lead): the section 4.3 of each other penicillin\'s own label: ampicillin and cloxacillin (Ampiclox), '
    + 'co-amoxiclav (Augmentin: the amoxicillin reference covers its amoxicillin), flucloxacillin, phenoxymethylpenicillin and benzylpenicillin.',
  'lab-metformin-egfr-45': 'TODO(clinical lead): the rule\'s own source is a DailyMed search page (label-metformin); confirm the UK SmPC is the label of record for Nigeria.',
};