# Early diagnosis of acute pancreatitis (Jin)

Jin AP prediction

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

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

## What it computes

Sum the Jin 2018 integer-point items for ED patients with lipase ≥3× ULN and return the published ≥8 high-PPV cut and the Jin 2024 ≥6 accuracy cut.

## When to use

When an agent already has lipase ≥3× ULN plus the published history and pain tokens and needs the Jin 2018 point total, not Ranson, BISAP, Glasgow-Imrie, a diagnosis, or an imaging order.

## When not to use

- Not a medical device. Not a diagnosis of acute pancreatitis. Not an imaging order. magent does not diagnose pancreatitis.
- Population is ED patients with serum lipase ≥3× ULN (Jin 2018). Lipase below 3× ULN is rejected.
- Not Ranson, not BISAP, and not Glasgow-Imrie. This tool is the Jin 2018 integer point score only.
- jin2018_high_ppv is the Jin 2018 diagnostic-risk cut (score ≥8; ≥99% estimated AP risk in that paper). jin2024_accuracy_cut is the Jin 2024 prospective-validation accuracy cut of that same score (score ≥6). magent does not invent other named bands.
- Caller assigns prior-episode, pain, surgery, and cholelithiasis tokens. magent does not take a history or examine the patient.

## Formula

```
AP prediction = prior_ap_episodes (0→0, 1→1, 2→2, 3→3, 4_or_more→4) + cholelithiasis (true +2) + abdominal_surgery_2mo (true -2) + epigastric_pain (true +2) + worsening_pain (true +1) + pain_duration_days (lt_5 0, gte_5 -1) + pain_severity (mild_0_3 0, moderate_4_6 +2, severe_7_10 +3) + lipase_uln_fold (≥3 and <10 → 0, ≥10 and <20 → +1, ≥20 → +2); Jin 2018; max 14; jin2018_high_ppv iff score ≥ 8; jin2024_accuracy_cut iff score ≥ 6
```

## Citation

[A Clinical Model for the Early Diagnosis of Acute Pancreatitis in the Emergency Department](https://doi.org/10.1097/MPA.0000000000001102)
Jin DX, McNabb-Baltar J, Suleiman SL, Wu BU, Khorasani R, Bollen TL, et al.
Pancreas. 2018;47(7):871-879
DOI: [10.1097/MPA.0000000000001102](https://doi.org/10.1097/MPA.0000000000001102)

## Worked example

### All lowest tokens and lipase 4× ULN

Given: `abdominal_surgery_2mo=false, cholelithiasis=false, epigastric_pain=false, lipase_uln_fold=4, pain_duration_days=lt_5, pain_severity=mild_0_3, prior_ap_episodes=0, worsening_pain=false`

1. prior 0, no stones, no surgery, no epigastric, not worsening, duration lt_5, mild_0_3, lipase 4× ULN
2. Score = 0 (max 14); jin2018_high_ppv false; jin2024_accuracy_cut false


### Prior 1 and cholelithiasis

Given: `abdominal_surgery_2mo=false, cholelithiasis=true, epigastric_pain=false, lipase_uln_fold=4, pain_duration_days=lt_5, pain_severity=mild_0_3, prior_ap_episodes=1, worsening_pain=false`

1. prior_ap_episodes 1 → +1; cholelithiasis true → +2; remaining items 0
2. Score = 3 (max 14); jin2018_high_ppv false; jin2024_accuracy_cut false


### Jin 2018 high-PPV cut

Given: `abdominal_surgery_2mo=false, cholelithiasis=true, epigastric_pain=true, lipase_uln_fold=4, pain_duration_days=lt_5, pain_severity=mild_0_3, prior_ap_episodes=4_or_more, worsening_pain=false`

1. prior 4_or_more → +4; cholelithiasis → +2; epigastric_pain → +2
2. Score = 8 (max 14); jin2018_high_ppv true; jin2024_accuracy_cut true


## Also searched as

- Jin pancreatitis score
- acute pancreatitis prediction
- ED lipase pancreatitis score
- Jin 2018 acute pancreatitis
- early diagnosis pancreatitis ED
- lipase 3 times ULN

## Parameters

- `prior_ap_episodes` (string, required): Caller-assigned prior acute-pancreatitis episode token (Jin 2018). 0 scores 0; 1 scores 1; 2 scores 2; 3 scores 3; 4_or_more scores 4. magent does not take a history.
- `cholelithiasis` (boolean, required): Caller-assigned cholelithiasis (Jin 2018). true scores +2; false scores 0. magent does not read imaging.
- `abdominal_surgery_2mo` (boolean, required): Caller-assigned abdominal surgery within 2 months (Jin 2018). true scores -2; false scores 0.
- `epigastric_pain` (boolean, required): Caller-assigned epigastric pain (Jin 2018). true scores +2; false scores 0. magent does not examine the patient.
- `worsening_pain` (boolean, required): Caller-assigned worsening pain (Jin 2018). true scores +1; false scores 0.
- `pain_duration_days` (string, required): Caller-assigned pain-duration token (Jin 2018). lt_5 (<5 days) scores 0; gte_5 (≥5 days) scores -1. magent does not take a history.
- `pain_severity` (string, required): Caller-assigned pain-severity token (Jin 2018). mild_0_3 (0-3) scores 0; moderate_4_6 (4-6) scores +2; severe_7_10 (7-10) scores +3. magent does not assign a pain scale.
- `lipase_uln_fold` (number, required): Serum lipase as a fold of the laboratory ULN. Population is lipase ≥3× ULN (Jin 2018). ≥3 and <10 scores 0; ≥10 and <20 scores +1; ≥20 scores +2. Below 3 is invalid_ap_prediction.

## Bulk (POST)

POST the same path with a JSON items array. The first item is the GET unit; each additional item is $0.002. Invalid items return HTTP 400 before settlement.

Method: `POST /api/calc/ap_prediction`
Max items: 25
Price: unit_amount + extra_item_amount * (n - 1) (unit 5000 atomic, extra 2000 atomic)
Status: PREVIEW

- 1 to 25 items. Each item uses the same keys as the GET query parameters.
- POST of 1 item costs the same as GET. Lists longer than 25: chunk into multiple POSTs. Extra items still execute; do not pad dummy rows.
- 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": [
    {
      "abdominal_surgery_2mo": "false",
      "cholelithiasis": "false",
      "epigastric_pain": "false",
      "lipase_uln_fold": "4",
      "pain_duration_days": "lt_5",
      "pain_severity": "mild_0_3",
      "prior_ap_episodes": "0",
      "worsening_pain": "false"
    },
    {
      "abdominal_surgery_2mo": "false",
      "cholelithiasis": "false",
      "epigastric_pain": "false",
      "lipase_uln_fold": "4",
      "pain_duration_days": "lt_5",
      "pain_severity": "mild_0_3",
      "prior_ap_episodes": "0",
      "worsening_pain": "false"
    }
  ]
}
```

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

Example 200:

```json
{
  "count": 2,
  "path": "/api/calc/ap_prediction",
  "items": [
    {
      "components": [
        {
          "value": "0",
          "factor": "prior_ap_episodes",
          "points": 0,
          "present": true
        },
        {
          "factor": "cholelithiasis",
          "points": 0,
          "present": false
        },
        {
          "factor": "abdominal_surgery_2mo",
          "points": 0,
          "present": false
        },
        {
          "factor": "epigastric_pain",
          "points": 0,
          "present": false
        },
        {
          "factor": "worsening_pain",
          "points": 0,
          "present": false
        },
        {
          "value": "lt_5",
          "factor": "pain_duration_days",
          "points": 0,
          "present": true
        },
        {
          "value": "mild_0_3",
          "factor": "pain_severity",
          "points": 0,
          "present": true
        },
        {
          "value": 4.0,
          "factor": "lipase_uln_fold",
          "points": 0,
          "present": true
        }
      ],
      "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": "Jin DX, McNabb-Baltar J, Suleiman SL, Wu BU, Khorasani R, Bollen TL, et al.",
        "doi": "10.1097/MPA.0000000000001102",
        "id": "jin-2018",
        "pmid": "29975351",
        "source": "Pancreas. 2018;47(7):871-879",
        "title": "A Clinical Model for the Early Diagnosis of Acute Pancreatitis in the Emergency Department"
      },
      "formula": "ap_prediction",
      "formula_expression": "AP prediction = prior_ap_episodes (0→0, 1→1, 2→2, 3→3, 4_or_more→4) + cholelithiasis (true +2) + abdominal_surgery_2mo (true -2) + epigastric_pain (true +2) + worsening_pain (true +1) + pain_duration_days (lt_5 0, gte_5 -1) + pain_severity (mild_0_3 0, moderate_4_6 +2, severe_7_10 +3) + lipase_uln_fold (≥3 and <10 → 0, ≥10 and <20 → +1, ≥20 → +2); Jin 2018; max 14; jin2018_high_ppv iff score ≥ 8; jin2024_accuracy_cut iff score ≥ 6",
      "max_score": 14,
      "score": 0,
      "jin2018_high_ppv": false,
      "jin2024_accuracy_cut": false
    },
    {
      "components": [
        {
          "value": "0",
          "factor": "prior_ap_episodes",
          "points": 0,
          "present": true
        },
        {
          "factor": "cholelithiasis",
          "points": 0,
          "present": false
        },
        {
          "factor": "abdominal_surgery_2mo",
          "points": 0,
          "present": false
        },
        {
          "factor": "epigastric_pain",
          "points": 0,
          "present": false
        },
        {
          "factor": "worsening_pain",
          "points": 0,
          "present": false
        },
        {
          "value": "lt_5",
          "factor": "pain_duration_days",
          "points": 0,
          "present": true
        },
        {
          "value": "mild_0_3",
          "factor": "pain_severity",
          "points": 0,
          "present": true
        },
        {
          "value": 4.0,
          "factor": "lipase_uln_fold",
          "points": 0,
          "present": true
        }
      ],
      "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": "Jin DX, McNabb-Baltar J, Suleiman SL, Wu BU, Khorasani R, Bollen TL, et al.",
        "doi": "10.1097/MPA.0000000000001102",
        "id": "jin-2018",
        "pmid": "29975351",
        "source": "Pancreas. 2018;47(7):871-879",
        "title": "A Clinical Model for the Early Diagnosis of Acute Pancreatitis in the Emergency Department"
      },
      "formula": "ap_prediction",
      "formula_expression": "AP prediction = prior_ap_episodes (0→0, 1→1, 2→2, 3→3, 4_or_more→4) + cholelithiasis (true +2) + abdominal_surgery_2mo (true -2) + epigastric_pain (true +2) + worsening_pain (true +1) + pain_duration_days (lt_5 0, gte_5 -1) + pain_severity (mild_0_3 0, moderate_4_6 +2, severe_7_10 +3) + lipase_uln_fold (≥3 and <10 → 0, ≥10 and <20 → +1, ≥20 → +2); Jin 2018; max 14; jin2018_high_ppv iff score ≥ 8; jin2024_accuracy_cut iff score ≥ 6",
      "max_score": 14,
      "score": 0,
      "jin2018_high_ppv": false,
      "jin2024_accuracy_cut": false
    }
  ]
}
```

## Response fields

- `formula` (string): ap_prediction
- `formula_expression` (string): Exact expression used
- `score` (integer): Jin 2018 integer points (max 14)
- `max_score` (integer): 14
- `jin2018_high_ppv` (boolean): True when score ≥ 8 (Jin 2018 diagnostic-risk cut; ≥99% estimated AP risk in that paper). Not a diagnosis.
- `jin2024_accuracy_cut` (boolean): True when score ≥ 6 (Jin 2024 prospective validation highest-accuracy cut of this same score). Not a diagnosis.
- `components` (array): Per-item Jin 2018 points
- `citation` (object): Jin et al. Pancreas 2018 citation
- `disclaimer` (string): Not-a-device notice

## Example JSON

Frozen fixture. Not a live lookup.

```json
{
  "components": [
    {
      "value": "0",
      "factor": "prior_ap_episodes",
      "points": 0,
      "present": true
    },
    {
      "factor": "cholelithiasis",
      "points": 0,
      "present": false
    },
    {
      "factor": "abdominal_surgery_2mo",
      "points": 0,
      "present": false
    },
    {
      "factor": "epigastric_pain",
      "points": 0,
      "present": false
    },
    {
      "factor": "worsening_pain",
      "points": 0,
      "present": false
    },
    {
      "value": "lt_5",
      "factor": "pain_duration_days",
      "points": 0,
      "present": true
    },
    {
      "value": "mild_0_3",
      "factor": "pain_severity",
      "points": 0,
      "present": true
    },
    {
      "value": 4.0,
      "factor": "lipase_uln_fold",
      "points": 0,
      "present": true
    }
  ],
  "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": "Jin DX, McNabb-Baltar J, Suleiman SL, Wu BU, Khorasani R, Bollen TL, et al.",
    "doi": "10.1097/MPA.0000000000001102",
    "id": "jin-2018",
    "pmid": "29975351",
    "source": "Pancreas. 2018;47(7):871-879",
    "title": "A Clinical Model for the Early Diagnosis of Acute Pancreatitis in the Emergency Department"
  },
  "formula": "ap_prediction",
  "formula_expression": "AP prediction = prior_ap_episodes (0→0, 1→1, 2→2, 3→3, 4_or_more→4) + cholelithiasis (true +2) + abdominal_surgery_2mo (true -2) + epigastric_pain (true +2) + worsening_pain (true +1) + pain_duration_days (lt_5 0, gte_5 -1) + pain_severity (mild_0_3 0, moderate_4_6 +2, severe_7_10 +3) + lipase_uln_fold (≥3 and <10 → 0, ≥10 and <20 → +1, ≥20 → +2); Jin 2018; max 14; jin2018_high_ppv iff score ≥ 8; jin2024_accuracy_cut iff score ≥ 6",
  "max_score": 14,
  "score": 0,
  "jin2018_high_ppv": false,
  "jin2024_accuracy_cut": false
}
```

## Errors

- HTTP 400 `invalid_ap_prediction`: Acute-pancreatitis prediction inputs must match Jin 2018 prior-episode, surgery, pain, and lipase-fold categories from that paper. 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

- [Ranson](https://magentlab.com/docs/ranson) — Sum the eleven Ranson 1974 prognostic signs (five at admission, six during the first 48 hours) and return the published mortality band.
- [BISAP](https://magentlab.com/docs/bisap) — Compute the Wu 2008 BISAP score for early prediction of mortality in acute pancreatitis from BUN, caller-assigned impaired mental status, caller-assigned SIRS, age, and caller-assigned pleural effusion.
- [Glasgow-Imrie](https://magentlab.com/docs/glasgow-imrie) — Sum the eight Blamey 1984 Glasgow-Imrie factors and return whether severe pancreatitis is predicted (three or more factors).

## Payment

Unpaid requests return HTTP 402 even if query parameters or POST items are missing or invalid, so CDP and agents can index the path. After a PAYMENT-SIGNATURE, 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 accepts[0] (exact, EIP-3009) with validBefore = now + maxTimeoutSeconds (600 seconds), or accepts[1] (batch-settlement deposit/voucher) on product GET. Ping and POST {items} stay exact. Magent retries transient facilitator 429/5xx before answering.
- Retry the same URL with PAYMENT-SIGNATURE (base64 JSON of accepted and payload). Magent attaches canonical extensions.bazaar on CDP verify/settle; echoing 402 bazaar is optional.
- Success is HTTP 200 JSON plus PAYMENT-RESPONSE. exact settles before the tool. batch-settlement verifies (and deposit-settles) before the tool and commits the charge after HTTP 2xx. HTTP 503: retry the same PAYMENT-SIGNATURE. Mint a new exact 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.
- offered `batch-settlement` on eip155:8453: Payment-channel vouchers claimed later in batches. Exact stays accepts[0]. Same-path POST {items} is still exact. extra.assetTransferMethod=eip3009 extra.paymentFlow=authorization.

- 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.

Same-path POST {items} is still scheme exact: one EIP-3009 authorization for GET unit plus $0.002 per extra item. 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

- HTTP 402 is unpaid, including a missing query. After PAYMENT-SIGNATURE, invalid parameters return HTTP 400 before settlement. You are not charged. HTTP 402 never includes the tool JSON.
- exact: settlement finishes before the tool (paymentFlow upfront). batch-settlement: verify/deposit before the tool; chargedCumulativeAmount commits after HTTP 2xx. 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.
