public void cleanUpDifferential(StructureDefinition sd) { if (sd.getDifferential().getElement().size() > 1) cleanUpDifferential(sd, 1); }
for (ElementDefinition ec : profile.getDifferential().getElement()) checkExtensions(profile, errors, "differential", ec); rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "missing Snapshot at "+profile.getName()+"."+profile.getName());
tgt.getSnapshot().getElementFirstRep().getType().clear(); if (tgt.hasDifferential()) tgt.getDifferential().getElementFirstRep().getType().clear(); if (tgt.getKind() == StructureDefinitionKind.PRIMITIVETYPE && !tgt.getType().equals(tgt.getId())) { tgt.setDerivation(TypeDerivationRule.SPECIALIZATION);
private void cleanUpDifferential(StructureDefinition sd, int start) { int level = Utilities.charCount(sd.getDifferential().getElement().get(start).getPath(), '.'); int c = start; int len = sd.getDifferential().getElement().size(); HashSet<String> paths = new HashSet<String>(); while (c < len && Utilities.charCount(sd.getDifferential().getElement().get(c).getPath(), '.') == level) { ElementDefinition ed = sd.getDifferential().getElement().get(c); if (!paths.contains(ed.getPath())) { paths.add(ed.getPath()); int ic = c+1; while (ic < len && Utilities.charCount(sd.getDifferential().getElement().get(ic).getPath(), '.') > level) ic++; ElementDefinition slicer = null; List<ElementDefinition> slices = new ArrayList<ElementDefinition>(); slices.add(ed); while (ic < len && Utilities.charCount(sd.getDifferential().getElement().get(ic).getPath(), '.') == level) { ElementDefinition edi = sd.getDifferential().getElement().get(ic); if (ed.getPath().equals(edi.getPath())) { if (slicer == null) { slicer.setPath(edi.getPath()); slicer.getSlicing().setRules(SlicingRules.OPEN); sd.getDifferential().getElement().add(c, slicer); c++; ic++; while (ic < len && Utilities.charCount(sd.getDifferential().getElement().get(ic).getPath(), '.') > level) ic++; if (c < len && Utilities.charCount(sd.getDifferential().getElement().get(c).getPath(), '.') > level) {
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); }
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); } } } }
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>()); }
tgt.setBase(src.getBaseDefinition()); tgt.setSnapshot(convertStructureDefinitionSnapshotComponent(src.getSnapshot())); tgt.setDifferential(convertStructureDefinitionDifferentialComponent(src.getDifferential())); if (tgt.hasBase()) { if (tgt.hasDifferential())
public void populateLogicalSnapshot(StructureDefinition sd) throws FHIRException { sd.getSnapshot().getElement().add(sd.getDifferential().getElementFirstRep().copy()); if (sd.hasBaseDefinition()) { StructureDefinition base = context.fetchResource(StructureDefinition.class, sd.getBaseDefinition()); if (base == null) throw new FHIRException("Unable to find base definition for logical model: "+sd.getBaseDefinition()+" from "+sd.getUrl()); copyElements(sd, base.getSnapshot().getElement()); } copyElements(sd, sd.getDifferential().getElement()); }
tgt.getDifferential().getElementFirstRep().getType().clear();
public XhtmlNode generateTable(String defFile, StructureDefinition profile, boolean diff, String imageFolder, boolean inlineGraphics, String profileBaseFileName, boolean snapshot, String corePath, String imagePath, boolean logicalModel, boolean allInvariants, Set<String> outputTracker) throws IOException, FHIRException { assert(diff != snapshot);// check it's ok to get rid of one of these HierarchicalTableGenerator gen = new HierarchicalTableGenerator(imageFolder, inlineGraphics); gen.setTranslator(getTranslator()); TableModel model = gen.initNormalTable(corePath, false); List<ElementDefinition> list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement(); List<StructureDefinition> profiles = new ArrayList<StructureDefinition>(); profiles.add(profile); genElement(defFile == null ? null : defFile+"#", gen, model.getRows(), list.get(0), list, profiles, diff, profileBaseFileName, null, snapshot, corePath, imagePath, true, logicalModel, profile.getDerivation() == TypeDerivationRule.CONSTRAINT && usesMustSupport(list), allInvariants); try { return gen.generate(model, imagePath, 0, outputTracker); } catch (org.hl7.fhir.exceptions.FHIRException e) { throw new FHIRException(e.getMessage(), e); } }
int diffCursor = 0; // we need a diff cursor because we can only look ahead, in the bound scoped by longer paths if (derived.hasDifferential() && !derived.getDifferential().getElementFirstRep().getPath().contains(".") && !derived.getDifferential().getElementFirstRep().getType().isEmpty()) throw new Error("type on first differential element!"); for (ElementDefinition e : derived.getDifferential().getElement()) e.clearUserData(GENERATED_IN_SNAPSHOT); processPaths("", derived.getSnapshot(), base.getSnapshot(), derived.getDifferential(), baseCursor, diffCursor, base.getSnapshot().getElement().size()-1, derived.getDifferential().hasElement() ? derived.getDifferential().getElement().size()-1 : -1, url, derived.getId(), null, null, false, base.getUrl(), null, false); if (!derived.getSnapshot().getElementFirstRep().getType().isEmpty()) throw new Error("type on first snapshot element for "+derived.getSnapshot().getElementFirstRep().getPath()+" in "+derived.getUrl()+" from "+base.getUrl()); for (ElementDefinition e : derived.getDifferential().getElement()) { if (!e.hasUserData(GENERATED_IN_SNAPSHOT)) { System.out.println("Error in snapshot generation: Snapshot for "+derived.getUrl()+" does not contain differential element with id: " + e.getId()); System.out.println("Differential: "); for (ElementDefinition ed : derived.getDifferential().getElement()) System.out.println(" "+ed.getPath()+" : "+typeSummary(ed)+"["+ed.getMin()+".."+ed.getMax()+"]"+sliceSummary(ed)+" id = "+ed.getId()); System.out.println("Snapshot: ");
public void setIds(StructureDefinition sd, boolean checkFirst) throws DefinitionException { if (!checkFirst || !sd.hasDifferential() || hasMissingIds(sd.getDifferential().getElement())) { if (!sd.hasDifferential()) sd.setDifferential(new StructureDefinitionDifferentialComponent()); generateIds(sd.getDifferential().getElement(), sd.getName()); } if (!checkFirst || !sd.hasSnapshot() || hasMissingIds(sd.getSnapshot().getElement())) { if (!sd.hasSnapshot()) sd.setSnapshot(new StructureDefinitionSnapshotComponent()); generateIds(sd.getSnapshot().getElement(), sd.getName()); } }
if (src.hasSnapshot()) tgt.setSnapshot(convertStructureDefinitionSnapshotComponent(src.getSnapshot())); tgt.setDifferential(convertStructureDefinitionDifferentialComponent(src.getDifferential())); return tgt;
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);
for (ElementDefinition ec : profile.getDifferential().getElement()) checkExtensions(profile, errors, "differential", ec); rule(errors, IssueType.STRUCTURE, profile.getId(), profile.hasSnapshot(), "missing Snapshot at "+profile.getName()+"."+profile.getName());
ElementDefinition ednew = sd.getDifferential().addElement(); ednew.setPath(var.getProperty().profileProperty.getDefinition().getPath()+"."+pc.getName()); ednew.setUserData("slice-name", sliceName);
case -1353885513: return getDerivationElement(); case 284874180: return getSnapshot(); case -1196150917: return getDifferential(); default: return super.makeProperty(hash, name);
tgt.setBase(src.getBaseDefinition()); tgt.setSnapshot(convertStructureDefinitionSnapshotComponent(src.getSnapshot())); tgt.setDifferential(convertStructureDefinitionDifferentialComponent(src.getDifferential())); if (tgt.hasBase()) { if (tgt.hasDifferential())
if (src.hasSnapshot()) tgt.setSnapshot(convertStructureDefinitionSnapshotComponent(src.getSnapshot())); tgt.setDifferential(convertStructureDefinitionDifferentialComponent(src.getDifferential())); return tgt;