Java Code Examples for org.hl7.fhir.dstu3.model.ElementDefinition#hasSlicing()
The following examples show how to use
org.hl7.fhir.dstu3.model.ElementDefinition#hasSlicing() .
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 |
public static List<ElementDefinition> getSliceList(StructureDefinition profile, ElementDefinition element) throws DefinitionException { if (!element.hasSlicing()) throw new Error("getSliceList should only be called when the element has slicing"); List<ElementDefinition> res = new ArrayList<ElementDefinition>(); List<ElementDefinition> elements = profile.getSnapshot().getElement(); String path = element.getPath(); for (int index = elements.indexOf(element) + 1; index < elements.size(); index++) { ElementDefinition e = elements.get(index); if (e.getPath().startsWith(path + ".") || e.getPath().equals(path)) { // We want elements with the same path (until we hit an element that doesn't start with the same path) if (e.getPath().equals(element.getPath())) res.add(e); } else break; } return res; }
Example 2
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private String sliceSummary(ElementDefinition ed) { if (!ed.hasSlicing() && !ed.hasSliceName()) return ""; if (ed.hasSliceName()) return " (slicename = "+ed.getSliceName()+")"; StringBuilder b = new StringBuilder(); boolean first = true; for (ElementDefinitionSlicingDiscriminatorComponent d : ed.getSlicing().getDiscriminator()) { if (first) first = false; else b.append("|"); b.append(d.getPath()); } return " (slicing by "+b.toString()+")"; }
Example 3
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 4
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
public void sortDifferential(StructureDefinition base, StructureDefinition diff, String name, List<String> errors) throws FHIRException { final List<ElementDefinition> diffList = diff.getDifferential().getElement(); // first, we move the differential elements into a tree if (diffList.isEmpty()) return; ElementDefinitionHolder edh = new ElementDefinitionHolder(diffList.get(0)); boolean hasSlicing = false; List<String> paths = new ArrayList<String>(); // in a differential, slicing may not be stated explicitly for(ElementDefinition elt : diffList) { if (elt.hasSlicing() || paths.contains(elt.getPath())) { hasSlicing = true; break; } paths.add(elt.getPath()); } if(!hasSlicing) { // if Differential does not have slicing then safe to pre-sort the list // so elements and subcomponents are together Collections.sort(diffList, new ElementNameCompare()); } int i = 1; processElementsIntoTree(edh, i, diff.getDifferential().getElement()); // now, we sort the siblings throughout the tree ElementDefinitionComparer cmp = new ElementDefinitionComparer(true, base.getSnapshot().getElement(), "", 0, name); sortElements(edh, cmp, errors); // now, we serialise them back to a list diffList.clear(); writeElements(edh, diffList); }
Example 5
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private String getCardinality(ElementDefinition ed, List<ElementDefinition> list) { int min = ed.getMin(); int max = !ed.hasMax() || ed.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(ed.getMax()); while (ed != null && ed.getPath().contains(".")) { ed = findParent(ed, list); if (ed.getMax().equals("0")) max = 0; else if (!ed.getMax().equals("1") && !ed.hasSlicing()) max = Integer.MAX_VALUE; if (ed.getMin() == 0) min = 0; } return Integer.toString(min)+".."+(max == Integer.MAX_VALUE ? "*" : Integer.toString(max)); }
Example 6
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
private boolean isSlicedToOneOnly(ElementDefinition e) { return (e.hasSlicing() && e.hasMaxElement() && e.getMax().equals("1")); }
Example 7
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
private boolean onlyInformationIsMapping(List<ElementDefinition> list, ElementDefinition e) { return (!e.hasSliceName() && !e.hasSlicing() && (onlyInformationIsMapping(e))) && getChildren(list, e).isEmpty(); }
Example 8
Source File: CSVWriter.java From org.hl7.fhir.core with Apache License 2.0 | 4 votes |
public void processElement(ElementDefinition ed) throws Exception { CSVLine line = new CSVLine(); lines.add(line); line.addString(ed.getPath()); line.addString(ed.getSliceName()); line.addString(itemList(ed.getAlias())); line.addString(ed.getLabel()); line.addValue(ed.getMin()); line.addValue(ed.getMax()); line.addString(ed.getMustSupport() ? "Y" : ""); line.addString(ed.getIsModifier() ? "Y" : ""); line.addString(ed.getIsSummary() ? "Y" : ""); line.addString(itemList(ed.getType())); line.addString(ed.getShort()); line.addString(ed.getDefinition()); line.addString(ed.getComment()); line.addString(ed.getRequirements()); line.addString(ed.getDefaultValue()!=null ? renderType(ed.getDefaultValue()) : ""); line.addString(ed.getMeaningWhenMissing()); line.addString(ed.hasFixed() ? renderType(ed.getFixed()) : ""); line.addString(ed.hasPattern() ? renderType(ed.getPattern()) : ""); line.addString(ed.hasExample() ? renderType(ed.getExample().get(0).getValue()) : ""); // todo...? line.addString(ed.hasMinValue() ? renderType(ed.getMinValue()) : ""); line.addString(ed.hasMaxValue() ? renderType(ed.getMaxValue()) : ""); line.addValue((ed.hasMaxLength() ? Integer.toString(ed.getMaxLength()) : "")); if (ed.hasBinding()) { line.addString(ed.getBinding().getStrength()!=null ? ed.getBinding().getStrength().toCode() : ""); line.addString(ed.getBinding().getDescription()); if (ed.getBinding().getValueSet()==null) line.addString(""); else if (ed.getBinding().getValueSet() instanceof Reference) line.addString(ed.getBinding().getValueSetReference().getReference()); else line.addString(ed.getBinding().getValueSetUriType().getValue()); } else { line.addValue(""); line.addValue(""); line.addValue(""); } line.addString(itemList(ed.getCode())); if (ed.hasSlicing()) { line.addString(itemList(ed.getSlicing().getDiscriminator())); line.addString(ed.getSlicing().getDescription()); line.addBoolean(ed.getSlicing().getOrdered()); line.addString(ed.getSlicing().getRules()!=null ? ed.getSlicing().getRules().toCode() : ""); } else { line.addValue(""); line.addValue(""); line.addValue(""); } if (ed.getBase()!=null) { line.addString(ed.getBase().getPath()); line.addValue(ed.getBase().getMin()); line.addValue(ed.getBase().getMax()); } else { line.addValue(""); line.addValue(""); line.addValue(""); } line.addString(itemList(ed.getCondition())); line.addString(itemList(ed.getConstraint())); for (StructureDefinitionMappingComponent mapKey : def.getMapping()) { for (ElementDefinitionMappingComponent map : ed.getMapping()) { if (map.getIdentity().equals(mapKey.getIdentity())) line.addString(map.getMap()); } } }
Example 9
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 10
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"); }