Search in sources :

Example 76 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testSlicingTask8742.

private void testSlicingTask8742() throws EOperationOutcome, Exception {
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Organization").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBase(base.getUrl());
    ElementDefinition id = focus.getDifferential().addElement();
    id.setPath("Organization.address");
    id.setMin(1);
    id.setMax("1");
    id.setMustSupport(true);
    id = focus.getDifferential().addElement();
    id.setPath("Organization.address.extension");
    id.setName("USLabCountycodes");
    id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator("url");
    id.setShort("County/Parish FIPS codes");
    id.setDefinition("County/Parish FIPS codes.");
    id.setRequirements("County/Parish Code SHALL use FIPS 6-4  ( INCITS 31:2009).");
    id.setMin(0);
    id.setMax("1");
    id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/us-core-county");
    id.setMustSupport(true);
    id.getBinding().setStrength(BindingStrength.REQUIRED).setDescription("FIPS codes for US counties and county equivalent entities.").setValueSet(new Reference().setReference("http://hl7.org/fhir/ValueSet/fips-county"));
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test");
    // 14 for address with one sliced extension
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 13;
    if (!ok) {
        compareXml(base, focus);
        throw new FHIRException("Snap shot generation test 8742 failed");
    } else
        System.out.println("Snap shot generation test 8742 passed");
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.dstu2.utils.ProfileUtilities) Reference(org.hl7.fhir.dstu2.model.Reference) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 77 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition 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.setBase(base.getUrl());
    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");
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.dstu2.utils.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 78 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition 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.setBase(base.getUrl());
    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");
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.dstu2.utils.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 79 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition 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.setBase(base.getUrl());
    // set the slice up
    ElementDefinition id;
    if (!implicit) {
        id = focus.getDifferential().addElement();
        id.setPath("Patient.extension");
        id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator("url");
    }
    // first slice  - a simple one to get us going:
    id = focus.getDifferential().addElement();
    id.setPath("Patient.extension");
    id.setName("simple");
    id.addType().setCode("Extension").addProfile("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.setName("complex");
    id.addType().setCode("Extension").addProfile("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("url");
    }
    id = focus.getDifferential().addElement();
    id.setPath("Patient.extension.extension");
    id.setName("code");
    id.setMustSupport(true);
    id.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/patient-nationality#code");
    id = focus.getDifferential().addElement();
    id.setPath("Patient.extension.extension");
    id.setName("period");
    id.addType().setCode("Extension").addProfile("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).getName().equals("simple"), "element 8 (1st slice) name");
    ok = ok && rule(focus.getSnapshot().getElement().get(8).getType().get(0).getProfile().get(0).getValue().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).getName().equals("complex"), "element 8 (1st slice) name");
    ok = ok && rule(focus.getSnapshot().getElement().get(9).getType().get(0).getProfile().get(0).getValue().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");
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.dstu2.utils.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 80 with ElementDefinition

use of org.hl7.fhir.r4.model.ElementDefinition in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testSimple2.

/**
 * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base. for a different resource with recursion
 *
 * @param context2
 * @
 * @throws EOperationOutcome
 */
private void testSimple2() throws EOperationOutcome, Exception {
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBase(base.getUrl());
    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);
                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");
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.dstu2.utils.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37