Java Code Examples for org.hl7.fhir.r4.model.StructureDefinition#getKind()

The following examples show how to use org.hl7.fhir.r4.model.StructureDefinition#getKind() . 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 6 votes vote down vote up
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, ProfileUtilities.sdNs(getType(name), context.getOverrideVersionNs()));
    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;
	}
 
Example 2
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.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(tn, context.getOverrideVersionNs()));
  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 3
Source File: SimpleWorkerContext.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public void generateSnapshot(StructureDefinition p) throws DefinitionException, FHIRException {
  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.setThrowException(false);
    pu.sortDifferential(sd, p, p.getUrl(), 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(), Utilities.extractBaseUrl(sd.getUserString("path")), p.getName());
    for (ValidationMessage msg : msgs) {
      if ((!ignoreProfileErrors && 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 FHIRException("Profile "+p.getName()+" ("+p.getUrl()+"). Error generating snapshot");
    pu = null;
  }
}
 
Example 4
Source File: GraphQLSchemaGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private boolean isPrimitive(TypeRefComponent type) {
  String typeName = type.getWorkingCode();
  StructureDefinition sd = context.fetchTypeDefinition(typeName);
  if (sd == null)
    return false;
  return sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE;
}
 
Example 5
Source File: ProtoBufGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public void build() throws FHIRException {
  if (definition == null)
    throw new FHIRException("A definition must be provided");
  if (destination == null)
    throw new FHIRException("A destination must be provided");
  
  if (definition.getDerivation() == TypeDerivationRule.CONSTRAINT)
    throw new FHIRException("derivation = constraint is not supported yet");
  
  message = new Message(definition.getSnapshot().getElement().get(0).getPath());
  cursor = 1;
  while (cursor < definition.getSnapshot().getElement().size()) {
    ElementDefinition ed = definition.getSnapshot().getElement().get(0);
    Field fld = new Field();
    fld.name = tail(ed.getPath());
    fld.required = (ed.getMin() == 1);
    fld.repeating = (!ed.getMax().equals("1"));
    message.fields.add(fld);
    if (ed.getType().size() != 1)
      fld.type = "Unknown";
    else {
      StructureDefinition td = context.fetchTypeDefinition(ed.getTypeFirstRep().getWorkingCode());
      if (td == null)
        fld.type = "Unresolved";
      else if (td.getKind() == StructureDefinitionKind.PRIMITIVETYPE) {
        fld.type = protoTypeForFhirType(ed.getTypeFirstRep().getWorkingCode());
        fld = new Field();
        fld.name = tail(ed.getPath())+"Extra";
        fld.repeating = (!ed.getMax().equals("1"));
        fld.type = "Primitive";
        message.fields.add(fld);
      } else
        fld.type = ed.getTypeFirstRep().getWorkingCode();
    }   
  }
}
 
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> getResourceNames() {
  List<String> result = new ArrayList<String>();
  for (StructureDefinition sd : listStructures()) {
    if (sd.getKind() == StructureDefinitionKind.RESOURCE && 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 List<String> getTypeNames() {
  List<String> result = new ArrayList<String>();
  for (StructureDefinition sd : listStructures()) {
    if (sd.getKind() != StructureDefinitionKind.LOGICAL && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION)
      result.add(sd.getName());
  }
  Collections.sort(result);
  return result;
}
 
Example 8
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;
}
 
Example 9
Source File: ExtensionDefinitionGenerator.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private List<StructureDefinition> buildExtensions(List<StructureDefinition> definitions) throws DefinitionException, FHIRException {
  Set<String> types = new HashSet<>();
  List<StructureDefinition> list = new ArrayList<>();
  for (StructureDefinition type : definitions)
    if (type.getDerivation() == TypeDerivationRule.SPECIALIZATION && !type.getName().contains(".") && !types.contains(type.getName()) && type.getKind() != StructureDefinitionKind.PRIMITIVETYPE && !Utilities.existsInList(type.getName(), "Extension", "Narrative")) {
      types.add(type.getName());
      buildExtensions(type, list);
    }
  return list;
}
 
Example 10
Source File: QuestionnaireBuilder.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private boolean isPrimitive(TypeRefComponent t) {
  String code = t.getWorkingCode();
  StructureDefinition sd = context.fetchTypeDefinition(code);
  return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE;
}
 
Example 11
Source File: SnapShotGenerationTests.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isDatatype(String name) {
  StructureDefinition sd = TestingUtilities.context().fetchTypeDefinition(name);
  return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE || sd.getKind() == StructureDefinitionKind.COMPLEXTYPE);
}
 
Example 12
Source File: SnapShotGenerationTests.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isResource(String typeSimple) {
  StructureDefinition sd = TestingUtilities.context().fetchTypeDefinition(typeSimple);
  return (sd != null) && (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) && (sd.getKind() == StructureDefinitionKind.RESOURCE);
}