In FHIR, resources point at each other with references. A relative literal reference looks like:
Patient/123
Observation/abc-1/_history/4
ResourceType/id β points at the current version of a resource.ResourceType/id/_history/versionId β points at a specific version.This kata is the offline, deterministic version of Batch-1 Day 4, Assignment 1 (searching an OpenMRS FHIR facade): before you can follow a reference to another resource, you must be able to parse and build one.
Implement FhirReference with:
static FhirReference parse(String reference) β parse a relative reference.String type() β the resource type, e.g. "Patient".String id() β the logical id, e.g. "123".Optional<String> version() β the _history version id if present, else empty.boolean isVersioned() β true when a version id is present.String format() β reconstruct the canonical reference string.Type/id/_history/vid, and vid
must be non-empty."Patient", "Patient/", "/123",
"Patient/123/foo/4", "Patient/123/_history/") must throw
IllegalArgumentException.format() must round-trip: FhirReference.parse(s).format().equals(s) for every
valid s.Sign up to Exercism to learn and master FHIR with 9 exercises, and real human mentoring, all for free.