use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method testSlicingExtensionComplex.
/**
* we're going to slice Patient.extension and refer to extension by profile. one of the extensions is complex, and we're going to walk into
* it and make it must support
*
* implicit: whether to rely on implicit extension slicing
*/
private void testSlicingExtensionComplex(boolean implicit) throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBaseDefinition(base.getUrl());
focus.setType(base.getType());
focus.setDerivation(TypeDerivationRule.CONSTRAINT);
// set the slice up
ElementDefinition id;
if (!implicit) {
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
}
// first slice - a simple one to get us going:
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.setSliceName("simple");
id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-birthTime");
// second slice - the complex one
// we walk into this and fix properties on the inner extensions
id = focus.getDifferential().addElement();
id.setPath("Patient.extension");
id.setSliceName("complex");
id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality");
if (!implicit) {
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
}
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.setSliceName("code");
id.setMustSupport(true);
id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#code");
id = focus.getDifferential().addElement();
id.setPath("Patient.extension.extension");
id.setSliceName("period");
id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#period");
// prohibit this one....
id.setMax("0");
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
// ok, there's going to 1 (simple) + complex: 1 + id + extnesion.slice + extension.code + (4 inside from that) + extension.period + (4 inside from that) + value + url = 16
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 16;
// custom checks
ok = ok && rule(focus.getSnapshot().getElement().get(7).getPath().equals("Patient.extension"), "element 7 (base) path");
ok = ok && rule(focus.getSnapshot().getElement().get(7).hasSlicing(), "element 7 slicing");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getPath().equals("Patient.extension"), "element 8 (1st slice) path");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getSliceName().equals("simple"), "element 8 (1st slice) name");
ok = ok && rule(focus.getSnapshot().getElement().get(8).getType().get(0).getProfile().equals("http://hl7.org/fhir/StructureDefinition/patient-birthTime"), "element 9 (2nd slice) profile name");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getPath().equals("Patient.extension"), "element 9 (2nd slice) path");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getSliceName().equals("complex"), "element 8 (1st slice) name");
ok = ok && rule(focus.getSnapshot().getElement().get(9).getType().get(0).getProfile().equals("http://hl7.org/fhir/StructureDefinition/patient-nationality"), "element 9 (2nd slice) profile name");
ok = ok && rule(focus.getSnapshot().getElement().get(10).getPath().equals("Patient.extension.id"), "element 10 (2nd slice).id path");
ok = ok && rule(focus.getSnapshot().getElement().get(11).getPath().equals("Patient.extension.extension"), "element 11 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(12).getPath().equals("Patient.extension.extension"), "element 12 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(12).getMustSupport(), "element 12 (2nd slice).extension must support");
ok = ok && rule(focus.getSnapshot().getElement().get(13).getPath().equals("Patient.extension.extension.id"), "element 13 (2nd slice).extension.id path");
ok = ok && rule(focus.getSnapshot().getElement().get(14).getPath().equals("Patient.extension.extension.extension"), "element 14 (2nd slice).extension.extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(15).getPath().equals("Patient.extension.extension.url"), "element 15 (2nd slice).extension.url path");
ok = ok && rule(focus.getSnapshot().getElement().get(16).getPath().equals("Patient.extension.extension.valueCodeableConcept"), "element 16 (2nd slice).extension.valueCodeableConcept path");
ok = ok && rule(focus.getSnapshot().getElement().get(17).getPath().equals("Patient.extension.extension"), "element 17 (2nd slice).extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(17).getMax().equals("0"), "element 17 (2nd slice).extension cardinality");
ok = ok && rule(focus.getSnapshot().getElement().get(18).getPath().equals("Patient.extension.extension.id"), "element 18 (2nd slice).extension.id path");
ok = ok && rule(focus.getSnapshot().getElement().get(19).getPath().equals("Patient.extension.extension.extension"), "element 19 (2nd slice).extension.extension path");
ok = ok && rule(focus.getSnapshot().getElement().get(20).getPath().equals("Patient.extension.extension.url"), "element 20 (2nd slice).extension.url path");
ok = ok && rule(focus.getSnapshot().getElement().get(21).getPath().equals("Patient.extension.extension.valuePeriod"), "element 21 (2nd slice).extension.valuePeriod path");
ok = ok && rule(focus.getSnapshot().getElement().get(22).getPath().equals("Patient.extension.url"), "element 22 (2nd slice).url path");
ok = ok && rule(focus.getSnapshot().getElement().get(23).getPath().equals("Patient.extension.value[x]"), "element 23 (2nd slice).url path");
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i <= 7 ? i : i + 16);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.extension")) {
ok = f.hasSlicing();
if (ok)
f.setSlicing(null);
}
if (// no compare that because the definitions get overwritten
!f.getPath().equals("Patient.extension"))
ok = Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation slicing extensions complex (" + (implicit ? "implicit" : "not implicit") + ") failed");
} else
System.out.println("Snap shot generation slicing extensions complex (" + (implicit ? "implicit" : "not implicit") + ") passed");
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method textTypeNarrowing1.
/**
* check that narrowing types is working
* this one doesn't rename the path
*
* @param context2
* @
* @throws EOperationOutcome
*/
private void textTypeNarrowing1() throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBaseDefinition(base.getUrl());
focus.setType(base.getType());
focus.setDerivation(TypeDerivationRule.CONSTRAINT);
ElementDefinition id = focus.getDifferential().addElement();
id.setPath("Patient.deceased[x]");
id.addType().setCode("dateTime");
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.deceasedDateTime")) {
ok = f.getType().size() == 1 && f.getType().get(0).getCode().equals("dateTime");
if (ok) {
f.getType().clear();
b.getType().clear();
f.setPath(b.getPath());
}
}
ok = ok && Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation narrow type 1 failed");
} else
System.out.println("Snap shot generation narrow type 1 test passed");
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method textTypeNarrowing2.
/**
* check that narrowing types is working
* this one renames the path
*
* @param context2
* @
* @throws EOperationOutcome
*/
private void textTypeNarrowing2() throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBaseDefinition(base.getUrl());
focus.setType(base.getType());
focus.setDerivation(TypeDerivationRule.CONSTRAINT);
ElementDefinition id = focus.getDifferential().addElement();
id.setPath("Patient.deceasedDateTime");
id.addType().setCode("dateTime");
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.deceasedDateTime")) {
ok = f.getType().size() == 1 && f.getType().get(0).getCode().equals("dateTime");
if (ok) {
f.getType().clear();
b.getType().clear();
f.setPath(b.getPath());
}
}
ok = ok && Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation narrow type 2 failed");
} else
System.out.println("Snap shot generation narrow type 2 test passed");
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method testTypeWalk2.
/**
* Walking into a type, without explicitly doing so
*
* note: this currently fails.
*
* @param context2
* @
* @throws EOperationOutcome
*/
private void testTypeWalk2() throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBaseDefinition(base.getUrl());
focus.setType(base.getType());
focus.setDerivation(TypeDerivationRule.CONSTRAINT);
ElementDefinition id = focus.getDifferential().addElement();
id.setPath("Patient.identifier.system");
id.setMustSupport(true);
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
// the derived should be 8 longer
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 8;
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i <= 9 ? i : i + 8);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.identifier")) {
ok = f.getMustSupport() && !b.getMustSupport();
if (ok) {
f.setMustSupportElement(null);
}
}
ok = Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation simple test failed");
} else
System.out.println("Snap shot generation simple test passed");
}
use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method testTypeWalk.
/**
* Walking into a type
*
* @param context2
* @
* @throws EOperationOutcome
*/
private void testTypeWalk() throws EOperationOutcome, Exception {
StructureDefinition focus = new StructureDefinition();
StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
focus.setUrl(Utilities.makeUuidUrn());
focus.setBaseDefinition(base.getUrl());
focus.setType(base.getType());
focus.setDerivation(TypeDerivationRule.CONSTRAINT);
ElementDefinition id = focus.getDifferential().addElement();
id.setPath("Patient.identifier");
id.setMustSupport(true);
id = focus.getDifferential().addElement();
id.setPath("Patient.identifier.system");
id.setMustSupport(true);
List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
// the derived should be 8 longer
boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 8;
for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
if (ok) {
ElementDefinition b = base.getSnapshot().getElement().get(i);
ElementDefinition f = focus.getSnapshot().getElement().get(i <= 9 ? i : i + 8);
if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath()))
ok = false;
else {
f.setBase(null);
if (f.getPath().equals("Patient.identifier")) {
ok = f.getMustSupport() && !b.getMustSupport();
if (ok) {
f.setMustSupportElement(null);
}
}
ok = Base.compareDeep(b, f, true);
}
}
}
if (!ok) {
compareXml(base, focus);
throw new FHIRException("Snap shot generation simple test failed");
} else
System.out.println("Snap shot generation simple test passed");
}
Aggregations