コード例 #1
0
        void Create_Fixed(ProfileGenerator p)
        {
            StructureDefinition profile = CreateObservation("Fixed");

            {
                ElementDefinition e = profile.Differential.Element.GetOrCreateElement("Observation.identifier");
                e.Min   = 0;
                e.Max   = "1";
                e.Fixed = new Identifier("fixedIdentifierSystem", "fixedIdentifierValue");
            }
            {
                ElementDefinition e = profile.Differential.Element.GetOrCreateElement("Observation.status");
                e.Fixed = new Code("cancelled");
                e.Min   = 1;
                e.Max   = "1";
            }
            {
                ElementDefinition e = profile.Differential.Element.GetOrCreateElement("Observation.code");
                e.Min   = 0;
                e.Max   = "1";
                e.Fixed = new CodeableConcept("codeSystem", "codeCode", "codeDisplay", "codeText");
            }

            SnapshotCreator.Create(profile);
            p.AddProfile(profile);
            profile.SaveJson($@"c:\Temp\{profile.Name}.json");
        }
コード例 #2
0
        /// <summary>
        /// Process one fhir element
        /// </summary>
        void ProcessFhirElement(SDefInfo sDefInfo)
        {
            const string fcn = "ProcessFhirElement";

            StructureDefinition sDef = sDefInfo.SDef;

            if (this.IgnoreResource(sDef.Url) == true)
            {
                return;
            }

            sDef.SaveJson(Path.Combine(this.GeneratedPath, $"{sDef.Id}.json"));

            String baseDefinition = sDef.BaseDefinition;

            switch (baseDefinition)
            {
            case null:
                this.DoProcessFhirElementSpecialization(sDefInfo);
                break;

            case "http://hl7.org/fhir/StructureDefinition/Extension":
                break;

            default:
                switch (sDef.Derivation)
                {
                case null:
                    return;

                case StructureDefinition.TypeDerivationRule.Specialization:
                    this.DoProcessFhirElementSpecialization(sDefInfo);
                    break;

                case StructureDefinition.TypeDerivationRule.Constraint:
                    //this.DoProcessFhirElementConstraint(sDefInfo);
                    break;

                default:
                    throw new ConvertErrorException(this.GetType().Name, fcn, $"Internal error. Unknown derivation {sDef.Derivation}");
                }
                break;
            }
        }
コード例 #3
0
        public void SlicedNested()
        {
            SliceGenerator sliceGen = new SliceGenerator(SliceGenerator.OutputLanguageType.CSharp,
                                                         OutputNameSpace,
                                                         GenDir);
            StructureDefinition profile = CreateObservation("SlicedNested");

            {
                ElementDefinition e = profile.Differential.Element.GetOrCreateElement("Observation.component");
                e.Slicing = new ElementDefinition.SlicingComponent
                {
                    ElementId = "ObservationComponentSlice",
                    Ordered   = false,
                    Rules     = ElementDefinition.SlicingRules.Open
                };
                e.Slicing.Discriminator.Add(new ElementDefinition.DiscriminatorComponent
                {
                    Type = ElementDefinition.DiscriminatorType.Value,
                    Path = "code"
                });
            }
            {
                ElementDefinition e = new ElementDefinition
                {
                    ElementId = "Observation.component:Slice1",
                    Path      = "Observation.component",
                    SliceName = "Slice1"
                };
                profile.Differential.Element.Add(e);
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    Path      = "Observation.component.code",
                    ElementId = "Observation.component:Slice1.code",
                    Fixed     = new CodeableConcept("system", "Slice3aCode")
                };
                profile.Differential.Element.Add(e);
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    Path      = "Observation.component.code.coding",
                    ElementId = "Observation.component:Slice1.code.coding",
                };
                profile.Differential.Element.Add(e);

                e.Slicing = new ElementDefinition.SlicingComponent
                {
                    ElementId = "ObservationComponentSlice1",
                    Ordered   = false,
                    Rules     = ElementDefinition.SlicingRules.Open
                };
                e.Slicing.Discriminator.Add(new ElementDefinition.DiscriminatorComponent
                {
                    Type = ElementDefinition.DiscriminatorType.Value,
                    Path = "code"
                });
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    Path      = "Observation.component.code.coding.code",
                    ElementId = "Observation.component:Slice1.code.coding.code",
                    Fixed     = new Code("Slice3aCode")
                };
                profile.Differential.Element.Add(e);
            }

            SnapshotCreator.Create(profile);
            String outputPath = $@"\Temp\SlicedNested.json";

            profile.SaveJson(outputPath);
            //FhirValidator f = new FhirValidator();
            //{
            //    bool success = f.Validate("4.0.0", outputPath);
            //    StringBuilder sb = new StringBuilder();
            //    f.FormatMessages(sb);
            //    Trace.WriteLine(sb.ToString());
            //    Assert.True(success == true);
            //}
            sliceGen.AddProfile(profile);
            {
                bool success = sliceGen.Process();

                StringBuilder sb = new StringBuilder();
                sliceGen.FormatMessages(sb);
                Trace.WriteLine(sb.ToString());
                Assert.True(success == true);
            }
        }
コード例 #4
0
        /// <summary>
        /// To save time, store all structure definitions in a fhir bundle file. This need only be run when we get a new
        /// FHIR version.
        /// </summary>
        public void StoreFhirElements()
        {
            const String fcn = "StoreFhirElements";

            // const String fcn = "StoreFhirElements";
            foreach (String f in Directory.GetFiles(this.bundleDir))
            {
                File.Delete(f);
            }

            foreach (String d in Directory.GetDirectories(this.bundleDir))
            {
                Directory.Delete(d, true);
            }

            {
                String rDir = Path.Combine(this.bundleDir, "StructDefs");
                if (Directory.Exists(rDir))
                {
                    Directory.Delete(rDir, true);
                }
            }
            String primitiveDir = Path.Combine(this.bundleDir, "StructDefs", "Primitive");

            Directory.CreateDirectory(primitiveDir);

            String logicalDir = Path.Combine(this.bundleDir, "StructDefs", "Logical");

            Directory.CreateDirectory(logicalDir);

            String complexDir = Path.Combine(this.bundleDir, "StructDefs", "Complex");

            Directory.CreateDirectory(complexDir);

            String resourceDir = Path.Combine(this.bundleDir, "StructDefs", "Resources");

            Directory.CreateDirectory(resourceDir);

            Bundle b = new Bundle();

            foreach (string uri in this.source.ListResourceUris())
            {
                StructureDefinition sDef = this.source.ResolveByUri(uri) as StructureDefinition;
                if (sDef != null)
                {
                    // This is to get rid of the http://....//de-... entries.
                    if (sDef.Snapshot.Element[0].Path.Split('.').Length == 1)
                    {
                        b.AddResourceEntry(sDef, sDef.Url);

                        switch (sDef.Kind)
                        {
#if FHIR_R4 || FHIR_R3
                        case StructureDefinition.StructureDefinitionKind.PrimitiveType:
                            sDef.SaveJson(Path.Combine(primitiveDir, $"{sDef.Name}.json"));
                            break;

                        case StructureDefinition.StructureDefinitionKind.ComplexType:
                            sDef.SaveJson(Path.Combine(complexDir, $"{sDef.Name}.json"));
                            break;
#endif
                        case StructureDefinition.StructureDefinitionKind.Logical:
                            sDef.SaveJson(Path.Combine(logicalDir, $"{sDef.Name}.json"));
                            break;

                        case StructureDefinition.StructureDefinitionKind.Resource:
                            sDef.SaveJson(Path.Combine(resourceDir, $"{sDef.Name}.json"));
                            break;

                        default:
                            throw new ConvertErrorException(this.GetType().Name, fcn, $"Invalid kind {sDef.Kind}. Item {sDef.Name}");
                        }
                    }
                }
            }
            b.SaveJson(this.bundlePath);
        }
コード例 #5
0
        void Create_SlicedMultiple(ProfileGenerator p)
        {
            StructureDefinition profile = CreateObservation("SlicedMultiple");

            {
                ElementDefinition e = profile.Differential.Element.GetOrCreateElement("Observation.component");
                e.Slicing = new ElementDefinition.SlicingComponent
                {
                    ElementId = "ObservationComponentSlice",
                    Ordered   = false,
                    Rules     = ElementDefinition.SlicingRules.Open
                };
                e.Slicing.Discriminator.Add(new ElementDefinition.DiscriminatorComponent
                {
                    Type = ElementDefinition.DiscriminatorType.Value,
                    Path = "code"
                });
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    ElementId = "Observation.component:Slice1",
                    Path      = "Observation.component",
                    SliceName = "Slice1"
                };
                profile.Differential.Element.Add(e);
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    Path      = "Observation.component.code",
                    ElementId = "Observation.component:Slice1.code",
                    Fixed     = new CodeableConcept("http://www.test.com/SliceSystem", "Slice1Code")
                };
                profile.Differential.Element.Add(e);
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    ElementId = "Observation.component:Slice2",
                    Path      = "Observation.component",
                    SliceName = "Slice2"
                };
                profile.Differential.Element.Add(e);
            }

            {
                ElementDefinition e = new ElementDefinition
                {
                    Path      = "Observation.component.code",
                    ElementId = "Observation.component:Slice2.code",
                    Fixed     = new CodeableConcept("http://www.test.com/SliceSystem", "Slice2Code")
                };
                profile.Differential.Element.Add(e);
            }

            SnapshotCreator.Create(profile);
            p.AddProfile(profile);
            profile.SaveJson($@"c:\Temp\SlicedMultiple.json");
        }