Tracks
/
FHIR
FHIR
/
Exercises
/
Validate against a Profile (Java)
Validate against a Profile (Java)

Validate against a Profile (Java)

Medium

Instructions

FHIR profiles tighten the base spec: an Implementation Guide (IG) like US Core adds constraints on top of a base resource. Before a server accepts a Patient, it validates the resource against the US Core Patient profile.

This kata is the offline, deterministic version of Batch-1 Day 6, Week 2, Assignment 6 (running US Core IG validation on a HAPI R5 server): instead of calling a live validator, you implement a tiny slice of the profile rules yourself.

The Patient is modeled as a java.util.Map<String,Object>. You validate three simplified US Core Patient constraints and return the errors in a fixed order.

Implement UsCoreValidator with:

  • static List<String> validate(Map<String,Object> patient) β€” return the error messages in the order below, or an empty list when the patient is valid.

Rules

Checks run in this exact order, and each contributes at most one message:

  1. identifier must be a non-empty List (min cardinality 1). Missing or empty β†’ Patient.identifier: minimum cardinality 1 not met
  2. name must be a non-empty List (min cardinality 1). Missing or empty β†’ Patient.name: minimum cardinality 1 not met
  3. gender must be a String in the value set {male, female, other, unknown} (min cardinality 1).
    • Missing or null β†’ Patient.gender: minimum cardinality 1 not met
    • Present but not in the value set β†’ Patient.gender: code '<value>' is not in the value set
    • Never emit both gender messages for the same patient.

A fully valid patient returns an empty list.


Source

Batch-1 Day 6 Week 2 Assignment 6 (US Core IG validation on a HAPI R5 server), refactored to an offline profile-validation kata.
Edit via GitHub The link opens in a new window or tab
FHIR Exercism

Ready to start Validate against a Profile (Java)?

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