Search in sources :

Example 21 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class ValidatorUtils method messagesToOutcome.

protected static OperationOutcome messagesToOutcome(List<ValidationMessage> messages, SimpleWorkerContext context, FHIRPathEngine fpe) throws IOException, FHIRException, EOperationOutcome {
    OperationOutcome op = new OperationOutcome();
    for (ValidationMessage vm : filterMessages(messages)) {
        try {
            fpe.parse(vm.getLocation());
        } catch (Exception e) {
            System.out.println("Internal error in location for message: '" + e.getMessage() + "', loc = '" + vm.getLocation() + "', err = '" + vm.getMessage() + "'");
        }
        op.getIssue().add(OperationOutcomeUtilities.convertToIssue(vm, op));
    }
    if (!op.hasIssue()) {
        op.addIssue().setSeverity(OperationOutcome.IssueSeverity.INFORMATION).setCode(OperationOutcome.IssueType.INFORMATIONAL).getDetails().setText(context.formatMessage(I18nConstants.ALL_OK));
    }
    RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, RenderingContext.ResourceRendererMode.END_USER);
    RendererFactory.factory(op, rc).render(op);
    return op;
}
Also used : RenderingContext(org.hl7.fhir.r5.renderers.utils.RenderingContext) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) OperationOutcome(org.hl7.fhir.r5.model.OperationOutcome) EOperationOutcome(org.hl7.fhir.r5.utils.EOperationOutcome) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 22 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method genOpParam.

private void genOpParam(ResourceContext rcontext, XhtmlNode tbl, String path, OperationDefinitionParameterComponent p) throws EOperationOutcome, FHIRException, IOException {
    XhtmlNode tr;
    tr = tbl.tr();
    tr.td().addText(p.getUse().toString());
    tr.td().addText(path + p.getName());
    tr.td().addText(Integer.toString(p.getMin()) + ".." + p.getMax());
    tr.td().addText(p.hasType() ? p.getType() : "");
    XhtmlNode td = tr.td();
    if (p.hasBinding() && p.getBinding().hasValueSet()) {
        if (p.getBinding().getValueSet() instanceof Reference)
            AddVsRef(rcontext, p.getBinding().getValueSetReference().getReference(), td);
        else
            td.ah(p.getBinding().getValueSetUriType().getValue()).tx("External Reference");
        td.tx(" (" + p.getBinding().getStrength().getDisplay() + ")");
    }
    addMarkdown(tr.td(), p.getDocumentation());
    if (!p.hasType()) {
        for (OperationDefinitionParameterComponent pp : p.getPart()) {
            genOpParam(rcontext, tbl, path + p.getName() + ".", pp);
        }
    }
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) OperationDefinitionParameterComponent(org.hl7.fhir.dstu3.model.OperationDefinition.OperationDefinitionParameterComponent)

Example 23 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testSimple.

// /**
// * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base
// *
// * @param context2
// * @
// * @throws EOperationOutcome
// */
@Test
public void testSimple() throws FHIRException, FileNotFoundException, IOException, UcumException {
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType("Patient");
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://hl7.org/fhir/R4", "Simple Test");
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        ElementDefinition b = base.getSnapshot().getElement().get(i);
        ElementDefinition f = focus.getSnapshot().getElement().get(i);
        if (ok) {
            if (!f.hasBase())
                ok = false;
            else if (!b.getPath().equals(f.getPath()))
                ok = false;
            else {
                b.setBase(null);
                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.r4.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) Test(org.junit.jupiter.api.Test)

Example 24 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome 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
// */
@Test
public void testSimple2() throws EOperationOutcome, Exception {
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy();
    StructureDefinition focus = base.copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setSnapshot(null);
    focus.setDifferential(null);
    List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
    new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://hl7.org/fhir/R4", "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.getPath()))
                ok = false;
            else {
                f.setBase(null);
                b.setBase(null);
                ok = Base.compareDeep(b, f, true);
            }
        }
    }
    if (!ok) {
        compareXml(base, focus);
        System.out.println("Snap shot generation simple test failed");
        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.r4.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) Test(org.junit.jupiter.api.Test)

Example 25 with EOperationOutcome

use of org.hl7.fhir.r5.utils.EOperationOutcome in project org.hl7.fhir.core by hapifhir.

the class NarrativeGeneratorTests method process.

private void process(String path) throws FileNotFoundException, IOException, XmlPullParserException, EOperationOutcome, FHIRException {
    XmlParser p = new XmlParser();
    DomainResource r = (DomainResource) p.parse(new FileInputStream(path));
    gen.generate(r, null);
    FileOutputStream s = new FileOutputStream(TestingUtilities.resourceNameToFile("gen", "gen.xml"));
    new XmlParser().compose(s, r, true);
    s.close();
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) DomainResource(org.hl7.fhir.r4.model.DomainResource) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)52 FHIRException (org.hl7.fhir.exceptions.FHIRException)38 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)37 ArrayList (java.util.ArrayList)35 ProfileUtilities (org.hl7.fhir.dstu3.conformance.ProfileUtilities)14 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)13 ProfileUtilities (org.hl7.fhir.dstu2.utils.ProfileUtilities)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)13 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)13 FileOutputStream (java.io.FileOutputStream)10 Test (org.junit.jupiter.api.Test)10 IOException (java.io.IOException)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 DomainResource (org.hl7.fhir.r5.model.DomainResource)7 DomainResource (org.hl7.fhir.r4b.model.DomainResource)6 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)6 BaseWrapper (org.hl7.fhir.r4b.renderers.utils.BaseWrappers.BaseWrapper)6 BaseWrapper (org.hl7.fhir.r5.renderers.utils.BaseWrappers.BaseWrapper)6 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5