A FHIR Bundle is a container that carries a collection of resources β for example the results of a search on a server. This kata is the offline, deterministic version of Batch-1 Day 4, Assignment 1 (searching resources on an OpenMRS FHIR facade): instead of calling a live server, you are handed the Bundle in memory and must implement the search/filter utilities a client would use.
A resource is modelled by the immutable helper class BundleSearch.Resource,
which is already provided for you:
Resource(String type, String id, Map<String,String> fields) β construct a
resource, e.g. type "Patient", id "1", fields {name: "Smith"}.String type() β the resource type, e.g. "Patient".String id() β the logical id, e.g. "1".String field(String key) β the value of a field, or null if absent.A Bundle is simply a List<Resource>.
Implement the four static search methods on BundleSearch:
List<Resource> ofType(List<Resource> bundle, String type) β every entry whose
type equals type, preserving the input order.Optional<Resource> byId(List<Resource> bundle, String type, String id) β the
first entry matching both type and id, or Optional.empty() if none.List<Resource> where(List<Resource> bundle, String type, String field, String value)
β every entry of type whose field(field) equals value, in input order.int count(List<Resource> bundle, String type) β how many entries have the
given type.type, id, and field values.Optional.empty(), or 0 β never null and
never an exception.Sign up to Exercism to learn and master FHIR with 9 exercises, and real human mentoring, all for free.