Java Code Examples for org.hl7.fhir.dstu3.model.StructureDefinition#getUrl()

The following examples show how to use org.hl7.fhir.dstu3.model.StructureDefinition#getUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static String describeExtensionContext(StructureDefinition ext) {
  CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
  for (StringType t : ext.getContext())
    b.append(t.getValue());
  if (!ext.hasContextType())
    throw new Error("no context type on "+ext.getUrl());
  switch (ext.getContextType()) {
  case DATATYPE: return "Use on data type: "+b.toString();
  case EXTENSION: return "Use on extension: "+b.toString();
  case RESOURCE: return "Use on element: "+b.toString();
  default:
    return "??";
  }
}
 
Example 2
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void populateLogicalSnapshot(StructureDefinition sd) throws FHIRException {
  sd.getSnapshot().getElement().add(sd.getDifferential().getElementFirstRep().copy());
  
  if (sd.hasBaseDefinition()) {
  StructureDefinition base = context.fetchResource(StructureDefinition.class, sd.getBaseDefinition());
  if (base == null)
    throw new FHIRException("Unable to find base definition for logical model: "+sd.getBaseDefinition()+" from "+sd.getUrl());
  copyElements(sd, base.getSnapshot().getElement());
  }
  copyElements(sd, sd.getDifferential().getElement());
}
 
Example 3
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 4
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void seeExtensionDefinition(String url, StructureDefinition ed) throws Exception {
  if (extensionDefinitions.get(ed.getUrl()) != null) {
    throw new Exception("duplicate extension definition: " + ed.getUrl());
  }
  extensionDefinitions.put(ed.getId(), ed);
  extensionDefinitions.put(url, ed);
  extensionDefinitions.put(ed.getUrl(), ed);
}
 
Example 5
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void seeProfile(String url, StructureDefinition p) throws Exception {
  if (profiles.containsKey(p.getUrl())) {
    throw new Exception("Duplicate Profile " + p.getUrl());
  }
  profiles.put(p.getId(), p);
  profiles.put(url, p);
  profiles.put(p.getUrl(), p);
}
 
Example 6
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void seeProfile(String url, StructureDefinition p) throws FHIRException {
   if (Utilities.noString(url))
     url = p.getUrl();
   
   if (!p.hasSnapshot() && p.getKind() != StructureDefinitionKind.LOGICAL) {
     if (!p.hasBaseDefinition())
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+") has no base and no snapshot");
     StructureDefinition sd = fetchResource(StructureDefinition.class, p.getBaseDefinition());
     if (sd == null)
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+") base "+p.getBaseDefinition()+" could not be resolved");
     List<ValidationMessage> msgs = new ArrayList<ValidationMessage>();
     List<String> errors = new ArrayList<String>();
     ProfileUtilities pu = new ProfileUtilities(this, msgs, this);
     pu.sortDifferential(sd, p, url, errors);
     for (String err : errors)
       msgs.add(new ValidationMessage(Source.ProfileValidator, IssueType.EXCEPTION,p.getUserString("path"), "Error sorting Differential: "+err, ValidationMessage.IssueSeverity.ERROR));
     pu.generateSnapshot(sd, p, p.getUrl(), p.getName());
     for (ValidationMessage msg : msgs) {
       if (msg.getLevel() == ValidationMessage.IssueSeverity.ERROR || msg.getLevel() == ValidationMessage.IssueSeverity.FATAL)
         throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+"). Error generating snapshot: "+msg.getMessage());
     }
     if (!p.hasSnapshot())
       throw new DefinitionException("Profile "+p.getName()+" ("+p.getUrl()+"). Error generating snapshot");
     pu = null;
   }
	if (structures.containsKey(p.getUrl()) && !allowLoadingDuplicates)
		throw new DefinitionException("Duplicate structures " + p.getUrl());
	structures.put(p.getId(), p);
	structures.put(p.getUrl(), p);
	if (!p.getUrl().equals(url))
		structures.put(url, p);
}
 
Example 7
Source File: Stu3StructureDefinitions.java    From bunsen with Apache License 2.0 3 votes vote down vote up
private <T> List<StructureField<T>> transformChildren(DefinitionVisitor<T> visitor,
    StructureDefinition rootDefinition,
    List<ElementDefinition> definitions,
    Deque<QualifiedPath> stack,
    ElementDefinition element) {

  QualifiedPath qualifiedPath = new QualifiedPath(rootDefinition.getUrl(),  element.getPath());

  if (shouldTerminateRecursive(visitor, qualifiedPath, stack)) {

    return Collections.emptyList();

  } else {
    stack.push(qualifiedPath);

    // Handle composite type
    List<StructureField<T>> childElements = new ArrayList<>();

    for (ElementDefinition child: getChildren(element, definitions)) {

      List<StructureField<T>> childFields = elementToFields(visitor, rootDefinition,
          child, definitions, stack);

      childElements.addAll(childFields);
    }

    stack.pop();

    return childElements;
  }
}