Tracks
/
FHIR
FHIR
/
Exercises
/
FHIR Reference (Java)
FHIR Reference (Java)

FHIR Reference (Java)

Easy

Instructions

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.

Rules

  • A valid reference has a non-empty resource type and a non-empty id.
  • The type must start with an uppercase letter (FHIR resource types are PascalCase).
  • A versioned reference has exactly the segments Type/id/_history/vid, and vid must be non-empty.
  • Anything else (null, 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.

Source

Batch-1 Day 4 Week 1 Assignment 1 (OpenMRS FHIR facade client), refactored to an offline kata.
Edit via GitHub The link opens in a new window or tab
FHIR Exercism

Ready to start FHIR Reference (Java)?

Sign up to Exercism to learn and master FHIR with 9 exercises, and real human mentoring, all for free.