public void MergeCode() { try { // should work. PreFhirGenerator p = this.CreatePreFhir(); StructureDefinition pBase = this.CreateBaseProfile(); StructureDefinition frag = this.CreateFragment("Fragment", "http://www.test.com/frag1"); // use snapshot min and max in base check. { ElementDefinition e = new ElementDefinition { Path = "Observation.category", ElementId = "Observation.category" }; e.Code.Add(new Coding("s-base", "c-base")); pBase.AddSnapElement(e); } String fragRoot = frag.Differential.Element[0].Path; { ElementDefinition e = new ElementDefinition { Path = $"{fragRoot}.category", ElementId = $"{fragRoot}.category", }; e.Code.Add(new Coding("s-frag", "c-frag")); frag.AddDiffElement(e); } pBase.AddFragRef(frag); p.AddFragment(pBase); p.AddFragment(frag); Assert.True(p.Process() == true); StringBuilder sb = new StringBuilder(); p.FormatMessages(sb); Trace.WriteLine(sb.ToString()); Assert.True(p.HasErrors == false); Assert.True(pBase.Differential.Element.Count == 2); { ElementDefinition category = pBase.Differential.Element[1]; Assert.True(category.Path == "Observation.category"); Assert.True(category.Code.Count == 2); Assert.True(category.Code[0].System == "s-base"); Assert.True(category.Code[1].System == "s-frag"); } } catch { Assert.False(true); } }
public void MergeTypes2() { try { PreFhirGenerator p = this.CreatePreFhir(); StructureDefinition pBase = this.CreateBaseProfile(); StructureDefinition frag = this.CreateFragment("Fragment", "http://www.test.com/frag1"); String fragRoot = frag.Differential.Element[0].Path; { ElementDefinition e = new ElementDefinition { Path = "Observation.value[x]", ElementId = "Observation.value[x]" }; e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "integer" }); e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "decimal" }); pBase.AddSnapElement(e); } { ElementDefinition e = new ElementDefinition { Path = $"{fragRoot}.value[x]", ElementId = $"{fragRoot}.value[x]", }; e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "string" }); frag.AddDiffElement(e); } pBase.AddFragRef(frag); p.AddFragment(pBase); p.AddFragment(frag); Assert.True(p.Process() == false); } catch { Assert.False(true); } }
public void MergeCardinalities4() { try { // should work. PreFhirGenerator p = this.CreatePreFhir(); StructureDefinition pBase = this.CreateBaseProfile(); StructureDefinition frag = this.CreateFragment("Fragment", "http://www.test.com/frag1"); pBase.AddSnapElement(new ElementDefinition { Path = "Observation.partOf", ElementId = "Observation.partOf", Min = 0, Max = "*", }); String fragRoot = frag.Differential.Element[0].Path; frag.AddDiffElement(new ElementDefinition { Path = $"{fragRoot}.partOf", ElementId = $"{fragRoot}.partOf", Min = 1, Max = "2", }); pBase.AddFragRef(frag); p.AddFragment(pBase); p.AddFragment(frag); Assert.True(p.Process() == true); StringBuilder sb = new StringBuilder(); p.FormatMessages(sb); Trace.WriteLine(sb.ToString()); Assert.True(p.HasErrors == false); Assert.True(pBase.Differential.Element.Count == 2); Assert.True(pBase.Differential.Element[1].Min == 1); Assert.True(pBase.Differential.Element[1].Max == "2"); } catch { Assert.False(true); } }
public static ElementDefinition AddSnapElement(this StructureDefinition sDef, String id, String propertyPath) { if (sDef is null) { throw new ArgumentNullException(nameof(sDef)); } ElementDefinition retVal = new ElementDefinition { ElementId = id, Min = 0, Max = "1", Path = propertyPath, Type = new List <ElementDefinition.TypeRefComponent>() }; sDef.AddSnapElement(retVal); return(retVal); }
public void MergeLabelErr() { try { // should work. PreFhirGenerator p = this.CreatePreFhir(); StructureDefinition pBase = this.CreateBaseProfile(); StructureDefinition frag = this.CreateFragment("Fragment", "http://www.test.com/frag1"); // use snapshot min and max in base check. pBase.AddSnapElement(new ElementDefinition { Path = "Observation.category", ElementId = "Observation.category", Label = "1234" }); String fragRoot = frag.Differential.Element[0].Path; { ElementDefinition e = new ElementDefinition { Path = $"{fragRoot}.category", ElementId = $"{fragRoot}.category", Label = "xxyyz" }; frag.AddDiffElement(e); } pBase.AddFragRef(frag); p.AddFragment(pBase); p.AddFragment(frag); Assert.True(p.Process() == false); } catch { Assert.False(true); } }
StructureDefinition CreateBaseProfile() { StructureDefinition pBase = new StructureDefinition { Abstract = false, Kind = StructureDefinition.StructureDefinitionKind.Resource, Name = "PreFhirTest", Type = "Observation", Description = new Markdown("PreFhir Test Base Profile"), Url = "http://www.test.com/PreFhirTest", BaseDefinition = "http://hl7.org/fhir/StructureDefinition/Observation", Differential = new StructureDefinition.DifferentialComponent() }; pBase.AddSnapElement(new ElementDefinition { Path = "Observation", ElementId = "Observation", Min = 0, Max = "*" }); return(pBase); }
public void MergeSlicing() { try { // should work. PreFhirGenerator p = this.CreatePreFhir(); StructureDefinition pBase = this.CreateBaseProfile(); StructureDefinition frag = this.CreateFragment("Fragment", "http://www.test.com/frag1"); // use snapshot min and max in base check. pBase.AddSnapElement(new ElementDefinition { Path = "Observation.category", ElementId = "Observation.category" }); String fragRoot = frag.Differential.Element[0].Path; { ElementDefinition e = new ElementDefinition { Path = $"{fragRoot}.category", ElementId = $"{fragRoot}.category", Slicing = new ElementDefinition.SlicingComponent { Description = "Slicing description", Ordered = true, Rules = ElementDefinition.SlicingRules.OpenAtEnd } }; e.Slicing.Discriminator.Add(new ElementDefinition.DiscriminatorComponent { Type = ElementDefinition.DiscriminatorType.Value, Path = "coding" }); frag.AddDiffElement(e); } pBase.AddFragRef(frag); p.AddFragment(pBase); p.AddFragment(frag); Assert.True(p.Process() == true); StringBuilder sb = new StringBuilder(); p.FormatMessages(sb); Trace.WriteLine(sb.ToString()); Assert.True(p.HasErrors == false); Assert.True(pBase.Differential.Element.Count == 2); { ElementDefinition category = pBase.Differential.Element[1]; Assert.True(category.Path == "Observation.category"); Assert.True(category.Slicing != null); Assert.True(category.Slicing.Discriminator.Count == 1); Assert.True(category.Slicing.Discriminator[0].Type == ElementDefinition.DiscriminatorType.Value); Assert.True(category.Slicing.Discriminator[0].Path == "coding"); Assert.True(category.Slicing.Description == "Slicing description"); Assert.True(category.Slicing.Ordered == true); Assert.True(category.Slicing.Rules == ElementDefinition.SlicingRules.OpenAtEnd); } } catch { Assert.False(true); } }
public void MergeFrag1() { try { // should work. PreFhirGenerator p = this.CreatePreFhir(); StructureDefinition pBase = this.CreateBaseProfile(); { ElementDefinition e = new ElementDefinition { Path = $"Observation.category", ElementId = $"Observation.category", Min = 0, Max = "*" }; pBase.AddSnapElement(e); } { ElementDefinition e = new ElementDefinition { Path = $"Observation.effective[x]", ElementId = $"Observation.effective[x]", Min = 0, Max = "*" }; e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "integer" }); e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "dateTime" }); pBase.AddSnapElement(e); } { ElementDefinition e = new ElementDefinition { Path = "Observation.value[x]", ElementId = "Observation.value[x]" }; pBase.AddSnapElement(e); e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "string" }); e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "decimal" }); e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "coding" }); } StructureDefinition frag1 = this.CreateFragment("Frag1", "http://www.test.com/frag1"); StructureDefinition frag2 = this.CreateFragment("Frag2", "http://www.test.com/frag2"); StructureDefinition frag3 = this.CreateFragment("Frag3", "http://www.test.com/frag3"); { ElementDefinition e = new ElementDefinition { Path = $"Frag1.value[x]", ElementId = $"Frag1.value[x]", }; e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "string" }); frag1.AddDiffElement(e); } { ElementDefinition e = new ElementDefinition { Path = $"Frag2.effective[x]", ElementId = $"Frag2.effective[x]", Min = 1 }; e.Type.Add(new ElementDefinition.TypeRefComponent { Code = "dateTime" }); frag2.AddDiffElement(e); } { ElementDefinition e = new ElementDefinition { Path = $"Frag3.category", ElementId = $"Frag3.category", Min = 1, Max = "1" }; frag3.AddDiffElement(e); } pBase.AddFragRef(frag1); frag1.AddFragRef(frag2); frag2.AddFragRef(frag3); p.AddFragment(pBase); p.AddFragment(frag1); p.AddFragment(frag2); p.AddFragment(frag3); Assert.True(p.Process() == true); StringBuilder sb = new StringBuilder(); p.FormatMessages(sb); Trace.WriteLine(sb.ToString()); Assert.True(p.HasErrors == false); Assert.True(frag2.Differential.Element.Count == 3); Assert.True(frag1.Differential.Element.Count == 4); Assert.True(pBase.Differential.Element.Count == 4); Assert.True(pBase.Differential.Element[1].Path == "Observation.category"); Assert.True(pBase.Differential.Element[2].Path == "Observation.effective[x]"); Assert.True(pBase.Differential.Element[2].Type.Count == 1); Assert.True(pBase.Differential.Element[2].Type[0].Code == "dateTime"); Assert.True(pBase.Differential.Element[3].Path == "Observation.value[x]"); Assert.True(pBase.Differential.Element[3].Type.Count == 1); Assert.True(pBase.Differential.Element[3].Type[0].Code == "string"); } catch { Assert.False(true); } }