Java Code Examples for org.hl7.fhir.dstu3.model.ElementDefinition#hasId()

The following examples show how to use org.hl7.fhir.dstu3.model.ElementDefinition#hasId() . 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: Property.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public String getType(String elementName) {
   if (!definition.getPath().contains("."))
     return definition.getPath();
   ElementDefinition ed = definition;
   if (definition.hasContentReference()) {
     if (!definition.getContentReference().startsWith("#"))
       throw new Error("not handled yet");
     boolean found = false;
     for (ElementDefinition d : structure.getSnapshot().getElement()) {
       if (d.hasId() && d.getId().equals(definition.getContentReference().substring(1))) {
         found = true;
         ed = d;
       }
     }
     if (!found)
       throw new Error("Unable to resolve "+definition.getContentReference()+" at "+definition.getPath()+" on "+structure.getUrl());
   }
   if (ed.getType().size() == 0)
		return null;
   else if (ed.getType().size() > 1) {
     String t = ed.getType().get(0).getCode();
		boolean all = true;
     for (TypeRefComponent tr : ed.getType()) {
			if (!t.equals(tr.getCode()))
				all = false;
		}
		if (all)
			return t;
     String tail = ed.getPath().substring(ed.getPath().lastIndexOf(".")+1);
     if (tail.endsWith("[x]") && elementName != null && elementName.startsWith(tail.substring(0, tail.length()-3))) {
			String name = elementName.substring(tail.length()-3);
       return isPrimitive(lowFirst(name)) ? lowFirst(name) : name;        
		} else
       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();
}
 
Example 2
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Given a Structure, navigate to the element given by the path and return the direct children of that element
 *
 * @param structure The structure to navigate into
 * @param path The path of the element within the structure to get the children for
 * @return A List containing the element children (all of them are Elements)
 */
public static List<ElementDefinition> getChildList(StructureDefinition profile, String path, String id) {
  List<ElementDefinition> res = new ArrayList<ElementDefinition>();

  boolean capturing = id==null;
  if (id==null && !path.contains("."))
    capturing = true;
  
  for (ElementDefinition e : profile.getSnapshot().getElement()) {
    if (!capturing && id!=null && e.getId().equals(id)) {
      capturing = true;
    }
    
    // If our element is a slice, stop capturing children as soon as we see the next slice
    if (capturing && e.hasId() && id!= null && !e.getId().equals(id) && e.getPath().equals(path))
      break;
    
    if (capturing) {
      String p = e.getPath();

      if (!Utilities.noString(e.getContentReference()) && path.startsWith(p)) {
        if (path.length() > p.length())
          return getChildList(profile, e.getContentReference()+"."+path.substring(p.length()+1), null);
        else
          return getChildList(profile, e.getContentReference(), null);
        
      } else if (p.startsWith(path+".") && !p.equals(path)) {
        String tail = p.substring(path.length()+1);
        if (!tail.contains(".")) {
          res.add(e);
        }
      }
    }
  }

  return res;
}
 
Example 3
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean hasMissingIds(List<ElementDefinition> list) {
  for (ElementDefinition ed : list) {
    if (!ed.hasId())
      return true;
  }    
  return false;
}
 
Example 4
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private ElementDefinition getElementById(List<ElementDefinition> elements, String contentReference) {
  for (ElementDefinition ed : elements)
    if (ed.hasId() && ("#"+ed.getId()).equals(contentReference))
      return ed;
  return null;
}