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

The following examples show how to use org.hl7.fhir.dstu3.model.StructureDefinition#getDerivation() . 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
private SpanEntry buildSpanningTable(String name, String cardinality, StructureDefinition profile, Set<String> processed, boolean onlyConstraints, String constraintPrefix) throws IOException {
  SpanEntry res = buildSpanEntryFromProfile(name, cardinality, profile);
  boolean wantProcess = !processed.contains(profile.getUrl());
  processed.add(profile.getUrl());
  if (wantProcess && profile.getDerivation() == TypeDerivationRule.CONSTRAINT) {
    for (ElementDefinition ed : profile.getSnapshot().getElement()) {
      if (!"0".equals(ed.getMax()) && ed.getType().size() > 0) {
        String card = getCardinality(ed, profile.getSnapshot().getElement());
        if (!card.endsWith(".0")) {
          List<String> refProfiles = listReferenceProfiles(ed);
          if (refProfiles.size() > 0) {
            String uri = refProfiles.get(0);
            if (uri != null) {
              StructureDefinition sd = context.fetchResource(StructureDefinition.class, uri);
              if (sd != null && (!onlyConstraints || (sd.getDerivation() == TypeDerivationRule.CONSTRAINT && (constraintPrefix == null || sd.getUrl().startsWith(constraintPrefix))))) {
                res.getChildren().add(buildSpanningTable(nameForElement(ed), card, sd, processed, onlyConstraints, constraintPrefix));
              }
            }
          }
        }
      } 
    }
  }
  return res;
}
 
Example 2
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void generateSchematrons(OutputStream dest, StructureDefinition structure) throws IOException, DefinitionException {
  if (structure.getDerivation() != TypeDerivationRule.CONSTRAINT)
    throw new DefinitionException("not the right kind of structure to generate schematrons for");
  if (!structure.hasSnapshot())
    throw new DefinitionException("needs a snapshot");

	StructureDefinition base = context.fetchResource(StructureDefinition.class, structure.getBaseDefinition());

	SchematronWriter sch = new SchematronWriter(dest, SchematronType.PROFILE, base.getName());

  ElementDefinition ed = structure.getSnapshot().getElement().get(0);
  generateForChildren(sch, "f:"+ed.getPath(), ed, structure, base);
  sch.dump();
}
 
Example 3
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 4
Source File: BaseWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void cacheResource(Resource r) throws Exception {
  if (r instanceof ValueSet) {
    seeValueSet(((ValueSet) r).getUrl(), (ValueSet) r);
  } else if (r instanceof CodeSystem) {
    seeCodeSystem(((CodeSystem) r).getUrl(), (CodeSystem) r);
  } else if (r instanceof StructureDefinition) {
    StructureDefinition sd = (StructureDefinition) r;
    if ("http://hl7.org/fhir/StructureDefinition/Extension".equals(sd.getBaseDefinition())) {
      seeExtensionDefinition(sd.getUrl(), sd);
    } else if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT) {
      seeProfile(sd.getUrl(), sd);
    }
  }
}
 
Example 5
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getResourceNames() {
  List<String> result = new ArrayList<String>();
  for (StructureDefinition sd : structures.values()) {
    if (sd.getKind() == StructureDefinitionKind.RESOURCE && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION)
      result.add(sd.getName());
  }
  Collections.sort(result);
  return result;
}
 
Example 6
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getTypeNames() {
  List<String> result = new ArrayList<String>();
  for (StructureDefinition sd : structures.values()) {
    if (sd.getKind() != StructureDefinitionKind.LOGICAL && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION)
      result.add(sd.getName());
  }
  Collections.sort(result);
  return result;
}
 
Example 7
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isResource(String t) {
  StructureDefinition sd;
  try {
    sd = fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+t);
  } catch (Exception e) {
    return false;
  }
  if (sd == null)
    return false;
  if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT)
    return false;
  return sd.getKind() == StructureDefinitionKind.RESOURCE;
}