示例#1
1
        public static async Task<List<Medication>> GetMedicationDataForPatientAsync(string patientId, FhirClient client)
        {
            var mySearch = new SearchParams();
            mySearch.Parameters.Add(new Tuple<string, string>("patient", patientId));

            try
            {
                //Query the fhir server with search parameters, we will retrieve a bundle
                var searchResultResponse = await Task.Run(() => client.Search<Hl7.Fhir.Model.MedicationOrder>(mySearch));
                //There is an array of "entries" that can return. Get a list of all the entries.
                return
                    searchResultResponse
                        .Entry
                            .AsParallel() //as parallel since we are making network requests
                            .Select(entry =>
                            {
                                var medOrders = client.Read<MedicationOrder>("MedicationOrder/" + entry.Resource.Id);
                                var safeCast = (medOrders?.Medication as ResourceReference)?.Reference;
                                if (string.IsNullOrWhiteSpace(safeCast)) return null;
                                return client.Read<Medication>(safeCast);
                            })
                            .Where(a => a != null)
                            .ToList(); //tolist to force the queries to occur now
            }
            catch (AggregateException e)
            {
                throw e.Flatten();
            }
            catch (FhirOperationException)
            {
                // if we have issues we likely got a 404 and thus have no medication orders...
                return new List<Medication>();
            }
        }
示例#2
0
        public void RetrievesResults()
        {
            var client = new FhirClient("https://apps.hdap.gatech.edu/gt-fhir/fhir");
            var query  = new SearchParams();

            var backPainCode = "279039007";

            query.Add("code", backPainCode);
            query.LimitTo(20);

            var bundle = client.Search <Condition>(query);

            foreach (Bundle.EntryComponent entry in bundle.Entry)
            {
                if (entry.Resource is Condition c)
                {
                    var patientString = c.Subject.Reference;
                    var id            = Regex.Match(patientString, @"\d+");
                    var patientQuery  = new string[] { $"_id={id.Value}" };

                    var patientBundle = client.Search <Patient>(patientQuery);
                    var patient       = patientBundle.Entry.First().Resource as Patient;

                    Assert.That(patient.Id, Is.EqualTo(id.Value));
                    Assert.That(c.Code.Coding.First().Code, Is.EqualTo(backPainCode));
                }
            }
        }
示例#3
0
        public Patient ReadHl7FHIRPatientByName(string name)
        {
            //var location = new Uri("https://aseecest3fhirservice.azurewebsites.net/Patient?name=" + name);
            //var patient = client.Read<Patient>(location);

            //SearchParameter pram = new SearchParameter();

            SearchParams prammer = new SearchParams("/Patient?name=Asbjørn", "0");
            Bundle       result  = client.Search(prammer);


            foreach (Bundle.EntryComponent component in result.Entry)
            {
                try
                {
                    Patient patient = (Patient)component.Resource;
                    Console.WriteLine(patient.Name[0].ToString());
                }
                catch (Exception e)
                {
                }
            }

            return(new Patient());
        }
示例#4
0
        public LabListViewModel GetLabRequests()
        {
            //var searchParams = new SearchParams(Parameters)
            string[] criteria           = new string[] { "requester:Practitioner=smart-Practitioner-71081332" };
            var      labRequestResponse = FhirClientObj.Search <ProcedureRequest>(criteria);

            return(GenerateLabListFromBundle(labRequestResponse));
        }
示例#5
0
        public Observation GetObservationById(string observationId)
        {
            var searchParameters = new SearchParams();

            searchParameters.Add("", observationId);
            var result = _client.Search(searchParameters, ResourceType.Observation.ToString());
            var ob     = result.Entry.Select(s => (Observation)s.Resource);

            return(null);
        }
示例#6
0
        private Bundle SearchPatient(string firstName, string lastName)
        {
            var q = new Query()
                    .For("Patient")
                    .Where($"name:exact={firstName}")
                    .Where($"family:exact={lastName}")
                    .SummaryOnly().Include("Patient.managingOrganization")
                    .LimitTo(20);

            return(client.Search(q));
        }
示例#7
0
        public IEnumerable <TimelineEntry> GetTimelineForPatient(string patientIdentifier)
        {
            var timeline = new List <TimelineEntry>();

            var matchingEncounters = _client.Search(ResourceType.Encounter, "subject.identifier", patientIdentifier);
            var matchingAlerts     = _client.Search(ResourceType.Alert, "subject.identifier", patientIdentifier);

            ProcessAlerts(timeline, matchingAlerts);
            ProcessEncounters(timeline, matchingEncounters);

            return(timeline.OrderBy(x => x.StartTime).ThenBy(x => x.EndTime));
        }
        public ActionResult MedicalHistory(string ID)
        {
            SearchViewModel           m             = new SearchViewModel();
            List <ConditionViewModel> conditionList = new List <ConditionViewModel>();

            var client = new FhirClient("http://fhirtest.uhn.ca/baseDstu1");

            //search patients based on patientID clicked
            Bundle resultsPatients = client.Search <Patient>(new string[] { "_id=" + ID });


            //gets patient based on ID
            foreach (var entry in resultsPatients.Entries)
            {
                ResourceEntry <Patient> patient = (ResourceEntry <Patient>)entry;

                m = getPatientInfo(patient);
            }

            Bundle resultsConditions = client.Search <Condition>(new string[] { "subject=" + ID });

            foreach (var entry in resultsConditions.Entries)
            {
                ConditionViewModel        conditions = new ConditionViewModel();
                ResourceEntry <Condition> condition  = (ResourceEntry <Condition>)entry;
                if (condition.Resource.Code != null)
                {
                    conditions.ConditionName = condition.Resource.Code.Text;
                }
                else
                {
                    conditions.ConditionName = "Unknown";
                }

                if (condition.Resource.Onset != null)
                {
                    conditions.Date = (condition.Resource.Onset as Date).Value;
                }
                else
                {
                    conditions.Date = "Unknown";
                }
                m.ConditionsCount++;
                conditionList.Add(conditions);
            }

            m.Conditions = conditionList;

            patients.Add(m);
            return(View(patients));
        }
        public void Search()
        {
            // an endpoint that is known to support compression
            FhirClient client = new FhirClient("http://sqlonfhir-dstu2.azurewebsites.net/fhir"); // testEndpoint);
            Bundle     result;

            client.CompressRequestBody = true;
            client.OnBeforeRequest    += Compression_OnBeforeRequestGZip;
            client.OnAfterResponse    += Client_OnAfterResponse;

            result = client.Search <DiagnosticReport>();
            client.OnAfterResponse -= Client_OnAfterResponse;
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entry.Count() > 10, "Test should use testdata with more than 10 reports");

            client.OnBeforeRequest -= Compression_OnBeforeRequestZipOrDeflate;
            client.OnBeforeRequest += Compression_OnBeforeRequestZipOrDeflate;

            result = client.Search <DiagnosticReport>(pageSize: 10);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entry.Count <= 10);

            client.OnBeforeRequest -= Compression_OnBeforeRequestGZip;

            var withSubject =
                result.Entry.ByResourceType <DiagnosticReport>().FirstOrDefault(dr => dr.Subject != null);

            Assert.IsNotNull(withSubject, "Test should use testdata with a report with a subject");

            ResourceIdentity ri = withSubject.ResourceIdentity();

            // TODO: The include on Grahame's server doesn't currently work
            //result = client.SearchById<DiagnosticReport>(ri.Id,
            //            includes: new string[] { "DiagnosticReport:subject" });
            //Assert.IsNotNull(result);

            //Assert.AreEqual(2, result.Entry.Count);  // should have subject too

            //Assert.IsNotNull(result.Entry.Single(entry => entry.Resource.ResourceIdentity().ResourceType ==
            //            typeof(DiagnosticReport).GetCollectionName()));
            //Assert.IsNotNull(result.Entry.Single(entry => entry.Resource.ResourceIdentity().ResourceType ==
            //            typeof(Patient).GetCollectionName()));


            client.OnBeforeRequest += Compression_OnBeforeRequestDeflate;

            result = client.Search <Patient>(new string[] { "name=Chalmers", "name=Peter" });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entry.Count > 0);
        }
        //
        // GET: /Patient/
        public ActionResult Index(string ID)
        {
            try
            {
                SearchViewModel m = new SearchViewModel();

                var client = new FhirClient("http://fhirtest.uhn.ca/baseDstu1");

                //search patients based on patientID clicked
                Bundle resultsPatients = client.Search <Patient>(new string[] { "_id=" + ID });

                //gets patient based on ID
                foreach (var entry in resultsPatients.Entries)
                {
                    ResourceEntry <Patient> patient = (ResourceEntry <Patient>)entry;

                    m = getPatientInfo(patient);
                }

                Bundle resultsAllergies = client.Search <AllergyIntolerance>(new string[] { "subject=" + ID });
                foreach (var entry in resultsAllergies.Entries)
                {
                    m.AllergiesCount++;
                }
                Bundle resultsMedications = client.Search <MedicationPrescription>(new string[] { "patient._id=" + ID });
                foreach (var entry in resultsMedications.Entries)
                {
                    m.MedicationCount++;
                }
                Bundle resultsConditions = client.Search <Condition>(new string[] { "subject=" + ID });
                foreach (var entry in resultsConditions.Entries)
                {
                    m.ConditionsCount++;
                }
                Bundle resultsDevices = client.Search <Device>(new string[] { "patient._id=" + ID });
                foreach (var entry in resultsDevices.Entries)
                {
                    m.DevicesCount++;
                }


                patients.Add(m);

                return(View(patients));
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult Medications(string ID)
        {
            SearchViewModel            m = new SearchViewModel();
            List <MedicationViewModel> medicationList = new List <MedicationViewModel>();

            var client = new FhirClient("http://fhirtest.uhn.ca/baseDstu1");

            //search patients based on patientID clicked
            Bundle resultsPatients = client.Search <Patient>(new string[] { "_id=" + ID });


            //gets patient based on ID
            foreach (var entry in resultsPatients.Entries)
            {
                ResourceEntry <Patient> patient = (ResourceEntry <Patient>)entry;

                m = getPatientInfo(patient);
            }

            Bundle resultsMedications = client.Search <MedicationPrescription>(new string[] { "patient._id=" + ID });

            foreach (var entry in resultsMedications.Entries)
            {
                m.MedicationCount++;
                MedicationViewModel meds = new MedicationViewModel();
                ResourceEntry <MedicationPrescription> medication = (ResourceEntry <MedicationPrescription>)entry;

                //get name of medication
                meds.MedicationName = medication.Resource.Medication.Display;

                //get date medication was prescribed
                if (medication.Resource.DateWrittenElement == null)
                {
                    meds.IsActive = "Unknown";
                }
                else
                {
                    meds.IsActive = medication.Resource.DateWrittenElement.Value;
                }
                medicationList.Add(meds);
            }

            m.Medications = medicationList;

            patients.Add(m);

            return(View(patients));
        }
示例#12
0
        // When btnSearchPatient is clicked, search patient
        private void btnSearchPatient_Click(object sender, EventArgs e)
        {
            // Edit status text
            searchStatus.Text = "Searching...";
            
            // Set FHIR endpoint and create client
            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client = new FhirClient(endpoint);

            // Search endpoint with a family name, input from searchFamName
            var query = new string[] { "family=" + searchFamName.Text };
            Bundle result = client.Search<Patient>(query);

            // Edit status text
            searchStatus.Text = "Got " + result.Entry.Count() + " records!";
            
            // Clear results labels
            label1.Text = "";
            label2.Text = "";

            // For every patient in the result, add name and ID to a label
            foreach (var entry in result.Entry)
            {
                Patient p = (Patient)entry.Resource;
                label1.Text = label1.Text + p.Id + "\r\n";
                label2.Text = label2.Text + p.BirthDate + "\r\n";
            }
        }
        /// <summary>
        /// Retrieves the Cholesterol values we're going to use to calculate one of the something something something
        /// </summary>
        /// <remarks>Send in an Id for a patient and the loinc code for the the type of Cholesterol you want returned.</remarks>
        /// <param name="loinc_CholesterolType"></param>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public CholesterolValue GetLatestCholesterolValue(string patientId, string loinc_CholesterolType)
        {
            //Loinc code is made up of the url to the source as well as the code number itself.
            string loinc_path = loinc_Url + loinc_CholesterolType;

            var query          = new string[] { string.Format("patient={0}", patientId), string.Format("code={0}", loinc_path) };
            var myObservations = FhirClient.Search <Observation>(query);


            List <CholesterolValue> valuesList = new List <CholesterolValue>();

            //Here we get all of the selected observations they'll let us have.
            // Fhir is supposed to use pagination so we should only get a limited set of what's available.
            // I'm assuming, for some reason, that the first ones to show up are the latest ones.
            foreach (Bundle.EntryComponent entry in myObservations.Entry)
            {
                CholesterolValue cholesterolValue = new CholesterolValue();

                Observation myObservation = (Hl7.Fhir.Model.Observation)entry.Resource;

                if (myObservation.Value is Hl7.Fhir.Model.Quantity valueQuantity)
                {
                    Quantity myQuantity = (Hl7.Fhir.Model.Quantity)myObservation.Value;

                    cholesterolValue.Value           = myQuantity.Value;
                    cholesterolValue.IssuedDate      = myObservation.Issued.Value.DateTime;
                    cholesterolValue.CholesterolType = loinc_CholesterolType;

                    valuesList.Add(cholesterolValue);
                }
            }

            //Sort by the issued date so the most recent is on the top and then select that one.
            return(valuesList.OrderByDescending(a => a.IssuedDate).FirstOrDefault());
        }
示例#14
0
 static void Main(string[] args)
 {
     var uri    = new Uri("");
     var client = new FhirClient(uri);
     var query  = new SearchParams();
     var result = client.Search(query);
 }
示例#15
0
        public List <Patient> getAllPatients()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            List <Patient> patients = new List <Patient>();

            Bundle results = client.Search <Patient>(); //todo error handling

            while (results != null)
            {
                foreach (var entry in results.Entry)
                {
                    Patient pat = (Patient)entry.Resource;
                    patients.Add(pat);
                }
                results = client.Continue(results);
            }

            stopwatch.Stop();
            var ts = stopwatch.Elapsed;

            log.logTimeSpan("getAllPatients()_from_server", ts, patients.Count);

            return(patients);
        }
示例#16
0
        public List <QuestionnaireResponse> getQRByPatientId(long id)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();


            List <QuestionnaireResponse> QRs = new List <QuestionnaireResponse>();

            Bundle results = client.Search <QuestionnaireResponse>(new string[] { "subject=Patient/" + id });

            while (results != null)
            {
                foreach (var entry in results.Entry)
                {
                    QuestionnaireResponse QR = (QuestionnaireResponse)entry.Resource;
                    QRs.Add(QR);
                }

                results = client.Continue(results);
            }
            stopwatch.Stop();
            var ts = stopwatch.Elapsed;

            log.logTimeSpan("getQRByPatientId(" + id.ToString() + ")_from_server", ts, QRs.Count);

            return(QRs);
        }
        public void SearchSync_UsingSearchParams_SearchReturned()
        {
            var client = new FhirClient(_endpoint)
            {
                PreferredFormat    = ResourceFormat.Json,
                ReturnFullResource = true
            };

            var srch = new SearchParams()
                       .Where("name=Daniel")
                       .LimitTo(10)
                       .SummaryOnly()
                       .OrderBy("birthdate",
                                SortOrder.Descending);

            var result1 = client.Search <Patient>(srch);

            Assert.IsTrue(result1.Entry.Count >= 1);

            while (result1 != null)
            {
                foreach (var e in result1.Entry)
                {
                    Patient p = (Patient)e.Resource;
                    Console.WriteLine(
                        $"NAME: {p.Name[0].Given.FirstOrDefault()} {p.Name[0].Family.FirstOrDefault()}");
                }
                result1 = client.Continue(result1, PageDirection.Next);
            }

            Console.WriteLine("Test Completed");
        }
示例#18
0
        public void Paging()
        {
            FhirClient client = new FhirClient(testEndpoint);

            var result = client.Search(ResourceType.DiagnosticReport, count: 10);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entries.Count <= 10);

            var firstId = result.Entries.First().Id;

            // Browse forward
            result = client.Continue(result);
            Assert.IsNotNull(result);
            var nextId = result.Entries.First().Id;

            Assert.AreNotEqual(firstId, nextId);

            // Browse backward
            //result = client.Continue(result, PageDirection.Previous);
            result = client.Continue(result, PageDirection.First);
            Assert.IsNotNull(result);
            var prevId = result.Entries.First().Id;

            Assert.AreEqual(firstId, prevId);
        }
示例#19
0
        public IEnumerable <Person> Get()
        {
            Bundle results = client.Search <Person>(new SearchParams().LimitTo(100));

            return(results.Entry.Select(x => x.Resource).Cast <Person>().ToList());
            //PersonDTO personDTO = new PersonDTO()
            //{
            //    Names = new List<PersonNameDTO>()
            //    {
            //        new PersonNameDTO(){ Family="Зубенко", Givens=new List<string>(){"Михаил"}, Use=HumanName.NameUse.Official},
            //        new PersonNameDTO(){  Givens=new List<string>(){"Мишаня"}, Use=HumanName.NameUse.Usual}
            //    },
            //    Birthday = "1921-12-12",
            //    Gender = AdministrativeGender.Male,
            //    Addresses = new List<PersonAddressDTO>()
            //    {
            //        new PersonAddressDTO(){City="Тернополь", Lines=new List<string>(){"улица Пушкина" } }
            //    },
            //    Telecoms = new List<PersonTelecomDTO>()
            //    {
            //        new PersonTelecomDTO(){System= ContactPoint.ContactPointSystem.Phone, Use=ContactPoint.ContactPointUse.Mobile, Value="911911911" },
            //        new PersonTelecomDTO(){System= ContactPoint.ContactPointSystem.Email, Use=ContactPoint.ContactPointUse.Work, Value="*****@*****.**" }

            //    }
            //};

            //return personDTO;
        }
示例#20
0
        /// <summary>
        /// Searches for the patient's name in the given public FHIR test server.
        /// </summary>
        /// <param name="searchString">String to search</param>
        public ICollection SearchExternalDatabase(string nameToSearch)
        {
            try
            {
                List <Patient> listPatientsSearchResult = new List <Patient>();
                var            client = new FhirClient(PUBLIC_FHIR_TEST_SERVICE_ENDPOINT);

                SearchParams p = new SearchParams();

                var query  = new string[] { "name=" + nameToSearch };
                var bundle = client.Search("Patient", query);

                foreach (var entry in bundle.Entry)
                {
                    var patient = PatientResourceToPatientMapper.MapToPatient(entry.Resource as Hl7.Fhir.Model.Patient);
                    listPatientsSearchResult.Add(patient);
                }

                return(listPatientsSearchResult);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#21
0
        /// <summary>
        /// Metoden finder en patient i HL7-Fhir databasen med det givne PCPR og returnere et patient objekt.
        /// </summary>
        /// <param name="CPR"></param>
        /// <returns></returns>
        public CoreEFTest.Models.Patient GetPatient(string CPR)
        {
            CoreEFTest.Models.Patient patient = null;

            var con = new SearchParams();

            con.Add("identifier", CPR);

            Bundle result = client.Search <Hl7.Fhir.Model.Patient>(con);

            foreach (Bundle.EntryComponent component in result.Entry)
            {
                patient = new CoreEFTest.Models.Patient();
                Hl7.Fhir.Model.Patient Hl7patient = (Hl7.Fhir.Model.Patient)component.Resource;

                patient.CPR      = Hl7patient.Identifier[0].Value;
                patient.Name     = Hl7patient.Name[0].Text;
                patient.Lastname = Hl7patient.Name[0].Family;
                //patient.Age = Convert.ToInt32(Hl7patient.BirthDate);
                patient.Adress  = Hl7patient.Address[0].District;
                patient.City    = Hl7patient.Address[0].City;
                patient.zipcode = Convert.ToInt32(Hl7patient.Address[0].PostalCode);
                break;
            }
            return(patient);
        }
示例#22
0
        private List <VITAL_SIGNS> buildVitalSigns(FhirClient iClient, Patient iPatient)
        {
            List <VITAL_SIGNS> results = new List <VITAL_SIGNS>();

            Bundle o = iClient.Search <Observation>(new string[] { "patient=" + iPatient.Id });

            foreach (var tempD in o.Entry)
            {
                Observation obs = (Observation)tempD.Resource;

                foreach (CodeableConcept cc in obs.Category)
                {
                    foreach (var code in cc.Coding)
                    {
                        if (code.Code == "vital-signs")
                        {
                            // build VITAL_SIGNS rec
                            ;

                            ;
                        }
                    }
                }
            }

            return(results);
        }
示例#23
0
        // When btnSearchPatient is clicked, search patient
        private void btnSearchPatient_Click(object sender, EventArgs e)
        {
            // Edit status text
            searchStatus.Text = "Searching...";

            // Set FHIR endpoint and create client
            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client   = new FhirClient(endpoint);

            // Search endpoint with a family name, input from searchFamName
            var    query  = new string[] { "family=" + searchFamName.Text };
            Bundle result = client.Search <Patient>(query);

            // Edit status text
            searchStatus.Text = "Got " + result.Entry.Count() + " records!";

            // Clear results labels
            label1.Text = "";
            label2.Text = "";

            // For every patient in the result, add name and ID to a label
            foreach (var entry in result.Entry)
            {
                Patient p = (Patient)entry.Resource;
                label1.Text = label1.Text + p.Id + "\r\n";
                label2.Text = label2.Text + p.BirthDate + "\r\n";
            }
        }
        public void PagingInJson()
        {
            FhirClient client = new FhirClient(testEndpoint);

            client.PreferredFormat = ResourceFormat.Json;

            var result = client.Search <DiagnosticReport>(pageSize: 10);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entry.Count <= 10);

            var firstId = result.Entry.First().Resource.Id;

            // Browse forward
            result = client.Continue(result);
            Assert.IsNotNull(result);
            var nextId = result.Entry.First().Resource.Id;

            Assert.AreNotEqual(firstId, nextId);

            // Browse to first
            result = client.Continue(result, PageDirection.First);
            Assert.IsNotNull(result);
            var prevId = result.Entry.First().Resource.Id;

            Assert.AreEqual(firstId, prevId);

            // Forward, then backwards
            result = client.Continue(result, PageDirection.Next);
            Assert.IsNotNull(result);
            result = client.Continue(result, PageDirection.Previous);
            Assert.IsNotNull(result);
            prevId = result.Entry.First().Resource.Id;
            Assert.AreEqual(firstId, prevId);
        }
示例#25
0
        public void Paging()
        {
            FhirClient client = new FhirClient(testEndpoint);

            var result = client.Search <DiagnosticReport>(count: 10);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entries.Count <= 10);

            var firstId = result.Entries.First().Id;

            // Browse forward
            result = client.Continue(result);
            Assert.IsNotNull(result);
            var nextId = result.Entries.First().Id;

            Assert.AreNotEqual(firstId, nextId);

            // Browse to first
            result = client.Continue(result, PageDirection.First);
            Assert.IsNotNull(result);
            var prevId = result.Entries.First().Id;

            Assert.AreEqual(firstId, prevId);

            // Forward, then backwards
            // Does not work on Grahame's server yet
            //Assert.IsNotNull(client.Continue(result,PageDirection.Next));
            //result = client.Continue(result, PageDirection.Previous);
            //Assert.IsNotNull(result);
            //prevId = result.Entries.First().Id;
            //Assert.AreEqual(firstId, prevId);
        }
示例#26
0
        private void button1_Click(object sender, EventArgs e)
        {
            var endpoint = new Uri("http://spark.furore.com/fhir");
            var client   = new FhirClient(endpoint);
            var query    = new string[] { "name=peter" };
            var bundle   = client.Search("Patient", query);

            button1.Text = "Got " + bundle.Entry.Count() + " records!";
            label3.Text  = "";
            foreach (var entry in bundle.Entry)
            {
                Patient      p          = (Patient)entry.Resource;
                HumanName[]  human      = p.Name.ToArray();
                string       firstname  = String.Join(" ", human[0].Given);
                string       familyname = String.Join(" ", human[0].Family);
                string       comment    = String.Join(" ", human[0].FhirComments);
                Identifier[] Id         = p.Identifier.ToArray();
                try
                {
                    label3.Text = label3.Text + Id[0].Value + "\r\n";
                }
                catch (Exception ex)
                {
                    label3.Text = label3.Text + "\r\n";
                }
            }
        }
        public List <Observation> getAllObservationsByPatId(long id)
        {
            List <Observation> newObservations = new List <Observation>();
            Bundle             results         = client.Search <Observation>(new string[] { "subject=Patient/" + id });

            while (results != null)
            {
                foreach (var entry in results.Entry)
                {
                    Observation obs = (Observation)entry.Resource;
                    newObservations.Add(obs);
                }

                results = client.Continue(results);
            }
            return(newObservations);
        }
示例#28
0
        /// <summary>
        /// To get patient Allergies with the help of global Patient object
        /// </summary>
        public void getPatientAllergies()
        {
            try
            {
                SearchParams searchParams = new SearchParams();

                searchParams.Add("patient", Generalinformation.Id);

                searchParams.Add("_count", "20");

                Bundle bd = _fc.Search <AllergyIntolerance>(searchParams);

                bool isCountOver = false;

                while (!isCountOver)
                {
                    if (bd.NextLink == null)
                    {
                        isCountOver = true;
                    }

                    foreach (Bundle.EntryComponent et in bd.Entry)
                    {
                        if (et.Resource.ResourceType == ResourceType.AllergyIntolerance)
                        {
                            Allergies.Add((AllergyIntolerance)et.Resource);
                        }
                    }

                    bd = _fc.Continue(bd);
                }
            }
            catch (FhirOperationException foe)
            {
                isExceptionEncountered = true;
                ExceptionIssues        = foe.Outcome.Issue;
            }
            catch (Exception ex)
            {
                isExceptionEncountered = true;
                OperationOutcome.IssueComponent ic = new OperationOutcome.IssueComponent();
                ic.Diagnostics = ex.Message;
                ExceptionIssues.Add(ic);
            }
        }
示例#29
0
        public static string Search(this FhirClient client, Query query)
        {
            var searchquery = query.ToSearchParams();
            var bundle      = client.Search(searchquery, query.From);
            var navigators  = bundle.GetNavigators();
            var projections = navigators.QuerySelect(query);

            return(projections.ToJson());
        }
        public void TestSearchByPersonaCode()
        {
            var client = new FhirClient(testEndpoint);

            var pats =
                client.Search <Patient>(
                    new[] { string.Format("identifier={0}|{1}", "urn:oid:1.2.36.146.595.217.0.1", "12345") });
            var pat = (Patient)pats.Entry.First().Resource;
        }
示例#31
0
        public string SearchPatientsMedication(string patientID)
        {
            IList <string> listOfMedications = new List <string>();

            //First we need to set up the Search Param Object
            SearchParams mySearch = new SearchParams();

            //Create a tuple containing search parameters for SearchParam object
            // equivalent of "MedicationOrder?patient=6116";
            Tuple <string, string> mySearchTuple = new Tuple <string, string>("patient", patientID);

            mySearch.Parameters.Add(mySearchTuple);

            //Query the fhir server with search parameters, we will retrieve a bundle
            var searchResultResponse = fhirClient.Search <Hl7.Fhir.Model.MedicationOrder>(mySearch);

            //There is an array of "entries" that can return. Get a list of all the entries.
            var listOfentries = searchResultResponse.Entry;

            if (listOfentries.Count == 0)
            {
                return("No Medication Order entries found on the FHIR server for PatientID: " + patientID);
            }



            //Initializing in for loop is not the greatest.
            foreach (var entry in listOfentries)
            {
                //The entries we have, do not contain the medication reference.

                var medicationOrderResource = fhirClient.Read <Hl7.Fhir.Model.MedicationOrder>("MedicationOrder/" + entry.Resource.Id);

                //Casted this because ((ResourceReference)medicationOrderResource.Medication).Reference
                //is not pretty as a parameter
                ResourceReference castedResourceReference = (ResourceReference)medicationOrderResource.Medication;

                var medicationResource = fhirClient.Read <Hl7.Fhir.Model.Medication>(castedResourceReference.Reference);

                CodeableConcept castedCodeableConcept = medicationResource.Code;
                List <Coding>   listOfCodes           = castedCodeableConcept.Coding;


                foreach (var c in listOfCodes)
                {
                    listOfMedications.Add(c.Code);
                }
            }
            string returnResult = String.Empty;

            foreach (var m in listOfMedications)
            {
                returnResult += m + "\n"; //Stringbuilder class would be better
            }

            return(returnResult);
        }
        public ActionResult Allergies(string ID)
        {
            SearchViewModel         m           = new SearchViewModel();
            List <AllergyViewModel> allergyList = new List <AllergyViewModel>();

            var client = new FhirClient("http://fhirtest.uhn.ca/baseDstu1");

            //get patient basic info
            Bundle resultsPatients = client.Search <Patient>(new string[] { "_id=" + ID });

            foreach (var entry in resultsPatients.Entries)
            {
                ResourceEntry <Patient> patient = (ResourceEntry <Patient>)entry;

                m = getPatientInfo(patient);
            }

            //get patient allergy information
            Bundle resultsAllergies = client.Search <AllergyIntolerance>(new string[] { "subject=" + ID });

            foreach (var entry in resultsAllergies.Entries)
            {
                AllergyViewModel allergies = new AllergyViewModel();
                ResourceEntry <AllergyIntolerance> allergy = (ResourceEntry <AllergyIntolerance>)entry;
                allergies.AllergyName = allergy.Resource.Substance.DisplayElement.Value;

                if (allergy.Resource.Reaction != null)
                {
                    allergies.Severity = allergy.Resource.Reaction.FirstOrDefault <ResourceReference>().Display;
                }
                else
                {
                    allergies.Severity = "Unknown Sensitivity to";
                }
                m.AllergiesCount++;

                allergyList.Add(allergies);
            }
            m.Allergies = allergyList;

            patients.Add(m);

            return(View(patients));
        }
        private void FetchPatients()
        {
            FhirClient fhirClient = new FhirClient("https://fhir-open.sandboxcernerpowerchart.com/dstu2/d075cf8b-3261-481d-97e5-ba6c48d3b41f");
            fhirClient.PreferredFormat = ResourceFormat.Json;
            fhirClient.UseFormatParam = true;

            try
            {
                EditText patientNameField = FindViewById<EditText>(Resource.Id.PatientNameField);
                string patientName = patientNameField.Text;
                SearchParams searchParams = new SearchParams();
                searchParams.Add("name", patientName);
                searchParams.Add("_count", "50");
                Hl7.Fhir.Model.Bundle patients = fhirClient.Search<Patient>(searchParams);
                Log.Info(TAG, "Retrieved patients: " + patients.Total);

                RunOnUiThread(() =>
                {
                    ListView pxListView = FindViewById<ListView>(Resource.Id.PatientListView);
                    ArrayAdapter adapter = pxListView.Adapter as ArrayAdapter;
                    Log.Debug(TAG, "Adapter: " + adapter.ToString());
                    adapter.Clear();
                    adapter.AddAll(patients.Entry);
                }
                );
            }
            catch (Exception e)
            {
                Log.Warn(TAG, e.Message);
                RunOnUiThread(() =>
                {
                    Android.Widget.Toast.MakeText(this, e.Message, ToastLength.Long).Show();
                }
                );
            }
            finally
            {
                RunOnUiThread(() => {
                    EnableInputs();
                }
                );
            }
        }
示例#34
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            // Choose your preferred FHIR server or add your own
            // More at http://wiki.hl7.org/index.php?title=Publicly_Available_FHIR_Servers_for_testing

            //var client = new FhirClient("http://fhir2.healthintersections.com.au/open");
            var client = new FhirClient("http://spark.furore.com/fhir");
            //var client = new FhirClient("http://fhirtest.uhn.ca/baseDstu2");
            //var client = new FhirClient("https://fhir-open-api-dstu2.smarthealthit.org/");

            try
            {
                var q = new SearchParams().Where("name=pete");
                //var q = new SearchParams().Where("name=pete").Where("birthdate=1974-12-25");

                var results = client.Search<Patient>(q);

                txtDisplay.Text = "";

                while (results != null)
                {
                    if (results.Total == 0) txtDisplay.Text = "No results found";

                    foreach (var entry in results.Entry)
                    {
                        txtDisplay.Text += "Found patient with id " + entry.Resource.Id + Environment.NewLine;
                    }

                    // get the next page of results
                    results = client.Continue(results);
                }
            }
            catch (Exception err)
            {
                txtError.Lines = new string[] { "An error has occurred:", err.Message };
            }
        }
        public void TestSearchByPersonaCode()
        {
            var client = new FhirClient(testEndpoint);

            var pats =
              client.Search<Patient>(
                new[] { string.Format("identifier={0}|{1}", "http://hl7.org/fhir/sid/us-ssn", "444222222") });
            var pat = (Patient)pats.Entry.First().Resource;
            client.Update<Patient>(pat);
        }
        public void PagingInJson()
        {
            FhirClient client = new FhirClient(testEndpoint);
            client.PreferredFormat = ResourceFormat.Json;

            var result = client.Search<DiagnosticReport>(pageSize: 10);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entry.Count <= 10);

            var firstId = result.Entry.First().Resource.Id;

            // Browse forward
            result = client.Continue(result);
            Assert.IsNotNull(result);
            var nextId = result.Entry.First().Resource.Id;
            Assert.AreNotEqual(firstId, nextId);

            // Browse to first
            result = client.Continue(result, PageDirection.First);
            Assert.IsNotNull(result);
            var prevId = result.Entry.First().Resource.Id;
            Assert.AreEqual(firstId, prevId);

            // Forward, then backwards
            result = client.Continue(result, PageDirection.Next);
            Assert.IsNotNull(result);
            result = client.Continue(result, PageDirection.Previous);
            Assert.IsNotNull(result);
            prevId = result.Entry.First().Resource.Id;
            Assert.AreEqual(firstId, prevId);
        }
        public void Search()
        {
            FhirClient client = new FhirClient(testEndpoint);
            Bundle result;

            result = client.Search<DiagnosticReport>();
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entry.Count() > 10, "Test should use testdata with more than 10 reports");

            result = client.Search<DiagnosticReport>(pageSize: 10);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entry.Count <= 10);

            var withSubject =
                result.Entry.ByResourceType<DiagnosticReport>().FirstOrDefault(dr => dr.Subject != null);
            Assert.IsNotNull(withSubject, "Test should use testdata with a report with a subject");

            ResourceIdentity ri = withSubject.ResourceIdentity();

            result = client.SearchById<DiagnosticReport>(ri.Id,
                        includes: new string[] { "DiagnosticReport.subject" });
            Assert.IsNotNull(result);

            Assert.AreEqual(2, result.Entry.Count);  // should have subject too

            Assert.IsNotNull(result.Entry.Single(entry => entry.Resource.ResourceIdentity().ResourceType ==
                        typeof(DiagnosticReport).GetCollectionName()));
            Assert.IsNotNull(result.Entry.Single(entry => entry.Resource.ResourceIdentity().ResourceType ==
                        typeof(Patient).GetCollectionName()));

            result = client.Search<Patient>(new string[] { "name=Everywoman", "name=Eve" });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entry.Count > 0);
        }
示例#38
0
        public void TestSearchByPersonaCode()
        {
            var client = new FhirClient(testEndpoint);

            var pats =
              client.Search<Patient>(
                new[] { string.Format("identifier={0}|{1}", "urn:oid:1.2.36.146.595.217.0.1", "12345") });
            var pat = (Patient)pats.Entry.First().Resource;
        }
示例#39
0
        // Select a device
        private void btnDeviceSelect_Click(object sender, EventArgs e)
        {
            deviceSelectStatus.Text = "Selecting...";
            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client = new FhirClient(endpoint);

            var query = new string[] { "_id=" + selectDeviceSearch.Text.Trim() };
            Bundle result = client.Search<Device>(query);

            CurrentDevice = ((Device)result.Entry.FirstOrDefault().Resource);

            deviceID.Text = CurrentDevice.Id;
            deviceManufacturer.Text = CurrentDevice.Manufacturer;
            deviceModel.Text = CurrentDevice.Model;
            deviceSelectStatus.Text = "Done!";
        }
示例#40
0
        public void Search()
        {
            FhirClient client = new FhirClient(testEndpoint);
            Bundle result;

            result = client.Search(ResourceType.DiagnosticReport);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entries.Count > 0);
            Assert.IsTrue(result.Entries[0].Id.ToString().EndsWith("@101"));
            Assert.IsTrue(result.Entries.Count() > 10, "Test should use testdata with more than 10 reports");

            result = client.Search(ResourceType.DiagnosticReport,count:10);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entries.Count <= 10);
            Assert.IsTrue(result.Entries[0].Id.ToString().EndsWith("@101"));

            //result = client.SearchById<DiagnosticReport>("101", "DiagnosticReport/subject");
            result = client.Search(ResourceType.DiagnosticReport, "_id", "101", includes: new string[] { "DiagnosticReport.subject" } );
            Assert.IsNotNull(result);

            Assert.AreEqual(1,
                    result.Entries.Where(entry => entry.Links.SelfLink.ToString()
                        .Contains("diagnosticreport")).Count());

            Assert.IsTrue(result.Entries.Any(entry =>
                    entry.Links.SelfLink.ToString().Contains("patient/@pat2")));

            result = client.Search(ResourceType.DiagnosticReport, new SearchParam[]
                {
                    new SearchParam("name", new StringParamValue("Everywoman")),
                    new SearchParam("name", new StringParamValue("Eve"))
                });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entries[0].Links.SelfLink.ToString().Contains("patient/@1"));
        }
示例#41
0
        public void Paging()
        {
            FhirClient client = new FhirClient(testEndpoint);

            var result = client.Search(ResourceType.DiagnosticReport, count: 10);
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Entries.Count <= 10);

            var firstId = result.Entries.First().Id;

            // Browse forward
            result = client.Continue(result);
            Assert.IsNotNull(result);
            var nextId = result.Entries.First().Id;
            Assert.AreNotEqual(firstId, nextId);

            // Browse backward
            //result = client.Continue(result, PageDirection.Previous);
            result = client.Continue(result, PageDirection.First);
            Assert.IsNotNull(result);
            var prevId = result.Entries.First().Id;
            Assert.AreEqual(firstId, prevId);
        }
示例#42
0
        // When button 1 is clicked, select patient
        private void button1_Click_1(object sender, EventArgs e)
        {
            // Edit status text
            patientSelectStatus.Text = "Selecting...";

            // Set FHIR endpoint and create client
            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client = new FhirClient(endpoint);

            // Search patient based on ID from user input
            var query = new string[] { "_id=" + selectPatientSearchText.Text.Trim() };
            Bundle result = client.Search<Patient>(query);

            // Set the current patient
            CurrentPatient = ((Patient)result.Entry.FirstOrDefault().Resource);

            // Edit selected patient text
            patID.Text = CurrentPatient.Id;
            patBirthday.Text = CurrentPatient.BirthDate;
            
            // Edit status text
            patientSelectStatus.Text = "Done!";

        }
示例#43
0
        private void obsSearchButton_Click(object sender, EventArgs e)
        {
            obsSearchStatus.Text = "Searching...";

            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client = new FhirClient(endpoint);

            var query = new string[] { "subject=Patient/" + obsSearchPatient.Text };
            Bundle result = client.Search<Observation>(query);

            obsSearchStatus.Text = "Got " + result.Entry.Count() + " records!";

            obsFinderId.Text = "";
            obsFinderValue.Text = "";

            foreach (var entry in result.Entry)
            {
                Observation obs = (Observation)entry.Resource;
                String name = "Unknown";
                if (obs.Code != null) {
                    name = obs.Code.Text;
                }
                
                if (obs.Value is SampledData)
                {
                    obsFinderId.Text = obsFinderId.Text + name + "\r\n";
                    obsFinderValue.Text = obsFinderValue.Text + ((SampledData)obs.Value).Data.ToString() + "\r\n";
                }
                else if (obs.Value is Quantity)
                {
                    obsFinderId.Text = obsFinderId.Text + obs.Code.Coding[0] + "\r\n";
                    obsFinderValue.Text = obsFinderValue.Text + ((Quantity)obs.Value).Value.ToString() + "\r\n";
                }
            }
        }
示例#44
0
        // Search for a device
        private void btnDeviceSearch_Click(object sender, EventArgs e)
        {
            searchDeviceStatus.Text = "Searching...";

            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client = new FhirClient(endpoint);

            var query = new string[] { "manufacturer=" + searchDeviceText.Text.Trim() };
            Bundle result = client.Search<Device>(query);

            searchDeviceStatus.Text = "Got " + result.Entry.Count() + " records!";

            deviceRes1.Text = "";
            deviceRes2.Text = "";
            deviceRes3.Text = "";
            foreach (var entry in result.Entry)
            {
                Device d = (Device)entry.Resource;

                deviceRes1.Text = deviceRes1.Text + d.Id + "\r\n";
                deviceRes2.Text = deviceRes2.Text + d.Manufacturer + "\r\n";
                deviceRes3.Text = deviceRes3.Text + d.Model + "\r\n";
            }
        }