Java Code Examples for org.hl7.fhir.dstu3.model.ElementDefinition#setPath()
The following examples show how to use
org.hl7.fhir.dstu3.model.ElementDefinition#setPath() .
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: ISO21090Importer.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private void produceProperties(List<ElementDefinition> elements, String name, List<Property> properties, boolean attrMode, boolean snapshot) throws FHIRFormatError { for (Property p : properties) { if (p.isattr == attrMode) { ElementDefinition ed = new ElementDefinition(); elements.add(ed); ed.setPath(name+"."+p.name); if (p.type.startsWith("xsd:")) ToolingExtensions.addStringExtension(ed.addType(), ToolingExtensions.EXT_XML_TYPE, p.type); else ed.addType().setCode(p.type); ed.setMin(p.min); ed.setMax(p.max == Integer.MAX_VALUE ? "*" : Integer.toString(p.max)); ed.setDefinition(p.doco); if (p.isattr) ed.addRepresentation(PropertyRepresentation.XMLATTR); if (p.binding != null) ed.getBinding().setStrength(BindingStrength.REQUIRED).setValueSet(new UriType("http://hl7.org/fhir/iso21090/ValueSet/"+p.binding)); if (snapshot) ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax()); } } }
Example 2
Source File: ADLImporter.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private void genElements(StructureDefinition sd, String path, NodeTreeEntry item) throws Exception { ElementDefinition ed = sd.getSnapshot().addElement(); ed.setPath(path); ed.setMax(item.cardinality.max); ed.setMin(Integer.parseInt(item.cardinality.min)); ed.setShort(texts.get(item.atCode).text); ed.setDefinition(texts.get(item.atCode).description); ed.setComment(texts.get(item.atCode).comment); Element te = findTypeElement(item.typeName); if (te.hasAttribute("profile")) ed.addType().setCode(te.getAttribute("fhir")).setProfile(te.getAttribute("profile")); else ed.addType().setCode(te.getAttribute("fhir")); ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax()); for (NodeTreeEntry child : item.children) { genElements(sd, path+"."+child.name, child); } }
Example 3
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private void closeChildren(StructureDefinition base, ElementDefinition edb, StructureDefinition derived, ElementDefinition edm) { String path = edb.getPath()+"."; int baseStart = base.getSnapshot().getElement().indexOf(edb); int baseEnd = findEnd(base.getSnapshot().getElement(), edb, baseStart+1); int diffStart = derived.getDifferential().getElement().indexOf(edm); int diffEnd = findEnd(derived.getDifferential().getElement(), edm, diffStart+1); for (int cBase = baseStart; cBase < baseEnd; cBase++) { ElementDefinition edBase = base.getSnapshot().getElement().get(cBase); if (isImmediateChild(edBase, edb)) { ElementDefinition edMatch = getMatchInDerived(edBase, derived.getDifferential().getElement(), diffStart, diffEnd); if (edMatch == null) { ElementDefinition edd = derived.getDifferential().addElement(); edd.setPath(edBase.getPath()); edd.setMax("0"); } else { closeChildren(base, edBase, derived, edMatch); } } } }
Example 4
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
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 5
Source File: ISO21090Importer.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void generateType(DataType dt) throws Exception { StructureDefinition sd = new StructureDefinition(); sd.setId(dt.name); sd.setUrl("http://hl7.org/fhir/iso21090/StructureDefinition/"+sd.getId()); sd.setName(dt.name+" data type"); sd.setStatus(PublicationStatus.ACTIVE); sd.setExperimental(false); sd.setPublisher("HL7 / ISO"); sd.setDate(new Date()); sd.setDescription(dt.doco); sd.setKind(StructureDefinitionKind.LOGICAL); sd.setAbstract(Utilities.existsInList(dt.name, "HXIT", "QTY")); sd.setType("Element"); if (dt.parent == null) sd.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Element"); else sd.setBaseDefinition("http://hl7.org/fhir/iso21090/StructureDefinition/"+dt.parent); sd.setDerivation(TypeDerivationRule.SPECIALIZATION); ElementDefinition ed = sd.getDifferential().addElement(); ed.setPath(dt.name); produceProperties(sd.getDifferential().getElement(), dt.name, dt.properties, true, false); produceProperties(sd.getDifferential().getElement(), dt.name, dt.properties, false, false); ed = sd.getSnapshot().addElement(); ed.setPath(dt.name); if (dt.parent != null) addParentProperties(sd.getSnapshot().getElement(), dt.name, dt.parent, true, true); produceProperties(sd.getSnapshot().getElement(), dt.name, dt.properties, true, true); if (dt.parent != null) addParentProperties(sd.getSnapshot().getElement(), dt.name, dt.parent, false, true); produceProperties(sd.getSnapshot().getElement(), dt.name, dt.properties, false, true); ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax()); new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("c:\\temp\\iso21090\\StructureDefinition-"+dt.name+".xml"), sd); }
Example 6
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
/** * Change one cardinality. * * @param context2 * @ * @throws EOperationOutcome */ private void testCardinalityChange() 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.setMin(1); List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" ); boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); 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); if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) ok = false; else { f.setBase(null); if (f.getPath().equals("Patient.identifier")) { ok = f.getMin() == 1; if (ok) f.setMin(0); } ok = ok && Base.compareDeep(b, f, true); } } } if (!ok) { compareXml(base, focus); throw new FHIRException("Snap shot generation chenge cardinality test failed"); } else System.out.println("Snap shot generation chenge cardinality test passed"); }
Example 7
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void copyElements(StructureDefinition sd, List<ElementDefinition> list) { for (ElementDefinition ed : list) { if (ed.getPath().contains(".")) { ElementDefinition n = ed.copy(); n.setPath(sd.getSnapshot().getElementFirstRep().getPath()+"."+ed.getPath().substring(ed.getPath().indexOf(".")+1)); sd.getSnapshot().addElement(n); } } }
Example 8
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public void closeDifferential(StructureDefinition base, StructureDefinition derived) throws FHIRException { for (ElementDefinition edb : base.getSnapshot().getElement()) { if (isImmediateChild(edb) && !edb.getPath().endsWith(".id")) { ElementDefinition edm = getMatchInDerived(edb, derived.getDifferential().getElement()); if (edm == null) { ElementDefinition edd = derived.getDifferential().addElement(); edd.setPath(edb.getPath()); edd.setMax("0"); } else if (edb.hasSlicing()) { closeChildren(base, edb, derived, edm); } } } sortDifferential(base, derived, derived.getName(), new ArrayList<String>()); }
Example 9
Source File: ProfileComparer.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * 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 10
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
private PropertyWithType updateProfile(VariableForProfiling var, String element, TypeDetails type, StructureMap map, List<StructureDefinition> profiles, String sliceName, Type fixed, StructureMapGroupRuleTargetComponent tgt) throws FHIRException { if (var == null) { assert (Utilities.noString(element)); // 1. start the new structure definition StructureDefinition sdn = worker.fetchResource(StructureDefinition.class, type.getType()); if (sdn == null) throw new FHIRException("Unable to find definition for "+type.getType()); ElementDefinition edn = sdn.getSnapshot().getElementFirstRep(); PropertyWithType pn = createProfile(map, profiles, new PropertyWithType(sdn.getId(), new Property(worker, edn, sdn), null, type), sliceName, tgt); // // 2. hook it into the base bundle // if (type.getType().startsWith("http://hl7.org/fhir/StructureDefinition/") && worker.getResourceNames().contains(type.getType().substring(40))) { // StructureDefinition sd = var.getProperty().profileProperty.getStructure(); // ElementDefinition ed = sd.getDifferential().addElement(); // ed.setPath("Bundle.entry"); // ed.setName(sliceName); // ed.setMax("1"); // well, it is for now... // ed = sd.getDifferential().addElement(); // ed.setPath("Bundle.entry.fullUrl"); // ed.setMin(1); // ed = sd.getDifferential().addElement(); // ed.setPath("Bundle.entry.resource"); // ed.setMin(1); // ed.addType().setCode(pn.getProfileProperty().getStructure().getType()).setProfile(pn.getProfileProperty().getStructure().getUrl()); // } return pn; } else { assert (!Utilities.noString(element)); Property pvb = var.getProperty().getBaseProperty(); Property pvd = var.getProperty().getProfileProperty(); Property pc = pvb.getChild(element, var.property.types); if (pc == null) throw new DefinitionException("Unable to find a definition for "+pvb.getDefinition().getPath()+"."+element); // the profile structure definition (derived) StructureDefinition sd = var.getProperty().profileProperty.getStructure(); ElementDefinition ednew = sd.getDifferential().addElement(); ednew.setPath(var.getProperty().profileProperty.getDefinition().getPath()+"."+pc.getName()); ednew.setUserData("slice-name", sliceName); ednew.setFixed(fixed); for (ProfiledType pt : type.getProfiledTypes()) { if (pt.hasBindings()) ednew.setBinding(pt.getBindings().get(0)); if (pt.getUri().startsWith("http://hl7.org/fhir/StructureDefinition/")) { String t = pt.getUri().substring(40); t = checkType(t, pc, pt.getProfiles()); if (t != null) { if (pt.hasProfiles()) { for (String p : pt.getProfiles()) if (t.equals("Reference")) ednew.addType().setCode(t).setTargetProfile(p); else ednew.addType().setCode(t).setProfile(p); } else ednew.addType().setCode(t); } } } return new PropertyWithType(var.property.path+"."+element, pc, new Property(worker, ednew, sd), type); } }
Example 11
Source File: StructureMapUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
private PropertyWithType createProfile(StructureMap map, List<StructureDefinition> profiles, PropertyWithType prop, String sliceName, Base ctxt) throws DefinitionException { 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(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; }
Example 12
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * check that documentation appending is working * * @param context2 * @ * @throws EOperationOutcome */ private void testDocumentationAppend() 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.setDefinition("... some more doco"); List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" ); boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); 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); if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) ok = false; else { f.setBase(null); if (f.getPath().equals("Patient.identifier")) { ok = f.getDefinition().length() > b.getDefinition().length(); if (ok) { f.setDefinition(null); b.setDefinition(null); } } ok = ok && Base.compareDeep(b, f, true); } } } if (!ok) { compareXml(base, focus); throw new FHIRException("Snap shot generation documentation append failed"); } else System.out.println("Snap shot generation documentation append test passed"); }
Example 13
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * check that narrowing types is working * this one doesn't rename the path * * @param context2 * @ * @throws EOperationOutcome */ private void textTypeNarrowing1() 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.deceased[x]"); id.addType().setCode("dateTime"); List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" ); boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); 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); if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) ok = false; else { f.setBase(null); if (f.getPath().equals("Patient.deceasedDateTime")) { ok = f.getType().size() == 1 && f.getType().get(0).getCode().equals("dateTime"); if (ok) { f.getType().clear(); b.getType().clear(); f.setPath(b.getPath()); } } ok = ok && Base.compareDeep(b, f, true); } } } if (!ok) { compareXml(base, focus); throw new FHIRException("Snap shot generation narrow type 1 failed"); } else System.out.println("Snap shot generation narrow type 1 test passed"); }
Example 14
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * check that narrowing types is working * this one renames the path * * @param context2 * @ * @throws EOperationOutcome */ private void textTypeNarrowing2() 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.deceasedDateTime"); id.addType().setCode("dateTime"); List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" ); boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); 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); if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) ok = false; else { f.setBase(null); if (f.getPath().equals("Patient.deceasedDateTime")) { ok = f.getType().size() == 1 && f.getType().get(0).getCode().equals("dateTime"); if (ok) { f.getType().clear(); b.getType().clear(); f.setPath(b.getPath()); } } ok = ok && Base.compareDeep(b, f, true); } } } if (!ok) { compareXml(base, focus); throw new FHIRException("Snap shot generation narrow type 2 failed"); } else System.out.println("Snap shot generation narrow type 2 test passed"); }
Example 15
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * check that mapping resolution is working * * @param context2 * @ * @throws EOperationOutcome */ private void testMapping() 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.addMapping().setIdentity("rim").setMap("test"); List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" ); boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size(); 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); if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) ok = false; else { f.setBase(null); if (f.getPath().equals("Patient.identifier")) { ok = f.getMapping().size() > b.getMapping().size(); if (ok) { f.getMapping().clear(); b.getMapping().clear(); } } ok = ok && Base.compareDeep(b, f, true); } } } if (!ok) { compareXml(base, focus); throw new FHIRException("Snap shot generation mapping changes failed"); } else System.out.println("Snap shot generation mapping changes test passed"); }
Example 16
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * 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 17
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * 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"); }
Example 18
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * we're going to slice Patient.identifier */ private void testSlicingSimple() 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 = focus.getDifferential().addElement(); id.setPath("Patient.identifier"); id.getSlicing().setOrdered(false).setRules(SlicingRules.OPEN).addDiscriminator().setPath("use").setType(DiscriminatorType.VALUE); // first slice: id = focus.getDifferential().addElement(); id.setPath("Patient.identifier"); id.setSliceName("name1"); id = focus.getDifferential().addElement(); id.setPath("Patient.identifier.use"); id.setFixed(new CodeType("usual")); // second slice: id = focus.getDifferential().addElement(); id.setPath("Patient.identifier"); id.setSliceName("name2"); id = focus.getDifferential().addElement(); id.setPath("Patient.identifier.use"); id.setFixed(new CodeType("official")); List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); new ProfileUtilities(context, messages, null).generateSnapshot(base, focus, focus.getUrl(), "Simple Test" ); // 18 different: identifier + 8 inner children * 2 boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size() - 18; 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 + 18); if (!f.hasBase() || !b.getPath().equals(f.getBase().getPath())) ok = false; else { f.setBase(null); if (f.getPath().equals("Patient.identifier")) { ok = f.hasSlicing(); if (ok) f.setSlicing(null); } ok = Base.compareDeep(b, f, true); } } } // now, check that the slices we skipped are correct: for (int i = 10; i <= 18; i++) { if (ok) { ElementDefinition d1 = focus.getSnapshot().getElement().get(i); ElementDefinition d2 = focus.getSnapshot().getElement().get(i+9); if (d1.getPath().equals("Patient.identifier.use")) { ok = d1.hasFixed() && d2.hasFixed() && !Base.compareDeep(d1.getFixed(), d2.getFixed(), true); if (ok) { d1.setFixed(null); d2.setFixed(null); } } if (d1.getPath().equals("Patient.identifier")) { ok = d1.hasSliceName() && d2.hasSliceName() && !Base.compareDeep(d1.getSliceNameElement(), d2.getSliceNameElement(), true); if (ok) { d1.setSliceName(null); d2.setSliceName(null); } } ok = Base.compareDeep(d1, d2, true); } } // for throughness, we could check against identifier too, but this is not done now. if (!ok) { compareXml(base, focus); throw new FHIRException("Snap shot generation slicing failed"); } else System.out.println("Snap shot generation slicing passed"); }
Example 19
Source File: ProfileUtilitiesTests.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
/** * 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"); }