use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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++;
}
}
use of org.hl7.fhir.r4.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"));
}
use of org.hl7.fhir.r4.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);
}
use of org.hl7.fhir.r4.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);
}
Aggregations