Shared functions etc.
Define print_resource
- a generic way to print a resource
We use print_resource(procedure)
etc, rather than looking at specific resource details with code like procedure.code.coding[0].as_json()
, so that the demos won't fail if resouces are missing specific content.
from fastcore.test import test_eq, test_stdout
import fhirclient.models.patient as p
import fhirclient.models.humanname as hn
patient = p.Patient({'id': 'patient-1'})
expected = 'Patient {"id": "patient-1", "resourceType": "Patient"}'
test_eq(resource_to_string(patient), expected)
test_eq(resource_to_string([patient, patient]), [expected, expected])
test_stdout(lambda: print_resource(patient), expected)