> ## Documentation Index
> Fetch the complete documentation index at: https://docs.olira.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Log FHIR resource

> Submits a single FHIR R4 resource JSON object.

```python theme={null}
olira.log_fhir(patient_id: str, resource: dict[str, Any]) -> BatchResult
```

**Requires scope:** `sdk:event-log`

Olira maps it to one or more platform log types via the FHIR absorber (same schema mapper used by Epic/Cerner integrations and Console FHIR upload), then processes each event immediately for the patient — unlike olira.log(), you do not choose log\_type or build Olira-shaped payloads yourself. One resource may produce zero events (unsupported type or unmappable fields), one event, or several (e.g. CarePlan). See Supported FHIR resources below for the full resourceType → event type matrix.

## Parameters

<ParamField body="patient_id" type="str" required>
  Olira patient id (from create\_patient or your patient registry).
</ParamField>

<ParamField body="resource" type="dict[str, Any]" required>
  FHIR R4 resource object with resourceType set. Supported types are listed in Supported FHIR resources below (17 resource families, including Observation, Condition, MedicationRequest, Patient, DocumentReference, DiagnosticReport, etc.).
</ParamField>

## Returns

`BatchResult`

<ResponseField name="accepted" type="int">
  Number of mapped events processed through patient state.
</ResponseField>

<ResponseField name="failed" type="int">
  Number of mapped events skipped or failed.
</ResponseField>

<ResponseField name="errors" type="list[BatchError]">
  Mapping or processing errors (e.g. unknown resource fields, replay conflict).
</ResponseField>

## Supported FHIR resources

| FHIR `resourceType`                                                    | Olira event type(s)                                                                                                                                                            | Notes                                                                                                                                                                                                                                            |
| ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Observation`                                                          | `vitals_measurement`, `lab_results`, `genomic_variant`, `clinical_measurement`, `functional_class`, `clinical_finding`, `social_determinants`, `treatment_response_assessment` | Routed by category and LOINC. Vital-signs Observations at the same effectiveDateTime merge into one vitals\_measurement when submitted in a multi-entry Bundle; via log\_fhir (single resource) each vital-signs Observation is processed alone. |
| `Patient`                                                              | `demographics`                                                                                                                                                                 | —                                                                                                                                                                                                                                                |
| `Appointment`                                                          | `care_encounter`                                                                                                                                                               | —                                                                                                                                                                                                                                                |
| `Encounter`                                                            | `care_encounter`                                                                                                                                                               | —                                                                                                                                                                                                                                                |
| `Condition`                                                            | `condition`                                                                                                                                                                    | —                                                                                                                                                                                                                                                |
| `MedicationRequest`, `MedicationStatement`, `MedicationAdministration` | `medication_list_update`                                                                                                                                                       | Medication display/dose resolved from the resource; sibling Medication entries in a Bundle are not visible to log\_fhir.                                                                                                                         |
| `AllergyIntolerance`                                                   | `allergy_intolerance`                                                                                                                                                          | —                                                                                                                                                                                                                                                |
| `CarePlan`                                                             | `clinical_plan_item`, `treatment_phase`                                                                                                                                        | treatment\_phase uses a heuristic on plan category/text.                                                                                                                                                                                         |
| `CareTeam`                                                             | `care_team`                                                                                                                                                                    | —                                                                                                                                                                                                                                                |
| `DiagnosticReport`                                                     | `lab_results`, `imaging_result`, `procedure_result`, `unstructured_report`                                                                                                     | Never clinical\_note. Panel lab results need referenced Observation resources in the same Bundle; log\_fhir cannot resolve result\[] references across separate calls.                                                                           |
| `DocumentReference`                                                    | `clinical_note`, `unstructured_report`                                                                                                                                         | Inline base64 attachment.data is decoded into note text. attachment.url is not fetched — placeholder text only.                                                                                                                                  |
| `Procedure`                                                            | `procedure`                                                                                                                                                                    | —                                                                                                                                                                                                                                                |
| `Immunization`                                                         | `immunization`                                                                                                                                                                 | —                                                                                                                                                                                                                                                |
| `FamilyMemberHistory`                                                  | `family_history`                                                                                                                                                               | —                                                                                                                                                                                                                                                |
| `Goal`                                                                 | `care_goal`                                                                                                                                                                    | —                                                                                                                                                                                                                                                |
| `Coverage`                                                             | `insurance`                                                                                                                                                                    | —                                                                                                                                                                                                                                                |
| `RelatedPerson`                                                        | `emergency_contact`                                                                                                                                                            | —                                                                                                                                                                                                                                                |

### Per-resource examples

<CodeGroup>
  ```python Observation theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Observation",
          "id": "bp-example",
          "status": "final",
          "category": [{
              "coding": [{
                  "system": "http://terminology.hl7.org/CodeSystem/observation-category",
                  "code": "vital-signs",
              }],
          }],
          "code": {
              "coding": [{
                  "system": "http://loinc.org",
                  "code": "85354-9",
                  "display": "Blood pressure panel",
              }],
          },
          "subject": {"reference": "Patient/example"},
          "effectiveDateTime": "2026-05-01T10:00:00Z",
          "component": [
              {
                  "code": {"coding": [{"system": "http://loinc.org", "code": "8480-6"}]},
                  "valueQuantity": {"value": 120, "unit": "mmHg"},
              },
              {
                  "code": {"coding": [{"system": "http://loinc.org", "code": "8462-4"}]},
                  "valueQuantity": {"value": 80, "unit": "mmHg"},
              },
          ],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python Patient theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Patient",
          "id": "patient-example",
          "name": [{"given": ["Camila"], "family": "Lopez"}],
          "gender": "female",
          "birthDate": "1987-09-12",
          "telecom": [
              {"system": "email", "value": "camila@example.com"},
              {"system": "phone", "value": "+1-469-555-0100"},
          ],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python Appointment theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Appointment",
          "id": "appt-example",
          "status": "booked",
          "appointmentType": {
              "coding": [{"system": "http://terminology.hl7.org/CodeSystem/v3-ActCode", "code": "AMB"}],
          },
          "start": "2026-06-15T14:00:00Z",
          "end": "2026-06-15T14:30:00Z",
          "created": "2026-06-01",
          "participant": [{
              "actor": {"reference": "Patient/example"},
              "status": "accepted",
          }],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python Encounter theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Encounter",
          "id": "enc-example",
          "status": "finished",
          "class": {"system": "http://terminology.hl7.org/CodeSystem/v3-ActCode", "code": "AMB"},
          "subject": {"reference": "Patient/example"},
          "period": {"start": "2026-06-15T14:00:00Z", "end": "2026-06-15T14:45:00Z"},
          "reasonCode": [{"text": "Follow-up visit"}],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python Condition theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Condition",
          "id": "condition-example",
          "clinicalStatus": {
              "coding": [{
                  "system": "http://terminology.hl7.org/CodeSystem/condition-clinical",
                  "code": "active",
              }],
          },
          "code": {
              "coding": [{
                  "system": "http://snomed.info/sct",
                  "code": "254837009",
                  "display": "Breast cancer",
              }],
              "text": "Breast cancer",
          },
          "subject": {"reference": "Patient/example"},
          "onsetDateTime": "2025-01-10T00:00:00Z",
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python MedicationRequest theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "MedicationRequest",
          "id": "med-example",
          "status": "active",
          "intent": "order",
          "medicationCodeableConcept": {
              "coding": [{"system": "http://www.nlm.nih.gov/research/umls/rxnorm", "code": "860975"}],
              "text": "Metformin 500 MG Oral Tablet",
          },
          "subject": {"reference": "Patient/example"},
          "authoredOn": "2026-03-01T09:00:00Z",
          "dosageInstruction": [{"text": "Take 500 mg twice daily with meals"}],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python AllergyIntolerance theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "AllergyIntolerance",
          "id": "allergy-example",
          "clinicalStatus": {
              "coding": [{
                  "system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical",
                  "code": "active",
              }],
          },
          "code": {
              "coding": [{
                  "system": "http://snomed.info/sct",
                  "code": "91936005",
                  "display": "Allergy to penicillin",
              }],
              "text": "Penicillin",
          },
          "patient": {"reference": "Patient/example"},
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python CarePlan theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "CarePlan",
          "id": "careplan-example",
          "status": "active",
          "intent": "plan",
          "category": [{
              "coding": [{
                  "system": "http://hl7.org/fhir/us/core/CodeSystem/careplan-category",
                  "code": "assess-plan",
              }],
          }],
          "subject": {"reference": "Patient/example"},
          "activity": [{
              "detail": {
                  "status": "in-progress",
                  "description": "Monitor blood glucose daily",
              },
          }],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python CareTeam theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "CareTeam",
          "id": "careteam-example",
          "status": "active",
          "subject": {"reference": "Patient/example"},
          "participant": [{
              "role": [{"text": "Primary oncologist"}],
              "member": {"display": "Dr. Sarah Patel"},
          }],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python DiagnosticReport theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "DiagnosticReport",
          "id": "imaging-report-example",
          "status": "final",
          "category": [{"coding": [{"code": "RAD", "display": "Radiology"}]}],
          "code": {"text": "CT chest"},
          "subject": {"reference": "Patient/example"},
          "effectiveDateTime": "2026-05-01T10:00:00Z",
          "conclusion": "No acute cardiopulmonary findings.",
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python DocumentReference theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "DocumentReference",
          "id": "note-example",
          "status": "current",
          "type": {"coding": [{"system": "http://loinc.org", "code": "11506-3"}]},
          "subject": {"reference": "Patient/example"},
          "date": "2026-05-01",
          "content": [{
              "attachment": {
                  "contentType": "text/plain",
                  "data": "UHJvZ3Jlc3Mgbm90ZTogUGF0aWVudCBzdGFibGUu",
              },
          }],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python Procedure theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Procedure",
          "id": "procedure-example",
          "status": "completed",
          "code": {
              "coding": [{"system": "http://www.ama-assn.org/go/cpt", "code": "93306"}],
              "text": "Transthoracic echocardiogram",
          },
          "subject": {"reference": "Patient/example"},
          "performedDateTime": "2026-04-20T15:30:00Z",
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python Immunization theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Immunization",
          "id": "immunization-example",
          "status": "completed",
          "vaccineCode": {
              "coding": [{"system": "http://hl7.org/fhir/sid/cvx", "code": "115"}],
              "text": "Tdap",
          },
          "patient": {"reference": "Patient/example"},
          "occurrenceDateTime": "2026-02-10",
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python FamilyMemberHistory theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "FamilyMemberHistory",
          "id": "fmh-example",
          "status": "completed",
          "patient": {"reference": "Patient/example"},
          "relationship": {"coding": [{"code": "MTH", "display": "Mother"}]},
          "condition": [{
              "code": {
                  "coding": [{
                      "system": "http://snomed.info/sct",
                      "code": "44054006",
                      "display": "Type 2 diabetes mellitus",
                  }],
              },
          }],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python Goal theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Goal",
          "id": "goal-example",
          "lifecycleStatus": "active",
          "description": {"text": "Walk 30 minutes daily"},
          "subject": {"reference": "Patient/example"},
          "target": [{
              "measure": {"coding": [{"code": "steps"}]},
              "detailQuantity": {"value": 30, "unit": "min"},
          }],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python Coverage theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Coverage",
          "id": "coverage-example",
          "status": "active",
          "order": 1,
          "subscriberId": "MEM123",
          "type": {"coding": [{"code": "PPO", "display": "Commercial PPO"}]},
          "payor": [{"display": "Blue Shield"}],
          "class": [
              {"type": {"coding": [{"code": "plan"}]}, "name": "Gold PPO", "value": "GP1"},
              {"type": {"coding": [{"code": "group"}]}, "value": "GRP-9"},
          ],
          "period": {"start": "2026-01-01"},
      },
  )
  print(result.accepted, result.failed)
  ```

  ```python RelatedPerson theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "RelatedPerson",
          "id": "related-person-example",
          "patient": {"reference": "Patient/example"},
          "relationship": [{"coding": [{"code": "SPS", "display": "spouse"}]}],
          "name": [{"given": ["Bob"], "family": "Lopez"}],
          "telecom": [
              {"system": "phone", "value": "555-0100"},
              {"system": "email", "value": "bob@example.com"},
          ],
      },
  )
  print(result.accepted, result.failed)
  ```
</CodeGroup>

<Note>
  Each call accepts one FHIR resource. Linked resources in the same payload are not resolved together (for example, lab Observations referenced from a DiagnosticReport). Use historical ingestion or an EHR integration when you need multi-resource imports.
</Note>

<Note>
  Unsupported resource types (zero events accepted): QuestionnaireResponse, ImagingStudy, ServiceRequest, Task, AdverseEvent, Device, EpisodeOfCare, ClinicalImpression, MolecularSequence, and standalone Binary. Support for additional FHIR resource types is added continuously.
</Note>

<Note>
  Ingested data is stored as Olira event logs (type and payload), not as raw FHIR. Read it back with get\_logs() or logs().
</Note>

## Raises

| Exception         | When                                                                                                                                                                                                                                         |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `AuthError`       | HTTP 401 or 403 — invalid API key or insufficient OAuth scope for this endpoint.                                                                                                                                                             |
| `ServerError`     | HTTP 409 (e.g. conflicting external identifier) or repeated 5xx after retries; includes status\_code when applicable.                                                                                                                        |
| `RateLimitError`  | HTTP 429 — rate limited; check retry\_after (seconds).                                                                                                                                                                                       |
| `NetworkError`    | Connection timeout, DNS failure, or read error after retries.                                                                                                                                                                                |
| `ValidationError` | HTTP 422 — missing resourceType or malformed request. Also raised when the resource maps to zero Olira events (unsupported type, unrecognized fields, or Observation with unrecognized category/LOINC) — the exception message explains why. |

<RequestExample>
  ```python Python theme={null}
  import olira

  olira.init(api_key="YOUR_API_KEY")
  result = olira.log_fhir(
      patient_id="8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
      resource={
          "resourceType": "Observation",
          "id": "bp-example",
          "status": "final",
          "category": [{
              "coding": [{
                  "system": "http://terminology.hl7.org/CodeSystem/observation-category",
                  "code": "vital-signs",
              }],
          }],
          "code": {
              "coding": [{
                  "system": "http://loinc.org",
                  "code": "85354-9",
                  "display": "Blood pressure panel",
              }],
          },
          "subject": {"reference": "Patient/example"},
          "effectiveDateTime": "2026-05-01T10:00:00Z",
          "component": [
              {
                  "code": {"coding": [{"system": "http://loinc.org", "code": "8480-6"}]},
                  "valueQuantity": {"value": 120, "unit": "mmHg"},
              },
              {
                  "code": {"coding": [{"system": "http://loinc.org", "code": "8462-4"}]},
                  "valueQuantity": {"value": 80, "unit": "mmHg"},
              },
          ],
      },
  )
  print(result.accepted, result.failed)
  ```

  ```http HTTP theme={null}
  POST /v1/fhir/resource
  Authorization: Bearer YOUR_API_KEY
  Content-Type: application/json

  {
    "patient_id": "8a4fde23-0f1b-4c2a-9d7e-b36c1a5f0e82",
    "resource": {
      "resourceType": "Observation",
      "status": "final",
      "category": [{
        "coding": [{
          "system": "http://terminology.hl7.org/CodeSystem/observation-category",
          "code": "vital-signs"
        }]
      }],
      "code": {
        "coding": [{ "system": "http://loinc.org", "code": "85354-9" }]
      },
      "subject": { "reference": "Patient/example" },
      "effectiveDateTime": "2026-05-01T10:00:00Z"
    }
  }
  ```
</RequestExample>

<ResponseExample>
  ```python 200 theme={null}
  BatchResult(accepted=1, failed=0, errors=[])
  ```

  ```json 401 theme={null}
  {
    "error": true,
    "status_code": 401,
    "error_type": "authentication_error",
    "message": "Could not validate credentials",
    "details": [
      {
        "type": "authentication_error",
        "message": "Could not validate credentials"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 403 theme={null}
  {
    "error": true,
    "status_code": 403,
    "error_type": "authorization_error",
    "message": "Insufficient OAuth scope for this endpoint",
    "details": [
      {
        "type": "authorization_error",
        "message": "Insufficient OAuth scope for this endpoint"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 404 theme={null}
  {
    "error": true,
    "status_code": 404,
    "error_type": "not_found_error",
    "message": "Patient not found",
    "details": [
      {
        "type": "not_found_error",
        "message": "Patient not found"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 422 theme={null}
  {
    "error": true,
    "status_code": 422,
    "error_type": "validation_error",
    "message": "Request validation failed (1 error)",
    "details": [
      {
        "type": "missing",
        "message": "Field required",
        "field": "patient_id",
        "location": ["body", "patient_id"],
        "input_value": null
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 429 theme={null}
  {
    "error": true,
    "status_code": 429,
    "error_type": "server_error",
    "message": "Rate limit exceeded",
    "details": [
      {
        "type": "rate_limit",
        "message": "Too many requests; retry after backoff"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```

  ```json 500 theme={null}
  {
    "error": true,
    "status_code": 500,
    "error_type": "internal_server_error",
    "message": "An internal server error occurred",
    "details": [
      {
        "type": "internal_server_error",
        "message": "An unexpected error occurred while processing your request"
      }
    ],
    "timestamp": "2026-05-06T12:00:00+00:00"
  }
  ```
</ResponseExample>
