Exemplo n.º 1
0
        public void Generate(StructureDefinition structure)
        {
            if (structure.Differential == null) throw Error.Argument("structure", "structure does not contain a differential specification");
            if (!structure.IsConstraint) throw Error.Argument("structure", "structure is not a constraint or extension");
            if(structure.Base == null) throw Error.Argument("structure", "structure is a constraint, but no base has been specified");

            var differential = structure.Differential;

            var baseStructure = _resolver.GetStructureDefinition(structure.Base);

            if (baseStructure == null) throw Error.InvalidOperation("Could not locate the base StructureDefinition for url " + structure.Base);
            if (baseStructure.Snapshot == null) throw Error.InvalidOperation("Snapshot generator required the base at {0} to have a snapshot representation", structure.Base);

            var snapshot = (StructureDefinition.SnapshotComponent)baseStructure.Snapshot.DeepCopy();
            generateBaseElements(snapshot.Element);
            var snapNav = new ElementNavigator(snapshot.Element);

            // Fill out the gaps (mostly missing parents) in the differential representation
            var fullDifferential = new DifferentialTreeConstructor(differential.Element).MakeTree();
            var diffNav = new ElementNavigator(fullDifferential);

            merge(snapNav, diffNav);
           
            structure.Snapshot = new StructureDefinition.SnapshotComponent() { Element = snapNav.ToListOfElements() };
        }
Exemplo n.º 2
0
        public ElementNavigator(StructureDefinition structure)
        {
            if (structure == null) throw Error.ArgumentNull("structure");
            if (structure.Snapshot == null) throw Error.Argument("structure", "structure must have a 'snapshot' representation included");
            if (structure.Snapshot.Element == null) throw Error.Argument("structure", "snapshot in structure does not have elements");

            setupElems(structure.Snapshot.Element);
            Structure = structure;
        }
Exemplo n.º 3
0
 public ElementDefinitionInfo Element_Period;                                                                                        // MakerGen.cs:217
                                                                                                                                     // MakerGen.cs:387
 public override void Write(Hl7.Fhir.Model.StructureDefinition sDef)                                                                 // MakerGen.cs:388
 {                                                                                                                                   // MakerGen.cs:389
     base.Write(sDef);                                                                                                               // MakerGen.cs:390
     sDef.Differential.Element.Add(new Hl7.Fhir.Model.ElementDefinition                                                              // MakerGen.cs:391
     {                                                                                                                               // MakerGen.cs:392
         Path      = "Address",                                                                                                      // MakerGen.cs:393
         ElementId = "Address"                                                                                                       // MakerGen.cs:394
     });                                                                                                                             // MakerGen.cs:395
     Element_Use.Write(sDef);                                                                                                        // MakerGen.cs:221
     Element_Type.Write(sDef);                                                                                                       // MakerGen.cs:221
     Element_Text.Write(sDef);                                                                                                       // MakerGen.cs:221
     Element_Line.Write(sDef);                                                                                                       // MakerGen.cs:221
     Element_City.Write(sDef);                                                                                                       // MakerGen.cs:221
     Element_District.Write(sDef);                                                                                                   // MakerGen.cs:221
     Element_State.Write(sDef);                                                                                                      // MakerGen.cs:221
     Element_PostalCode.Write(sDef);                                                                                                 // MakerGen.cs:221
     Element_Country.Write(sDef);                                                                                                    // MakerGen.cs:221
     Element_Period.Write(sDef);                                                                                                     // MakerGen.cs:221
 }                                                                                                                                   // MakerGen.cs:397
Exemplo n.º 4
0
        private static void generateSnapshotAndCompare(StructureDefinition original, ArtifactResolver source)
        {
            var generator = new SnapshotGenerator(source, markChanges: false);        

            var expanded = (StructureDefinition)original.DeepCopy();
            Assert.IsTrue(original.IsExactly(expanded));

            generator.Generate(expanded);
           
            var areEqual = original.IsExactly(expanded);

            if (!areEqual)
            {
                File.WriteAllText("c:\\temp\\snapshotgen-source.xml", FhirSerializer.SerializeResourceToXml(original));
                File.WriteAllText("c:\\temp\\snapshotgen-dest.xml", FhirSerializer.SerializeResourceToXml(expanded));
            }

            Assert.IsTrue(areEqual);
        }
Exemplo n.º 5
0
 public ElementDefinitionInfo Element_Scoring;                                                                                       // MakerGen.cs:217
                                                                                                                                     // MakerGen.cs:387
 public override void Write(Hl7.Fhir.Model.StructureDefinition sDef)                                                                 // MakerGen.cs:388
 {                                                                                                                                   // MakerGen.cs:389
     base.Write(sDef);                                                                                                               // MakerGen.cs:390
     sDef.Differential.Element.Add(new Hl7.Fhir.Model.ElementDefinition                                                              // MakerGen.cs:391
     {                                                                                                                               // MakerGen.cs:392
         Path      = "ProdCharacteristic",                                                                                           // MakerGen.cs:393
         ElementId = "ProdCharacteristic"                                                                                            // MakerGen.cs:394
     });                                                                                                                             // MakerGen.cs:395
     Element_Height.Write(sDef);                                                                                                     // MakerGen.cs:221
     Element_Width.Write(sDef);                                                                                                      // MakerGen.cs:221
     Element_Depth.Write(sDef);                                                                                                      // MakerGen.cs:221
     Element_Weight.Write(sDef);                                                                                                     // MakerGen.cs:221
     Element_NominalVolume.Write(sDef);                                                                                              // MakerGen.cs:221
     Element_ExternalDiameter.Write(sDef);                                                                                           // MakerGen.cs:221
     Element_Shape.Write(sDef);                                                                                                      // MakerGen.cs:221
     Element_Color.Write(sDef);                                                                                                      // MakerGen.cs:221
     Element_Imprint.Write(sDef);                                                                                                    // MakerGen.cs:221
     Element_Image.Write(sDef);                                                                                                      // MakerGen.cs:221
     Element_Scoring.Write(sDef);                                                                                                    // MakerGen.cs:221
 }                                                                                                                                   // MakerGen.cs:397
Exemplo n.º 6
0
 public ElementDefinitionInfo Element_Header;                                                                                        // MakerGen.cs:217
                                                                                                                                     // MakerGen.cs:387
 public override void Write(Hl7.Fhir.Model.StructureDefinition sDef)                                                                 // MakerGen.cs:388
 {                                                                                                                                   // MakerGen.cs:389
     base.Write(sDef);                                                                                                               // MakerGen.cs:390
     sDef.Differential.Element.Add(new Hl7.Fhir.Model.ElementDefinition                                                              // MakerGen.cs:391
     {                                                                                                                               // MakerGen.cs:392
         Path      = "Endpoint",                                                                                                     // MakerGen.cs:393
         ElementId = "Endpoint"                                                                                                      // MakerGen.cs:394
     });                                                                                                                             // MakerGen.cs:395
     Element_Identifier.Write(sDef);                                                                                                 // MakerGen.cs:221
     Element_Status.Write(sDef);                                                                                                     // MakerGen.cs:221
     Element_ConnectionType.Write(sDef);                                                                                             // MakerGen.cs:221
     Element_Name.Write(sDef);                                                                                                       // MakerGen.cs:221
     Element_ManagingOrganization.Write(sDef);                                                                                       // MakerGen.cs:221
     Element_Contact.Write(sDef);                                                                                                    // MakerGen.cs:221
     Element_Period.Write(sDef);                                                                                                     // MakerGen.cs:221
     Element_PayloadType.Write(sDef);                                                                                                // MakerGen.cs:221
     Element_PayloadMimeType.Write(sDef);                                                                                            // MakerGen.cs:221
     Element_Address.Write(sDef);                                                                                                    // MakerGen.cs:221
     Element_Header.Write(sDef);                                                                                                     // MakerGen.cs:221
 }                                                                                                                                   // MakerGen.cs:397
Exemplo n.º 7
0
 public ElementDefinitionInfo Element_Comment;                                                                                       // MakerGen.cs:217
                                                                                                                                     // MakerGen.cs:387
 public override void Write(Hl7.Fhir.Model.StructureDefinition sDef)                                                                 // MakerGen.cs:388
 {                                                                                                                                   // MakerGen.cs:389
     base.Write(sDef);                                                                                                               // MakerGen.cs:390
     sDef.Differential.Element.Add(new Hl7.Fhir.Model.ElementDefinition                                                              // MakerGen.cs:391
     {                                                                                                                               // MakerGen.cs:392
         Path      = "Slot",                                                                                                         // MakerGen.cs:393
         ElementId = "Slot"                                                                                                          // MakerGen.cs:394
     });                                                                                                                             // MakerGen.cs:395
     Element_Identifier.Write(sDef);                                                                                                 // MakerGen.cs:221
     Element_ServiceCategory.Write(sDef);                                                                                            // MakerGen.cs:221
     Element_ServiceType.Write(sDef);                                                                                                // MakerGen.cs:221
     Element_Specialty.Write(sDef);                                                                                                  // MakerGen.cs:221
     Element_AppointmentType.Write(sDef);                                                                                            // MakerGen.cs:221
     Element_Schedule.Write(sDef);                                                                                                   // MakerGen.cs:221
     Element_Status.Write(sDef);                                                                                                     // MakerGen.cs:221
     Element_Start.Write(sDef);                                                                                                      // MakerGen.cs:221
     Element_End.Write(sDef);                                                                                                        // MakerGen.cs:221
     Element_Overbooked.Write(sDef);                                                                                                 // MakerGen.cs:221
     Element_Comment.Write(sDef);                                                                                                    // MakerGen.cs:221
 }                                                                                                                                   // MakerGen.cs:397
Exemplo n.º 8
0
 private void testStructureDefinition(Model.StructureDefinition sd)
 {
     testBoolean(sd, sd, "StructureDefinition", "snapshot.element.tail().all(path.startsWith(%resource.snapshot.element.first().path&'.')) and differential.element.tail().all(path.startsWith(%resource.differential.element.first().path&'.'))", true);
 }
        private static StructureDefinition createTestStructure()
        {
            var struc = new StructureDefinition();
            struc.Snapshot = new StructureDefinition.StructureDefinitionSnapshotComponent();
            struc.Snapshot.Element = new List<ElementDefinition>();
            var e = struc.Snapshot.Element;

            e.Add(new ElementDefinition() { Path = "A" });
            e.Add(new ElementDefinition() { Path = "A.B" });
            e.Add(new ElementDefinition() { Path = "A.B.C1" });
            e.Add(new ElementDefinition() { Path = "A.B.C2" });
            e.Add(new ElementDefinition() { Path = "A.B" });
            e.Add(new ElementDefinition() { Path = "A.B" });
            e.Add(new ElementDefinition() { Path = "A.B.C1" });
            e.Add(new ElementDefinition() { Path = "A.B.C1.D" });
            e.Add(new ElementDefinition() { Path = "A.D" });
            return struc;
        }
        public void CopyChildTree()
        {
            var dest = createTestNav();

            var struc = new StructureDefinition();
            struc.Snapshot = new StructureDefinition.StructureDefinitionSnapshotComponent();
            struc.Snapshot.Element = new List<ElementDefinition>();
            var e = struc.Snapshot.Element;

            e.Add(new ElementDefinition() { Path = "X" });
            e.Add(new ElementDefinition() { Path = "X.Y1" });
            e.Add(new ElementDefinition() { Path = "X.Y2" });
            e.Add(new ElementDefinition() { Path = "X.Y2.Z1" });
            e.Add(new ElementDefinition() { Path = "X.Y2.Z2" });
            var source = new ElementNavigator(struc);

            Assert.IsTrue(dest.JumpToFirst("A.D"));
            var dstPos = dest.OrdinalPosition;

            source.MoveToFirstChild();
            var srcPos = source.OrdinalPosition;

            Assert.IsTrue(dest.CopyChildren(source));
            Assert.AreEqual(srcPos, source.OrdinalPosition, "source did not remain on original position");
            Assert.AreEqual(dstPos, dest.OrdinalPosition, "dest did not remain on original position");

            Assert.IsTrue(dest.MoveToFirstChild());
            Assert.AreEqual("Y1", dest.PathName);
            Assert.IsTrue(dest.MoveToNext());
            Assert.AreEqual("Y2", dest.PathName);
            Assert.IsFalse(dest.MoveToNext());
            Assert.IsTrue(dest.MoveToFirstChild());
            Assert.AreEqual("Z1", dest.PathName);
            Assert.IsTrue(dest.MoveToNext());
            Assert.AreEqual("Z2", dest.PathName);
            Assert.IsFalse(dest.MoveToNext());
        }
Exemplo n.º 11
0
        private static void generateSnapshotAndCompare(StructureDefinition original, ArtifactResolver source)
        {
            var generator = new SnapshotGenerator(source, markChanges: false);        

            var expanded = (StructureDefinition)original.DeepCopy();
            Assert.IsTrue(original.IsExactly(expanded));

            generator.Generate(expanded);

            // Simulate bug in Grahame's expander
            if (original.Snapshot.Element.Count == expanded.Snapshot.Element.Count)
            {
                for (var ix = 0; ix < expanded.Snapshot.Element.Count; ix++)
                {
                    if (original.Snapshot.Element[ix].Path == expanded.Snapshot.Element[ix].Path)
                    {
                        expanded.Snapshot.Element[ix].Min = original.Snapshot.Element[ix].Min;
                        expanded.Snapshot.Element[ix].MustSupport = original.Snapshot.Element[ix].MustSupport;
                    }
                }
            }
            
            var areEqual = original.IsExactly(expanded);

            if (!areEqual)
            {
                File.WriteAllText("c:\\temp\\snapshotgen-source.xml", FhirSerializer.SerializeResourceToXml(original));
                File.WriteAllText("c:\\temp\\snapshotgen-dest.xml", FhirSerializer.SerializeResourceToXml(expanded));
            }

            Assert.IsTrue(areEqual);
        }
Exemplo n.º 12
0
 public IEnumerable<ConceptMap> GetConceptMapsForSource(StructureDefinition source)
 {
     return GetConceptMapsForSource(source.Url);
 }