obscyro

Api / Extract Contexts

/v1/extract/contexts

Determine the clinical context of concept spans - whether they are negated, historical, about a family member, or uncertain - with auditable rule triggers.

POST/v1/extract/contexts

A SNOMED code alone does not tell you whether the patient has the condition. "Nie toute fievre" (denies any fever) and "antecedent familial de cancer du sein" (family history of breast cancer) both mention a concept that is not an active patient problem. extract/contexts applies rule-based ConText analysis (EN + FR lexicons) to each span and returns five context axes, each with the exact trigger phrase that fired so the decision is auditable.

Pass the spans (and optional codes) you got from /v1/extract/concepts.

Request body

Parameters

  • textstringrequired
    The full clinical text the spans came from. After trimming, must be at least 2 characters.
  • language"en" | "fr" | "auto"optionaldefault: auto
    Language hint selecting the lexicon. auto infers it.
  • conceptsobject[]required
    At least one span to analyze. Each item is { span: string, code?: string | null }.

Response

One entry per submitted span
{
  "contexts": [
    {
      "code": "386661006",
      "span": "fievre",
      "context": {
        "assertion": { "value": "negated", "confidence": 0.95, "trigger": "nie toute" },
        "subject": { "value": "patient", "confidence": 0.9, "trigger": null },
        "temporality": { "value": "current", "confidence": 0.8, "trigger": null },
        "certainty": { "value": "confirmed", "confidence": 0.8, "trigger": null },
        "role": { "value": "finding", "confidence": 0.8, "trigger": null }
      },
      "context_confidence": 0.9,
      "readable_note": "Fever - negated (patient denies)"
    }
  ]
}

Context shape

  • codestring | nulloptional
    The SCTID you passed for the span, echoed back (may be null).
  • spanstringoptional
    The span that was analyzed.
  • contextobjectoptional
    Five axes, each { value, confidence, trigger } or null when not applicable.
  • context_confidencenumberoptional
    Aggregate confidence across the axes.
  • readable_notestringoptional
    A short human-readable summary of the resolved context.

Context axes

  • assertion"affirmed" | "negated" | "uncertain"optional
    Whether the concept is present, denied, or unclear.
  • subject"patient" | "family" | "other"optional
    Who the concept is about.
  • temporality"current" | "past" | "chronic"optional
    When it applies.
  • certainty"confirmed" | "differential" | "suspected"optional
    How certain the clinician is.
  • role"finding" | "reason_for_encounter" | "history"optional
    The clinical role of the concept in the note.

Examples

curl -X POST https://api.obscyro.com/v1/extract/contexts \
  -H "Authorization: Bearer $OBS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Il nie toute fievre. Sa mere est atteinte d un cancer du sein.",
    "language": "fr",
    "concepts": [
      { "span": "fievre", "code": "386661006" },
      { "span": "cancer du sein", "code": "254837009" }
    ]
  }'

Tips

  • Every fired axis includes a trigger phrase, so you can show clinicians why a concept was marked negated or historical.
  • A negated or family-subject assertion usually means the concept should not be added to the active problem list, even if extract/concepts resolved it confidently.
  • Run /v1/extract/concepts first to get the spans, then pass them here in one call.

Errors

  • VALIDATION_ERROR

    Body did not pass schema validation (missing text, empty concepts).

  • INVALID_INPUT

    text was shorter than 2 characters after trimming.

  • INVALID_API_KEY

    Missing or invalid bearer token.

  • RATE_LIMITED

    Per-minute rate limit exceeded for this key.

  • NLP_UPSTREAM_ERROR

    The extraction service returned an error.

  • NLP_UNAVAILABLE

    The extraction service is not configured or unreachable.