예제 #1
0
        public void ReadRelativeAsync()
        {
            FhirClient client = new FhirClient(testEndpoint);

            var loc = client.ReadAsync <Location>(new Uri("Location/1", UriKind.Relative)).Result;

            Assert.IsNotNull(loc);
            Assert.AreEqual("Den Burg", loc.Resource.Address.City);

            var ri = ResourceIdentity.Build(testEndpoint, "Location", "1");

            loc = client.ReadAsync <Location>(ri).Result;
            Assert.IsNotNull(loc);
            Assert.AreEqual("Den Burg", loc.Resource.Address.City);
        }
예제 #2
0
        public async Task <ActionResult> GetPatientByIdAsync(int id)
        {
            var patient = await _client.ReadAsync <Patient>($"Patient/{id}");

            if (patient == null)
            {
                return(NotFound());
            }

            return(Ok(patient));
        }
        public async Task <IActionResult> GetDiagnosticByIdAsync(int id)
        {
            var diag = await _client.ReadAsync <Patient>($"DiagnosticReport/{id}");

            if (diag == null)
            {
                return(NotFound());
            }

            return(Ok(diag));
        }
예제 #4
0
        public async Task <IActionResult> GetPractitionerByIdAsync(string id)
        {
            var practitioner = await _client.ReadAsync <Practitioner>($"Practitioner/{id}");

            if (practitioner == null)
            {
                return(NotFound());
            }

            return(Ok(practitioner));
        }
예제 #5
0
        public async Task UpdateDelete_UsingResourceIdentity_ResultReturned()
        {
            var client = new FhirClient(_endpoint)
            {
                PreferredFormat    = ResourceFormat.Json,
                ReturnFullResource = true
            };

            var pat = new Patient()
            {
                Name = new List <HumanName>()
                {
                    new HumanName()
                    {
                        Given = new List <string>()
                        {
                            "test_given"
                        },
                        Family = new List <string>()
                        {
                            "test_family"
                        },
                    }
                },
                Id = "async-test-patient"
            };

            // Create the patient
            Console.WriteLine("Creating patient...");
            Patient p = await client.UpdateAsync <Patient>(pat);

            Assert.IsNotNull(p);

            // Refresh the patient
            Console.WriteLine("Refreshing patient...");
            await client.RefreshAsync(p);

            // Delete the patient
            Console.WriteLine("Deleting patient...");
            await client.DeleteAsync(p);

            Console.WriteLine("Reading patient...");
            Func <Task> act = async() =>
            {
                await client.ReadAsync <Patient>(new ResourceIdentity("/Patient/async-test-patient"));
            };

            // VERIFY //
            Assert.ThrowsException <FhirOperationException>(act, "the patient is no longer on the server");


            Console.WriteLine("Test Completed");
        }
예제 #6
0
        public async Task Read_UsingLocationString_ResultReturned()
        {
            var client = new FhirClient(_endpoint)
            {
                PreferredFormat    = ResourceFormat.Json,
                ReturnFullResource = true
            };

            Patient p = await client.ReadAsync <Patient>("/Patient/SMART-1288992");

            Assert.IsNotNull(p);
            Assert.IsNotNull(p.Name[0].Given);
            Assert.IsNotNull(p.Name[0].Family);
            Console.WriteLine($"NAME: {p.Name[0].Given.FirstOrDefault()} {p.Name[0].Family.FirstOrDefault()}");
            Console.WriteLine("Test Completed");
        }
        public async Task <GetPatient.Model> Handle(GetPatient.Query request, CancellationToken cancellationToken)
        {
            #region how nested Bundle was handled
            //var transaction = new TransactionBuilder(_client.Endpoint);

            //var patientById = new SearchParams()
            // .Where($"_id={request.PatientId}");

            //transaction.Search(patientById, "Patient");// went away from the transaction builder because it returned nested Bundles (which were handled successfullly, but no need to add complexity) and added an additional search to the server. Unclear if the Include method is also a serach but I should be much more effiecient. Also, not all servers support TransactionsBuilder.
            //transaction.Search(conception, "Observation");
            //var qResult = await _client.TransactionAsync(transaction.ToBundle());

            //var patBundle = (Bundle)qResult.Entry.First().Resource;
            //var pat = (Patient)patBundle.Entry.First().Resource;

            //var concpetionBundle = (Bundle)qResult.Entry[1].Resource;
            #endregion

            //var conception = new SearchParams()
            //                .Where($"subject={request.PatientId}")
            //                .Where("code=33067-0")//Fixed to ConceptionDate LOINC
            //                .LimitTo(1)//Incase there is more than one, though there shouldnt be, but I added two to the FHIR server to see what happens
            //                .Include("Observation:subject");//TODO: this will get all Observation infor from the server on Patient?

            var qResult = await client.ReadAsync <Patient>($"Patient/{request.PatientId}");

            //var conceptionObservation = (Observation)qResult.Entry[0].Resource;
            //var conceptionFhirDateTime = (FhirDateTime)conceptionObservation.Value;
            //var pat = (Patient)qResult.Entry[1].Resource;

            //Create map from FHIR Patient to your Patient.
            //Decided to see what it would be like if my Patient type inheirited FHIRs.
            var modelPatient = new LockStepPatient()
            {
                FhirPatient = qResult,
                LastName    = qResult.Name[0].Family,
            };
            modelPatient.GivenNames.AddRange(qResult.Name.SelectMany(n => n.GivenElement.Select(nm => nm.Value)));
            modelPatient.DateOfBirth = qResult.BirthDateElement.ToDateTimeOffset();
            return(new GetPatient.Model()
            {
                QueriedPatient = modelPatient
            });
        }
예제 #8
0
        public async Task <GetPatient.Model> Handle(GetPatient.Query request, CancellationToken cancellationToken)
        {
            var qResult = await client.ReadAsync <Patient>($"Patient/{request.PatientId}");

            //Create map from FHIR Patient to your Patient.
            //Decided to see what it would be like if my Patient type inheirited FHIRs.
            var modelPatient = new LockStepPatient()
            {
                FhirPatient = qResult,
                LastName    = qResult.Name[0].Family,
            };

            modelPatient.GivenNames.AddRange(qResult.Name.SelectMany(n => n.GivenElement.Select(nm => nm.Value)));
            modelPatient.DateOfBirth = qResult.BirthDateElement.ToDateTimeOffset();
            return(new GetPatient.Model()
            {
                QueriedPatient = modelPatient
            });
        }
예제 #9
0
		public void CreateEditDeleteAsync()
		{
			var furore = new Organization
			{
				Name = "Furore",
				Identifier = new List<Identifier> { new Identifier("http://hl7.org/test/1", "3141") },
				Telecom = new List<Contact> { new Contact { System = Contact.ContactSystem.Phone, Value = "+31-20-3467171" } }
			};

			FhirClient client = new FhirClient(testEndpoint);
			var tags = new List<Tag> { new Tag("http://nu.nl/testname", Tag.FHIRTAGSCHEME_GENERAL, "TestCreateEditDelete") };

			var fe = client.CreateAsync<Organization>(furore, tags: tags, refresh: true).Result;

			Assert.IsNotNull(furore);
			Assert.IsNotNull(fe);
			Assert.IsNotNull(fe.Id);
			Assert.IsNotNull(fe.SelfLink);
			Assert.AreNotEqual(fe.Id, fe.SelfLink);
			Assert.IsNotNull(fe.Tags);
			Assert.AreEqual(1, fe.Tags.Count(), "Tag count on new organization record don't match");
			Assert.AreEqual(fe.Tags.First(), tags[0]);
			createdTestOrganizationUrl = fe.Id;

			fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
			var fe2 = client.UpdateAsync(fe, refresh: true).Result;

			Assert.IsNotNull(fe2);
			Assert.AreEqual(fe.Id, fe2.Id);
			Assert.AreNotEqual(fe.SelfLink, fe2.SelfLink);
			Assert.AreEqual(2, fe2.Resource.Identifier.Count);

			Assert.IsNotNull(fe2.Tags);
			Assert.AreEqual(1, fe2.Tags.Count(), "Tag count on updated organization record don't match");
			Assert.AreEqual(fe2.Tags.First(), tags[0]);

			fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
			var fe3 = client.UpdateAsync(fe2.Id, fe.Resource, refresh: true).Result;
			Assert.IsNotNull(fe3);
			Assert.AreEqual(3, fe3.Resource.Identifier.Count);

			client.DeleteAsync(fe3).Wait();

			try
			{
				// Get most recent version
				fe = client.ReadAsync<Organization>(new ResourceIdentity(fe.Id)).Result;
				Assert.Fail();
			}
			catch
			{
				Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.Gone);
			}
		}
예제 #10
0
		public void ReadRelativeAsync()
		{
			FhirClient client = new FhirClient(testEndpoint);

			var loc = client.ReadAsync<Location>(new Uri("Location/1", UriKind.Relative)).Result;
			Assert.IsNotNull(loc);
			Assert.AreEqual("Den Burg", loc.Resource.Address.City);

			var ri = ResourceIdentity.Build(testEndpoint, "Location", "1");
			loc = client.ReadAsync<Location>(ri).Result;
			Assert.IsNotNull(loc);
			Assert.AreEqual("Den Burg", loc.Resource.Address.City);
		}
예제 #11
0
        public void CreateEditDeleteAsync()
        {
            var furore = new Organization
            {
                Name       = "Furore",
                Identifier = new List <Identifier> {
                    new Identifier("http://hl7.org/test/1", "3141")
                },
                Telecom = new List <Contact> {
                    new Contact {
                        System = Contact.ContactSystem.Phone, Value = "+31-20-3467171"
                    }
                }
            };

            FhirClient client = new FhirClient(testEndpoint);
            var        tags   = new List <Tag> {
                new Tag("http://nu.nl/testname", Tag.FHIRTAGSCHEME_GENERAL, "TestCreateEditDelete")
            };

            var fe = client.CreateAsync <Organization>(furore, tags: tags, refresh: true).Result;

            Assert.IsNotNull(furore);
            Assert.IsNotNull(fe);
            Assert.IsNotNull(fe.Id);
            Assert.IsNotNull(fe.SelfLink);
            Assert.AreNotEqual(fe.Id, fe.SelfLink);
            Assert.IsNotNull(fe.Tags);
            Assert.AreEqual(1, fe.Tags.Count(), "Tag count on new organization record don't match");
            Assert.AreEqual(fe.Tags.First(), tags[0]);
            createdTestOrganizationUrl = fe.Id;

            fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/2", "3141592"));
            var fe2 = client.UpdateAsync(fe, refresh: true).Result;

            Assert.IsNotNull(fe2);
            Assert.AreEqual(fe.Id, fe2.Id);
            Assert.AreNotEqual(fe.SelfLink, fe2.SelfLink);
            Assert.AreEqual(2, fe2.Resource.Identifier.Count);

            Assert.IsNotNull(fe2.Tags);
            Assert.AreEqual(1, fe2.Tags.Count(), "Tag count on updated organization record don't match");
            Assert.AreEqual(fe2.Tags.First(), tags[0]);

            fe.Resource.Identifier.Add(new Identifier("http://hl7.org/test/3", "3141592"));
            var fe3 = client.UpdateAsync(fe2.Id, fe.Resource, refresh: true).Result;

            Assert.IsNotNull(fe3);
            Assert.AreEqual(3, fe3.Resource.Identifier.Count);

            client.DeleteAsync(fe3).Wait();

            try
            {
                // Get most recent version
                fe = client.ReadAsync <Organization>(new ResourceIdentity(fe.Id)).Result;
                Assert.Fail();
            }
            catch
            {
                Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.Gone);
            }
        }