示例#1
0
 public void Setup()
 {
     Server = StaticTestData.StartupServer();
 }
示例#2
0
        public void Setup()
        {
            Server = StaticTestData.StartupServer();

            clientFhir         = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false);
            clientFhir.Timeout = 1000 * 720; // give the call a while to execute (particularly while debugging).

            //This Set up creates an Observation linked to a Patient as the 'subject' and an Organization as the 'performer'
            // Observation1
            //           --> Patient
            //           --> Organization - > Endpoint
            //           --> Observation2
            //                           ----> Observation3

            //Add a Endpoint resource
            //Loop only here for load testing
            for (int i = 0; i < 1; i++)
            {
                Endpoint EndpointOnex = new Endpoint();
                EndpointOnex.Name    = EndpointOneName;
                EndpointOneIdentifer = Guid.NewGuid().ToString();
                EndpointOnex.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, EndpointOneIdentifer));
                Endpoint EndPointOneResult = null;
                try
                {
                    EndPointOneResult = clientFhir.Create(EndpointOnex);
                }
                catch (Exception Exec)
                {
                    Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
                }
                Assert.NotNull(EndPointOneResult, "Resource created but returned resource is null");
                EndpointOneResourceId = EndPointOneResult.Id;
            }

            //Add a Endpoint resource
            Endpoint EndpointTwo = new Endpoint();

            EndpointTwo.Name = EndpointOneName;
            string EndpointTwoIdentifer = Guid.NewGuid().ToString();

            EndpointTwo.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, EndpointTwoIdentifer));
            Endpoint EndPointTwoResult = null;

            try
            {
                EndPointTwoResult = clientFhir.Create(EndpointTwo);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
            }
            Assert.NotNull(EndPointTwoResult, "Resource created but returned resource is null");
            string EndpointTwoResourceId = EndPointTwoResult.Id;



            //Add a Organization resource by Update
            Organization OrganizationOne = new Organization();

            OrganizationOne.Name     = OrganizationOneName;
            OrganizationOneIdentifer = Guid.NewGuid().ToString();
            OrganizationOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, OrganizationOneIdentifer));
            OrganizationOne.Endpoint = new List <ResourceReference>()
            {
                new ResourceReference($"{ResourceType.Endpoint.GetLiteral()}/{EndpointOneResourceId}")
            };
            Organization OrganizationOneResult = null;

            try
            {
                OrganizationOneResult = clientFhir.Create(OrganizationOne);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
            }
            Assert.NotNull(OrganizationOneResult, "Resource created but returned resource is null");
            OrganizationOneResourceId = OrganizationOneResult.Id;

            //Patient where Obs.performer -> Org.name
            // Add a Patient to Link to a Observation below  ================================
            //Loop only here for load testing debugging
            for (int i = 0; i < 10; i++)
            {
                Patient PatientOne = new Patient();
                PatientOne.Name.Add(HumanName.ForFamily(PatientOneFamily).WithGiven("Test"));
                PatientOne.BirthDateElement = new Date("1979-09-30");
                PatientOneMRNIdentifer      = Guid.NewGuid().ToString();
                PatientOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, PatientOneMRNIdentifer));
                PatientOne.Gender = AdministrativeGender.Unknown;
                PatientOne.ManagingOrganization = new ResourceReference($"{ResourceType.Organization.GetLiteral()}/{OrganizationOneResourceId}");
                Patient PatientResult = null;
                try
                {
                    PatientResult = clientFhir.Create(PatientOne);
                }
                catch (Exception Exec)
                {
                    Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
                }
                Assert.NotNull(PatientResult, "Resource created but returned resource is null");
                PatientResourceId = PatientResult.Id;
            }

            //Here we set up 3 observations linked in a chain Obs1 -> Obs2 - > Obs3 to test recursive includes

            // Add Observation 3 Linked to no other observation
            // This is to test recursive includes
            Observation ObsResourceThree = new Observation();

            ObsResourceThree.Status   = ObservationStatus.Final;
            ObsResourceThree.Code     = new CodeableConcept("http://somesystem.net/ObSystem", "WCC");
            ObservationThreeIdentifer = Guid.NewGuid().ToString();
            ObsResourceThree.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, ObservationTwoIdentifer));
            ObsResourceThree.Subject   = new ResourceReference($"{ResourceType.Patient.GetLiteral()}/{PatientResourceId}");
            ObsResourceThree.Performer = new List <ResourceReference>()
            {
                new ResourceReference($"{ResourceType.Organization.GetLiteral()}/{OrganizationOneResourceId}")
            };
            Observation ObservationThreeResult = null;

            try
            {
                ObservationThreeResult = clientFhir.Create(ObsResourceThree);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on Observation resource two create: " + Exec.Message);
            }
            Assert.NotNull(ObservationThreeResult, "Resource created but returned resource is null");
            ObservationThreeResourceId = ObservationThreeResult.Id;
            ObservationThreeResult     = null;


            // Add Observation 2 Linked to the Observation3 above and Patient above
            // This is to test recursive includes
            Observation ObsResourceTwo = new Observation();

            ObsResourceTwo.Status   = ObservationStatus.Final;
            ObsResourceTwo.Code     = new CodeableConcept("http://somesystem.net/ObSystem", "WCC");
            ObservationTwoIdentifer = Guid.NewGuid().ToString();
            ObsResourceTwo.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, ObservationTwoIdentifer));
            ObsResourceTwo.Subject   = new ResourceReference($"{ResourceType.Patient.GetLiteral()}/{PatientResourceId}");
            ObsResourceTwo.Performer = new List <ResourceReference>()
            {
                new ResourceReference($"{ResourceType.Organization.GetLiteral()}/{OrganizationOneResourceId}")
            };
            ObsResourceTwo.Related = new List <Observation.RelatedComponent>();
            var RelatedArtifact2 = new Observation.RelatedComponent();

            RelatedArtifact2.Target = new ResourceReference($"{ResourceType.Observation.GetLiteral()}/{ObservationThreeResourceId}");
            ObsResourceTwo.Related.Add(RelatedArtifact2);
            Observation ObservationTwoResult = null;

            try
            {
                ObservationTwoResult = clientFhir.Create(ObsResourceTwo);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on Observation resource two create: " + Exec.Message);
            }
            Assert.NotNull(ObservationTwoResult, "Resource created but returned resource is null");
            ObservationTwoResourceId = ObservationTwoResult.Id;
            ObservationTwoResult     = null;

            // Add Observation1 linked to Observation 2 above and the Patient above ================================
            Observation ObsResourceOne = new Observation();

            ObsResourceOne.Status   = ObservationStatus.Final;
            ObsResourceOne.Code     = new CodeableConcept("http://somesystem.net/ObSystem", "HB");
            ObservationOneIdentifer = Guid.NewGuid().ToString();
            ObsResourceOne.Identifier.Add(new Identifier(StaticTestData.TestIdentiferSystem, ObservationOneIdentifer));
            ObsResourceOne.Subject   = new ResourceReference($"{ResourceType.Patient.GetLiteral()}/{PatientResourceId}");
            ObsResourceOne.Performer = new List <ResourceReference>()
            {
                new ResourceReference($"{ResourceType.Organization.GetLiteral()}/{OrganizationOneResourceId}")
            };
            ObsResourceOne.Related = new List <Observation.RelatedComponent>();
            var RelatedArtifact1 = new Observation.RelatedComponent();

            RelatedArtifact1.Target = new ResourceReference($"{ResourceType.Observation.GetLiteral()}/{ObservationTwoResourceId}");
            ObsResourceOne.Related.Add(RelatedArtifact1);
            Observation ObservationOneResult = null;

            try
            {
                ObservationOneResult = clientFhir.Create(ObsResourceOne);
            }
            catch (Exception Exec)
            {
                Assert.True(false, "Exception thrown on resource Create: " + Exec.Message);
            }
            Assert.NotNull(ObservationOneResult, "Resource created but returned resource is null");
            ObservationOneResourceId = ObservationOneResult.Id;
            ObservationOneResult     = null;
        }