From 0a11c3c74f927941b6b67db9941c0554d39c1463 Mon Sep 17 00:00:00 2001 From: Lee Surprenant Date: Fri, 11 Nov 2022 17:32:39 -0500 Subject: [PATCH] issue #4073 - add support for the "exists" discriminator Signed-off-by: Lee Surprenant --- .../fhir/profile/ConstraintGenerator.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fhir-profile/src/main/java/org/linuxforhealth/fhir/profile/ConstraintGenerator.java b/fhir-profile/src/main/java/org/linuxforhealth/fhir/profile/ConstraintGenerator.java index 34116be686e..28a10c9e9a7 100644 --- a/fhir-profile/src/main/java/org/linuxforhealth/fhir/profile/ConstraintGenerator.java +++ b/fhir-profile/src/main/java/org/linuxforhealth/fhir/profile/ConstraintGenerator.java @@ -413,6 +413,25 @@ private String discriminator(Node node) { .append(")") .append( ")"); } + } else if (DiscriminatorType.Value.EXISTS.equals(key)) { + // TODO support more than one? + String path = paths.get(0); + + String id = "$this".equals(path) ? + elementDefinition.getId() : + elementDefinition.getId() + "." + path; + + String snippet = path + ".exists()"; + // The slices are differentiated by the fact that one must have a max of 0 + ElementDefinition existsTarget = elementDefinitionMap.get(id); + if ("0".equals(existsTarget.getMax().getValue())) { + snippet += ".not()"; + } + + sb.append(identifier) + .append(".where(") + .append(snippet) + .append(")"); } } if (identifier.equals(sb.toString())) {