Search in sources :

Example 51 with ProfileUtilities

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

the class InstanceValidator method validate.

@Override
public org.hl7.fhir.r5.elementmodel.Element validate(Object appContext, List<ValidationMessage> errors, JsonObject object, List<StructureDefinition> profiles) throws FHIRException {
    JsonParser parser = new JsonParser(context, new ProfileUtilities(context, null, null, fpe));
    parser.setupValidation(ValidationPolicy.EVERYTHING, errors);
    long t = System.nanoTime();
    Element e = parser.parse(object);
    timeTracker.load(t);
    if (e != null)
        validate(appContext, errors, null, e, profiles);
    return e;
}
Also used : ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) Element(org.hl7.fhir.r5.elementmodel.Element) JsonParser(org.hl7.fhir.r5.elementmodel.JsonParser)

Example 52 with ProfileUtilities

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

the class QuestionnaireBuilder method makeTypeList.

private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
    ValueSet vs = new ValueSet();
    vs.setName("Type options for " + path);
    vs.setDescription(vs.present());
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setExpansion(new ValueSetExpansionComponent());
    vs.getExpansion().setIdentifier(Factory.createUUID());
    vs.getExpansion().setTimestampElement(DateTimeType.now());
    for (TypeRefComponent t : types) {
        if (t.hasTarget()) {
            for (UriType u : t.getTargetProfile()) {
                if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                    ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
                    cc.setCode(u.getValue().substring(40));
                    cc.setSystem("http://hl7.org/fhir/resource-types");
                    cc.setDisplay(cc.getCode());
                }
            }
        } else if (!t.hasProfile()) {
            ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
            cc.setCode(t.getWorkingCode());
            cc.setDisplay(t.getWorkingCode());
            cc.setSystem("http://hl7.org/fhir/data-types");
        } else
            for (UriType u : t.getProfile()) {
                ProfileUtilities pu = new ProfileUtilities(context, null, null);
                StructureDefinition ps = pu.getProfile(profile, u.getValue());
                if (ps != null) {
                    ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
                    cc.setCode(u.getValue());
                    cc.setDisplay(ps.getType());
                    cc.setSystem("http://hl7.org/fhir/resource-types");
                }
            }
    }
    return vs;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) ValueSet(org.hl7.fhir.r4.model.ValueSet) UriType(org.hl7.fhir.r4.model.UriType)

Example 53 with ProfileUtilities

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

the class QuestionnaireBuilder method selectTypes.

private void selectTypes(StructureDefinition profile, QuestionnaireItemComponent sub, TypeRefComponent t, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> source, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> dest) throws FHIRFormatError {
    List<QuestionnaireResponse.QuestionnaireResponseItemComponent> temp = new ArrayList<QuestionnaireResponse.QuestionnaireResponseItemComponent>();
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : source) if (instanceOf(t, (Element) g.getUserData("object")))
        temp.add(g);
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) source.remove(g);
    for (QuestionnaireResponse.QuestionnaireResponseItemComponent g : temp) {
        // it should be empty
        assert (g.getItem().size() == 0);
        QuestionnaireResponse.QuestionnaireResponseItemComponent q = g.addItem();
        q.setLinkId(g.getLinkId() + "._type");
        q.setText("type");
        QuestionnaireResponseItemAnswerComponent a = q.addAnswer();
        if (t.hasTarget()) {
            for (UriType u : t.getTargetProfile()) {
                if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                    Coding cc = new Coding();
                    a.setValue(cc);
                    cc.setCode(u.getValue().substring(40));
                    cc.setSystem("http://hl7.org/fhir/resource-types");
                }
            }
        } else {
            Coding cc = new Coding();
            a.setValue(cc);
            ProfileUtilities pu = new ProfileUtilities(context, null, null);
            StructureDefinition ps = null;
            if (t.hasProfile())
                ps = pu.getProfile(profile, t.getProfile().get(0).getValue());
            if (ps != null) {
                cc.setCode(t.getProfile().get(0).getValue());
                cc.setSystem("http://hl7.org/fhir/resource-types");
            } else {
                cc.setCode(t.getWorkingCode());
                cc.setSystem("http://hl7.org/fhir/data-types");
            }
        }
        // 1st: create the subgroup
        QuestionnaireResponse.QuestionnaireResponseItemComponent subg = a.addItem();
        dest.add(subg);
        subg.setLinkId(sub.getLinkId());
        subg.setText(sub.getText());
        subg.setUserData("object", g.getUserData("object"));
    }
}
Also used : QuestionnaireResponseItemAnswerComponent(org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) Coding(org.hl7.fhir.r4.model.Coding) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) Element(org.hl7.fhir.r4.model.Element) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) UriType(org.hl7.fhir.r4.model.UriType)

Example 54 with ProfileUtilities

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

the class StructureMapUtilities method analyse.

/**
 * Given a structure map, return a set of analyses on it.
 *
 * Returned:
 *   - a list or profiles for what it will create. First profile is the target
 *   - a table with a summary (in xhtml) for easy human undertanding of the mapping
 *
 * @param appInfo
 * @param map
 * @return
 * @throws Exception
 */
public StructureMapAnalysis analyse(Object appInfo, StructureMap map) throws FHIRException {
    ids.clear();
    StructureMapAnalysis result = new StructureMapAnalysis();
    TransformContext context = new TransformContext(appInfo);
    VariablesForProfiling vars = new VariablesForProfiling(false, false);
    StructureMapGroupComponent start = map.getGroup().get(0);
    for (StructureMapGroupInputComponent t : start.getInput()) {
        PropertyWithType ti = resolveType(map, t.getType(), t.getMode());
        if (t.getMode() == StructureMapInputMode.SOURCE)
            vars.add(VariableMode.INPUT, t.getName(), ti);
        else
            vars.add(VariableMode.OUTPUT, t.getName(), createProfile(map, result.profiles, ti, start.getName(), start));
    }
    result.summary = new XhtmlNode(NodeType.Element, "table").setAttribute("class", "grid");
    XhtmlNode tr = result.summary.addTag("tr");
    tr.addTag("td").addTag("b").addText("Source");
    tr.addTag("td").addTag("b").addText("Target");
    log("Start Profiling Transform " + map.getUrl());
    analyseGroup("", context, map, vars, start, result);
    ProfileUtilities pu = new ProfileUtilities(worker, null, pkp);
    for (StructureDefinition sd : result.getProfiles()) pu.cleanUpDifferential(sd);
    return result;
}
Also used : StructureMapGroupComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupComponent) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) StructureMapGroupInputComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupInputComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 55 with ProfileUtilities

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

the class NarrativeGenerator method generate.

public boolean generate(ResourceContext rcontext, StructureDefinition sd, Set<String> outputTracker) throws EOperationOutcome, FHIRException, IOException {
    ProfileUtilities pu = new ProfileUtilities(context, null, pkp);
    XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
    x.getChildNodes().add(pu.generateTable(definitionsTarget, sd, true, destDir, false, sd.getId(), false, corePath, "", false, false, outputTracker));
    inject(sd, x, NarrativeStatus.GENERATED);
    return true;
}
Also used : ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

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