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

The following examples show how to use org.hl7.fhir.dstu3.model.ElementDefinition#setMustSupport() . 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: ProfileUtilitiesTests.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void testSlicingTask8742() throws EOperationOutcome, Exception {
  StructureDefinition focus = new StructureDefinition();
  StructureDefinition base = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Organization").copy();
  focus.setUrl(Utilities.makeUuidUrn());
  focus.setBaseDefinition(base.getUrl());
  focus.setType(base.getType());
  focus.setDerivation(TypeDerivationRule.CONSTRAINT);
  
  ElementDefinition id = focus.getDifferential().addElement();
  id.setPath("Organization.address");
  id.setMin(1);
  id.setMax("1");
  id.setMustSupport(true);
      
  id = focus.getDifferential().addElement();
  id.setPath("Organization.address.extension");
  id.setSliceName("USLabCountycodes");
  id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("url").setType(DiscriminatorType.VALUE);
  id.setShort("County/Parish FIPS codes");
  id.setDefinition("County/Parish FIPS codes.");
  id.setRequirements("County/Parish Code SHALL use FIPS 6-4  ( INCITS 31:2009).");
  id.setMin(0);
  id.setMax("1");
  id.addType().setCode("Extension").setProfile("http://hl7.org/fhir/StructureDefinition/us-core-county");
  id.setMustSupport(true);
  id.getBinding().setStrength(BindingStrength.REQUIRED).setDescription("FIPS codes for US counties and county equivalent entities.").setValueSet(new Reference().setReference("http://hl7.org/fhir/ValueSet/fips-county"));
  List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
  
  new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );

  // 14 for address with one sliced extension
  boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 13;
  
  if (!ok) {
    compareXml(base, focus);
    throw new FHIRException("Snap shot generation test 8742 failed");
  } else 
    System.out.println("Snap shot generation test 8742 passed");
}
 
Example 2
Source File: ProfileComparer.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
/**
   * left and right refer to the same element. Are they compatible?   
   * @param outcome 
   * @param outcome
   * @param path
   * @param left
   * @param right
   * @- if there's a problem that needs fixing in this code
   * @throws DefinitionException 
   * @throws IOException 
   * @throws FHIRFormatError 
   */
  private boolean compareElements(ProfileComparison outcome, String path, DefinitionNavigator left, DefinitionNavigator right) throws DefinitionException, IOException, FHIRFormatError {
//    preconditions:
    assert(path != null);
    assert(left != null);
    assert(right != null);
    assert(left.path().equals(right.path()));
    
    // we ignore slicing right now - we're going to clone the root one anyway, and then think about clones 
    // simple stuff
    ElementDefinition subset = new ElementDefinition();
    subset.setPath(left.path());
    
    // not allowed to be different: 
    subset.getRepresentation().addAll(left.current().getRepresentation()); // can't be bothered even testing this one
    if (!outcome.ruleCompares(subset, left.current().getDefaultValue(), right.current().getDefaultValue(), path+".defaultValue[x]", BOTH_NULL))
      return false;
    subset.setDefaultValue(left.current().getDefaultValue());
    if (!outcome.ruleEqual(path, subset, left.current().getMeaningWhenMissing(), right.current().getMeaningWhenMissing(), "meaningWhenMissing Must be the same", true))
      return false;
    subset.setMeaningWhenMissing(left.current().getMeaningWhenMissing());
    if (!outcome.ruleEqual(subset, left.current().getIsModifier(), right.current().getIsModifier(), path, "isModifier"))
      return false;
    subset.setIsModifier(left.current().getIsModifier());
    if (!outcome.ruleEqual(subset, left.current().getIsSummary(), right.current().getIsSummary(), path, "isSummary"))
      return false;
    subset.setIsSummary(left.current().getIsSummary());
    
    // descriptive properties from ElementDefinition - merge them:
    subset.setLabel(mergeText(subset, outcome, path, "label", left.current().getLabel(), right.current().getLabel()));
    subset.setShort(mergeText(subset, outcome, path, "short", left.current().getShort(), right.current().getShort()));
    subset.setDefinition(mergeText(subset, outcome, path, "definition", left.current().getDefinition(), right.current().getDefinition()));
    subset.setComment(mergeText(subset, outcome, path, "comments", left.current().getComment(), right.current().getComment()));
    subset.setRequirements(mergeText(subset, outcome, path, "requirements", left.current().getRequirements(), right.current().getRequirements()));
    subset.getCode().addAll(mergeCodings(left.current().getCode(), right.current().getCode()));
    subset.getAlias().addAll(mergeStrings(left.current().getAlias(), right.current().getAlias()));
    subset.getMapping().addAll(mergeMappings(left.current().getMapping(), right.current().getMapping()));
    // left will win for example
    subset.setExample(left.current().hasExample() ? left.current().getExample() : right.current().getExample());

    subset.setMustSupport(left.current().getMustSupport() || right.current().getMustSupport());
    ElementDefinition superset = subset.copy();


    // compare and intersect
    superset.setMin(unionMin(left.current().getMin(), right.current().getMin()));
    superset.setMax(unionMax(left.current().getMax(), right.current().getMax()));
    subset.setMin(intersectMin(left.current().getMin(), right.current().getMin()));
    subset.setMax(intersectMax(left.current().getMax(), right.current().getMax()));
    outcome.rule(subset, subset.getMax().equals("*") || Integer.parseInt(subset.getMax()) >= subset.getMin(), path, "Cardinality Mismatch: "+card(left)+"/"+card(right));
    
    superset.getType().addAll(unionTypes(path, left.current().getType(), right.current().getType()));
    subset.getType().addAll(intersectTypes(subset, outcome, path, left.current().getType(), right.current().getType()));
    outcome.rule(subset, !subset.getType().isEmpty() || (!left.current().hasType() && !right.current().hasType()), path, "Type Mismatch:\r\n  "+typeCode(left)+"\r\n  "+typeCode(right));
//    <fixed[x]><!-- ?? 0..1 * Value must be exactly this --></fixed[x]>
//    <pattern[x]><!-- ?? 0..1 * Value must have at least these property values --></pattern[x]>
    superset.setMaxLengthElement(unionMaxLength(left.current().getMaxLength(), right.current().getMaxLength()));
    subset.setMaxLengthElement(intersectMaxLength(left.current().getMaxLength(), right.current().getMaxLength()));
    if (left.current().hasBinding() || right.current().hasBinding()) {
      compareBindings(outcome, subset, superset, path, left.current(), right.current());
    }

    // note these are backwards
    superset.getConstraint().addAll(intersectConstraints(path, left.current().getConstraint(), right.current().getConstraint()));
    subset.getConstraint().addAll(unionConstraints(subset, outcome, path, left.current().getConstraint(), right.current().getConstraint()));

    // now process the slices
    if (left.current().hasSlicing() || right.current().hasSlicing()) {
      if (isExtension(left.path()))
        return compareExtensions(outcome, path, superset, subset, left, right);
//      return true;
      else
        throw new DefinitionException("Slicing is not handled yet");
    // todo: name 
    }

    // add the children
    outcome.subset.getSnapshot().getElement().add(subset);
    outcome.superset.getSnapshot().getElement().add(superset);
    return compareChildren(subset, outcome, path, left, right);
  }
 
Example 3
Source File: ProfileUtilitiesTests.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
/**
 * Walking into a type 
 * 
 * @param context2
 * @
 * @throws EOperationOutcome 
 */
private void testTypeWalk() 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);
  ElementDefinition id = focus.getDifferential().addElement();
  id.setPath("Patient.identifier");
  id.setMustSupport(true);
  id = focus.getDifferential().addElement();
  id.setPath("Patient.identifier.system");
  id.setMustSupport(true);
  List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
  new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );

  // the derived should be 8 longer
  boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 8;
  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 <= 9 ? i : i + 8);
      if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) 
        ok = false;
      else {
        f.setBase(null);
        if (f.getPath().equals("Patient.identifier")) {
          ok = f.getMustSupport() && !b.getMustSupport();
          if (ok) {
            f.setMustSupportElement(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 4
Source File: ProfileUtilitiesTests.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
/**
 * Walking into a type, without explicitly doing so 
 * 
 * note: this currently fails.
 * 
 * @param context2
 * @
 * @throws EOperationOutcome 
 */
private void testTypeWalk2() 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);
  ElementDefinition id = focus.getDifferential().addElement();
  id.setPath("Patient.identifier.system");
  id.setMustSupport(true);
  List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
  new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" );

  // the derived should be 8 longer
  boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 8;
  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 <= 9 ? i : i + 8);
      if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) 
        ok = false;
      else {
        f.setBase(null);
        if (f.getPath().equals("Patient.identifier")) {
          ok = f.getMustSupport() && !b.getMustSupport();
          if (ok) {
            f.setMustSupportElement(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");
}