Esempio n. 1
0
        public void HistoryForSpecificResource()
        {
            initialize();
            if (CreateDate == null)
            {
                TestResult.Skip();
            }

            history = client.History(location);
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(history);

            // There's one version less here, because we don't have the deletion
            int expected = Versions.Count + 1;

            if (history.Entries.Count != expected)
            {
                TestResult.Fail(String.Format("{0} versions expected after crud test, found {1}", expected, history.Entries.Count));
            }

            if (!history.Entries.OfType <ResourceEntry>()
                .All(ent => Versions.Contains(ent.SelfLink)))
            {
                TestResult.Fail("Selflinks on returned versions do not match links returned on creation" + history.Entries.Count);
            }


            checkSortOrder(history);
        }
Esempio n. 2
0
        public void HistoryForSpecificResourceId()
        {
            if (CreateDate == null)
            {
                TestResult.Skip();
            }

            var before = CreateDate.Value.AddMinutes(-1);
            var after  = before.AddHours(1);

            var history = client.History(location, before);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(history);
            checkSortOrder(history);
            var historySl = history.Entries.Select(entry => entry.SelfLink).ToArray();

            if (!history.Entries.All(entry => historySl.Contains(entry.SelfLink)))
            {
                TestResult.Fail("history with _since does not contain all versions of instance");
            }

            history = client.History(location, after);
            if (history.Entries.Count != 0)
            {
                TestResult.Fail("Setting since to after the last update still returns history");
            }
        }
Esempio n. 3
0
        public void PageFwdThroughResourceHistory()
        {
            var pageSize = 30;
            var page     = client.TypeHistory <Patient>(pageSize: pageSize);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(page);

            forwardCount = 0;

            // Browse forwards
            while (page != null)
            {
                if (page.Entries.Count > pageSize)
                {
                    TestResult.Fail("Server returned a page with more entries than set by _count");
                }

                forwardCount += page.Entries.Count;
                lastPage      = page;
                HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(page);
                page = client.Continue(page);
            }

            //if (total.HasValue && forwardCount < total)
            //    TestResult.Fail(String.Format("Paging did not return all entries(expected at least {0}, {1} returned)",
            //                    total, forwardCount));
        }
Esempio n. 4
0
        public void PageBackThroughResourceHistory()
        {
            if (forwardCount == -1)
            {
                TestResult.Skip();
            }

            var pageSize = 30;
            var page     = client.TypeHistory <Patient>(pageSize: pageSize);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(page);

            page = client.Continue(page, PageDirection.Last);
            var backwardsCount = 0;

            // Browse backwards
            while (page != null)
            {
                if (page.Entries.Count > pageSize)
                {
                    TestResult.Fail("Server returned a page with more entries than set by count");
                }

                backwardsCount += page.Entries.Count;
                HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(page);
                page = client.Continue(page, PageDirection.Previous);
            }

            if (backwardsCount != forwardCount)
            {
                TestResult.Fail(String.Format("Paging forward returns {0} entries, backwards returned {1}",
                                              forwardCount, backwardsCount));
            }
        }
Esempio n. 5
0
        public void HistoryForResourceType()
        {
            if (CreateDate == null)
            {
                TestResult.Skip();
            }

            var before = CreateDate.Value.AddMinutes(-1);
            var after  = before.AddHours(1);

            var history = client.TypeHistory <Patient>(since: before);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(history);
            typeHistory = history;
            checkSortOrder(history);

            var historyLinks = history.Entries.Select(be => be.SelfLink).ToArray();

            if (!history.Entries.All(ent => historyLinks.Contains(ent.SelfLink)))
            {
                TestResult.Fail("history with _since does not contain all versions of instance");
            }

            history = client.History(location, DateTimeOffset.Now.AddMinutes(1));

            if (history.Entries.Count != 0)
            {
                TestResult.Fail("Setting since to a future moment still returns history");
            }
        }
Esempio n. 6
0
        public void HistoryForWholeSystem()
        {
            if (CreateDate == null)
            {
                TestResult.Skip();
            }
            var    before = CreateDate.Value.AddMinutes(-1);
            Bundle history;


            history = client.WholeSystemHistory(before);
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(history);

            HttpTests.AssertHasAllForwardNavigationLinks(history); // Assumption: system has more history than pagesize
            systemHistory = history;
            checkSortOrder(history);

            var historyLinks = history.Entries.Select(be => be.SelfLink).ToArray();

            if (!Versions.All(sl => historyLinks.Contains(sl)))
            {
                TestResult.Fail("history with _since does not contain all versions of instance");
            }

            history = client.History(location, DateTimeOffset.Now.AddMinutes(1));

            if (history.Entries.Count != 0)
            {
                TestResult.Fail("Setting since to a future moment still returns history");
            }
        }
Esempio n. 7
0
        public void PostBundleWithUpdates()
        {
            var newMasterId = "urn:oid:123.456.7.8.9";
            var doc         = postResult.Entries.OfType <ResourceEntry <DocumentReference> >().First();

            doc.Resource.MasterIdentifier.Value = newMasterId;

            var pat = postResult.Entries.OfType <ResourceEntry <Patient> >().First();

            pat.Resource.Identifier[0].Value = "3141592";

            var entries        = postResult.Entries.ToList();
            var returnedBundle = client.Transaction(postResult);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(returnedBundle);

            var entries2 = returnedBundle.Entries.ToList();

            if (entries2[0].Id != entries[0].Id || entries2[4].Id != entries[4].Id)  // etcetera
            {
                TestResult.Fail("submitting a batch with updates created new resources");
            }

            var refreshedBundle = client.RefreshBundle(returnedBundle);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(refreshedBundle);

            if (refreshedBundle.Entries.OfType <ResourceEntry <DocumentReference> >().First().Resource.MasterIdentifier.Value != newMasterId)
            {
                TestResult.Fail("update on document resource was not reflected in batch result");
            }

            if (refreshedBundle.Entries.OfType <ResourceEntry <Patient> >().First().Resource.Identifier[0].Value != "3141592")
            {
                TestResult.Fail("update on patient was not reflected in batch result");
            }

            doc = client.Read <DocumentReference>(doc.Id);
            if (doc.Resource.MasterIdentifier.Value != newMasterId)
            {
                TestResult.Fail("update on document resource was not reflected in new version");
            }

            pat = client.Read <Patient>(pat.Id);
            if (pat.Resource.Identifier[0].Value != "3141592")
            {
                TestResult.Fail("update on patient was not reflected in new version");
            }
        }
Esempio n. 8
0
        public void PostBundleAgain()
        {
            var bundle  = DemoData.GetDemoXdsBundle();
            var trans   = client.Transaction(bundle);
            var entries = trans.Entries.ToList();

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(trans);

            // If server honors the 'search' link, it might *not* re-create the patient
            if (entries[0].Id == connDoc.Id || entries[4].Id == binDoc.Id)  // etcetera
            {
                TestResult.Fail("submitting a bundle with identical cids should still create new resources");
            }

            //TODO: verify server honors the 'search' link
        }
Esempio n. 9
0
        public void SearchResourcesWithNameCriterium()
        {
            if (allPatients == null)
            {
                TestResult.Skip();
            }
            // First create a search argument: any family name present in the
            // previous unlimited search result that has at least 5 characters
            var name = allPatients.Entries.ByResourceType <Patient>()
                       .Where(p => p.Resource.Name != null)
                       .SelectMany(p => p.Resource.Name)
                       .Where(hn => hn.Family != null)
                       .SelectMany(hn => hn.Family)
                       .Where(s => s.Length > 5).First();

            // Take the first three characters
            name = name.Substring(0, 3);


            var result = client.Search <Patient>(new string[] { "family=" + name });

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(result);

            if (result.Entries.Count == 0)
            {
                TestResult.Fail("search did not return any results");
            }

            // Each patient returned should have a family name with the
            // criterium
            var names = result.Entries.ByResourceType <Patient>()
                        .Where(p => p.Resource.Name != null)
                        .SelectMany(p => p.Resource.Name)
                        .Where(hn => hn.Family != null)
                        .SelectMany(hn => hn.Family);

            var correct = result.Entries.ByResourceType <Patient>()
                          .All(p => p.Resource.Name != null &&
                               p.Resource.Name.Where(hn => hn.Family != null)
                               .SelectMany(hn => hn.Family)
                               .Any(s => s.ToLower().Contains(name.ToLower())));

            if (!correct)
            {
                TestResult.Fail("search result contains patients that do not match the criterium");
            }
        }
Esempio n. 10
0
        public void TestPostXdsWidthCid()
        {
            Bundle xdsBundle = DemoData.GetDemoConn5CidExampleBundle();

            xdsBundle.SetBundleType(BundleType.Document);

            _deliveryResult = client.DeliverToMailbox(xdsBundle);

            if (_deliveryResult.Entries.Count != 7)
            {
                TestResult.Fail("Result bundle should contain exactly 7 resources");
            }
            if (_deliveryResult.Entries.ByResourceType <DocumentReference>().Count() != 1)
            {
                TestResult.Fail("Result bundle should contain one DocumentReference");
            }
            if (_deliveryResult.Entries.ByResourceType <Binary>().Count() != 1)
            {
                TestResult.Fail("Result bundle should contain one Binary");
            }
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(_deliveryResult);
        }
Esempio n. 11
0
        public void SearchResourcesWithoutCriteria()
        {
            var result = client.Search <Patient>(pageSize: 10);

            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(result);

            if (result.Entries.Count == 0)
            {
                TestResult.Fail("search did not return any results");
            }

            if (result.Entries.Count > 10)
            {
                TestResult.Fail("search returned more patients than specified in _count");
            }

            if (result.Entries.ByResourceType <Patient>().Count() == 0)
            {
                TestResult.Fail("search returned entries other than patient");
            }

            allPatients = result;
        }
Esempio n. 12
0
        public void PostBundle()
        {
            var bundle = DemoData.GetDemoXdsBundle();

            postResult = client.Transaction(bundle);
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(postResult);
            if (postResult.Entries.Count != 5)
            {
                TestResult.Fail(String.Format("Bundle response contained {0} entries in stead of 5", postResult.Entries.Count));
            }

            postResult = client.RefreshBundle(postResult);
            HttpTests.AssertEntryIdsArePresentAndAbsoluteUrls(postResult);
            var entries = postResult.Entries.ToList();

            connDoc = entries[0];

            if (new ResourceIdentity(connDoc.Id).Id == null)
            {
                TestResult.Fail("failed to assign id to new xds document");
            }
            if (new ResourceIdentity(connDoc.SelfLink).VersionId == null)
            {
                TestResult.Fail("failed to assign a version id to new xds document");
            }

            patDoc = entries[1];
            if (new ResourceIdentity(patDoc.Id) == null)
            {
                TestResult.Fail("failed to assign id to new patient");
            }

            prac1Doc = entries[2];
            if (new ResourceIdentity(prac1Doc.Id).Id == null)
            {
                TestResult.Fail("failed to assign id to new practitioner (#1)");
            }
            if (new ResourceIdentity(prac1Doc.SelfLink).VersionId == null)
            {
                TestResult.Fail("failed to assign a version id to new practitioner (#1)");
            }

            prac2Doc = entries[3];
            if (new ResourceIdentity(prac2Doc.Id).Id == null)
            {
                TestResult.Fail("failed to assign id to new practitioner (#2)");
            }
            if (new ResourceIdentity(prac2Doc.SelfLink).VersionId == null)
            {
                TestResult.Fail("failed to assign a version id to new practitioner (#2)");
            }

            binDoc = entries[4];
            if (new ResourceIdentity(binDoc.Id).Id == null)
            {
                TestResult.Fail("failed to assign id to new binary");
            }
            if (new ResourceIdentity(binDoc.SelfLink).VersionId == null)
            {
                TestResult.Fail("failed to assign a version id to new binary");
            }

            var docResource = ((ResourceEntry <DocumentReference>)connDoc).Resource;

            if (!prac1Doc.Id.ToString().Contains(docResource.Author[0].Reference))
            {
                TestResult.Fail("doc reference's author[0] does not reference newly created practitioner #1");
            }
            if (!prac2Doc.Id.ToString().Contains(docResource.Author[1].Reference))
            {
                TestResult.Fail("doc reference's author[1] does not reference newly created practitioner #2");
            }

            var binRl = new ResourceIdentity(binDoc.Id);

            if (!docResource.Text.Div.Contains(binRl.OperationPath.ToString()))
            {
                TestResult.Fail("href in narrative was not fixed to point to newly created binary");
            }
        }
Esempio n. 13
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)");
            }
        }