# YEARS algorithm

YEARS algorithm

Status: LIVE
Price: $0.005 USDC
`GET /api/calc/years`
HTML: https://magentlab.com/docs/years
Markdown: https://magentlab.com/docs/years.md

Not a medical device. Not a diagnosis, dose, or listing recommendation.

## What it computes

Apply the van der Hulle 2017 YEARS algorithm: count three caller-assigned items and return whether PE is excluded at the published D-dimer threshold.

## When to use

When an agent has caller-assigned YEARS items and a D-dimer in ng/mL FEU and needs the published PE-excluded or CTPA-indicated result.

## When not to use

- Not a diagnosis of pulmonary embolism. YEARS is a diagnostic-management algorithm, not a PE confirmation.
- Not the Wells PE score and not PERC. Do not substitute those tools.
- The 2017 YEARS cohort excluded pregnancy. This tool does not apply a pregnancy-adapted YEARS rule and has no pregnancy parameter.
- The caller assigns clinical_signs_dvt, hemoptysis, and pe_most_likely. magent does not decide whether PE is the most likely diagnosis and does not examine the patient.
- D-dimer is ng/mL fibrinogen-equivalent units (FEU) as in the paper. Other D-dimer units are not this tool.
- Thresholds are strict less-than: 1000 ng/mL when years_items is 0; 500 ng/mL when years_items is 1-3. Equality is not PE-excluded.

## Formula

```
PE excluded iff (years_items == 0 and d_dimer_ng_ml < 1000) or (years_items >= 1 and d_dimer_ng_ml < 500); years_items counts clinical_signs_dvt, hemoptysis, and pe_most_likely
```

## Citation

[Simplified diagnostic management of suspected pulmonary embolism (the YEARS study): a prospective, multicentre, cohort study](https://doi.org/10.1016/S0140-6736(17)30885-1)
van der Hulle T, Cheung WY, Kooij S, et al.
Lancet. 2017;390(10091):289-297
DOI: [10.1016/S0140-6736(17)30885-1](https://doi.org/10.1016/S0140-6736(17)30885-1)

## Worked example

### Zero YEARS items, D-dimer 499 ng/mL FEU

Given: `clinical_signs_dvt=false, d_dimer_ng_ml=499, hemoptysis=false, pe_most_likely=false`

1. clinical_signs_dvt, hemoptysis, and pe_most_likely are false → years_items = 0
2. Threshold is 1000 ng/mL FEU
3. 499 < 1000 → PE excluded; CTPA not indicated


### Zero YEARS items, D-dimer equal to 1000 is not excluded

Given: `clinical_signs_dvt=false, d_dimer_ng_ml=1000, hemoptysis=false, pe_most_likely=false`

1. years_items = 0 so the threshold is 1000
2. 1000 is not < 1000 → PE not excluded; CTPA indicated


## Also searched as

- YEARS algorithm
- YEARS PE
- van der Hulle YEARS
- YEARS D-dimer
- simplified PE YEARS
- YEARS pulmonary embolism

## Parameters

- `clinical_signs_dvt` (boolean, required): Clinical signs of deep-vein thrombosis. true or false as assigned by the caller. Counts as one unweighted YEARS item when true.
- `hemoptysis` (boolean, required): Hemoptysis. true or false as assigned by the caller. Counts as one unweighted YEARS item when true.
- `pe_most_likely` (boolean, required): PE is the most likely diagnosis, as assigned by the caller. magent does not decide PE most likely. Counts as one unweighted YEARS item when true.
- `d_dimer_ng_ml` (number, required): D-dimer in ng/mL fibrinogen-equivalent units (FEU) as in van der Hulle 2017 (0-20000). PE excluded only when strictly below 1000 (0 YEARS items) or 500 (1-3 items). Equality is not excluded.

## Bulk (POST)

POST the same path with a JSON items array. Price is n times the GET unit. Invalid items return HTTP 400 before settlement.

Method: `POST /api/calc/years`
Max items: 25
Price: unit_amount * n (unit 5000 atomic)
Status: PREVIEW

- 1 to 25 items. Each item uses the same keys as the GET query parameters.
- The first invalid item fails the whole request (index in the 400 JSON). You are not charged.
- HTTP 200 is {count, path, items}. Each items[i] is the GET 200 body for that row.
- Catalog misses (empty matches, found=false) stay paid 200s inside that slot.
- x402 resource URL is this path plus n and body_sha256. Browsers that prefer text/html get the same paywall as GET; Pay retries POST with the same items.

Example request:

```json
{
  "items": [
    {
      "clinical_signs_dvt": "false",
      "d_dimer_ng_ml": "499",
      "hemoptysis": "false",
      "pe_most_likely": "false"
    },
    {
      "clinical_signs_dvt": "false",
      "d_dimer_ng_ml": "499",
      "hemoptysis": "false",
      "pe_most_likely": "false"
    }
  ]
}
```

Human paywall (two-item fixture): https://api.magentlab.com/paywall/bulk/years

Example 200:

```json
{
  "count": 2,
  "path": "/api/calc/years",
  "items": [
    {
      "disclaimer": "Not a medical device. Deterministic published-formula or published-code output for autonomous agents. A licensed clinician remains responsible for patient care and billing submissions.",
      "citation": {
        "authors": "van der Hulle T, Cheung WY, Kooij S, et al.",
        "doi": "10.1016/S0140-6736(17)30885-1",
        "id": "van-der-hulle-2017",
        "source": "Lancet. 2017;390(10091):289-297",
        "title": "Simplified diagnostic management of suspected pulmonary embolism (the YEARS study): a prospective, multicentre, cohort study"
      },
      "formula": "years",
      "formula_expression": "PE excluded iff (years_items == 0 and d_dimer_ng_ml < 1000) or (years_items >= 1 and d_dimer_ng_ml < 500); years_items counts clinical_signs_dvt, hemoptysis, and pe_most_likely",
      "criteria": [
        {
          "factor": "clinical_signs_dvt",
          "met": false
        },
        {
          "factor": "hemoptysis",
          "met": false
        },
        {
          "factor": "pe_most_likely",
          "met": false
        }
      ],
      "ctpa_indicated": false,
      "d_dimer_ng_ml": 499.0,
      "d_dimer_threshold_ng_ml": 1.0e3,
      "pe_excluded": true,
      "years_items": 0
    },
    {
      "disclaimer": "Not a medical device. Deterministic published-formula or published-code output for autonomous agents. A licensed clinician remains responsible for patient care and billing submissions.",
      "citation": {
        "authors": "van der Hulle T, Cheung WY, Kooij S, et al.",
        "doi": "10.1016/S0140-6736(17)30885-1",
        "id": "van-der-hulle-2017",
        "source": "Lancet. 2017;390(10091):289-297",
        "title": "Simplified diagnostic management of suspected pulmonary embolism (the YEARS study): a prospective, multicentre, cohort study"
      },
      "formula": "years",
      "formula_expression": "PE excluded iff (years_items == 0 and d_dimer_ng_ml < 1000) or (years_items >= 1 and d_dimer_ng_ml < 500); years_items counts clinical_signs_dvt, hemoptysis, and pe_most_likely",
      "criteria": [
        {
          "factor": "clinical_signs_dvt",
          "met": false
        },
        {
          "factor": "hemoptysis",
          "met": false
        },
        {
          "factor": "pe_most_likely",
          "met": false
        }
      ],
      "ctpa_indicated": false,
      "d_dimer_ng_ml": 499.0,
      "d_dimer_threshold_ng_ml": 1.0e3,
      "pe_excluded": true,
      "years_items": 0
    }
  ]
}
```

## Response fields

- `formula` (string): years
- `formula_expression` (string): YEARS item count plus strict D-dimer thresholds
- `years_items` (integer): Count of true YEARS items (0-3). Each item is one, not weighted.
- `d_dimer_ng_ml` (number): Caller D-dimer in ng/mL FEU
- `d_dimer_threshold_ng_ml` (number): 1000.0 when years_items is 0; 500.0 when years_items is 1-3
- `pe_excluded` (boolean): true only when D-dimer is strictly below the item-count threshold. Not a diagnosis.
- `ctpa_indicated` (boolean): true when PE is not excluded (not pe_excluded)
- `criteria` (array): Per-item YEARS rows with factor and met (true when that item is present)
- `citation` (object): van der Hulle 2017 Lancet citation
- `disclaimer` (string): Not-a-device notice

## Example JSON

Frozen fixture. Not a live lookup.

```json
{
  "disclaimer": "Not a medical device. Deterministic published-formula or published-code output for autonomous agents. A licensed clinician remains responsible for patient care and billing submissions.",
  "citation": {
    "authors": "van der Hulle T, Cheung WY, Kooij S, et al.",
    "doi": "10.1016/S0140-6736(17)30885-1",
    "id": "van-der-hulle-2017",
    "source": "Lancet. 2017;390(10091):289-297",
    "title": "Simplified diagnostic management of suspected pulmonary embolism (the YEARS study): a prospective, multicentre, cohort study"
  },
  "formula": "years",
  "formula_expression": "PE excluded iff (years_items == 0 and d_dimer_ng_ml < 1000) or (years_items >= 1 and d_dimer_ng_ml < 500); years_items counts clinical_signs_dvt, hemoptysis, and pe_most_likely",
  "criteria": [
    {
      "factor": "clinical_signs_dvt",
      "met": false
    },
    {
      "factor": "hemoptysis",
      "met": false
    },
    {
      "factor": "pe_most_likely",
      "met": false
    }
  ],
  "ctpa_indicated": false,
  "d_dimer_ng_ml": 499.0,
  "d_dimer_threshold_ng_ml": 1.0e3,
  "pe_excluded": true,
  "years_items": 0
}
```

## Errors

- HTTP 400 `invalid_flag`: boolean clinical flags must be true or false Returned before settlement; you are not charged.
- HTTP 400 `invalid_d_dimer`: d_dimer_ng_ml must be a number from 0 to 20000. Returned before settlement; you are not charged.
- HTTP 400 `invalid_items`: POST body must be a JSON object with only an items array Returned before settlement; you are not charged.
- HTTP 400 `invalid_item_count`: items must be an array of 1 to 25 objects Returned before settlement; you are not charged.
- HTTP 400 `invalid_item`: each items entry must be a JSON object Returned before settlement; you are not charged.

Shared HTTP 402 and 503: https://magentlab.com/docs/payments

## Related tools

- [Wells PE](https://magentlab.com/docs/wells-pe) — Compute the Wells pulmonary-embolism probability score and return three-tier and two-tier bands.
- [PERC rule](https://magentlab.com/docs/perc) — Apply the Kline 2004 eight-factor pulmonary embolism rule-out criteria and return whether all eight are met (PERC-negative).

## Payment

Required query parameters must be present and valid. Invalid params return HTTP 400 JSON before settlement. magent does not charge. Fix the params, then request a new 402 quote for that complete URL. Catalog misses (empty matches, found=false) are valid paid 200s.

- GET the tool with Accept: application/json (do not send Accept: text/html unless you want the human paywall).
- HTTP 402 means you have not paid. Decode the base64 PAYMENT-REQUIRED header. HTTP 503 is not a new quote.
- Sign EIP-3009 (scheme exact, assetTransferMethod eip3009) with validBefore = now + accepts[0].maxTimeoutSeconds (600 seconds). That window starts when you sign and must cover wallet confirmation plus CDP verify and settle. Magent retries transient facilitator 429/5xx before answering. Do not send upto or batch-settlement payloads; magent does not offer those schemes.
- Retry the same URL with PAYMENT-SIGNATURE (base64 JSON echoing accepted, payload, and extensions when present).
- Success is HTTP 200 JSON plus PAYMENT-RESPONSE. Settlement happens before the tool runs. HTTP 503 settlement_uncertain or settle_failed: retry the same PAYMENT-SIGNATURE. Mint a new nonce only after a new HTTP 402.

- offered `exact` on eip155:8453: Fixed-price USDC on Base. The buyer authorizes the advertised amount (EIP-3009). magent settles before the tool runs (paymentFlow upfront). extra.assetTransferMethod=eip3009 extra.paymentFlow=upfront.

- not offered `upto`: Not offered. Usage-based: buyer authorizes a ceiling, seller settles the actual amount after work. Reserved for a future metered tool. Not for current calculators or code search.
- not offered `batch-settlement`: Not offered. Payment-channel vouchers claimed later in batches. Not the same as POST {items} bulk (that is still exact).

Same-path POST {items} is still scheme exact: one EIP-3009 authorization for n times the GET unit. That is not x402 batch-settlement (payment channels / vouchers).

Shared HTTP 402 and 503 table: https://magentlab.com/docs/payments

Stdio MCP (one process per host): https://magentlab.com/docs/mcp

## Guarantees

- Invalid query parameters return HTTP 400 before settlement. You are not charged.
- Settlement finishes before the tool executes (paymentFlow upfront). Uncertain or failed settlement fails closed (HTTP 503). Retry the same PAYMENT-SIGNATURE.
- HTTP 402 is unpaid only. Do not sign a second authorization because of a 503.
- Execution is timeout-bounded and concurrency-capped.
- Calculator inputs are stored encrypted for allowlisted operators (Magent Console). They are not in public logs, SSH lookups, catalog, or rollups. Request logs store path without query.
