healthcare.dev docs
Agents

Example: referral checker

An agent that checks a referral's NPI and diagnosis codes before it's sent.

Checks the structured parts of a referral: the receiving provider's NPI and the ICD-10-CM codes. It works on identifiers only; patient details never leave your system.

import { HealthcareDev, isValidNpi } from "@healthcare.dev/sdk";

const hdev = new HealthcareDev();

export async function checkReferral(input: { npi: string; diagnosisCodes: string[] }) {
  const issues: string[] = [];
  if (!isValidNpi(input.npi)) issues.push(`NPI ${input.npi} fails the check digit`);

  const { data, meta } = await hdev.codes.batch("icd10cm", input.diagnosisCodes);
  for (const r of data) {
    if (!r.found) issues.push(`${r.code} is not an ICD-10-CM code`);
    else if (r.record && !r.record.billable)
      issues.push(`${r.code} is a header code; pick a more specific child`);
    else if (r.record && r.record.status !== "active")
      issues.push(
        `${r.code} is ${r.record.status}; replaced by ${r.record.replaced_by.join(", ") || "nothing listed"}`,
      );
  }
  return { ok: issues.length === 0, issues, cite: `${meta.source} ${meta.data_version}` };
}

With MCP, give the agent validate_npi, lookup_code and explain_code_hierarchy and the instruction: "Check each code is billable and active; suggest children for header codes; never choose a diagnosis yourself."