Tracks
/
FHIR
FHIR
/
Exercises
/
FHIR Reference (.NET)
FHIR Reference (.NET)

FHIR Reference (.NET)

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 2 (the .NET OpenMRS FHIR facade client): 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".
  • string Version β€” the _history version id, or null when unversioned.
  • bool 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 ArgumentException.
  • Format() must round-trip: FhirReference.Parse(s).Format() == s for every valid s.

Source

Batch-1 Day 4 Week 1 Assignment 2 (.NET 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 (.NET)?

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