Ejemplo n.º 1
0
        public void TestGetTemplates()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

            mockRepo.InitializeFHIR3Repository();
            mockRepo.InitializeLCGAndLogin();

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

            HttpRequestMessage request = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost:8080/api/FHIR3/StructureDefinition")
            };
            HttpRequest  contextRequest  = new HttpRequest(null, "http://localhost:8080/api/FHIR3/StructureDefinition", null);
            HttpResponse contextResponse = new HttpResponse(new StringWriter());

            HttpContext.Current = new HttpContext(contextRequest, contextResponse);

            FHIR3StructureDefinitionController controller = new FHIR3StructureDefinitionController(mockRepo, request);
            var response = controller.GetTemplates();
            var result   = AssertHelper.IsType <NegotiatedContentResult <Bundle> >(response);

            Assert.IsNotNull(result.Content);
            Assert.AreEqual(1, result.Content.Entry.Count);

            var firstEntry = result.Content.Entry.First();

            Assert.AreEqual("http://localhost:8080/api/FHIR3/StructureDefinition/1", firstEntry.FullUrl);
            Assert.IsNotNull(firstEntry.Resource);

            var firstStrucDef = AssertHelper.IsType <StructureDefinition>(firstEntry.Resource);

            Assert.AreEqual("Test-Composition", firstStrucDef.Id);
        }
Ejemplo n.º 2
0
        public void TestFailedCreate_Id()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

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

            var strucDefJson             = Helper.GetSampleContents("Trifolia.Test.DocSamples.FHIR.STU3.cqif-questionnaire-strucdef.json");
            StructureDefinition strucDef = (StructureDefinition)FhirParser.ParseResourceFromJson(strucDefJson);

            strucDef.Id = "cqif-questionnaire";

            HttpRequestMessage request = new HttpRequestMessage();

            request.RequestUri = new Uri("http://localhost:8080/api/FHIR3/StructureDefinition");

            HttpRequest  contextRequest  = new HttpRequest(null, "http://localhost:8080/api/FHIR3/StructureDefinition", null);
            HttpResponse contextResponse = new HttpResponse(new StringWriter());

            HttpContext.Current = new HttpContext(contextRequest, contextResponse);

            FHIR3StructureDefinitionController controller = new FHIR3StructureDefinitionController(mockRepo, request);
            var response = controller.CreateStructureDefinition(strucDef);
            var result   = AssertHelper.IsType <NegotiatedContentResult <OperationOutcome> >(response);

            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);

            Assert.IsNotNull(result.Content);
            Assert.AreEqual(1, result.Content.Issue.Count);
        }
Ejemplo n.º 3
0
        public void TestSuccessfulCreate()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

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

            var strucDefJson             = Helper.GetSampleContents("Trifolia.Test.DocSamples.FHIR.STU3.cqif-questionnaire-strucdef.json");
            StructureDefinition strucDef = (StructureDefinition)FhirParser.ParseResourceFromJson(strucDefJson);

            HttpRequestMessage request = new HttpRequestMessage();

            request.RequestUri = new Uri("http://localhost:8080/api/FHIR3/StructureDefinition");

            HttpRequest  contextRequest  = new HttpRequest(null, "http://localhost:8080/api/FHIR3/StructureDefinition", null);
            HttpResponse contextResponse = new HttpResponse(new StringWriter());

            HttpContext.Current = new HttpContext(contextRequest, contextResponse);

            FHIR3StructureDefinitionController controller = new FHIR3StructureDefinitionController(mockRepo, request);
            var response = controller.CreateStructureDefinition(strucDef);
            var result   = AssertHelper.IsType <TrifoliaApiController.CustomHeadersWithContentResult <StructureDefinition> >(response);

            Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
            Assert.IsNotNull(result.CustomHeaders["Location"]);
            Assert.AreEqual(result.CustomHeaders["Location"], "http://localhost:8080/api/FHIR3/StructureDefinition/1");

            Assert.IsNotNull(result.Content);
            Assert.AreEqual(strucDef.Name, result.Content.Name);
        }
        public void STU3_TestSuccessfulCreate()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

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

            var parserSettings = new ParserSettings();

            parserSettings.AcceptUnknownMembers        = true;
            parserSettings.AllowUnrecognizedEnums      = true;
            parserSettings.DisallowXsiAttributesOnRoot = false;

            var strucDefJson             = Helper.GetSampleContents("Trifolia.Test.DocSamples.FHIR.STU3.cqif-questionnaire-strucdef.json");
            var fhirJsonParser           = new FhirJsonParser(parserSettings);
            StructureDefinition strucDef = fhirJsonParser.Parse <StructureDefinition>(strucDefJson);

            HttpRequestMessage request = new HttpRequestMessage();

            request.RequestUri = new Uri("http://localhost:8080/api/FHIR3/StructureDefinition");

            HttpRequest  contextRequest  = new HttpRequest(null, "http://localhost:8080/api/FHIR3/StructureDefinition", null);
            HttpResponse contextResponse = new HttpResponse(new StringWriter());

            HttpContext.Current = new HttpContext(contextRequest, contextResponse);

            FHIR3StructureDefinitionController controller = new FHIR3StructureDefinitionController(mockRepo, request);
            var response = controller.CreateStructureDefinition(strucDef);
            var result   = AssertHelper.IsType <TrifoliaApiController.CustomHeadersWithContentResult <StructureDefinition> >(response);

            Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
            Assert.IsNotNull(result.CustomHeaders["Location"]);
            Assert.AreEqual(result.CustomHeaders["Location"], "http://localhost:8080/api/FHIR3/StructureDefinition/1");

            Assert.IsNotNull(result.Content);
            Assert.AreEqual(strucDef.Name, result.Content.Name);
        }
Ejemplo n.º 5
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");
        }
Ejemplo n.º 6
0
        public static void SetupData(TestContext context)
        {
            tdb = new MockObjectRepository();
            tdb.InitializeFHIR3Repository();
            igType          = tdb.ImplementationGuideTypes.Single(y => y.Name == Constants.IGTypeNames.FHIR_STU3);
            compositionType = tdb.TemplateTypes.Single(y => y.ImplementationGuideType == igType && y.Name == "Composition");
            extensionType   = tdb.TemplateTypes.Single(y => y.ImplementationGuideType == igType && y.Name == "Extension");

            ig                   = tdb.FindOrCreateImplementationGuide(igType, "STU3 IG Publisher Build Package");
            ig.Identifier        = "http://test.com/ig";
            ig.WebDescription    = "This Implementation Guide (IG) defines a series of FHIR profiles on the Composition resource to represent the various document types in C - CDA.This release does not directly map every C - CDA template to FHIR profiles, rather tries to accomplish the C - CDA use case using Composition resource profiles created under this project(the equivalent of Level 2 CDA documents), and begins by linking to the profiles created under the US Core project for any coded entries that would normally be included in C - CDA sections.To have a simpler, more streamlined standard that reuses existing work and focuses on the 80 % that implementers actually need in production systems, the resources of US Core represents a portion of the 80 % needed for coded entries for coded entries of CCD, Care Plan and Discharge Summary).";
            ig.WebReadmeOverview = "We encourage feedback on these Composition profiles, and the general approach to the project as a whole. We also encourage implementers who wish to see more of the coded data from C - CDA mapped to FHIR to comment on the US Core project and make their requests known there.  Once US Core creates new profiles, this project can reference them.";

            tdb.CreateImplementationGuideSection(ig, "Test Heading", "Test Content", 1, level: 3);

            var CCDAonFHIRParticipantProfile = tdb.CreateTemplate(
                "http://test.com/ig/StructureDefinition/CCDA-on-FHIR-Participant",
                extensionType,
                "C-CDAonFHIRParticipant",
                ig,
                "Extension",
                "Extension",
                "C-CDA on FHIR Participant Extension");

            CCDAonFHIRParticipantProfile.Bookmark = "CCDA-on-FHIR-Participant";

            var CCDAonFHIRAuthorizationProfile = tdb.CreateTemplate(
                "http://test.com/ig/StructureDefinition/CCDA-on-FHIR-Authorization",
                extensionType,
                "C-CDAonFHIRAuthorization",
                ig,
                "Extension",
                "Extension",
                "C-CDA on FHIR Authorization Extension");

            CCDAonFHIRAuthorizationProfile.Bookmark = "CCDA-on-FHIR-Authorization";

            var USCorePatientProfile = tdb.CreateTemplate(
                "http://test.com/ig/StructureDefinition/us-core-patient",
                compositionType,
                "U.S.CorePatient",
                ig,
                "Composition",
                "Composition",
                "Defines basic constraints and extensions on the Patient resource for use with other US Core resources.");

            USCorePatientProfile.Bookmark = "us-core-patient";

            USCorePatientProfile.Author           = new User();
            USCorePatientProfile.Author.FirstName = "Sarah";
            USCorePatientProfile.Author.LastName  = "Gaunt";
            USCorePatientProfile.Author.Email     = "*****@*****.**";

            var USCorePractitionerProfile = tdb.CreateTemplate(
                "http://test.com/ig/StructureDefinition/us-core-practitioner",
                compositionType,
                "U.S.CorePractitioner",
                ig,
                "Composition",
                "Composition",
                "Defines basic constraints and extensions on the Practitioner resource for use with other US Core resources.");

            USCorePractitionerProfile.Bookmark = "us-core-practitioner";

            USCorePractitionerProfile.Author           = new User();
            USCorePractitionerProfile.Author.FirstName = "Eric";
            USCorePractitionerProfile.Author.LastName  = "Parapini";
            USCorePractitionerProfile.Author.Email     = "*****@*****.**";

            var USCoreOrganizationProfile = tdb.CreateTemplate(
                "http://test.com/ig/StructureDefinition/us-core-organization",
                compositionType,
                "U.S.CoreOrganization",
                ig,
                "Composition",
                "Composition",
                "Defines basic constraints and extensions on the Organization resource for use with other US Core resources.");

            USCoreOrganizationProfile.Bookmark = "us-core-organization";

            USCoreOrganizationProfile.Author           = new User();
            USCoreOrganizationProfile.Author.FirstName = "Meenaxi";
            USCoreOrganizationProfile.Author.LastName  = "Gosai";
            USCoreOrganizationProfile.Author.Email     = "*****@*****.**";

            var USRealmHeaderProfile = tdb.CreateTemplate(
                "http://test.com/ig/StructureDefinition/CCDA-on-FHIR-US-Realm-Header",
                compositionType,
                "US.RealmHeader",
                ig,
                "Composition",
                "Composition",
                "This profile defines constraints that represent common administrative and demographic concepts for US Realm clinical documents. Further specification, such as type, are provided in document profiles that conform to this profile.");

            USRealmHeaderProfile.Bookmark = "CCDA-on-FHIR-US-Realm-Header";                // This translates to the StructureDefinition.id, which is important

            USRealmHeaderProfile.Author           = new User();
            USRealmHeaderProfile.Author.FirstName = "Sean";
            USRealmHeaderProfile.Author.LastName  = "McIlvenna";
            USRealmHeaderProfile.Author.Email     = "*****@*****.**";

            // Add basic constraints to the  profile
            tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, null, "identifier", "SHALL", "1..1");
            tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, null, "date", "SHALL", "1..1");
            tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, null, "type", "SHALL", "1..1");
            tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, null, "title", "SHALL", "1..1");
            tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, null, "status", "SHALL", "1..1");
            tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, null, "language", "SHALL", "1..1");


            // Add a reference constraint to a contained profile
            TemplateConstraint t3tc1 = tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, USCorePatientProfile, "subject", "SHALL", "1..1");

            // Add a reference constraint to a contained profile
            TemplateConstraint t3tc2 = tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, USCorePractitionerProfile, "author", "SHALL", "1..1");

            // Add a reference constraint to a contained profile
            TemplateConstraint t3tc3 = tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, USCoreOrganizationProfile, "custodian", "SHALL", "1..1");

            // Constraint with a child (child has code system)
            CodeSystem         t1tc4_cs = tdb.FindOrCreateCodeSystem("FHIR CompositionAttestationMode", "http://hl7.org/fhir/composition-attestation-mode");
            TemplateConstraint t1tc4    = tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, null, "attester", "SHOULD", "0..1");
            TemplateConstraint t1tc4_2  = tdb.AddConstraintToTemplate(USRealmHeaderProfile, t1tc4, null, "mode", "SHALL", "1..1", "CE", "SHALL", "legal", null, codeSystem: t1tc4_cs);

            // Add an extension constraint with a contained profile
            TemplateConstraint t5tc1 = tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, CCDAonFHIRAuthorizationProfile, "extension", "SHALL", "1..1", "Extension");

            // Add a Constraint with a child (child has valueset)
            ValueSet           t1tc6_vs = tdb.FindOrCreateValueSet("v3-ConfidentialityClassification", "http://hl7.org/fhir/ValueSet/v3-ConfidentialityClassification");
            TemplateConstraint t1tc6    = tdb.AddConstraintToTemplate(USRealmHeaderProfile, null, null, "confidentiality", "SHALL", "1..1", "CE", "SHALL", null, null, valueSet: t1tc6_vs);

            extractDirectory = Path.Combine(context.TestDeploymentDir, dstu2ExtractFolder);
        }