"""Tests for Observation extractors."""

from fhir_agent_tools.observation import (
    get_observation_code,
    get_observation_summary,
    get_observation_value,
)


OBSERVATION_JSON = '''
{
  "resourceType": "Observation",
  "id": "obs1",
  "status": "final",
  "code": {"coding": [{"display": "Blood pressure"}]},
  "valueQuantity": {"value": 120, "unit": "mmHg"},
  "effectiveDateTime": "2024-01-15T10:00:00Z"
}
'''


def test_get_observation_summary():
    result = get_observation_summary(OBSERVATION_JSON)
    assert result["success"] is True
    data = result["data"]
    assert data["id"] == "obs1"
    assert data["code"] == "Blood pressure"
    assert data["value"] == 120
    assert "2024-01-15" in str(data["effective"])


def test_get_observation_value():
    result = get_observation_value(OBSERVATION_JSON)
    assert result["success"] is True
    assert result["data"] == 120


def test_get_observation_code():
    result = get_observation_code(OBSERVATION_JSON)
    assert result["success"] is True
    assert result["data"] == "Blood pressure"
