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

The following examples show how to use org.hl7.fhir.dstu3.model.ElementDefinition#hasType() . 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 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 2
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private static void renderDE(DataElement de, List<String> cols, StringBuilder b, boolean profileLink, String linkBase) {
  b.append("<tr>");
  for (String col : cols) {
    String v;
    ElementDefinition dee = de.getElement().get(0);
    if (col.equals("DataElement.name")) {
      v = de.hasName() ? Utilities.escapeXml(de.getName()) : "";
    } else if (col.equals("DataElement.status")) {
      v = de.hasStatusElement() ? de.getStatusElement().asStringValue() : "";
    } else if (col.equals("DataElement.code")) {
      v = renderCoding(dee.getCode());
    } else if (col.equals("DataElement.type")) {
      v = dee.hasType() ? Utilities.escapeXml(dee.getType().get(0).getCode()) : "";
    } else if (col.equals("DataElement.units")) {
      v = renderDEUnits(ToolingExtensions.getAllowedUnits(dee));
    } else if (col.equals("DataElement.binding")) {
      v = renderBinding(dee.getBinding());
    } else if (col.equals("DataElement.minValue")) {
      v = ToolingExtensions.hasExtension(de, "http://hl7.org/fhir/StructureDefinition/minValue") ? Utilities.escapeXml(ToolingExtensions.readPrimitiveExtension(de, "http://hl7.org/fhir/StructureDefinition/minValue").asStringValue()) : "";
    } else if (col.equals("DataElement.maxValue")) {
      v = ToolingExtensions.hasExtension(de, "http://hl7.org/fhir/StructureDefinition/maxValue") ? Utilities.escapeXml(ToolingExtensions.readPrimitiveExtension(de, "http://hl7.org/fhir/StructureDefinition/maxValue").asStringValue()) : "";
    } else if (col.equals("DataElement.maxLength")) {
      v = ToolingExtensions.hasExtension(de, "http://hl7.org/fhir/StructureDefinition/maxLength") ? Utilities.escapeXml(ToolingExtensions.readPrimitiveExtension(de, "http://hl7.org/fhir/StructureDefinition/maxLength").asStringValue()) : "";
    } else if (col.equals("DataElement.mask")) {
      v = ToolingExtensions.hasExtension(de, "http://hl7.org/fhir/StructureDefinition/mask") ? Utilities.escapeXml(ToolingExtensions.readPrimitiveExtension(de, "http://hl7.org/fhir/StructureDefinition/mask").asStringValue()) : "";
    } else 
      throw new Error("Unknown column name: "+col);

    b.append("<td>"+v+"</td>");
  }
  if (profileLink) {
    b.append("<td><a href=\""+linkBase+"-"+de.getId()+".html\">Profile</a>, <a href=\"http://www.opencem.org/#/20140917/Intermountain/"+de.getId()+"\">CEM</a>");
    if (ToolingExtensions.hasExtension(de, ToolingExtensions.EXT_CIMI_REFERENCE)) 
      b.append(", <a href=\""+ToolingExtensions.readStringExtension(de, ToolingExtensions.EXT_CIMI_REFERENCE)+"\">CIMI</a>");
    b.append("</td>");
  }
  b.append("</tr>\r\n");
}
 
Example 3
Source File: ProfileUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private String pathTail(List<ElementDefinition> diffMatches, int i) {
  
  ElementDefinition d = diffMatches.get(i);
  String s = d.getPath().contains(".") ? d.getPath().substring(d.getPath().lastIndexOf(".")+1) : d.getPath();
  return "."+s + (d.hasType() && d.getType().get(0).hasProfile() ? "["+d.getType().get(0).getProfile()+"]" : "");
}
 
Example 4
Source File: ProfileUtilitiesTests.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
/**
 * we're going to slice Patient.extension and refer to extension by profile
 * 
 * implicit: whether to rely on implicit extension slicing
 */
private void testSlicingExtension(boolean implicit) throws EOperationOutcome, Exception {
  
  StructureDefinition focus = new StructureDefinition();
  StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
  focus.setUrl(Utilities.makeUuidUrn());
  focus.setBaseDefinition(base.getUrl());
  focus.setType(base.getType());
  focus.setDerivation(TypeDerivationRule.CONSTRAINT);
  
  // set the slice up
  ElementDefinition id;
  if (!implicit) {
    id = focus.getDifferential().addElement();
    id.setPath("Patient.extension");
    id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
    id.setMax("3");
  }
  // first slice: 
  id = focus.getDifferential().addElement();
  id.setPath("Patient.extension");
  id.setSliceName("name1");
  id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-birthTime");
  id.setMin(1);
  
  // second slice:
  id = focus.getDifferential().addElement();
  id.setPath("Patient.extension");
  id.setSliceName("name2");
  id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/patient-mothersMaidenName");    
  
  List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
  ProfileUtilities pu = new ProfileUtilities(context, messages, null);
  pu.generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );

  // 2 different: extension slices 
  boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 2;
  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 <= 7 ? i : i + 2);
      if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) 
        ok = false;
      else {
        f.setBase(null);
        if (f.getPath().equals("Patient.extension")) {
          ok = f.hasSlicing() && (implicit || f.getMax().equals("3"));
          if (ok) {
            f.setSlicing(null);
            f.setMaxElement(b.getMaxElement());
          }
        }            
        if (!f.getPath().equals("Patient.extension")) // no compare that because the definitions get overwritten 
          ok = Base.compareDeep(b, f, true);
      }
    }
  }
  // now, check that the slices we skipped are correct:
  if (ok) {
    ElementDefinition d1 = focus.getSnapshot().getElement().get(8);
    ElementDefinition d2 = focus.getSnapshot().getElement().get(9);
    ok = d1.hasType() && d1.getType().get(0).hasProfile() && d2.hasType() && d2.getType().get(0).hasProfile() && !Base.compareDeep(d1.getType(), d2.getType(), true) &&
          d1.getMin() == 1 && d2.getMin() == 0 && d1.getMax().equals("1") && d2.getMax().equals("1");
    if (ok) {
      d1.getType().clear();
      d2.getType().clear();
      d1.setSliceName("x");
      d2.setSliceName("x");
      d1.setMin(0);
    }
    ok = Base.compareDeep(d1, d2, true);
    // for throughness, we could check against extension too, but this is not done now.
  }
  
  if (!ok) {
    compareXml(base, focus);
    throw new FHIRException("Snap shot generation slicing extensions simple ("+(implicit ? "implicit" : "not implicit")+") failed");
  } else 
    System.out.println("Snap shot generation slicing extensions simple ("+(implicit ? "implicit" : "not implicit")+") passed");
}