Search in sources :

Example 26 with MessageHeader

use of org.hl7.fhir.dstu3.model.MessageHeader in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeMessageHeaderMessageSourceComponent.

protected void composeMessageHeaderMessageSourceComponent(Complex parent, String parentType, String name, MessageHeader.MessageSourceComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "source", name, element, index);
    if (element.hasNameElement())
        composeString(t, "MessageHeader", "name", element.getNameElement(), -1);
    if (element.hasSoftwareElement())
        composeString(t, "MessageHeader", "software", element.getSoftwareElement(), -1);
    if (element.hasVersionElement())
        composeString(t, "MessageHeader", "version", element.getVersionElement(), -1);
    if (element.hasContact())
        composeContactPoint(t, "MessageHeader", "contact", element.getContact(), -1);
    if (element.hasEndpointElement())
        composeUrl(t, "MessageHeader", "endpoint", element.getEndpointElement(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 27 with MessageHeader

use of org.hl7.fhir.dstu3.model.MessageHeader in project org.hl7.fhir.core by hapifhir.

the class BundleValidator method validateBundle.

public void validateBundle(List<ValidationMessage> errors, Element bundle, NodeStack stack, boolean checkSpecials, ValidatorHostContext hostContext) {
    List<Element> entries = new ArrayList<Element>();
    bundle.getNamedChildren(ENTRY, entries);
    String type = bundle.getNamedChildValue(TYPE);
    type = StringUtils.defaultString(type);
    if (entries.size() == 0) {
        rule(errors, IssueType.INVALID, stack.getLiteralPath(), !(type.equals(DOCUMENT) || type.equals(MESSAGE)), I18nConstants.BUNDLE_BUNDLE_ENTRY_NOFIRST);
    } else {
        // Get the first entry, the MessageHeader
        Element firstEntry = entries.get(0);
        // Get the stack of the first entry
        NodeStack firstStack = stack.push(firstEntry, 1, null, null);
        String fullUrl = firstEntry.getNamedChildValue(FULL_URL);
        if (type.equals(DOCUMENT)) {
            Element resource = firstEntry.getNamedChild(RESOURCE);
            if (rule(errors, IssueType.INVALID, firstEntry.line(), firstEntry.col(), stack.addToLiteralPath(ENTRY, PATH_ARG), resource != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOFIRSTRESOURCE)) {
                String id = resource.getNamedChildValue(ID);
                validateDocument(errors, entries, resource, firstStack.push(resource, -1, null, null), fullUrl, id);
            }
            if (!VersionUtilities.isThisOrLater(FHIRVersion._4_0_1.getDisplay(), bundle.getProperty().getStructure().getFhirVersion().getDisplay())) {
                handleSpecialCaseForLastUpdated(bundle, errors, stack);
            }
            checkAllInterlinked(errors, entries, stack, bundle, true);
        }
        if (type.equals(MESSAGE)) {
            Element resource = firstEntry.getNamedChild(RESOURCE);
            String id = resource.getNamedChildValue(ID);
            if (rule(errors, IssueType.INVALID, firstEntry.line(), firstEntry.col(), stack.addToLiteralPath(ENTRY, PATH_ARG), resource != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOFIRSTRESOURCE)) {
                validateMessage(errors, entries, resource, firstStack.push(resource, -1, null, null), fullUrl, id);
            }
            checkAllInterlinked(errors, entries, stack, bundle, VersionUtilities.isR5Ver(context.getVersion()));
        }
        if (type.equals(SEARCHSET)) {
            checkSearchSet(errors, bundle, entries, stack);
        }
    // We do not yet have rules requiring that the id and fullUrl match when dealing with messaging Bundles
    // validateResourceIds(errors, entries, stack);
    }
    int count = 0;
    Map<String, Integer> counter = new HashMap<>();
    boolean fullUrlOptional = Utilities.existsInList(type, "transaction", "transaction-response", "batch", "batch-response");
    for (Element entry : entries) {
        NodeStack estack = stack.push(entry, count, null, null);
        String fullUrl = entry.getNamedChildValue(FULL_URL);
        String url = getCanonicalURLForEntry(entry);
        String id = getIdForEntry(entry);
        if (url != null) {
            if (!(!url.equals(fullUrl) || (url.matches(uriRegexForVersion()) && url.endsWith("/" + id))) && !isV3orV2Url(url))
                rule(errors, IssueType.INVALID, entry.line(), entry.col(), stack.addToLiteralPath(ENTRY, PATH_ARG), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_MISMATCHIDURL, url, fullUrl, id);
            rule(errors, IssueType.INVALID, entry.line(), entry.col(), stack.addToLiteralPath(ENTRY, PATH_ARG), !url.equals(fullUrl) || serverBase == null || (url.equals(Utilities.pathURL(serverBase, entry.getNamedChild(RESOURCE).fhirType(), id))), I18nConstants.BUNDLE_BUNDLE_ENTRY_CANONICAL, url, fullUrl);
        }
        if (!VersionUtilities.isR2Ver(context.getVersion())) {
            rule(errors, IssueType.INVALID, entry.line(), entry.col(), estack.getLiteralPath(), fullUrlOptional || fullUrl != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_FULLURL_REQUIRED);
        }
        // check bundle profile requests
        if (entry.hasChild(RESOURCE)) {
            String rtype = entry.getNamedChild(RESOURCE).fhirType();
            int rcount = counter.containsKey(rtype) ? counter.get(rtype) + 1 : 0;
            counter.put(rtype, rcount);
            for (BundleValidationRule bvr : validator.getBundleValidationRules()) {
                if (meetsRule(bvr, rtype, rcount, count)) {
                    StructureDefinition defn = validator.getContext().fetchResource(StructureDefinition.class, bvr.getProfile());
                    if (defn == null) {
                        throw new Error(validator.getContext().formatMessage(I18nConstants.BUNDLE_RULE_PROFILE_UNKNOWN, bvr.getRule(), bvr.getProfile()));
                    } else {
                        Element res = entry.getNamedChild(RESOURCE);
                        NodeStack rstack = estack.push(res, -1, null, null);
                        if (validator.isCrumbTrails()) {
                            res.addMessage(signpost(errors, IssueType.INFORMATIONAL, res.line(), res.col(), stack.getLiteralPath(), I18nConstants.VALIDATION_VAL_PROFILE_SIGNPOST_BUNDLE_PARAM, defn.getUrl()));
                        }
                        stack.resetIds();
                        validator.startInner(hostContext, errors, res, res, defn, rstack, false);
                    }
                }
            }
        }
        // todo: check specials
        count++;
    }
}
Also used : BundleValidationRule(org.hl7.fhir.r5.utils.validation.BundleValidationRule) HashMap(java.util.HashMap) IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 28 with MessageHeader

use of org.hl7.fhir.dstu3.model.MessageHeader in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_messageheader_example.

@Test
public void test_messageheader_example() throws FileNotFoundException, IOException, Exception {
    System.out.println("messageheader-example.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\messageheader-example.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Example 29 with MessageHeader

use of org.hl7.fhir.dstu3.model.MessageHeader in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeMessageHeader.

protected void composeMessageHeader(Complex parent, String parentType, String name, MessageHeader element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "MessageHeader", name, element, index);
    if (element.hasEvent())
        composeType(t, "MessageHeader", "event", element.getEvent(), -1);
    for (int i = 0; i < element.getDestination().size(); i++) composeMessageHeaderMessageDestinationComponent(t, "MessageHeader", "destination", element.getDestination().get(i), i);
    if (element.hasSender())
        composeReference(t, "MessageHeader", "sender", element.getSender(), -1);
    if (element.hasEnterer())
        composeReference(t, "MessageHeader", "enterer", element.getEnterer(), -1);
    if (element.hasAuthor())
        composeReference(t, "MessageHeader", "author", element.getAuthor(), -1);
    if (element.hasSource())
        composeMessageHeaderMessageSourceComponent(t, "MessageHeader", "source", element.getSource(), -1);
    if (element.hasResponsible())
        composeReference(t, "MessageHeader", "responsible", element.getResponsible(), -1);
    if (element.hasReason())
        composeCodeableConcept(t, "MessageHeader", "reason", element.getReason(), -1);
    if (element.hasResponse())
        composeMessageHeaderMessageHeaderResponseComponent(t, "MessageHeader", "response", element.getResponse(), -1);
    for (int i = 0; i < element.getFocus().size(); i++) composeReference(t, "MessageHeader", "focus", element.getFocus().get(i), i);
    if (element.hasDefinitionElement())
        composeCanonical(t, "MessageHeader", "definition", element.getDefinitionElement(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 30 with MessageHeader

use of org.hl7.fhir.dstu3.model.MessageHeader in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeMessageHeaderMessageHeaderResponseComponent.

protected void composeMessageHeaderMessageHeaderResponseComponent(Complex parent, String parentType, String name, MessageHeader.MessageHeaderResponseComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "response", name, element, index);
    if (element.hasIdentifierElement())
        composeId(t, "MessageHeader", "identifier", element.getIdentifierElement(), -1);
    if (element.hasCodeElement())
        composeEnum(t, "MessageHeader", "code", element.getCodeElement(), -1);
    if (element.hasDetails())
        composeReference(t, "MessageHeader", "details", element.getDetails(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Aggregations

BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)11 Bundle (org.hl7.fhir.r4.model.Bundle)10 MessageHeader (org.hl7.fhir.r4.model.MessageHeader)8 Resource (org.hl7.fhir.r4.model.Resource)7 Test (org.junit.jupiter.api.Test)7 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)6 InvalidRequestException (ca.uhn.fhir.rest.server.exceptions.InvalidRequestException)5 ArrayList (java.util.ArrayList)5 Reference (org.hl7.fhir.r4.model.Reference)5 Date (java.util.Date)4 CS (net.ihe.gazelle.hl7v3.datatypes.CS)4 PRPAMT201301UV02Patient (net.ihe.gazelle.hl7v3.prpamt201301UV02.PRPAMT201301UV02Patient)4 Patient (org.hl7.fhir.r4.model.Patient)4 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)4 FHIRContext (io.github.linuxforhealth.fhir.FHIRContext)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 COCTMT090003UV01AssignedEntity (net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01AssignedEntity)3 COCTMT090003UV01Organization (net.ihe.gazelle.hl7v3.coctmt090003UV01.COCTMT090003UV01Organization)3 COCTMT150003UV03ContactParty (net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03ContactParty)3 COCTMT150003UV03Organization (net.ihe.gazelle.hl7v3.coctmt150003UV03.COCTMT150003UV03Organization)3