org.hl7.fhir.dstu3.model.StructureDefinition Java Examples

The following examples show how to use org.hl7.fhir.dstu3.model.StructureDefinition. 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 6 votes vote down vote up
public void updateMaps(StructureDefinition base, StructureDefinition derived) throws DefinitionException {
  if (base == null)
      throw new DefinitionException("no base profile provided");
  if (derived == null)
    throw new DefinitionException("no derived structure provided");
  
  for (StructureDefinitionMappingComponent baseMap : base.getMapping()) {
    boolean found = false;
    for (StructureDefinitionMappingComponent derivedMap : derived.getMapping()) {
      if (derivedMap.getUri().equals(baseMap.getUri())) {
        found = true;
        break;
      }
    }
    if (!found)
      derived.getMapping().add(baseMap);
  }
}
 
Example #2
Source File: StructureDefinitionProvider.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam StructureDefinition structureDefinition)

{
    log.info("create method is called");
    resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();

    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        StructureDefinition newStructureDefinition = structureDefinitionDao.create(ctx,structureDefinition);
        method.setCreated(true);
        method.setId(newStructureDefinition.getIdElement());
        method.setResource(newStructureDefinition);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }
    return method;
}
 
Example #3
Source File: ShExGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a type reference and optional value set definition
 * @param sd Containing StructureDefinition
 * @param ed Element being defined
 * @param typ Element type
 * @return Type definition
 */
private String simpleElement(StructureDefinition sd, ElementDefinition ed, String typ) {
  String addldef = "";
  ElementDefinition.ElementDefinitionBindingComponent binding = ed.getBinding();
  if(binding.hasStrength() && binding.getStrength() == Enumerations.BindingStrength.REQUIRED && "code".equals(typ)) {
    ValueSet vs = resolveBindingReference(sd, binding.getValueSet());
    if (vs != null) {
      addldef = tmplt(VALUESET_DEFN_TEMPLATE).add("vsn", vsprefix(vs.getUrl())).render();
      required_value_sets.add(vs);
    }
  }
  // TODO: check whether value sets and fixed are mutually exclusive
  if(ed.hasFixed()) {
    addldef = tmplt(FIXED_VALUE_TEMPLATE).add("val", ed.getFixed().primitiveValue()).render();
  }
  return tmplt(SIMPLE_ELEMENT_DEFN_TEMPLATE).add("typ", typ).add("vsdef", addldef).render();
}
 
Example #4
Source File: ADLImporter.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void genElements(StructureDefinition sd, String path, NodeTreeEntry item) throws Exception {
  ElementDefinition ed = sd.getSnapshot().addElement();
  ed.setPath(path);
  ed.setMax(item.cardinality.max);
  ed.setMin(Integer.parseInt(item.cardinality.min));
  ed.setShort(texts.get(item.atCode).text);
  ed.setDefinition(texts.get(item.atCode).description);
  ed.setComment(texts.get(item.atCode).comment);
  Element te = findTypeElement(item.typeName);
  if (te.hasAttribute("profile"))
    ed.addType().setCode(te.getAttribute("fhir")).setProfile(te.getAttribute("profile"));
  else
  	ed.addType().setCode(te.getAttribute("fhir"));
   ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax());

 	for (NodeTreeEntry child : item.children) {
 		genElements(sd, path+"."+child.name, child);
 	}
}
 
Example #5
Source File: ShExGenerator.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a definition for a referenced element
 * @param sd Containing structure definition
 * @param ed Inner element
 * @return ShEx representation of element reference
 */
private String genInnerTypeDef(StructureDefinition sd, ElementDefinition ed) {
  String path = ed.hasBase() ? ed.getBase().getPath() : ed.getPath();;
  ST element_reference = tmplt(SHAPE_DEFINITION_TEMPLATE);
  element_reference.add("resourceDecl", "");  // Not a resource
  element_reference.add("id", path);
  String comment = ed.getShort();
  element_reference.add("comment", comment == null? " " : "# " + comment);

  List<String> elements = new ArrayList<String>();
  for (ElementDefinition child: ProfileUtilities.getChildList(sd, path, null))
    elements.add(genElementDefinition(sd, child));

  element_reference.add("elements", StringUtils.join(elements, "\n"));
  return element_reference.render();
}
 
Example #6
Source File: QuestionnaireBuilderTester.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
		QuestionnaireBuilder b = new QuestionnaireBuilder(null);
		for (String f : new File(TEST_PROFILE_DIR).list()) {
			if (f.endsWith(".profile.xml") && !f.contains("type-")) {
				System.out.println("process "+f);
				try {
					StructureDefinition p = (StructureDefinition) new XmlParser().parse(new FileInputStream(TEST_PROFILE_DIR+"\\"+f));
//					Questionnaire q = b.buildQuestionnaire(p);
//					new XmlComposer().compose(new FileOutputStream(TEST_DEST+f), q, true);
					  throw new FHIRException("test");
        } catch (Exception e) {
	        e.printStackTrace();
        }
			}
		}
	}
 
Example #7
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private org.hl7.fhir.dstu3.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
  Type v = accessor.getExampleValue(ed);
  if (v != null) {
    return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
  } else {
    org.hl7.fhir.dstu3.elementmodel.Element res = new org.hl7.fhir.dstu3.elementmodel.Element(tail(ed.getPath()), new Property(context, ed, profile));
    boolean hasValue = false;
    List<ElementDefinition> children = getChildMap(profile, ed);
    for (ElementDefinition child : children) {
      if (!child.hasContentReference()) {
      org.hl7.fhir.dstu3.elementmodel.Element e = createExampleElement(profile, child, accessor);
      if (e != null) {
        hasValue = true;
        res.getChildren().add(e);
      }
    }
    }
    if (hasValue)
      return res;
    else
      return null;
  }
}
 
Example #8
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private Slicer generateSlicer(ElementDefinition child, ElementDefinitionSlicingComponent slicing, StructureDefinition structure) {
  // given a child in a structure, it's sliced. figure out the slicing xpath
  if (child.getPath().endsWith(".extension")) {
    ElementDefinition ued = getUrlFor(structure, child);
    if ((ued == null || !ued.hasFixed()) && !(child.hasType() && (child.getType().get(0).hasProfile())))
      return new Slicer(false);
    else {
    Slicer s = new Slicer(true);
    String url = (ued == null || !ued.hasFixed()) ? child.getType().get(0).getProfile() : ((UriType) ued.getFixed()).asStringValue();
    s.name = " with URL = '"+url+"'";
    s.criteria = "[@url = '"+url+"']";
    return s;
    }
  } else
    return new Slicer(false);
}
 
Example #9
Source File: ObjectConverter.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private Element convertElement(Property property, Base base) throws FHIRException {
  if (base == null)
    return null;
  String tn = base.fhirType();
  StructureDefinition sd = context.fetchTypeDefinition(tn);
  if (sd == null)
    throw new FHIRException("Unable to find definition for type "+tn);
  Element res = new Element(property.getName(), property);
  if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE) 
    res.setValue(((PrimitiveType) base).asStringValue());

  List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElementFirstRep()); 
  for (ElementDefinition child : children) {
    String n = tail(child.getPath());
    if (sd.getKind() != StructureDefinitionKind.PRIMITIVETYPE || !"value".equals(n)) {
      Base[] values = base.getProperty(n.hashCode(), n, false);
      if (values != null)
        for (Base value : values) {
          res.getChildren().add(convertElement(new Property(context, child, sd), value));
        }
    }
  }
  return res;
}
 
Example #10
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public StructureDefinition getProfile(StructureDefinition source, String url) {
	StructureDefinition profile = null;
	String code = null;
	if (url.startsWith("#")) {
		profile = source;
		code = url.substring(1);
	} else if (context != null) {
		String[] parts = url.split("\\#");
		profile = context.fetchResource(StructureDefinition.class, parts[0]);
    code = parts.length == 1 ? null : parts[1];
	}  	  
	if (profile == null)
		return null;
	if (code == null)
		return profile;
	for (Resource r : profile.getContained()) {
		if (r instanceof StructureDefinition && r.getId().equals(code))
			return (StructureDefinition) r;
	}
	return null;
}
 
Example #11
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public void seeResource(String url, Resource r) throws FHIRException {
   if (r instanceof StructureDefinition)
     seeProfile(url, (StructureDefinition) r);
   else if (r instanceof ValueSet)
     seeValueSet(url, (ValueSet) r);
   else if (r instanceof CodeSystem)
     seeCodeSystem(url, (CodeSystem) r);
   else if (r instanceof OperationDefinition)
     seeOperationDefinition(url, (OperationDefinition) r);
   else if (r instanceof ConceptMap)
     maps.put(((ConceptMap) r).getUrl(), (ConceptMap) r);
   else if (r instanceof StructureMap)
     transforms.put(((StructureMap) r).getUrl(), (StructureMap) r);
   else if (r instanceof NamingSystem)
   	systems.add((NamingSystem) r);
}
 
Example #12
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void setIds(StructureDefinition sd, boolean checkFirst) throws DefinitionException  {
  if (!checkFirst || !sd.hasDifferential() || hasMissingIds(sd.getDifferential().getElement())) {
    if (!sd.hasDifferential())
      sd.setDifferential(new StructureDefinitionDifferentialComponent());
    generateIds(sd.getDifferential().getElement(), sd.getName());
  }
  if (!checkFirst || !sd.hasSnapshot() || hasMissingIds(sd.getSnapshot().getElement())) {
    if (!sd.hasSnapshot())
      sd.setSnapshot(new StructureDefinitionSnapshotComponent());
    generateIds(sd.getSnapshot().getElement(), sd.getName());
  }
}
 
Example #13
Source File: ShExGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a flattened definition for the inner types
 * @return stringified inner type definitions
 */
private String emitInnerTypes() {
  StringBuilder itDefs = new StringBuilder();
  while(emittedInnerTypes.size() < innerTypes.size()) {
    for (Pair<StructureDefinition, ElementDefinition> it : new HashSet<Pair<StructureDefinition, ElementDefinition>>(innerTypes)) {
      if (!emittedInnerTypes.contains(it)) {
        itDefs.append("\n").append(genInnerTypeDef(it.getLeft(), it.getRight()));
        emittedInnerTypes.add(it);
      }
    }
  }
  return itDefs.toString();
}
 
Example #14
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void copyElements(StructureDefinition sd, List<ElementDefinition> list) {
  for (ElementDefinition ed : list) {
    if (ed.getPath().contains(".")) {
      ElementDefinition n = ed.copy();
      n.setPath(sd.getSnapshot().getElementFirstRep().getPath()+"."+ed.getPath().substring(ed.getPath().indexOf(".")+1));
      sd.getSnapshot().addElement(n);
    }
  }
}
 
Example #15
Source File: SnapShotGenerationTests.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private StructureDefinition getSD(String url, SnapShotGenerationTestsContext context) throws DefinitionException, FHIRException {
  StructureDefinition sd = TestingUtilities.context.fetchResource(StructureDefinition.class, url);
  if (sd == null)
    sd = context.snapshots.get(url);
  if (sd == null)
    sd = findContainedProfile(url, context);
  return sd;
}
 
Example #16
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private SpanEntry buildSpanEntryFromProfile(String name, String cardinality, StructureDefinition profile) throws IOException {
  SpanEntry res = new SpanEntry();
  res.setName(name);
  res.setCardinality(cardinality);
  res.setProfileLink(profile.getUserString("path"));
  res.setResType(profile.getType());
  StructureDefinition base = context.fetchResource(StructureDefinition.class, res.getResType());
  if (base != null)
    res.setResLink(base.getUserString("path"));
  res.setId(profile.getId());
  res.setProfile(profile.getDerivation() == TypeDerivationRule.CONSTRAINT);
  StringBuilder b = new StringBuilder();
  b.append(res.getResType());
  boolean first = true;
  boolean open = false;
  if (profile.getDerivation() == TypeDerivationRule.CONSTRAINT) {
    res.setDescription(profile.getName());
    for (ElementDefinition ed : profile.getSnapshot().getElement()) {
      if (isKeyProperty(ed.getBase().getPath()) && ed.hasFixed()) {
        if (first) {
          open = true;
          first = false;
          b.append("[");
        } else {
          b.append(", ");
        }
        b.append(tail(ed.getBase().getPath()));
        b.append("=");
        b.append(summarise(ed.getFixed()));
      }
    }
    if (open)
      b.append("]");
  } else
    res.setDescription("Base FHIR "+profile.getName());
  res.setType(b.toString());
  return res ;
}
 
Example #17
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private ValueSet resolveVS(StructureDefinition ctxtLeft, Type vsRef) {
  if (vsRef == null)
    return null;
  if (vsRef instanceof UriType)
    return null;
  else {
    Reference ref = (Reference) vsRef;
    if (!ref.hasReference())
      return null;
    return context.fetchResource(ValueSet.class, ref.getReference());
  }
}
 
Example #18
Source File: ShExGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public ShExGenerator(IWorkerContext context) {
  super();
  this.context = context;
  innerTypes = new HashSet<Pair<StructureDefinition, ElementDefinition>>();
  emittedInnerTypes = new HashSet<Pair<StructureDefinition, ElementDefinition>>();
  datatypes = new HashSet<String>();
  emittedDatatypes = new HashSet<String>();
  references = new HashSet<String>();
  required_value_sets = new HashSet<ValueSet>();
  known_resources = new HashSet<String>();
}
 
Example #19
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
* Given a structure map, return a set of analyses on it. 
* 
* Returned:
*   - a list or profiles for what it will create. First profile is the target
*   - a table with a summary (in xhtml) for easy human undertanding of the mapping
*   
* 
* @param appInfo
* @param map
* @return
* @throws Exception
*/
public StructureMapAnalysis analyse(Object appInfo, StructureMap map) throws Exception {
  ids.clear();
  StructureMapAnalysis result = new StructureMapAnalysis(); 
  TransformContext context = new TransformContext(appInfo);
  VariablesForProfiling vars = new VariablesForProfiling(false, false);
  StructureMapGroupComponent start = map.getGroup().get(0);
  for (StructureMapGroupInputComponent t : start.getInput()) {
    PropertyWithType ti = resolveType(map, t.getType(), t.getMode());
    if (t.getMode() == StructureMapInputMode.SOURCE)
     vars.add(VariableMode.INPUT, t.getName(), ti);
    else 
      vars.add(VariableMode.OUTPUT, t.getName(), createProfile(map, result.profiles, ti, start.getName(), start));
  }

  result.summary = new XhtmlNode(NodeType.Element, "table").setAttribute("class", "grid");
  XhtmlNode tr = result.summary.addTag("tr");
  tr.addTag("td").addTag("b").addText("Source");
  tr.addTag("td").addTag("b").addText("Target");
  
  log("Start Profiling Transform "+map.getUrl());
  analyseGroup("", context, map, vars, start, result);
  ProfileUtilities pu = new ProfileUtilities(worker, null, pkp);
  for (StructureDefinition sd : result.getProfiles())
    pu.cleanUpDifferential(sd);
  return result;
}
 
Example #20
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public List<StructureDefinition> allStructures() {
  List<StructureDefinition> result = new ArrayList<StructureDefinition>();
  Set<StructureDefinition> set = new HashSet<StructureDefinition>();
  for (StructureDefinition sd : structures.values()) {
    if (!set.contains(sd)) {
      result.add(sd);
      set.add(sd);
    }
  }
  return result;
}
 
Example #21
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void sortDifferential(StructureDefinition base, StructureDefinition diff, String name, List<String> errors) throws FHIRException  {

    final List<ElementDefinition> diffList = diff.getDifferential().getElement();
    // first, we move the differential elements into a tree
    if (diffList.isEmpty())
      return;
    ElementDefinitionHolder edh = new ElementDefinitionHolder(diffList.get(0));

    boolean hasSlicing = false;
    List<String> paths = new ArrayList<String>(); // in a differential, slicing may not be stated explicitly
    for(ElementDefinition elt : diffList) {
      if (elt.hasSlicing() || paths.contains(elt.getPath())) {
        hasSlicing = true;
        break;
      }
      paths.add(elt.getPath());
    }
    if(!hasSlicing) {
      // if Differential does not have slicing then safe to pre-sort the list
      // so elements and subcomponents are together
      Collections.sort(diffList, new ElementNameCompare());
    }

    int i = 1;
    processElementsIntoTree(edh, i, diff.getDifferential().getElement());

    // now, we sort the siblings throughout the tree
    ElementDefinitionComparer cmp = new ElementDefinitionComparer(true, base.getSnapshot().getElement(), "", 0, name);
    sortElements(edh, cmp, errors);

    // now, we serialise them back to a list
    diffList.clear();
    writeElements(edh, diffList);
  }
 
Example #22
Source File: NarrativeGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void generateResourceSummary(XhtmlNode x, ResourceWrapper res, boolean textAlready, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
  if (!textAlready) {
    XhtmlNode div = res.getNarrative();
    if (div != null) {
      if (div.allChildrenAreText())
        x.getChildNodes().addAll(div.getChildNodes());
      if (div.getChildNodes().size() == 1 && div.getChildNodes().get(0).allChildrenAreText())
        x.getChildNodes().addAll(div.getChildNodes().get(0).getChildNodes());
    }
    x.tx("Generated Summary: ");
  }
  String path = res.getName();
  StructureDefinition profile = context.fetchResource(StructureDefinition.class, path);
  if (profile == null)
    x.tx("unknown resource " +path);
  else {
    boolean firstElement = true;
    boolean last = false;
    for (PropertyWrapper p : res.children()) {
      ElementDefinition child = getElementDefinition(profile.getSnapshot().getElement(), path+"."+p.getName(), p);
      if (p.getValues().size() > 0 && p.getValues().get(0) != null && child != null && isPrimitive(child) && includeInSummary(child)) {
        if (firstElement)
          firstElement = false;
        else if (last)
          x.tx("; ");
        boolean first = true;
        last = false;
        for (BaseWrapper v : p.getValues()) {
          if (first)
            first = false;
          else if (last)
            x.tx(", ");
          last = displayLeaf(res, v, child, x, p.getName(), showCodeDetails) || last;
        }
      }
    }
  }
}
 
Example #23
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public XhtmlNode generateGrid(String defFile, StructureDefinition profile, String imageFolder, boolean inlineGraphics, String profileBaseFileName, String corePath, String imagePath, Set<String> outputTracker) throws IOException, FHIRException {
  HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
  gen.setTranslator(getTranslator());
  TableModel model = gen.initGridTable(corePath, profile.getId());
  List<ElementDefinition> list = profile.getSnapshot().getElement();
  List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
  profiles.add(profile);
  genGridElement(defFile == null ? null : defFile+"#", gen, model.getRows(), list.get(0), list, profiles, true, profileBaseFileName, null, corePath, imagePath, true, profile.getDerivation() == TypeDerivationRule.CONSTRAINT && usesMustSupport(list));
  try {
    return gen.generate(model, imagePath, 1, outputTracker);
  } catch (org.hl7.fhir.exceptions.FHIRException e) {
    throw new FHIRException(e.getMessage(), e);
  }
}
 
Example #24
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public XhtmlNode generateTable(String defFile, StructureDefinition profile, boolean diff, String imageFolder, boolean inlineGraphics, String profileBaseFileName, boolean snapshot, String corePath, String imagePath, boolean logicalModel, boolean allInvariants, Set<String> outputTracker) throws IOException, FHIRException {
  assert(diff != snapshot);// check it's ok to get rid of one of these
  HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics);
  gen.setTranslator(getTranslator());
  TableModel model = gen.initNormalTable(corePath, false, true, profile.getId()+(diff ? "d" : "s"), false);
  List<ElementDefinition> list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement();
  List<StructureDefinition> profiles = new ArrayList<StructureDefinition>();
  profiles.add(profile);
  genElement(defFile == null ? null : defFile+"#", gen, model.getRows(), list.get(0), list, profiles, diff, profileBaseFileName, null, snapshot, corePath, imagePath, true, logicalModel, profile.getDerivation() == TypeDerivationRule.CONSTRAINT && usesMustSupport(list), allInvariants);
  try {
    return gen.generate(model, imagePath, 0, outputTracker);
	} catch (org.hl7.fhir.exceptions.FHIRException e) {
		throw new FHIRException(e.getMessage(), e);
	}
}
 
Example #25
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 #26
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private String getLogicalMappingId(StructureDefinition sd) {
  String id = null;
  for (StructureDefinitionMappingComponent map : sd.getMapping()) {
    if ("http://hl7.org/fhir/logical".equals(map.getUri()))
      return map.getIdentity();
  }
  return null;
}
 
Example #27
Source File: ProfileUtilitiesTests.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
/**
 * This is simple: we just create an empty differential, generate the snapshot, and then insist it must match the base. for a different resource with recursion 
 * 
 * @param context2
 * @
 * @throws EOperationOutcome 
 */
private void testSimple2() throws EOperationOutcome, Exception {
  StructureDefinition focus = new StructureDefinition();
  StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/ValueSet").copy();
  focus.setUrl(Utilities.makeUuidUrn());
  focus.setBaseDefinition(base.getUrl());
  focus.setType(base.getType());
  focus.setDerivation(TypeDerivationRule.CONSTRAINT);
  List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
  new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );

  boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
  for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
    if (ok) {
      ElementDefinition b = base.getSnapshot().getElement().get(i);
      ElementDefinition f = focus.getSnapshot().getElement().get(i);
      if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) 
        ok = false;
      else {
        f.setBase(null);
        ok = Base.compareDeep(b, f, true);
      }
    }
  }
  
  if (!ok) {
    compareXml(base, focus);
    throw new FHIRException("Snap shot generation simple test failed");
  } else 
    System.out.println("Snap shot generation simple test passed");
}
 
Example #28
Source File: R2R3ConversionManager.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public Base createType(Object appInfo, String name) throws FHIRException {
  SimpleWorkerContext context = ((TransformContext) appInfo).getContext();
  if (context == contextR2) {
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/DSTU2/StructureDefinition/"+name);
    if (sd == null)
      throw new FHIRException("Type not found: '"+name+"'");
    return Manager.build(context, sd);
  } else
    return ResourceFactory.createResourceOrType(name);
}
 
Example #29
Source File: ShExGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public String generate(HTMLLinkPolicy links, StructureDefinition structure) {
  List<StructureDefinition> list = new ArrayList<StructureDefinition>();
  list.add(structure);
  innerTypes.clear();
  emittedInnerTypes.clear();
  datatypes.clear();
  emittedDatatypes.clear();
  references.clear();
  required_value_sets.clear();
  known_resources.clear();
  return generate(links, list);
}
 
Example #30
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void closeDifferential(StructureDefinition base, StructureDefinition derived) throws FHIRException {
  for (ElementDefinition edb : base.getSnapshot().getElement()) {
    if (isImmediateChild(edb) && !edb.getPath().endsWith(".id")) {
      ElementDefinition edm = getMatchInDerived(edb, derived.getDifferential().getElement());
      if (edm == null) {
        ElementDefinition edd = derived.getDifferential().addElement();
        edd.setPath(edb.getPath());
        edd.setMax("0");
      } else if (edb.hasSlicing()) {
        closeChildren(base, edb, derived, edm);
      }
    }
  }
  sortDifferential(base, derived, derived.getName(), new ArrayList<String>());
}