private StructureDefinition getProfileForType(String type) { if (logical != null) for (BundleEntryComponent be : logical.getEntry()) { if (be.hasResource() && be.getResource() instanceof StructureDefinition) { StructureDefinition sd = (StructureDefinition) be.getResource(); if (sd.getId().equals(type)) return sd; } } long t = System.nanoTime(); try { return context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + type); } finally { sdTime = sdTime + (System.nanoTime() - t); } }
private void checkExtensions(StructureDefinition profile, List<ValidationMessage> errors, String kind, ElementDefinition ec) { if (!ec.getType().isEmpty() && "Extension".equals(ec.getType().get(0).getCode()) && ec.getType().get(0).hasProfile()) { String url = ec.getType().get(0).getProfile(); StructureDefinition defn = context.fetchResource(StructureDefinition.class, url); rule(errors, IssueType.BUSINESSRULE, profile.getId(), defn != null, "Unable to find Extension '"+url+"' referenced at "+profile.getUrl()+" "+kind+" "+ec.getPath()+" ("+ec.getSliceName()+")"); } }
private ElementDefinition resolveType(String type) { if (logical != null) for (BundleEntryComponent be : logical.getEntry()) { if (be.hasResource() && be.getResource() instanceof StructureDefinition) { StructureDefinition sd = (StructureDefinition) be.getResource(); if (sd.getId().equals(type)) return sd.getSnapshot().getElement().get(0); } } String url = "http://hl7.org/fhir/StructureDefinition/" + type; long t = System.nanoTime(); StructureDefinition sd = context.fetchResource(StructureDefinition.class, url); sdTime = sdTime + (System.nanoTime() - t); if (sd == null || !sd.hasSnapshot()) return null; else return sd.getSnapshot().getElement().get(0); }
public void checkAllInvariants(){ for (StructureDefinition sd : context.allStructures()) { if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) { for (ElementDefinition ed : sd.getSnapshot().getElement()) { for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) { if (inv.hasExpression()) { try { ExpressionNode n = (ExpressionNode) inv.getUserData("validator.expression.cache"); if (n == null) { n = fpe.parse(inv.getExpression()); inv.setUserData("validator.expression.cache", n); } fpe.check(null, sd.getKind() == StructureDefinitionKind.RESOURCE ? sd.getType() : "DomainResource", ed.getPath(), n); } catch (Exception e) { System.out.println("Error processing structure ["+sd.getId()+"] path "+ed.getPath()+":"+inv.getKey()+" (\""+inv.getExpression()+"\"): "+e.getMessage()); } } } } } } }
rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "missing Snapshot at "+profile.getName()+"."+profile.getName()); for (ElementDefinition ec : profile.getSnapshot().getElement()) checkExtensions(profile, errors, "snapshot", ec); if (rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "A snapshot is required")) { for (ElementDefinition ed : profile.getSnapshot().getElement()) { checkExtensions(profile, errors, "snapshot", ed); if (forBuild) { if (!inExemptList(inv.getKey())) { if (rule(errors, IssueType.BUSINESSRULE, profile.getId()+"::"+ed.getPath()+"::"+inv.getKey(), inv.hasExpression(), "The invariant has no FHIR Path expression ("+inv.getXpath()+")")) { try { new FHIRPathEngine(context).check(null, profile.getType(), ed.getPath(), inv.getExpression()); // , inv.hasXpath() && inv.getXpath().startsWith("@value")
String type = defn.getKind() == StructureDefinitionKind.LOGICAL ? defn.getId() : defn.getType();
for (org.hl7.fhir.instance.model.StructureDefinition.StructureDefinitionMappingComponent t : src.getMapping()) tgt.addMapping(convertStructureDefinitionMappingComponent(t)); tgt.setKind(convertStructureDefinitionKind(src.getKind(), tgt.getId())); tgt.setAbstract(src.getAbstract()); tgt.setContextType(convertExtensionContext(src.getContextType())); if (tgt.hasDifferential()) tgt.getDifferential().getElementFirstRep().getType().clear(); if (tgt.getKind() == StructureDefinitionKind.PRIMITIVETYPE && !tgt.getType().equals(tgt.getId())) { tgt.setDerivation(TypeDerivationRule.SPECIALIZATION); tgt.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/"+tgt.getType()); tgt.setType(tgt.getId());
private StructureDefinition getProfileForType(String type) { if (logical != null) for (BundleEntryComponent be : logical.getEntry()) { if (be.hasResource() && be.getResource() instanceof StructureDefinition) { StructureDefinition sd = (StructureDefinition) be.getResource(); if (sd.getId().equals(type)) return sd; } } long t = System.nanoTime(); try { return context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/" + type); } finally { sdTime = sdTime + (System.nanoTime() - t); } }
private void checkExtensions(StructureDefinition profile, List<ValidationMessage> errors, String kind, ElementDefinition ec) { if (!ec.getType().isEmpty() && "Extension".equals(ec.getType().get(0).getCode()) && ec.getType().get(0).hasProfile()) { String url = ec.getType().get(0).getProfile(); StructureDefinition defn = context.fetchResource(StructureDefinition.class, url); rule(errors, IssueType.BUSINESSRULE, profile.getId(), defn != null, "Unable to find Extension '"+url+"' referenced at "+profile.getUrl()+" "+kind+" "+ec.getPath()+" ("+ec.getSliceName()+")"); } }
private ElementDefinition resolveType(String type) { if (logical != null) for (BundleEntryComponent be : logical.getEntry()) { if (be.hasResource() && be.getResource() instanceof StructureDefinition) { StructureDefinition sd = (StructureDefinition) be.getResource(); if (sd.getId().equals(type)) return sd.getSnapshot().getElement().get(0); } } String url = "http://hl7.org/fhir/StructureDefinition/" + type; long t = System.nanoTime(); StructureDefinition sd = context.fetchResource(StructureDefinition.class, url); sdTime = sdTime + (System.nanoTime() - t); if (sd == null || !sd.hasSnapshot()) return null; else return sd.getSnapshot().getElement().get(0); }
private String getActualType(StructureMap map, String statedType) throws FHIRException { // check the aliases for (StructureMapStructureComponent imp : map.getStructure()) { if (imp.hasAlias() && statedType.equals(imp.getAlias())) { StructureDefinition sd = worker.fetchResource(StructureDefinition.class, imp.getUrl()); if (sd == null) throw new FHIRException("Unable to resolve structure "+imp.getUrl()); return sd.getId(); // should be sd.getType(), but R2... } } return statedType; }
throw new Error("logic error, gettype when types > 1, name mismatch for "+elementName+" on at "+ed.getPath()); } else if (ed.getType().get(0).getCode() == null) { return structure.getId(); } else return ed.getType().get(0).getCode();
private PropertyWithType resolveType(StructureMap map, String type, StructureMapInputMode mode) throws Exception { for (StructureMapStructureComponent imp : map.getStructure()) { if ((imp.getMode() == StructureMapModelMode.SOURCE && mode == StructureMapInputMode.SOURCE) || (imp.getMode() == StructureMapModelMode.TARGET && mode == StructureMapInputMode.TARGET)) { StructureDefinition sd = worker.fetchResource(StructureDefinition.class, imp.getUrl()); if (sd == null) throw new Exception("Import "+imp.getUrl()+" cannot be resolved"); if (sd.getId().equals(type)) { return new PropertyWithType(sd.getType(), new Property(worker, sd.getSnapshot().getElement().get(0), sd), null, new TypeDetails(CollectionStatus.SINGLETON, sd.getUrl())); } } } throw new Exception("Unable to find structure definition for "+type+" in imports"); }
if (nsd == null) throw new PathEngineException("Unknown type " + ed.getType().get(0).getCode()); return getElementDefinition(nsd, nsd.getId() + path.substring(ed.getPath().length()), allowTypedName);
public boolean IsLogicalAndHasPrimitiveValue(String name) { // if (canBePrimitive!= null) // return canBePrimitive; canBePrimitive = false; if (structure.getKind() != StructureDefinitionKind.LOGICAL) return false; if (!hasType(name)) return false; StructureDefinition sd = context.fetchResource(StructureDefinition.class, structure.getUrl().substring(0, structure.getUrl().lastIndexOf("/")+1)+getType(name)); if (sd == null) sd = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+getType(name)); if (sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) return true; if (sd == null || sd.getKind() != StructureDefinitionKind.LOGICAL) return false; for (ElementDefinition ed : sd.getSnapshot().getElement()) { if (ed.getPath().equals(sd.getId()+".value") && ed.getType().size() == 1 && isPrimitive(ed.getType().get(0).getCode())) { canBePrimitive = true; return true; } } return false; }
private org.hl7.fhir.dstu3.elementmodel.Element generateExample(StructureDefinition profile, ExampleValueAccessor accessor) throws FHIRException { ElementDefinition ed = profile.getSnapshot().getElementFirstRep(); org.hl7.fhir.dstu3.elementmodel.Element r = new org.hl7.fhir.dstu3.elementmodel.Element(ed.getPath(), new Property(context, ed, profile)); List<ElementDefinition> children = getChildMap(profile, ed); for (ElementDefinition child : children) { if (child.getPath().endsWith(".id")) { org.hl7.fhir.dstu3.elementmodel.Element id = new org.hl7.fhir.dstu3.elementmodel.Element("id", new Property(context, child, profile)); id.setValue(profile.getId()+accessor.getId()); r.getChildren().add(id); } else { org.hl7.fhir.dstu3.elementmodel.Element e = createExampleElement(profile, child, accessor); if (e != null) r.getChildren().add(e); } } return r; }
if (base != null) res.setResLink(base.getUserString("path")); res.setId(profile.getId()); res.setProfile(profile.getDerivation() == TypeDerivationRule.CONSTRAINT); StringBuilder b = new StringBuilder();
rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "missing Snapshot at "+profile.getName()+"."+profile.getName()); for (ElementDefinition ec : profile.getSnapshot().getElement()) checkExtensions(profile, errors, "snapshot", ec); if (rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "A snapshot is required")) { for (ElementDefinition ed : profile.getSnapshot().getElement()) { checkExtensions(profile, errors, "snapshot", ed); if (forBuild) { if (!inExemptList(inv.getKey())) { if (rule(errors, IssueType.BUSINESSRULE, profile.getId()+"::"+ed.getPath()+"::"+inv.getKey(), inv.hasExpression(), "The invariant has no FHIR Path expression ("+inv.getXpath()+")")) { try { new FHIRPathEngine(context).check(null, profile.getType(), ed.getPath(), inv.getExpression()); // , inv.hasXpath() && inv.getXpath().startsWith("@value")
public void checkAllInvariants(){ for (StructureDefinition sd : context.allStructures()) { if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) { for (ElementDefinition ed : sd.getSnapshot().getElement()) { for (ElementDefinitionConstraintComponent inv : ed.getConstraint()) { if (inv.hasExpression()) { try { ExpressionNode n = (ExpressionNode) inv.getUserData("validator.expression.cache"); if (n == null) { n = fpe.parse(inv.getExpression()); inv.setUserData("validator.expression.cache", n); } fpe.check(null, sd.getKind() == StructureDefinitionKind.RESOURCE ? sd.getType() : "DomainResource", ed.getPath(), n); } catch (Exception e) { System.out.println("Error processing structure ["+sd.getId()+"] path "+ed.getPath()+":"+inv.getKey()+" (\""+inv.getExpression()+"\"): "+e.getMessage()); } } } } } } }
String type = defn.getKind() == StructureDefinitionKind.LOGICAL ? defn.getId() : defn.getType();