support slicing on patternCoding

This commit is contained in:
Grahame Grieve 2020-02-28 14:27:04 +11:00
parent f1dc0e5754
commit 1c8797f628
2 changed files with 37 additions and 1 deletions

View File

@ -3209,6 +3209,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
CodeableConcept cc = (CodeableConcept) pattern;
expression.append(" and ");
buildCodeableConceptExpression(ed, expression, discriminator, cc);
} else if (pattern instanceof Coding) {
Coding c = (Coding) pattern;
expression.append(" and ");
buildCodingExpression(ed, expression, discriminator, c);
} else if (pattern instanceof Identifier) {
Identifier ii = (Identifier) pattern;
expression.append(" and ");
@ -3290,6 +3294,34 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
}
}
private void buildCodingExpression(ElementDefinition ed, StringBuilder expression, String discriminator, Coding c)
throws DefinitionException {
if (c.hasExtension())
throw new DefinitionException("Unsupported CodeableConcept pattern - extensions are not allowed - for discriminator(" + discriminator + ") for slice " + ed.getId());
expression.append(discriminator + ".coding.where(");
boolean first = true;
if (c.hasSystem()) {
first = false;
expression.append("system = '" + c.getSystem() + "'");
}
if (c.hasVersion()) {
if (first) first = false;
else expression.append(" and ");
expression.append("version = '" + c.getVersion() + "'");
}
if (c.hasCode()) {
if (first) first = false;
else expression.append(" and ");
expression.append("code = '" + c.getCode() + "'");
}
if (c.hasDisplay()) {
if (first) first = false;
else expression.append(" and ");
expression.append("display = '" + c.getDisplay() + "'");
}
expression.append(").exists()");
}
private void buildFixedExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
DataType fixed = criteriaElement.getFixed();
if (fixed instanceof CodeableConcept) {
@ -3300,6 +3332,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
Identifier ii = (Identifier) fixed;
expression.append(" and ");
buildIdentifierExpression(ed, expression, discriminator, ii);
} else if (fixed instanceof Coding) {
Coding c = (Coding) fixed;
expression.append(" and ");
buildCodingExpression(ed, expression, discriminator, c);
} else {
expression.append(" and (");
if (fixed instanceof StringType) {

View File

@ -17,7 +17,7 @@
<properties>
<hapi_fhir_version>4.2.0</hapi_fhir_version>
<validator_test_case_version>1.0.43-SNAPSHOT</validator_test_case_version>
<validator_test_case_version>1.0.44-SNAPSHOT</validator_test_case_version>
</properties>
<artifactId>org.hl7.fhir.core</artifactId>