use of org.hl7.fhir.r4b.model.UriType 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;
}
use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.
the class QuestionnaireBuilder method addReferenceQuestions.
// Special Types ---------------------------------------------------------------
private void addReferenceQuestions(QuestionnaireItemComponent group, ElementDefinition element, String path, List<CanonicalType> profileURL, List<QuestionnaireResponse.QuestionnaireResponseItemComponent> answerGroups) throws FHIRException {
// var
// rn : String;
// i : integer;
// q : TFhirQuestionnaireGroupQuestion;
ToolingExtensions.addFhirType(group, "Reference");
QuestionnaireItemComponent q = addQuestion(group, QuestionnaireItemType.REFERENCE, null, path, "value", group.getText(), answerGroups);
group.setText(null);
CommaSeparatedStringBuilder rn = new CommaSeparatedStringBuilder();
for (UriType u : profileURL) if (u.getValue().startsWith("http://hl7.org/fhir/StructureDefinition/"))
rn.append(u.getValue().substring(40));
if (rn.length() == 0)
ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
else {
ToolingExtensions.addAllowedResource(q, rn.toString());
ToolingExtensions.addReferenceFilter(q, "subject=$subj&patient=$subj&encounter=$encounter");
}
for (QuestionnaireResponse.QuestionnaireResponseItemComponent ag : answerGroups) ag.setText(null);
}
use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.
the class R3R4ConversionTests method checkLoad.
/*
* Supporting multiple versions at once is a little tricky. We're going to have
* 2 contexts: - an R3 context which is used to read/write R3 instances - an R4
* context which is used to perform the transforms
*
* R3 structure definitions are cloned into R3 context with a modified URL (as
* 3.0/)
*
*/
private void checkLoad() throws IOException, FHIRException, Exception {
if (contextR3 != null)
return;
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
R3ToR4Loader ldr = (R3ToR4Loader) new R3ToR4Loader().setPatchUrls(true).setKillPrimitives(true);
System.out.println("loading R3");
contextR3 = new SimpleWorkerContext();
contextR3.setAllowLoadingDuplicates(true);
contextR3.setOverrideVersionNs("http://hl7.org/fhir/3.0/StructureDefinition");
contextR3.loadFromPackage(pcm.loadPackage("hl7.fhir.core", "3.0.1"), ldr, new String[] {});
System.out.println("loading R4");
contextR4 = new SimpleWorkerContext();
contextR4 = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0"));
contextR4.setCanRunWithoutTerminology(true);
for (StructureDefinition sd : contextR3.allStructures()) {
StructureDefinition sdn = sd.copy();
sdn.getExtension().clear();
contextR4.cacheResource(sdn);
}
for (StructureDefinition sd : contextR4.allStructures()) {
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
contextR3.cacheResource(sd);
StructureDefinition sdn = sd.copy();
sdn.setUrl(sdn.getUrl().replace("http://hl7.org/fhir/", "http://hl7.org/fhir/3.0/"));
sdn.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace").setValue(new UriType("http://hl7.org/fhir"));
contextR3.cacheResource(sdn);
contextR4.cacheResource(sdn);
}
}
contextR3.setExpansionProfile(new org.hl7.fhir.r4.model.Parameters());
contextR4.setExpansionProfile(new org.hl7.fhir.r4.model.Parameters());
contextR3.setName("R3");
contextR4.setName("R4");
// contextR4.setValidatorFactory(new InstanceValidatorFactory());
// TODO: this has to be R% now... contextR4.setValidatorFactory(new InstanceValidatorFactory());
System.out.println("loading Maps");
loadLib(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R4toR3"));
loadLib(Utilities.path(TestingUtilities.home(), "implementations", "r3maps", "R3toR4"));
System.out.println("loaded");
}
use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method validateContains.
private void validateContains(ValidatorHostContext hostContext, List<ValidationMessage> errors, String path, ElementDefinition child, ElementDefinition context, Element resource, Element element, NodeStack stack, IdStatus idstatus, StructureDefinition parentProfile) throws FHIRException {
SpecialElement special = element.getSpecial();
ContainedReferenceValidationPolicy containedValidationPolicy = getPolicyAdvisor() == null ? ContainedReferenceValidationPolicy.CHECK_VALID : getPolicyAdvisor().policyForContained(this, hostContext, context.fhirType(), context.getId(), special, path, parentProfile.getUrl());
if (containedValidationPolicy.ignore()) {
return;
}
String resourceName = element.getType();
TypeRefComponent typeForResource = null;
CommaSeparatedStringBuilder bt = new CommaSeparatedStringBuilder();
// Iterate through all possible types
for (TypeRefComponent type : child.getType()) {
bt.append(type.getCode());
if (type.getCode().equals("Resource") || type.getCode().equals(resourceName)) {
typeForResource = type;
break;
}
}
stack.qualifyPath(".ofType(" + resourceName + ")");
if (typeForResource == null) {
rule(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_TYPE, resourceName, bt.toString());
} else if (isValidResourceType(resourceName, typeForResource)) {
if (containedValidationPolicy.checkValid()) {
// special case: resource wrapper is reset if we're crossing a bundle boundary, but not otherwise
ValidatorHostContext hc = null;
if (special == SpecialElement.BUNDLE_ENTRY || special == SpecialElement.BUNDLE_OUTCOME || special == SpecialElement.PARAMETER) {
resource = element;
assert Utilities.existsInList(hostContext.getRootResource().fhirType(), "Bundle", "Parameters") : "Resource is " + hostContext.getRootResource().fhirType() + ", expected Bundle or Parameters";
// root becomes the grouping resource (should be either bundle or parameters)
hc = hostContext.forEntry(element, hostContext.getRootResource());
} else {
hc = hostContext.forContained(element);
}
stack.resetIds();
if (special != null) {
switch(special) {
case BUNDLE_ENTRY:
case BUNDLE_OUTCOME:
case PARAMETER:
idstatus = IdStatus.OPTIONAL;
break;
case CONTAINED:
stack.setContained(true);
idstatus = IdStatus.REQUIRED;
break;
default:
break;
}
}
if (typeForResource.getProfile().size() == 1) {
long t = System.nanoTime();
StructureDefinition profile = this.context.fetchResource(StructureDefinition.class, typeForResource.getProfile().get(0).asStringValue());
timeTracker.sd(t);
trackUsage(profile, hostContext, element);
if (rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), profile != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOPROFILE_EXPL, special.toHuman(), resourceName, typeForResource.getProfile().get(0).asStringValue())) {
validateResource(hc, errors, resource, element, profile, idstatus, stack);
}
} else if (typeForResource.getProfile().isEmpty()) {
long t = System.nanoTime();
StructureDefinition profile = this.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + resourceName);
timeTracker.sd(t);
trackUsage(profile, hostContext, element);
if (rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), profile != null, I18nConstants.BUNDLE_BUNDLE_ENTRY_NOPROFILE_TYPE, special == null ? "??" : special.toHuman(), resourceName)) {
validateResource(hc, errors, resource, element, profile, idstatus, stack);
}
} else {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (CanonicalType u : typeForResource.getProfile()) {
b.append(u.asStringValue());
}
rule(errors, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_MULTIPLE_PROFILES, special.toHuman(), typeForResource.getCode(), b.toString());
}
}
} else {
List<String> types = new ArrayList<>();
for (UriType u : typeForResource.getProfile()) {
StructureDefinition sd = this.context.fetchResource(StructureDefinition.class, u.getValue());
if (sd != null && !types.contains(sd.getType())) {
types.add(sd.getType());
}
}
if (types.size() == 1) {
rule(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_TYPE2, resourceName, types.get(0));
} else {
rule(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), false, I18nConstants.BUNDLE_BUNDLE_ENTRY_TYPE3, resourceName, types);
}
}
}
use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method generate.
public boolean generate(ResourceContext rcontext, ConceptMap cm) throws FHIRFormatError, DefinitionException, IOException {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
x.h2().addText(cm.getName() + " (" + cm.getUrl() + ")");
XhtmlNode p = x.para();
if (cm.hasSource() || cm.hasTarget())
p.tx("Mapping from ");
if (!cm.hasSource())
p.tx("(unspecified)");
else
AddVsRef(rcontext, cm.getSource() instanceof Reference ? ((Reference) cm.getSource()).getReference() : ((UriType) cm.getSource()).asStringValue(), p);
p.tx(" to ");
if (!cm.hasTarget())
p.tx("(unspecified)");
else
AddVsRef(rcontext, cm.getTarget() instanceof Reference ? ((Reference) cm.getTarget()).getReference() : ((UriType) cm.getTarget()).asStringValue(), p);
p = x.para();
if (cm.getExperimental())
p.addText(Utilities.capitalize(cm.getStatus().toString()) + " (not intended for production usage). ");
else
p.addText(Utilities.capitalize(cm.getStatus().toString()) + ". ");
p.tx("Published on " + (cm.hasDate() ? cm.getDateElement().toHumanDisplay() : "??") + " by " + cm.getPublisher());
if (!cm.getContact().isEmpty()) {
p.tx(" (");
boolean firsti = true;
for (ContactDetail ci : cm.getContact()) {
if (firsti)
firsti = false;
else
p.tx(", ");
if (ci.hasName())
p.addText(ci.getName() + ": ");
boolean first = true;
for (ContactPoint c : ci.getTelecom()) {
if (first)
first = false;
else
p.tx(", ");
addTelecom(p, c);
}
}
p.tx(")");
}
p.tx(". ");
p.addText(cm.getCopyright());
if (!Utilities.noString(cm.getDescription()))
addMarkdown(x, cm.getDescription());
x.br();
for (ConceptMapGroupComponent grp : cm.getGroup()) {
String src = grp.getSource();
boolean comment = false;
boolean ok = true;
Map<String, HashSet<String>> sources = new HashMap<String, HashSet<String>>();
Map<String, HashSet<String>> targets = new HashMap<String, HashSet<String>>();
sources.put("code", new HashSet<String>());
targets.put("code", new HashSet<String>());
SourceElementComponent cc = grp.getElement().get(0);
String dst = grp.getTarget();
sources.get("code").add(grp.getSource());
targets.get("code").add(grp.getTarget());
for (SourceElementComponent ccl : grp.getElement()) {
ok = ok && ccl.getTarget().size() == 1 && ccl.getTarget().get(0).getDependsOn().isEmpty() && ccl.getTarget().get(0).getProduct().isEmpty();
for (TargetElementComponent ccm : ccl.getTarget()) {
comment = comment || !Utilities.noString(ccm.getComment());
for (OtherElementComponent d : ccm.getDependsOn()) {
if (!sources.containsKey(d.getProperty()))
sources.put(d.getProperty(), new HashSet<String>());
sources.get(d.getProperty()).add(d.getSystem());
}
for (OtherElementComponent d : ccm.getProduct()) {
if (!targets.containsKey(d.getProperty()))
targets.put(d.getProperty(), new HashSet<String>());
targets.get(d.getProperty()).add(d.getSystem());
}
}
}
String display;
if (ok) {
// simple
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
tr.td().b().tx("Source Code");
tr.td().b().tx("Equivalence");
tr.td().b().tx("Destination Code");
if (comment)
tr.td().b().tx("Comment");
for (SourceElementComponent ccl : grp.getElement()) {
tr = tbl.tr();
XhtmlNode td = tr.td();
td.addText(ccl.getCode());
display = getDisplayForConcept(grp.getSource(), ccl.getCode());
if (display != null)
td.tx(" (" + display + ")");
TargetElementComponent ccm = ccl.getTarget().get(0);
tr.td().addText(!ccm.hasEquivalence() ? "" : ccm.getEquivalence().toCode());
td = tr.td();
td.addText(ccm.getCode());
display = getDisplayForConcept(grp.getTarget(), ccm.getCode());
if (display != null)
td.tx(" (" + display + ")");
if (comment)
tr.td().addText(ccm.getComment());
}
} else {
XhtmlNode tbl = x.table("grid");
XhtmlNode tr = tbl.tr();
XhtmlNode td;
tr.td().colspan(Integer.toString(sources.size())).b().tx("Source Concept");
tr.td().b().tx("Equivalence");
tr.td().colspan(Integer.toString(targets.size())).b().tx("Destination Concept");
if (comment)
tr.td().b().tx("Comment");
tr = tbl.tr();
if (sources.get("code").size() == 1)
tr.td().b().tx("Code " + sources.get("code").toString() + "");
else
tr.td().b().tx("Code");
for (String s : sources.keySet()) {
if (!s.equals("code")) {
if (sources.get(s).size() == 1)
tr.td().b().addText(getDescForConcept(s) + " " + sources.get(s).toString());
else
tr.td().b().addText(getDescForConcept(s));
}
}
tr.td();
if (targets.get("code").size() == 1)
tr.td().b().tx("Code " + targets.get("code").toString());
else
tr.td().b().tx("Code");
for (String s : targets.keySet()) {
if (!s.equals("code")) {
if (targets.get(s).size() == 1)
tr.td().b().addText(getDescForConcept(s) + " " + targets.get(s).toString() + "");
else
tr.td().b().addText(getDescForConcept(s));
}
}
if (comment)
tr.td();
for (SourceElementComponent ccl : grp.getElement()) {
tr = tbl.tr();
td = tr.td();
if (sources.get("code").size() == 1)
td.addText(ccl.getCode());
else
td.addText(grp.getSource() + " / " + ccl.getCode());
display = getDisplayForConcept(grp.getSource(), ccl.getCode());
if (display != null)
td.tx(" (" + display + ")");
TargetElementComponent ccm = ccl.getTarget().get(0);
for (String s : sources.keySet()) {
if (!s.equals("code")) {
td = tr.td();
td.addText(getCode(ccm.getDependsOn(), s, sources.get(s).size() != 1));
display = getDisplay(ccm.getDependsOn(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
if (!ccm.hasEquivalence())
tr.td().tx(":" + "(" + ConceptMapEquivalence.EQUIVALENT.toCode() + ")");
else
tr.td().tx(":" + ccm.getEquivalence().toCode());
td = tr.td();
if (targets.get("code").size() == 1)
td.addText(ccm.getCode());
else
td.addText(grp.getTarget() + " / " + ccm.getCode());
display = getDisplayForConcept(grp.getTarget(), ccm.getCode());
if (display != null)
td.tx(" (" + display + ")");
for (String s : targets.keySet()) {
if (!s.equals("code")) {
td = tr.td();
td.addText(getCode(ccm.getProduct(), s, targets.get(s).size() != 1));
display = getDisplay(ccm.getProduct(), s);
if (display != null)
td.tx(" (" + display + ")");
}
}
if (comment)
tr.td().addText(ccm.getComment());
}
}
}
inject(cm, x, NarrativeStatus.GENERATED);
return true;
}
Aggregations