예제 #1
0
 public void MatchesPublishingTopic(string subscriptionAsString, string publishingAsString, bool isMatched)
 {
     SubscriptionTopic.From(subscriptionAsString)
     .Matches(PublishingTopic.From(publishingAsString))
     .Should()
     .Be(isMatched);
 }
예제 #2
0
        public void ToStringReturnsSameTopicAsInput()
        {
            const string expectedTopicString = "finance/ibm";
            var          topic = new SubscriptionTopic(expectedTopicString);

            Assert.Equal(expectedTopicString, topic.ToString());
        }
        /// <summary>Adds or updates a Topic</summary>
        /// <param name="topic">The topic.</param>
        public static void AddOrUpdate(SubscriptionTopic topic)
        {
            if (topic == null)
            {
                return;
            }

            _instance._AddOrUpdate(topic);
        }
        /// <summary>Creates the topics.</summary>
        private void CreateTopics()
        {
            // make sure our lists are clear
            _titleTopicDict.Clear();
            _canonicalUrlTopicDict.Clear();
            _idTopicDict.Clear();

            // create our known topics
            SubscriptionTopic topic = new SubscriptionTopic()
            {
                Title           = "encounter-start",
                Id              = "encounter-start",
                Url             = "http://argonautproject.org/encounters-ig/SubscriptionTopic/encounter-start",
                Version         = "1.1",
                Status          = PublicationStatus.Draft,
                Experimental    = true,
                Description     = new Markdown("Beginning of a clinical encounter"),
                Date            = "2020-05-11",
                ResourceTrigger = new SubscriptionTopic.ResourceTriggerComponent()
                {
                    Description  = "Beginning of a clinical encounter",
                    ResourceType = new ResourceType?[]
                    {
                        ResourceType.Encounter,
                    },
                    QueryCriteria = new SubscriptionTopic.QueryCriteriaComponent()
                    {
                        Previous    = "status:not=in-progress",
                        Current     = "status:in-progress",
                        RequireBoth = true,
                    },
                    FhirPathCriteria = new string[]
                    {
                        "%previous.status!='in-progress' and %current.status='in-progress'",
                    },
                },
                CanFilterBy = new List <SubscriptionTopic.CanFilterByComponent>()
                {
                    new SubscriptionTopic.CanFilterByComponent()
                    {
                        SearchParamName = "patient",
                        SearchModifier  = new SubscriptionSearchModifier?[]
                        {
                            SubscriptionSearchModifier.Equal,
                            SubscriptionSearchModifier.In,
                        },
                        Documentation = new Markdown("Exact match to a patient resource (reference)"),
                    },
                },
            };

            // add this topic
            _AddOrUpdate(topic);
        }
 /// <summary>Wrap in basic.</summary>
 /// <param name="topic">The topic.</param>
 /// <returns>A Basic.</returns>
 private Basic WrapInBasic(SubscriptionTopic topic)
 {
     return(new Basic()
     {
         Id = topic.Id,
         Code = new CodeableConcept(
             "http://hl7.org/fhir/resource-types",
             "R5SubscriptionTopic",
             "Backported R5 SubscriptionTopic"),
         Extension = new List <Extension>()
         {
             new Extension()
             {
                 Url = "http://hl7.org/fhir/StructureDefinition/json-embedded-resource",
                 Value = new FhirString(_firelySerializer.SerializeToString(topic)),
             },
         },
     });
 }
예제 #6
0
        public void TopicWithSingleWildcardMatchesTopicEmptyFragmentAtThatPoint()
        {
            var topic = new SubscriptionTopic("finance/+/closingprice");

            Assert.True(topic.Matches(new PublicationTopic("finance//closingprice")));
        }
예제 #7
0
        public void TopicWithSingleAndMultiWildcardMatchesTopicWithAnyValueAtThoseLevelsAndDeeper()
        {
            var topic = new SubscriptionTopic("finance/+/closingprice/month/#");

            Assert.True(topic.Matches(new PublicationTopic("finance/ibm/closingprice/month/october/2014")));
        }
예제 #8
0
        public void SingleLevelEqualTopicsMatch()
        {
            var topic = new SubscriptionTopic("finance");

            Assert.True(topic.Matches(new PublicationTopic("finance")));
        }
예제 #9
0
        public void TopicsDifferingOnlyByCaseDoNotMatch()
        {
            var topic = new SubscriptionTopic("finance");

            Assert.False(topic.Matches(new PublicationTopic("Finance")));
        }
예제 #10
0
        public void MultiLevelNonEqualTopicsDoNotMatch()
        {
            var topic = new SubscriptionTopic("finance/ibm/closingprice");

            Assert.False(topic.Matches(new PublicationTopic("some/random/topic")));
        }
예제 #11
0
        public void TopicWithSingleWildcardAtEndDoesNotMatchTopicThatGoesDeeper()
        {
            var topic = new SubscriptionTopic("finance/+");

            Assert.False(topic.Matches(new PublicationTopic("finance/ibm/closingprice")));
        }
예제 #12
0
 public void CanCreateSubscriptionFromValidString(string subscriptionAsString)
 {
     SubscriptionTopic.From(subscriptionAsString);
 }
예제 #13
0
        public void CannotCreateInvalidSubscription(string subscriptionAsString)
        {
            var ex = Assert.Throws <InvalidTopicException>(() => SubscriptionTopic.From(subscriptionAsString));

            Assert.NotNull(ex);
        }
        /// <summary>Adds or updates a Topic</summary>
        /// <param name="topic">The topic.</param>
        private void _AddOrUpdate(SubscriptionTopic topic)
        {
            string localUrl = Program.UrlForR5ResourceId("SubscriptionTopic", topic.Title);

            // check for local url already existing
            if (_localUrlTopicDict.ContainsKey(localUrl))
            {
                SubscriptionTopic oldTopic = _localUrlTopicDict[localUrl];

                // remove if this topic exists in other dictionaries
                RemoveIfExists(_canonicalUrlTopicDict, oldTopic.Url);
                RemoveIfExists(_titleTopicDict, localUrl);
                RemoveIfExists(_idTopicDict, oldTopic.Title);

                // remove from this dict
                _localUrlTopicDict.Remove(topic.Title);
            }

            // check for this canonical url already existing
            if (_canonicalUrlTopicDict.ContainsKey(topic.Url))
            {
                SubscriptionTopic oldTopic = _canonicalUrlTopicDict[topic.Url];

                // remove if this topic exists in other dictionaries
                RemoveIfExists(_localUrlTopicDict, localUrl);
                RemoveIfExists(_titleTopicDict, oldTopic.Url);
                RemoveIfExists(_idTopicDict, oldTopic.Title);

                // remove from this dict
                _canonicalUrlTopicDict.Remove(topic.Url);
            }

            // check for title already existing
            if (_titleTopicDict.ContainsKey(topic.Title))
            {
                SubscriptionTopic oldTopic = _titleTopicDict[topic.Title];

                // remove if this topic exists in other dictionaries
                RemoveIfExists(_localUrlTopicDict, localUrl);
                RemoveIfExists(_canonicalUrlTopicDict, oldTopic.Url);
                RemoveIfExists(_idTopicDict, oldTopic.Title);

                // remove from this dict
                _titleTopicDict.Remove(topic.Title);
            }

            // check for this id already existing
            if (_idTopicDict.ContainsKey(topic.Id))
            {
                SubscriptionTopic oldTopic = _idTopicDict[topic.Id];

                // remove if this topic exists in other dictionaries
                RemoveIfExists(_localUrlTopicDict, localUrl);
                RemoveIfExists(_canonicalUrlTopicDict, oldTopic.Url);
                RemoveIfExists(_titleTopicDict, oldTopic.Title);

                // remove from this dict
                _idTopicDict.Remove(topic.Id);
            }

            // add to local url dictionary
            _localUrlTopicDict.Add(localUrl, topic);

            // add to canonical url dictionary
            _canonicalUrlTopicDict.Add(topic.Url, topic);

            // add to the title dictionary
            _titleTopicDict.Add(topic.Title, topic);

            // add to id dictionary
            _idTopicDict.Add(topic.Id, topic);
        }
예제 #15
0
        public void TopicWithSingleWildcardAtEndMatchesTopicWithEmptyLastFragmentAtThatSpot()
        {
            var topic = new SubscriptionTopic("finance/ibm/+");

            Assert.True(topic.Matches(new PublicationTopic("finance/ibm/")));
        }
예제 #16
0
        public void SingleLevelNonEqualTopicsDoNotMatch()
        {
            var topic = new SubscriptionTopic("finance");

            Assert.False(topic.Matches(new PublicationTopic("money")));
        }
예제 #17
0
        public void MultiWildcardOnlyTopicMatchesTopicStartingWithSeparator()
        {
            var topic = new SubscriptionTopic("#");

            Assert.True(topic.Matches(new PublicationTopic("/finance/ibm/closingprice")));
        }
예제 #18
0
        public void TopicWithSingleWildcardAtEndDoesNotMatchTopicThatDoesNotContainAnythingAtSameLevel()
        {
            var topic = new SubscriptionTopic("finance/+");

            Assert.False(topic.Matches(new PublicationTopic("finance")));
        }
예제 #19
0
        public void TopicWithMultiWildcardAtEndMatchesTopicThatDoesNotMatchSameDepth()
        {
            var topic = new SubscriptionTopic("finance/#");

            Assert.True(topic.Matches(new PublicationTopic("finance")));
        }
예제 #20
0
        public void TopicWithMultiWildcardDoesNotMatchTopicWithDifferenceBeforeWildcardLevel()
        {
            var topic = new SubscriptionTopic("finance/#");

            Assert.False(topic.Matches(new PublicationTopic("money/ibm")));
        }
예제 #21
0
        public void TopicWithMultiWildcardAtEndMatchesTopicWithAnythingAtWildcardLevel()
        {
            var topic = new SubscriptionTopic("finance/#");

            Assert.True(topic.Matches(new PublicationTopic("finance/ibm")));
        }
예제 #22
0
        public void TopicWithSingleWildcardAtEndMatchesAnythingInSameLevel()
        {
            var topic = new SubscriptionTopic("finance/+/closingprice");

            Assert.True(topic.Matches(new PublicationTopic("finance/ibm/closingprice")));
        }
예제 #23
0
        public void TopicWithMoreThanOneSingleWildcardAtDifferentLevelsMatchesTopicWithAnyValueAtThoseLevels()
        {
            var topic = new SubscriptionTopic("finance/+/closingprice/month/+");

            Assert.True(topic.Matches(new PublicationTopic("finance/ibm/closingprice/month/october")));
        }
예제 #24
0
        public void MultiWildcardOnlyTopicMatchesAnyRandomTopic()
        {
            var topic = new SubscriptionTopic("#");

            Assert.True(topic.Matches(new PublicationTopic("finance/ibm/closingprice")));
        }
        /// <summary>Attempts to get topic a SubscriptionTopic from the given string.</summary>
        /// <param name="key">  The key for the topic</param>
        /// <param name="topic">[out] The topic.</param>
        /// <returns>True if it succeeds, false if it fails.</returns>
        public static bool TryGetTopic(string key, out SubscriptionTopic topic)
        {
            topic = GetTopic(key);

            return(topic != null);
        }