public void PatientCreationUpdateDeletion() { Patient patient = null !; "When creating a patient resource".x( async() => patient = await _client.CreateAsync( new Patient { Active = true, Name = { new HumanName { Family = "Tester", Given = new[]{ "Anne" }, Use = HumanName.NameUse.Usual } } }).ConfigureAwait(false)); "Then patient has id".x(() => Assert.NotNull(patient.Id)); "And patient can be updated".x( async() => { patient.BirthDateElement = new Date(1970, 1, 1); patient = await _client.UpdateAsync(patient).ConfigureAwait(false); Assert.NotNull(patient.BirthDate); }); "and can be found when searched".x( async() => { var p = await _client.SearchByIdAsync <Patient>(patient.Id).ConfigureAwait(false); Assert.NotEmpty(p.GetResources()); }); "When patient can be deleted".x( async() => { await _client.DeleteAsync(patient).ConfigureAwait(false); }); "Then cannot be found".x( async() => { var p = await _client.SearchByIdAsync <Patient>(patient.Id).ConfigureAwait(false); Assert.Empty(p.GetResources()); }); }
/// <summary> /// Get all patients of a given Practitioner /// </summary> /// <param name="practitionerId"></param> /// <returns> a list of Patients </returns> public static async Task <List <Models.Patient> > GetPatientsOfPractitioner(string practitionerId) { List <Models.Patient> patientList = new List <Models.Patient>(); SortedSet <string> patientIdList = new SortedSet <string>(); try { var encounterQuery = new SearchParams() .Where("participant.identifier=http://hl7.org/fhir/sid/us-npi|" + practitionerId) .Include("Encounter.participant.individual") .Include("Encounter.patient") .LimitTo(LIMIT_ENTRY); Bundle Result = await Client.SearchAsync <Encounter>(encounterQuery); // implement paging for HAPI FHIR API Bundle while (Result != null) { foreach (var Entry in Result.Entry) { // Get patient id and add to a list Encounter encounter = (Encounter)Entry.Resource; string patientRef = encounter.Subject.Reference; string patientId = patientRef.Split('/')[1]; patientIdList.Add(patientId); } Result = Client.Continue(Result, PageDirection.Next); } // fetch patient data from the list of patient ids foreach (var patientId in patientIdList) { Bundle PatientResult = await Client.SearchByIdAsync <Hl7.Fhir.Model.Patient>(patientId); if (PatientResult.Entry.Count > 0) { // Map the FHIR Patient object to App's Patient object Hl7.Fhir.Model.Patient fhirPatient = (Hl7.Fhir.Model.Patient)PatientResult.Entry[0].Resource; PatientMapper mapper = new PatientMapper(); Models.Patient patient = mapper.Map(fhirPatient); patientList.Add(patient); } } } catch (FhirOperationException FhirException) { System.Diagnostics.Debug.WriteLine("Fhir error message: " + FhirException.Message); } catch (Exception GeneralException) { System.Diagnostics.Debug.WriteLine("General error message: " + GeneralException.Message); } return(patientList); }
/// <summary> /// Get Patient by resource Id /// </summary> /// <param name="resourceId"></param> /// <returns>Patient</returns> public async Task <Patient> SearchByResourceIdAsync(string resourceId) { Patient result = null; var bundle = await _fhirClient.SearchByIdAsync <Patient>(resourceId).ConfigureAwait(false); if (bundle.Entry.Any()) { result = (Patient)bundle.Entry.First().Resource; } return(result); }
public void SearchAsync() { FhirClient client = new FhirClient(testEndpoint); Bundle result; result = client.SearchAsync <DiagnosticReport>().Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count() > 10, "Test should use testdata with more than 10 reports"); result = client.SearchAsync <DiagnosticReport>(pageSize: 10).Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count <= 10); var withSubject = result.Entry.ByResourceType <DiagnosticReport>().FirstOrDefault(dr => dr.Resource.Subject != null); Assert.IsNotNull(withSubject, "Test should use testdata with a report with a subject"); ResourceIdentity ri = new ResourceIdentity(withSubject.Id); result = client.SearchByIdAsync <DiagnosticReport>(ri.Id, includes: new string[] { "DiagnosticReport.subject" }).Result; Assert.IsNotNull(result); Assert.AreEqual(2, result.Entry.Count); // should have subject too Assert.IsNotNull(result.Entry.Single(entry => new ResourceIdentity(entry.Id).Collection == typeof(DiagnosticReport).GetCollectionName())); Assert.IsNotNull(result.Entry.Single(entry => new ResourceIdentity(entry.Id).Collection == typeof(Patient).GetCollectionName())); result = client.SearchAsync <Patient>(new string[] { "name=Everywoman", "name=Eve" }).Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count > 0); }
public void SearchAsync() { FhirClient client = new FhirClient(testEndpoint); Bundle result; result = client.SearchAsync<DiagnosticReport>().Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count() > 10, "Test should use testdata with more than 10 reports"); result = client.SearchAsync<DiagnosticReport>(pageSize: 10).Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count <= 10); var withSubject = result.Entry.ByResourceType<DiagnosticReport>().FirstOrDefault(dr => dr.Resource.Subject != null); Assert.IsNotNull(withSubject, "Test should use testdata with a report with a subject"); ResourceIdentity ri = new ResourceIdentity(withSubject.Id); result = client.SearchByIdAsync<DiagnosticReport>(ri.Id, includes: new string[] { "DiagnosticReport.subject" }).Result; Assert.IsNotNull(result); Assert.AreEqual(2, result.Entry.Count); // should have subject too Assert.IsNotNull(result.Entry.Single(entry => new ResourceIdentity(entry.Id).Collection == typeof(DiagnosticReport).GetCollectionName())); Assert.IsNotNull(result.Entry.Single(entry => new ResourceIdentity(entry.Id).Collection == typeof(Patient).GetCollectionName())); result = client.SearchAsync<Patient>(new string[] { "name=Everywoman", "name=Eve" }).Result; Assert.IsNotNull(result); Assert.IsTrue(result.Entry.Count > 0); }
/// <summary> /// Get Patient's single observation /// </summary> /// <param name="observationId">Observation resource Id</param> /// <returns>Observation</returns> public async Task <Observation> GetObservationAsync(string observationId) { var result = await _fhirClient.SearchByIdAsync <Observation>(observationId).ConfigureAwait(false); return(result.Entry.Select(entry => (Observation)entry.Resource).FirstOrDefault()); }
private async Task <Organization> GetOrganizationFromFHIRAsync(string id) { var bundle = await _client.SearchByIdAsync <Organization>(id).ConfigureAwait(false); return(((bundle.Entry != null) && (bundle.Entry.Count > 0)) ? (Organization)bundle.Entry[0].Resource : null); }