コード例 #1
0
        public IHttpActionResult UpdateStructureDefinition(
            [FromBody] StructureDefinition strucDef,
            [FromUri] string bookmark)
        {
            Template existingTemplate = this.tdb.Templates.SingleOrDefault(y => y.Bookmark.ToLower().Trim() == bookmark.ToLower().Trim());

            // Make sure the profile exists
            if (existingTemplate == null)
            {
                return(CreateErrorResponse(App_GlobalResources.TrifoliaLang.TemplateNotFoundMessageFormat));
            }

            if (!CheckPoint.Instance.GrantEditTemplate(existingTemplate.Id))
            {
                throw new UnauthorizedAccessException();
            }

            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            StructureDefinitionImporter importer = new StructureDefinitionImporter(this.tdb, uri.Scheme, uri.Authority);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);

            Template updatedTemplate;

            try
            {
                User author = CheckPoint.Instance.GetUser(this.tdb);
                updatedTemplate = importer.Convert(strucDef, existingTemplate, author);
            }
            catch (Exception ex)
            {
                return(CreateErrorResponse(ex.Message, OperationOutcome.IssueType.Exception));
            }

            if (existingTemplate == null)
            {
                this.tdb.Templates.Add(updatedTemplate);
            }

            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR3/StructureDefinition/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            updatedTemplate.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, updatedTemplate.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(updatedTemplate.PrimaryContextType);

            StructureDefinition updatedStrucDef = exporter.Convert(updatedTemplate, schema);

            return(Content <Resource>((existingTemplate == null ? HttpStatusCode.Created : HttpStatusCode.OK), updatedStrucDef, headers));
        }
コード例 #2
0
        public IHttpActionResult CreateStructureDefinition(
            [FromBody] StructureDefinition strucDef)
        {
            if (!string.IsNullOrEmpty(strucDef.Id))
            {
                OperationOutcome error = new OperationOutcome();
                error.Issue.Add(new OperationOutcome.IssueComponent()
                {
                    Severity    = OperationOutcome.IssueSeverity.Error,
                    Diagnostics = App_GlobalResources.TrifoliaLang.CreateFHIR2TemplateFailedDuplicateId
                });
                return(Content <OperationOutcome>(HttpStatusCode.BadRequest, error));
            }

            var foundProfile = this.tdb.Templates.SingleOrDefault(y => y.Oid == strucDef.Url);

            if (foundProfile != null)
            {
                OperationOutcome oo = new OperationOutcome()
                {
                    Issue = new List <OperationOutcome.IssueComponent> {
                        new OperationOutcome.IssueComponent()
                        {
                            Severity    = OperationOutcome.IssueSeverity.Error,
                            Code        = OperationOutcome.IssueType.Duplicate,
                            Diagnostics = "A StructureDefinition with the same url already exists. To update, use PUT."
                        }
                    }
                };

                return(Content <OperationOutcome>(HttpStatusCode.Created, oo));
            }

            var template = CreateTemplate(strucDef);

            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR3/StructureDefinition/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            template.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);
            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, template.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(template.PrimaryContextType);

            StructureDefinition newStrucDef = exporter.Convert(template, schema);

            return(Content <StructureDefinition>(HttpStatusCode.Created, newStrucDef, headers));
        }
コード例 #3
0
        public IHttpActionResult GetTemplate(
            [FromUri] string templateId,
            [FromUri(Name = "_summary")] SummaryType?summary = null)
        {
            Template template = this.tdb.Templates.SingleOrDefault(y => y.Oid == this.Request.RequestUri.AbsoluteUri || y.Id.ToString() == templateId);

            // Return an operation outcome indicating that the profile was not found
            if (template == null)
            {
                OperationOutcome oo = new OperationOutcome();
                oo.Issue.Add(new OperationOutcome.OperationOutcomeIssueComponent()
                {
                    Severity    = OperationOutcome.IssueSeverity.Fatal,
                    Diagnostics = "Profile was not found"
                });

                return(Content <OperationOutcome>(HttpStatusCode.NotFound, oo));
            }

            // Redirect the user to the Trifolia web interface if an acceptable format is text/html, and no format or summary was specified
            if (Request.Headers.Accept.Any(y => y.MediaType == "text/html") && summary == null)
            {
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Location", Request.RequestUri.Scheme + "://" + Request.RequestUri.Authority + "/TemplateManagement/View/Id/" + template.Id);

                OperationOutcome redirectOutcome = new OperationOutcome();
                redirectOutcome.Issue.Add(new OperationOutcome.OperationOutcomeIssueComponent()
                {
                    Severity    = OperationOutcome.IssueSeverity.Information,
                    Diagnostics = "Detecting browser-based request, redirecting to Trifolia web interface."
                });

                return(Content <OperationOutcome>(HttpStatusCode.Redirect, redirectOutcome, headers));
            }

            if (template.TemplateType.ImplementationGuideType != this.implementationGuideType)
            {
                throw new FormatException(App_GlobalResources.TrifoliaLang.TemplateNotFHIRSTU3);
            }

            if (!CheckPoint.Instance.GrantViewTemplate(template.Id))
            {
                throw new UnauthorizedAccessException();
            }

            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);
            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, template.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(template.PrimaryContextType);

            StructureDefinition strucDef = exporter.Convert(template, schema, summary);

            return(Content <StructureDefinition>(HttpStatusCode.OK, strucDef));
        }
コード例 #4
0
        public void STU3_StructureDefinitionExport()
        {
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(tdb, "http", "localhost");
            var structureDefinition = exporter.Convert(STU3Tests.template1, schema.GetSchemaFromContext(RESOURCE_TYPE_OBS));

            Assert.IsNotNull(structureDefinition);
            Assert.AreEqual("Test_Observation", structureDefinition.Id);
            Assert.AreEqual("Test Observation", structureDefinition.Name);
            Assert.AreEqual(DESCRIPTION, structureDefinition.Description.Value);
            Assert.AreEqual("http://test.com/StructureDefinition/1", structureDefinition.Url);
            Assert.IsNotNull(structureDefinition.Differential);
        }
コード例 #5
0
        public void STU3_TestChoiceWithTwoOptions()
        {
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(tdb, "http", "localhost");
            var structureDefinition = exporter.Convert(STU3Tests.template2, schema.GetSchemaFromContext(RESOURCE_TYPE_OBS));
            var xml = fhir_stu3.Hl7.Fhir.Serialization.FhirSerializer.SerializeToXml(structureDefinition);

            Assert.IsNotNull(structureDefinition);
            Assert.IsNotNull(structureDefinition.Differential);

            var diff = structureDefinition.Differential;

            Assert.AreEqual(6, diff.Element.Count);
            Assert.AreEqual("Observation", diff.Element[0].Path);

            var extension = diff.Element[1];

            Assert.AreEqual("Observation.extension", extension.Path);

            var valueChoice = diff.Element[2];

            Assert.AreEqual("Observation.extension.value[x]", valueChoice.ElementId);
            Assert.AreEqual("Observation.extension.value[x]", valueChoice.Path);
            Assert.IsNotNull(valueChoice.Slicing);
            Assert.IsNotNull(valueChoice.Slicing.Discriminator);
            Assert.AreEqual(1, valueChoice.Slicing.Discriminator.Count());
            Assert.AreEqual(1, valueChoice.Min);
            Assert.AreEqual("1", valueChoice.Max);

            var discriminator = valueChoice.Slicing.Discriminator.FirstOrDefault();

            Assert.IsNotNull(discriminator);
            Assert.AreEqual(fhir_stu3.Hl7.Fhir.Model.ElementDefinition.DiscriminatorType.Type, discriminator.Type);
            Assert.AreEqual("$this", discriminator.Path);

            var valueCodeableConcept = diff.Element[3];

            Assert.AreEqual("Observation.extension.value[x]:valueCodeableConcept", valueCodeableConcept.ElementId);
            Assert.AreEqual("Observation.extension.valueCodeableConcept", valueCodeableConcept.Path);
            Assert.AreEqual("valueCodeableConcept", valueCodeableConcept.SliceName);

            var valuePeriod = diff.Element[4];

            Assert.AreEqual("Observation.extension.value[x]:valuePeriod", valuePeriod.ElementId);
            Assert.AreEqual("Observation.extension.valuePeriod", valuePeriod.Path);
            Assert.AreEqual("valuePeriod", valuePeriod.SliceName);

            var start = diff.Element[5];

            Assert.AreEqual("Observation.extension.value[x]:valuePeriod.start", start.ElementId);
            Assert.AreEqual("Observation.extension.valuePeriod.start", start.Path);
            Assert.AreEqual("valuePeriod", start.SliceName);
        }
コード例 #6
0
        public IHttpActionResult CreateStructureDefinition(
            [FromBody] StructureDefinition strucDef)
        {
            var foundProfile = this.tdb.Templates.SingleOrDefault(y => y.Oid == strucDef.Url);

            if (foundProfile != null)
            {
                return(CreateErrorResponse(App_GlobalResources.TrifoliaLang.StructureDefinitionSameUrlExists, OperationOutcome.IssueType.Duplicate));
            }

            Template template;

            try
            {
                User author = CheckPoint.Instance.GetUser(this.tdb);

                template = CreateTemplate(strucDef, author);
                this.tdb.SaveChanges();
            }
            catch (Exception ex)
            {
                return(CreateErrorResponse(ex.Message, OperationOutcome.IssueType.Exception));
            }

            string location = string.Format("{0}://{1}/api/FHIR3/StructureDefinition/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            template.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);
            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, template.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(template.PrimaryContextType);

            StructureDefinition newStrucDef = exporter.Convert(template, schema);

            return(Content <StructureDefinition>(HttpStatusCode.Created, newStrucDef, headers));
        }
コード例 #7
0
        public void DSTU2_TestConvertExtension()
        {
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(StructureDefinitionControllerTest.mockRepo1, "http", "test.com");
            SimpleSchema schema = SimpleSchema.CreateSimpleSchema(
                Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                    new ImplementationGuideType()
            {
                Name           = Constants.IGTypeNames.FHIR_DSTU2,
                SchemaLocation = "fhir-all.xsd"
            }));

            StructureDefinition strucDef = exporter.Convert(StructureDefinitionControllerTest.profile1, schema);

            Assert.IsNotNull(strucDef);
            Assert.IsNotNull(strucDef.Extension);
            Assert.AreEqual(strucDef.Extension.Count, 4);

            // Extension 1
            Assert.AreEqual(strucDef.Extension[0].Url, "http://test.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[0].Value, typeof(FhirString));
            Assert.AreEqual(((FhirString)strucDef.Extension[0].Value).Value, "Test string extension value");

            // Extension 2
            Assert.AreEqual(strucDef.Extension[1].Url, "http://test2.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[1].Value, typeof(Date));
            Assert.AreEqual(((Date)strucDef.Extension[1].Value).Value, "2016234234234");

            // Extension 3
            Assert.AreEqual(strucDef.Extension[2].Url, "http://test3.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[2].Value, typeof(Coding));
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).Code, "xyz-123");
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).Display, "display");
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).System, "urn:oid:2.16.113");

            // Extension 4
            Assert.AreEqual(strucDef.Extension[3].Url, "http://test4.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[3].Value, typeof(CodeableConcept));
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding.Count, 1);
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].Code, "xyz-123");
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].Display, "display");
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].System, "urn:oid:2.16.113");
        }
コード例 #8
0
        public IHttpActionResult UpdateStructureDefinition(
            [FromBody] StructureDefinition strucDef,
            [FromUri] int templateId)
        {
            Template existingTemplate = this.tdb.Templates.SingleOrDefault(y => y.Id == templateId);

            if (!CheckPoint.Instance.GrantEditTemplate(templateId))
            {
                throw new UnauthorizedAccessException();
            }

            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            StructureDefinitionImporter importer = new StructureDefinitionImporter(this.tdb, uri.Scheme, uri.Authority);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);

            Template updatedTemplate = importer.Convert(strucDef, existingTemplate);

            if (existingTemplate == null)
            {
                this.tdb.Templates.AddObject(updatedTemplate);
            }

            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR2/StructureDefinition/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            updatedTemplate.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, updatedTemplate.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(updatedTemplate.PrimaryContextType);

            StructureDefinition updatedStrucDef = exporter.Convert(updatedTemplate, schema);

            return(Content <Resource>((existingTemplate == null ? HttpStatusCode.Created : HttpStatusCode.OK), updatedStrucDef, headers));
        }
コード例 #9
0
        public void STU3_TestCommentValue()
        {
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(tdb, "http", "localhost");
            var structureDefinition = exporter.Convert(STU3Tests.template3, schema.GetSchemaFromContext(RESOURCE_TYPE_OBS));
            var xml = fhir_stu3.Hl7.Fhir.Serialization.FhirSerializer.SerializeToXml(structureDefinition);

            Assert.IsNotNull(structureDefinition);
            Assert.IsNotNull(structureDefinition.Differential);

            var diff = structureDefinition.Differential;

            Assert.AreEqual(2, diff.Element.Count);
            Assert.AreEqual("Observation", diff.Element[0].Path);

            var comment = diff.Element[1];

            Assert.AreEqual("Observation.comment", comment.Path);
            Assert.AreEqual("Observation.comment", comment.ElementId);
            Assert.AreEqual(1, comment.Min);
            Assert.AreEqual("1", comment.Max);
            Assert.IsNull(comment.SliceName);
            Assert.IsNull(comment.Slicing);
        }
コード例 #10
0
ファイル: LatestTests.cs プロジェクト: yasir2000/trifolia
        public void Latest_TestChoiceWithOneOption()
        {
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(tdb, "http", "localhost");
            var structureDefinition = exporter.Convert(LatestTests.template1, schema.GetSchemaFromContext(RESOURCE_TYPE_OBS));
            var xml = fhir_latest.Hl7.Fhir.Serialization.FhirSerializer.SerializeToXml(structureDefinition);

            Assert.IsNotNull(structureDefinition);
            Assert.IsNotNull(structureDefinition.Differential);

            var diff = structureDefinition.Differential;

            Assert.AreEqual(4, diff.Element.Count);
            Assert.AreEqual("Observation", diff.Element[0].ElementId);
            Assert.AreEqual("Observation", diff.Element[0].Path);

            var extension = diff.Element[1];

            Assert.AreEqual("Observation.extension", extension.ElementId);
            Assert.AreEqual("Observation.extension", extension.Path);

            var valueChoice = diff.Element[2];

            Assert.AreEqual("Observation.extension.value[x]", valueChoice.ElementId);
            Assert.AreEqual("Observation.extension.value[x]", valueChoice.Path);
            Assert.IsNotNull(valueChoice.Slicing);
            Assert.IsNotNull(valueChoice.Slicing.Discriminator);
            Assert.AreEqual(1, valueChoice.Slicing.Discriminator.Count);
            Assert.AreEqual(fhir_latest.Hl7.Fhir.Model.ElementDefinition.DiscriminatorType.Type, valueChoice.Slicing.Discriminator[0].Type);
            Assert.AreEqual("$this", valueChoice.Slicing.Discriminator[0].Path);

            var valueCodeableConcept = diff.Element[3];

            Assert.AreEqual("Observation.extension.value[x]:valueCodeableConcept", valueCodeableConcept.ElementId);
            Assert.AreEqual("Observation.extension.valueCodeableConcept", valueCodeableConcept.Path);
            Assert.AreEqual("valueCodeableConcept", valueCodeableConcept.SliceName);
        }
コード例 #11
0
        public IHttpActionResult GetTemplates(
            [FromUri(Name = "_id")] int?templateId           = null,
            [FromUri(Name = "name")] string name             = null,
            [FromUri(Name = "_summary")] SummaryType?summary = null)
        {
            var uri       = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            var templates = this.tdb.Templates.Where(y => y.TemplateType.ImplementationGuideType == this.implementationGuideType);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);

            if (!CheckPoint.Instance.IsDataAdmin)
            {
                User currentUser = CheckPoint.Instance.GetUser(this.tdb);
                templates = (from t in templates
                             join vtp in this.tdb.ViewTemplatePermissions on t.Id equals vtp.TemplateId
                             where vtp.UserId == currentUser.Id
                             select t);
            }

            if (templateId != null)
            {
                templates = templates.Where(y => y.Id == templateId);
            }

            if (!string.IsNullOrEmpty(name))
            {
                templates = templates.Where(y => y.Name.ToLower().Contains(name.ToLower()));
            }

            Bundle bundle = new Bundle()
            {
                Type = Bundle.BundleType.BatchResponse
            };

            foreach (var template in templates)
            {
                SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, template.ImplementationGuideType);
                schema = schema.GetSchemaFromContext(template.PrimaryContextType);

                bool isMatch = true;
                StructureDefinition strucDef = exporter.Convert(template, schema, summary);
                var fullUrl = string.Format("{0}://{1}/api/FHIR2/StructureDefinition/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            template.Id);

                // Skip adding the structure definition to the response if a criteria rules it out
                foreach (var queryParam in this.Request.GetQueryNameValuePairs())
                {
                    if (queryParam.Key == "_id" || queryParam.Key == "name" || queryParam.Key == "_format" || queryParam.Key == "_summary")
                    {
                        continue;
                    }

                    if (queryParam.Key.Contains("."))
                    {
                        throw new NotSupportedException(App_GlobalResources.TrifoliaLang.FHIRSearchCriteriaNotSupported);
                    }

                    var propertyDef = strucDef.GetType().GetProperty(queryParam.Key, System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

                    if (propertyDef == null)
                    {
                        continue;
                    }

                    var value       = propertyDef.GetValue(strucDef);
                    var valueString = value != null?value.ToString() : string.Empty;

                    if (valueString != queryParam.Value)
                    {
                        isMatch = false;
                    }
                }

                if (isMatch)
                {
                    bundle.AddResourceEntry(strucDef, fullUrl);
                }
            }

            return(Content <Bundle>(HttpStatusCode.OK, bundle));
        }
コード例 #12
0
        public void TestConvertExtension()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

            mockRepo.InitializeFHIR3Repository();
            mockRepo.InitializeLCG();

            var ig       = mockRepo.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_FHIR_STU3_IG_TYPE_NAME, "Test IG");
            var template = mockRepo.GenerateTemplate("http://test.com/fhir/test", "Composition", "Test Composition", ig, "Composition", "Composition");

            template.Extensions.Add(new Trifolia.DB.TemplateExtension()
            {
                Identifier = "http://test.com/extension",
                Type       = "String",
                Value      = "Test string extension value"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()
            {
                Identifier = "http://test2.com/extension",
                Type       = "Date",
                Value      = "2016234234234" // Invalid date format, but should still be parsed by FHIR library
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()
            {
                Identifier = "http://test3.com/extension",
                Type       = "Coding",
                Value      = "xyz-123|display|urn:oid:2.16.113"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()
            {
                Identifier = "http://test4.com/extension",
                Type       = "CodeableConcept",
                Value      = "xyz-123|display|urn:oid:2.16.113"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()         // Extension has invalid value... It is skipped
            {
                Identifier = "http://test5.com/extension",
                Type       = "CodeableConcept",
                Value      = "test"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()         // Extension has invalid value... It is skipped
            {
                Identifier = "http://test6.com/extension",
                Type       = "Boolean",
                Value      = "test"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()         // Extension has invalid value... It is skipped
            {
                Identifier = "http://test7.com/extension",
                Type       = "Integer",
                Value      = "test"
            });

            StructureDefinitionExporter exporter = new StructureDefinitionExporter(mockRepo, "http", "test.com");
            SimpleSchema schema = SimpleSchema.CreateSimpleSchema(
                Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                    new ImplementationGuideType()
            {
                Name           = MockObjectRepository.DEFAULT_FHIR_STU3_IG_TYPE_NAME,
                SchemaLocation = "fhir-all.xsd"
            }));

            StructureDefinition strucDef = exporter.Convert(template, schema);

            Assert.IsNotNull(strucDef);
            Assert.IsNotNull(strucDef.Extension);
            Assert.AreEqual(strucDef.Extension.Count, 4);

            // Extension 1
            Assert.AreEqual(strucDef.Extension[0].Url, "http://test.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[0].Value, typeof(FhirString));
            Assert.AreEqual(((FhirString)strucDef.Extension[0].Value).Value, "Test string extension value");

            // Extension 2
            Assert.AreEqual(strucDef.Extension[1].Url, "http://test2.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[1].Value, typeof(Date));
            Assert.AreEqual(((Date)strucDef.Extension[1].Value).Value, "2016234234234");

            // Extension 3
            Assert.AreEqual(strucDef.Extension[2].Url, "http://test3.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[2].Value, typeof(Coding));
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).Code, "xyz-123");
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).Display, "display");
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).System, "urn:oid:2.16.113");

            // Extension 4
            Assert.AreEqual(strucDef.Extension[3].Url, "http://test4.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[3].Value, typeof(CodeableConcept));
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding.Count, 1);
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].Code, "xyz-123");
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].Display, "display");
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].System, "urn:oid:2.16.113");
        }
コード例 #13
0
        public void STU3_TestBranch()
        {
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(tdb, "http", "localhost");
            var structureDefinition = exporter.Convert(STU3Tests.template4, schema.GetSchemaFromContext(RESOURCE_TYPE_OBS));
            var xml = fhir_stu3.Hl7.Fhir.Serialization.FhirSerializer.SerializeToXml(structureDefinition);

            Assert.IsNotNull(structureDefinition);
            Assert.IsNotNull(structureDefinition.Differential);

            var diff = structureDefinition.Differential;

            Assert.AreEqual(8, diff.Element.Count);

            var referenceRangeSlice = diff.Element[1];

            Assert.AreEqual("Observation.referenceRange", referenceRangeSlice.ElementId);
            Assert.AreEqual("Observation.referenceRange", referenceRangeSlice.Path);
            Assert.IsNotNull(referenceRangeSlice.Slicing);
            Assert.IsNotNull(referenceRangeSlice.Slicing.Discriminator);
            Assert.AreEqual(1, referenceRangeSlice.Slicing.Discriminator.Count);
            Assert.AreEqual(fhir_stu3.Hl7.Fhir.Model.ElementDefinition.DiscriminatorType.Value, referenceRangeSlice.Slicing.Discriminator.First().Type);
            Assert.AreEqual("appliesTo", referenceRangeSlice.Slicing.Discriminator.First().Path);

            var referenceRangeSlice1 = diff.Element[2];

            Assert.AreEqual("Observation.referenceRange:referenceRange1", referenceRangeSlice1.ElementId);
            Assert.AreEqual("Observation.referenceRange", referenceRangeSlice1.Path);
            Assert.AreEqual("referenceRange1", referenceRangeSlice1.SliceName);
            Assert.AreEqual(1, referenceRangeSlice1.Min);
            Assert.AreEqual("1", referenceRangeSlice1.Max);

            var low1 = diff.Element[3];

            Assert.AreEqual("Observation.referenceRange:referenceRange1.low", low1.ElementId);
            Assert.AreEqual("Observation.referenceRange.low", low1.Path);
            Assert.AreEqual("referenceRange1", low1.SliceName);
            Assert.AreEqual(1, low1.Min);
            Assert.AreEqual("1", low1.Max);

            var appliesTo1 = diff.Element[4];

            Assert.AreEqual("Observation.referenceRange:referenceRange1.appliesTo", appliesTo1.ElementId);
            Assert.AreEqual("Observation.referenceRange.appliesTo", appliesTo1.Path);
            Assert.AreEqual("referenceRange1", appliesTo1.SliceName);
            Assert.AreEqual(1, appliesTo1.Min);
            Assert.AreEqual("1", appliesTo1.Max);
            Assert.IsNotNull(appliesTo1.Pattern);

            var referenceRangeSlice2 = diff.Element[5];

            Assert.AreEqual("Observation.referenceRange:referenceRange2", referenceRangeSlice2.ElementId);
            Assert.AreEqual("Observation.referenceRange", referenceRangeSlice2.Path);
            Assert.AreEqual("referenceRange2", referenceRangeSlice2.SliceName);
            Assert.AreEqual(1, referenceRangeSlice2.Min);
            Assert.AreEqual("1", referenceRangeSlice2.Max);

            var high2 = diff.Element[6];

            Assert.AreEqual("Observation.referenceRange:referenceRange2.high", high2.ElementId);
            Assert.AreEqual("Observation.referenceRange.high", high2.Path);
            Assert.AreEqual("referenceRange2", high2.SliceName);
            Assert.AreEqual(1, high2.Min);
            Assert.AreEqual("1", high2.Max);

            var appliesTo2 = diff.Element[7];

            Assert.AreEqual("Observation.referenceRange:referenceRange2.appliesTo", appliesTo2.ElementId);
            Assert.AreEqual("Observation.referenceRange.appliesTo", appliesTo2.Path);
            Assert.AreEqual("referenceRange2", appliesTo2.SliceName);
            Assert.AreEqual(1, appliesTo2.Min);
            Assert.AreEqual("1", appliesTo2.Max);
            Assert.IsNotNull(appliesTo2.Pattern);
        }