Search in sources :

Example 11 with ProfileUtilities

use of org.hl7.fhir.r4b.conformance.ProfileUtilities in project kindling by HL7.

the class ResourceParser method parseTypeDefinition.

private TypeDefn parseTypeDefinition(ProfileUtilities pu, ElementDefinition focus, StructureDefinition sd) throws IOException {
    TypeDefn ed = new TypeDefn();
    parseED(pu, ed, focus, sd, "");
    return ed;
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn)

Example 12 with ProfileUtilities

use of org.hl7.fhir.r4b.conformance.ProfileUtilities in project kindling by HL7.

the class ProfileGenerator method generate.

public StructureDefinition generate(ProfiledType pt, List<ValidationMessage> issues) throws Exception {
    StructureDefinition p = new StructureDefinition();
    p.setId(pt.getName());
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
    p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + pt.getBaseType());
    p.setKind(StructureDefinitionKind.COMPLEXTYPE);
    p.setType(pt.getBaseType());
    p.setDerivation(TypeDerivationRule.CONSTRAINT);
    p.setAbstract(false);
    p.setUserData("filename", pt.getName().toLowerCase());
    p.setUserData("path", "datatypes.html#" + pt.getName());
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    ToolingExtensions.setStandardsStatus(p, StandardsStatus.NORMATIVE, "4.0.0");
    p.setStatus(PublicationStatus.fromCode("active"));
    ToolResourceUtilities.updateUsage(p, "core");
    p.setName(pt.getName());
    p.setPublisher("HL7 FHIR Standard");
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    p.setDescription("Base StructureDefinition for Type " + pt.getName() + ": " + pt.getDefinition());
    p.setDescription(pt.getDefinition());
    p.setDate(genDate.getTime());
    // first, the differential
    p.setName(pt.getName());
    ElementDefinition e = new ElementDefinition();
    String idroot = e.getId();
    e.setPath(pt.getBaseType());
    // e.setSliceName(pt.getName());
    e.setShort(pt.getDefinition());
    e.setDefinition(preProcessMarkdown(pt.getDescription(), "??"));
    e.setMin(0);
    e.setMax("*");
    e.setIsModifier(false);
    String s = definitions.getTLAs().get(pt.getName().toLowerCase());
    if (s == null)
        throw new Exception("There is no TLA for '" + pt.getName() + "' in fhir.ini");
    ElementDefinitionConstraintComponent inv = new ElementDefinitionConstraintComponent();
    inv.setKey(s + "-1");
    inv.setRequirements(pt.getInvariant().getRequirements());
    inv.setSeverity(ConstraintSeverity.ERROR);
    inv.setHuman(pt.getInvariant().getEnglish());
    if (!"n/a".equals(pt.getInvariant().getExpression())) {
        fpUsages.add(new FHIRPathUsage(pt.getName(), pt.getName(), pt.getName(), null, pt.getInvariant().getExpression()));
        inv.setExpression(pt.getInvariant().getExpression());
    }
    inv.setXpath(pt.getInvariant().getXpath());
    e.getConstraint().add(inv);
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    p.getDifferential().getElement().add(e);
    StructureDefinition base = getTypeSnapshot(pt.getBaseType());
    if (!pt.getRules().isEmpty()) {
        // throw new Exception("todo");
        for (String rule : pt.getRules().keySet()) {
            String[] parts = rule.split("\\.");
            String value = pt.getRules().get(rule);
            ElementDefinition er = findElement(p.getDifferential(), pt.getBaseType() + '.' + parts[0]);
            if (er == null) {
                er = new ElementDefinition();
                er.setId(pt.getBaseType() + ':' + p.getId() + '.' + parts[0]);
                er.setPath(pt.getBaseType() + '.' + parts[0]);
                p.getDifferential().getElement().add(er);
            }
            if (parts[1].equals("min"))
                er.setMin(Integer.parseInt(value));
            else if (parts[1].equals("max"))
                er.setMax(value);
            else if (parts[1].equals("defn"))
                er.setDefinition(preProcessMarkdown(value, "er"));
        }
        List<String> errors = new ArrayList<String>();
        new ProfileUtilities(context, null, pkp).sortDifferential(base, p, p.getName(), errors, true);
        for (String se : errors) issues.add(new ValidationMessage(Source.ProfileValidator, IssueType.STRUCTURE, -1, -1, p.getUrl(), se, IssueSeverity.WARNING));
    }
    reset();
    // now, the snapshot
    new ProfileUtilities(context, issues, pkp).generateSnapshot(base, p, "http://hl7.org/fhir/StructureDefinition/" + pt.getBaseType(), "http://hl7.org/fhir", p.getName());
    // for (ElementDefinition ed : p.getSnapshot().getElement())
    // generateElementDefinition(ed, getParent(ed, p.getSnapshot().getElement()));
    p.getDifferential().getElement().get(0).getType().clear();
    p.getSnapshot().getElement().get(0).getType().clear();
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addTag("h2").addText("Data type " + pt.getName());
    div.addTag("p").addText(pt.getDefinition());
    div.addTag("h3").addText("Rule");
    div.addTag("p").addText(pt.getInvariant().getEnglish());
    div.addTag("p").addText("XPath:");
    div.addTag("blockquote").addTag("pre").addText(pt.getInvariant().getXpath());
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    addElementConstraintToSnapshot(p);
    new ProfileUtilities(context, issues, pkp).setIds(p, false);
    checkHasTypes(p);
    return p;
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ArrayList(java.util.ArrayList) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) FHIRPathUsage(org.hl7.fhir.definitions.validation.FHIRPathUsage)

Example 13 with ProfileUtilities

use of org.hl7.fhir.r4b.conformance.ProfileUtilities in project org.hl7.fhir.core by hapifhir.

the class ExtensionDefinitionGenerator method loadSource.

private List<StructureDefinition> loadSource() throws IOException, FHIRException {
    List<StructureDefinition> list = new ArrayList<>();
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    NpmPackage npm = pcm.loadPackage("hl7.fhir.core", sourceVersion.toCode());
    if (sourceVersion == FHIRVersion._4_0_0)
        context = SimpleWorkerContext.fromPackage(npm);
    else if (sourceVersion == FHIRVersion._3_0_1)
        context = SimpleWorkerContext.fromPackage(npm, new R3ToR4Loader());
    else if (sourceVersion == FHIRVersion._1_4_0)
        context = SimpleWorkerContext.fromPackage(npm, new R2016MayToR4Loader());
    else if (sourceVersion == FHIRVersion._1_0_2)
        context = SimpleWorkerContext.fromPackage(npm, new R2ToR4Loader());
    pu = new ProfileUtilities(context, null, null);
    for (String fn : npm.listResources("StructureDefinition")) {
        list.add((StructureDefinition) loadResource(npm.load("package", fn), sourceVersion));
    }
    for (StructureDefinition sd : list) if (sd.getName().equals("Extension")) {
        extbase = sd;
        extv = extbase.getSnapshot().getElement().get(extbase.getSnapshot().getElement().size() - 1);
    }
    return list;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) R2ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R2ToR4Loader) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) R3ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader) R2016MayToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R2016MayToR4Loader)

Example 14 with ProfileUtilities

use of org.hl7.fhir.r4b.conformance.ProfileUtilities 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.setBase(base.getUrl());
    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");
}
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 15 with ProfileUtilities

use of org.hl7.fhir.r4b.conformance.ProfileUtilities 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)

Aggregations

ArrayList (java.util.ArrayList)74 FHIRException (org.hl7.fhir.exceptions.FHIRException)59 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)52 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)48 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)38 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)21 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)20 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)16 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)16 FileOutputStream (java.io.FileOutputStream)15 ProfileUtilities (org.hl7.fhir.r4b.conformance.ProfileUtilities)14 IOException (java.io.IOException)13 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)13 ProfileUtilities (org.hl7.fhir.dstu2.utils.ProfileUtilities)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 ProfileUtilities (org.hl7.fhir.r4.conformance.ProfileUtilities)12 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)12 Test (org.junit.jupiter.api.Test)12 FileNotFoundException (java.io.FileNotFoundException)11