Java Code Examples for org.hl7.fhir.dstu3.model.ElementDefinition#hasFixed()
The following examples show how to use
org.hl7.fhir.dstu3.model.ElementDefinition#hasFixed() .
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 |
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: ShExGenerator.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
/** * Generate a type reference and optional value set definition * @param sd Containing StructureDefinition * @param ed Element being defined * @param typ Element type * @return Type definition */ private String simpleElement(StructureDefinition sd, ElementDefinition ed, String typ) { String addldef = ""; ElementDefinition.ElementDefinitionBindingComponent binding = ed.getBinding(); if(binding.hasStrength() && binding.getStrength() == Enumerations.BindingStrength.REQUIRED && "code".equals(typ)) { ValueSet vs = resolveBindingReference(sd, binding.getValueSet()); if (vs != null) { addldef = tmplt(VALUESET_DEFN_TEMPLATE).add("vsn", vsprefix(vs.getUrl())).render(); required_value_sets.add(vs); } } // TODO: check whether value sets and fixed are mutually exclusive if(ed.hasFixed()) { addldef = tmplt(FIXED_VALUE_TEMPLATE).add("val", ed.getFixed().primitiveValue()).render(); } return tmplt(SIMPLE_ELEMENT_DEFN_TEMPLATE).add("typ", typ).add("vsdef", addldef).render(); }
Example 3
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private boolean onlyInformationIsMapping(ElementDefinition d) { return !d.hasShort() && !d.hasDefinition() && !d.hasRequirements() && !d.getAlias().isEmpty() && !d.hasMinElement() && !d.hasMax() && !d.getType().isEmpty() && !d.hasContentReference() && !d.hasExample() && !d.hasFixed() && !d.hasMaxLengthElement() && !d.getCondition().isEmpty() && !d.getConstraint().isEmpty() && !d.hasMustSupportElement() && !d.hasBinding(); }
Example 4
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public Type getExampleValue(ElementDefinition ed) { if (ed.hasFixed()) return ed.getFixed(); if (ed.hasExample()) return ed.getExample().get(0).getValue(); else return null; }
Example 5
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
@Override public Type getExampleValue(ElementDefinition ed) { if (ed.hasFixed()) return ed.getFixed(); for (Extension ex : ed.getExtension()) { String ndx = ToolingExtensions.readStringExtension(ex, "index"); Type value = ToolingExtensions.getExtension(ex, "exValue").getValue(); if (index.equals(ndx) && value != null) return value; } return null; }
Example 6
Source File: ProfileUtilities.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private SpanEntry buildSpanEntryFromProfile(String name, String cardinality, StructureDefinition profile) throws IOException { SpanEntry res = new SpanEntry(); res.setName(name); res.setCardinality(cardinality); res.setProfileLink(profile.getUserString("path")); res.setResType(profile.getType()); StructureDefinition base = context.fetchResource(StructureDefinition.class, res.getResType()); if (base != null) res.setResLink(base.getUserString("path")); res.setId(profile.getId()); res.setProfile(profile.getDerivation() == TypeDerivationRule.CONSTRAINT); StringBuilder b = new StringBuilder(); b.append(res.getResType()); boolean first = true; boolean open = false; if (profile.getDerivation() == TypeDerivationRule.CONSTRAINT) { res.setDescription(profile.getName()); for (ElementDefinition ed : profile.getSnapshot().getElement()) { if (isKeyProperty(ed.getBase().getPath()) && ed.hasFixed()) { if (first) { open = true; first = false; b.append("["); } else { b.append(", "); } b.append(tail(ed.getBase().getPath())); b.append("="); b.append(summarise(ed.getFixed())); } } if (open) b.append("]"); } else res.setDescription("Base FHIR "+profile.getName()); res.setType(b.toString()); return res ; }
Example 7
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"); }