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

The following examples show how to use org.hl7.fhir.r4.model.StructureDefinition#setBaseDefinition() . 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
@Test
public void testSimple() throws FHIRException, FileNotFoundException, IOException, UcumException {

  StructureDefinition focus = new StructureDefinition();
  StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Patient").copy();
  focus.setUrl(Utilities.makeUuidUrn());
  focus.setBaseDefinition(base.getUrl());
  focus.setType("Patient");
  focus.setDerivation(TypeDerivationRule.CONSTRAINT);
  List<ValidationMessage> messages = new ArrayList<ValidationMessage>();
  new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://hl7.org/fhir/R4", "Simple Test");

  boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
  for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
    ElementDefinition b = base.getSnapshot().getElement().get(i);
    ElementDefinition f = focus.getSnapshot().getElement().get(i);
    if (ok) {
      if (!f.hasBase())
        ok = false;
      else if (!b.getPath().equals(f.getPath()))
        ok = false;
      else {
        b.setBase(null);
        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 2
Source File: StructureMapUtilities.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private PropertyWithType createProfile(StructureMap map, List<StructureDefinition> profiles, PropertyWithType prop, String sliceName, Base ctxt) throws FHIRException {
  if (prop.getBaseProperty().getDefinition().getPath().contains(".")) 
    throw new DefinitionException("Unable to process entry point");

  String type = prop.getBaseProperty().getDefinition().getPath();
  String suffix = "";
  if (ids.containsKey(type)) {
    int id = ids.get(type);
    id++;
    ids.put(type, id);
    suffix = "-"+Integer.toString(id);
  } else
    ids.put(type, 0);
  
  StructureDefinition profile = new StructureDefinition();
  profiles.add(profile);
  profile.setDerivation(TypeDerivationRule.CONSTRAINT);
  profile.setType(type);
  profile.setBaseDefinition(prop.getBaseProperty().getStructure().getUrl());
  profile.setName("Profile for "+profile.getType()+" for "+sliceName);
  profile.setUrl(map.getUrl().replace("StructureMap", "StructureDefinition")+"-"+profile.getType()+suffix);
  ctxt.setUserData("profile", profile.getUrl()); // then we can easily assign this profile url for validation later when we actually transform
  profile.setId(map.getId()+"-"+profile.getType()+suffix);
  profile.setStatus(map.getStatus());
  profile.setExperimental(map.getExperimental());
  profile.setDescription("Generated automatically from the mapping by the Java Reference Implementation");
  for (ContactDetail c : map.getContact()) {
    ContactDetail p = profile.addContact();
    p.setName(c.getName());
    for (ContactPoint cc : c.getTelecom()) 
      p.addTelecom(cc);
  }
  profile.setDate(map.getDate());
  profile.setCopyright(map.getCopyright());
  profile.setFhirVersion(FHIRVersion.fromCode(Constants.VERSION));
  profile.setKind(prop.getBaseProperty().getStructure().getKind());
  profile.setAbstract(false);
  ElementDefinition ed = profile.getDifferential().addElement();
  ed.setPath(profile.getType());
  prop.profileProperty = new Property(worker, ed, profile);
  return prop;
}