예제 #1
0
        public void SearchPatientByNonExistingParameter()
        {
            var    nrOfAllPatients    = client.Search <Patient>().Entries.ByResourceType <Patient>().Count();
            Bundle actual             = client.Search("Patient", criteria: new string[] { "bonkers=blabla" }); //Obviously a non-existing search parameter
            var    nrOfActualPatients = actual.Entries.ByResourceType <Patient>().Count();

            HttpTests.AssertCorrectNumberOfResults(nrOfAllPatients, nrOfActualPatients, "Expected all patients ({0}) since the only search parameter is non-existing, but got {1}.");
            var outcomes = actual.Entries.ByResourceType <OperationOutcome>();

            TestResult.Assert(outcomes.Any(), "There should be an OperationOutcome.");
            TestResult.Assert(outcomes.Any(o => o.Resource.Issue.Any(i => i.Severity == OperationOutcome.IssueSeverity.Warning)), "With a warning in it.");
        }
예제 #2
0
        public void SearchPatientByGenderMissing()
        {
            var patients = new List <ResourceEntry <Patient> >();
            var bundle   = client.Search <Patient>();

            while (bundle != null && bundle.Entries.ByResourceType <Patient>().Count() > 0)
            {
                patients.AddRange(bundle.Entries.ByResourceType <Patient>());
                bundle = client.Continue(bundle);
            }
            var patientsNoGender = patients.Where(p => p.Resource.Gender == null);
            var nrOfPatientsWithMissingGender = patientsNoGender.Count();

            var actual = client.Search <Patient>(new string[] { "gender:missing=true" }, pageSize: 500).Entries.ByResourceType <Patient>();

            HttpTests.AssertCorrectNumberOfResults(nrOfPatientsWithMissingGender, actual.Count(), "Expected {0} patients without gender, but got {1}.");
        }
예제 #3
0
        public void SearchConditionByPatientReference()
        {
            var conditions = client.Search <Condition>();

            if (conditions.Entries.Count == 0)
            {
                var patients = client.Search <Patient>();
                if (patients.Entries.Count == 0)
                {
                    TestResult.Fail("no patients found - cannot run test");
                }
                var newCondition = new Condition
                {
                    Subject = new ResourceReference
                    {
                        Reference = patients.Entries[0].Id.ToString()
                    }
                };
                client.Create(newCondition);
            }

            var conditionsForPatients = conditions.Entries.ByResourceType <Condition>()
                                        .Where(c => c.Resource.Subject != null && new ResourceIdentity(c.Resource.Subject.Url).Collection == "Patient");

            //We want a condition on a patient that has a name, for the last test in this method.
            ResourceIdentity        patientRef = null;
            ResourceEntry <Patient> patient    = null;
            string patFirstName = "";

            foreach (var cond in conditionsForPatients)
            {
                try
                {
                    patientRef   = new ResourceIdentity(cond.Resource.Subject.Url);
                    patient      = client.Read <Patient>(patientRef);
                    patFirstName = patient.Resource.Name[0].Family.First();
                    break;
                }
                catch (Exception)
                {
                    // Apparently this patient has no name, try again.
                }
            }
            if (patient == null)
            {
                TestResult.Fail("failed to find patient condition is referring to");
            }

            var allConditionsForThisPatient  = conditionsForPatients.Where(c => c.Resource.Subject != null && c.Resource.Subject.Url == patientRef);
            var nrOfConditionsForThisPatient = allConditionsForThisPatient.Count();

            var result = client.Search <Condition>(new string[] { "subject=" + patientRef });

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(result);

            HttpTests.AssertCorrectNumberOfResults(nrOfConditionsForThisPatient, result.Entries.Count(), "conditions for this patient (using subject=)");

            //Test for issue #6, https://github.com/furore-fhir/spark/issues/6
            result = client.Search <Condition>(new string[] { "subject:Patient=" + patientRef });
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(result);

            HttpTests.AssertCorrectNumberOfResults(nrOfConditionsForThisPatient, result.Entries.Count(), "conditions for this patient (using subject:Patient=)");

            result = client.Search <Condition>(new string[] { "subject._id=" + patientRef.Id });
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(result);

            HttpTests.AssertCorrectNumberOfResults(nrOfConditionsForThisPatient, result.Entries.Count(), "conditions for this patient (using subject._id=)");

            var param = "subject.name=" + patFirstName;

            result = client.Search <Condition>(new string[] { param });
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(result);

            if (result.Entries.Count() == 0)
            {
                TestResult.Fail("failed to find any conditions (using subject.name)");
            }

            string identifier = patient.Resource.Identifier[0].Value;

            result = client.Search <Condition>(new string[] { "subject.identifier=" + identifier });

            if (result.Entries.Count() == 0)
            {
                TestResult.Fail("failed to find any conditions (using subject.identifier)");
            }
        }