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.
/v1/extract/contextsA 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
textstringrequiredThe full clinical text the spans came from. After trimming, must be at least 2 characters.language"en" | "fr" | "auto"optionaldefault:autoLanguage hint selecting the lexicon.autoinfers it.conceptsobject[]requiredAt least one span to analyze. Each item is{ span: string, code?: string | null }.
Response
{
"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 | nulloptionalThe SCTID you passed for the span, echoed back (may benull).spanstringoptionalThe span that was analyzed.contextobjectoptionalFive axes, each{ value, confidence, trigger }ornullwhen not applicable.context_confidencenumberoptionalAggregate confidence across the axes.readable_notestringoptionalA short human-readable summary of the resolved context.
Context axes
assertion"affirmed" | "negated" | "uncertain"optionalWhether the concept is present, denied, or unclear.subject"patient" | "family" | "other"optionalWho the concept is about.temporality"current" | "past" | "chronic"optionalWhen it applies.certainty"confirmed" | "differential" | "suspected"optionalHow certain the clinician is.role"finding" | "reason_for_encounter" | "history"optionalThe 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
triggerphrase, so you can show clinicians why a concept was marked negated or historical. - A negated or family-subject
assertionusually means the concept should not be added to the active problem list, even ifextract/conceptsresolved it confidently. - Run
/v1/extract/conceptsfirst to get the spans, then pass them here in one call.
Errors
| Status | Code | When |
|---|---|---|
| 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. |
- VALIDATION_ERROR
Body did not pass schema validation (missing
text, emptyconcepts). - INVALID_INPUT
textwas 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.