private void stashDifferentialStructure(Profile differential, Profile.ProfileStructureComponent structure) { structure.Name += "-differential"; structure.SetStructureForm(StructureForm.Differential); structure.SetStructureBaseUri(StructureLoader.BuildBaseStructureUri(structure.TypeElement).ToString()); structure.Publish = false; }
public Profile.ProfileStructureComponent Expand(Profile.ProfileStructureComponent differential) { var baseStructure = _loader.LocateBaseStructure(differential.TypeElement); if (baseStructure == null) { throw Error.InvalidOperation("Could not locate the base profile for type {0}", differential.TypeElement.ToString()); } var baseUri = StructureLoader.BuildBaseStructureUri(differential.TypeElement).ToString(); var snapshot = (Profile.ProfileStructureComponent)baseStructure.DeepCopy(); snapshot.SetStructureForm(StructureForm.Snapshot); snapshot.SetStructureBaseUri(baseUri.ToString()); mergeStructure(snapshot, differential); var fullDifferential = new DifferentialTreeConstructor(differential).MakeTree(); var snapNav = new ElementNavigator(snapshot); snapNav.MoveToFirstChild(); var diffNav = new ElementNavigator(fullDifferential); diffNav.MoveToFirstChild(); merge(snapNav, diffNav); //TODO: Merge search params? snapNav.CommitChanges(); return(snapshot); }
public static bool ExpandElement(this ElementNavigator nav, StructureLoader source) { if (source == null) { throw Error.ArgumentNull("source"); } if (nav.Current == null) { throw Error.ArgumentNull("Navigator is not positioned on an element"); } if (nav.Current.Definition == null) { throw Error.Argument("Cannot move down into element {0} since it has no element definition information", nav.Path); } if (nav.HasChildren) { return(true); // already has children, we're not doing anything extra } if (nav.Current.Definition != null) { var defn = nav.Current.Definition; if (!String.IsNullOrEmpty(defn.NameReference)) { var sourceNav = resolveNameReference(nav.Structure, defn.NameReference); nav.CopyChildren(sourceNav); } else if (defn.Type != null && defn.Type.Count > 0) { if (defn.Type.Count > 1) { throw new NotImplementedException("Don't know how to implement navigation into choice types yet at node " + nav.Path); } else { var sourceNav = resolveStructureReference(source, defn.Type[0].CodeElement); if (sourceNav != null) { sourceNav.MoveToFirstChild(); nav.CopyChildren(sourceNav); } else { throw new FileNotFoundException("Cannot locate base-structure for datatype " + defn.Type[0].Code); } } } return(true); } return(false); }
public void LocateStructure() { var locator = new StructureLoader(ArtifactResolver.CreateDefault()); var profileUri = new Uri("http://hl7.org/fhir/Profile/Profile"); var prof = locator.Locate(profileUri, new Code("Profile")); Assert.IsNotNull(prof); Assert.AreEqual("Profile", prof.Type); //Assert.AreEqual(profileUri.ToString(), prof.GetProfileLocation()); // Try to locate a structure that cannot be found in the given profile prof = locator.Locate(profileUri, new Code("Patient")); Assert.IsNull(prof); profileUri = new Uri("http://take.from.disk/Profile/example-lipid-profile"); var profileUriWithFrag = new Uri(profileUri.ToString() + "#lipidResultMessage"); prof = locator.Locate(profileUriWithFrag, new Code("MessageHeader")); Assert.IsNotNull(prof); Assert.AreEqual("MessageHeader", prof.Type); Assert.AreEqual("lipidResultMessage", prof.Name); //Assert.AreEqual(profileUri.ToString(), prof.GetProfileLocation()); // Try to locate a structure that cannot be found in the profile by name profileUriWithFrag = new Uri(profileUri.ToString() + "#XXX"); prof = locator.Locate(profileUriWithFrag, new Code("Profile")); Assert.IsNull(prof); }
public void TestExpandChild() { var loader = new StructureLoader(ArtifactResolver.CreateDefault()); var profStruct = loader.Locate(new Uri("http://hl7.org/fhir/Profile/Profile"), new Code("Profile")); var nav = new ElementNavigator(profStruct); nav.JumpToFirst("Profile.telecom"); Assert.IsTrue(nav.ExpandElement(loader)); Assert.IsTrue(nav.MoveToChild("period")); nav.JumpToFirst("Profile.extensionDefn.definition"); Assert.IsTrue(nav.ExpandElement(loader)); Assert.IsTrue(nav.MoveToChild("max")); }
private static ElementNavigator resolveStructureReference(StructureLoader loader, Code code) { var result = loader.LocateBaseStructure(code); return result != null ? new ElementNavigator(result) : null; }
public static bool ExpandElement(this ElementNavigator nav, StructureLoader source) { if(source == null) throw Error.ArgumentNull("source"); if(nav.Current == null) throw Error.ArgumentNull("Navigator is not positioned on an element"); if (nav.Current.Definition == null) throw Error.Argument("Cannot move down into element {0} since it has no element definition information", nav.Path); if(nav.HasChildren) return true; // already has children, we're not doing anything extra if (nav.Current.Definition != null) { var defn = nav.Current.Definition; if (!String.IsNullOrEmpty(defn.NameReference)) { var sourceNav = resolveNameReference(nav.Structure, defn.NameReference); nav.CopyChildren(sourceNav); } else if (defn.Type != null && defn.Type.Count > 0) { if (defn.Type.Count > 1) throw new NotImplementedException("Don't know how to implement navigation into choice types yet at node " + nav.Path); else { var sourceNav = resolveStructureReference(source, defn.Type[0].CodeElement); if (sourceNav != null) { sourceNav.MoveToFirstChild(); nav.CopyChildren(sourceNav); } else throw new FileNotFoundException("Cannot locate base-structure for datatype " + defn.Type[0].Code); } } return true; } return false; }
private static ElementNavigator resolveStructureReference(StructureLoader loader, Code code) { var result = loader.LocateBaseStructure(code); return(result != null ? new ElementNavigator(result) : null); }
public ProfileExpander(IArtifactSource source) { _loader = new StructureLoader(source); }
public ProfileExpander() { _loader = new StructureLoader(new CachedArtifactSource(ArtifactResolver.CreateDefault())); }
public StructureExpander(Profile.ProfileStructureComponent structure, StructureLoader loader) { Structure = structure; _loader = loader; }