/// <summary>Topic list to r 5.</summary>
        /// <param name="t4">The R4 topic list (Parameters object)</param>
        /// <returns>A List&lt;r5.SubscriptionTopic&gt;.</returns>
        public static List <r5.SubscriptionTopic> TopicListToR5(r4.Parameters t4)
        {
            List <r5.SubscriptionTopic> t5List = new List <r5.SubscriptionTopic>();

            if (t4 == null)
            {
                return(t5List);
            }

            foreach (r4.Parameters.ParameterComponent param in t4.Parameter)
            {
                if ((param.Name == ParameterTopicName) &&
                    (param.Value != null))
                {
                    string topicUrl = string.Empty;

                    switch (param.Value)
                    {
                    case Canonical canonical:
                        topicUrl = canonical.Value;
                        break;

                    case FhirUri fhirUri:
                        topicUrl = fhirUri.Value;
                        break;

                    case FhirUrl fhirUrl:
                        topicUrl = fhirUrl.Value;
                        break;

                    case FhirString fhirString:
                        topicUrl = fhirString.Value;
                        break;
                    }

                    if (string.IsNullOrEmpty(topicUrl))
                    {
                        continue;
                    }

                    if (!SubscriptionTopicManager.TryGetTopic(topicUrl, out r5.SubscriptionTopic t5))
                    {
                        Console.WriteLine($"Unknown R5 SubscriptionTopic: {topicUrl}");
                        return(null);
                    }

                    t5List.Add(t5);
                }
            }

            return(t5List);
        }
        /// <summary>Topic list from r 5.</summary>
        /// <param name="t5List">The topics.</param>
        /// <returns>The r4.Parameters.</returns>
        public static r4.Parameters TopicListFromR5(List <r5.SubscriptionTopic> t5List)
        {
            r4.Parameters t4 = new r4.Parameters();

            if (t5List == null)
            {
                return(t4);
            }

            foreach (r5.SubscriptionTopic topic in t5List)
            {
                t4.Add("subscription-topic-canonical", new Canonical(topic.Url));
            }

            return(t4);
        }
        /// <summary>Converts a different FHIR version SubscriptionStatus to R5.</summary>
        /// <param name="status4">The SubscriptionStatus.</param>
        /// <returns>R5 SubscriptionStatus.</returns>
        public static r5.SubscriptionStatus StatusToR5(r4.Parameters status4)
        {
            if (status4 == null)
            {
                return(null);
            }

            r5.SubscriptionStatus status5 = new r5.SubscriptionStatus();

            foreach (r4.Parameters.ParameterComponent param in status4.Parameter)
            {
                switch (param.Name)
                {
                case "subscription":
                    break;

                case "topic":
                    break;

                case "events-since-subscription-start":
                    break;

                case "events-in-notification":
                    break;

                case "status":
                    break;

                case "type":
                    break;

                case "error":
                    break;
                }
            }

            return(status5);
        }
        /// <summary>Converts an R5 subscription to another FHIR version.</summary>
        /// <param name="status5">The SubscriptionStatus.</param>
        /// <returns>The desired version of a SubscriptionStatus.</returns>
        public static r4.Parameters StatusFromR5(r5.SubscriptionStatus status5)
        {
            if (status5 == null)
            {
                return(null);
            }

            r4.Parameters status4 = new r4.Parameters();

            status4.Add("subscription", new ResourceReference(Program.UrlForR5ResourceId("Subscription", status5.Subscription.Reference)));
            status4.Add("topic", new FhirUri(status5.Topic));
            status4.Add("events-since-subscription-start", new UnsignedInt((int?)status5.EventsSinceSubscriptionStart));
            status4.Add("events-in-notification", new UnsignedInt(status5.EventsInNotification));

            switch (status5.Status)
            {
            case r5.SubscriptionState.Active:
                status4.Add("status", new Code("active"));
                break;

            case r5.SubscriptionState.Error:
                status4.Add("status", new Code("error"));
                break;

            case r5.SubscriptionState.Off:
                status4.Add("status", new Code("off"));
                break;

            case r5.SubscriptionState.Requested:
                status4.Add("status", new Code("requested"));
                break;

            default:
                break;
            }

            switch (status5.Type)
            {
            case r5.SubscriptionStatus.SubscriptionNotificationType.Handshake:
                status4.Add("type", new Code("handshake"));
                break;

            case r5.SubscriptionStatus.SubscriptionNotificationType.Heartbeat:
                status4.Add("type", new Code("heartbeat"));
                break;

            case r5.SubscriptionStatus.SubscriptionNotificationType.EventNotification:
                status4.Add("type", new Code("event-notification"));
                break;

            case r5.SubscriptionStatus.SubscriptionNotificationType.QueryStatus:
                status4.Add("type", new Code("query-status"));
                break;
            }

            if ((status5.Error != null) && (status5.Error.Count > 0))
            {
                status4.Add("error", status5.Error[status5.Error.Count - 1]);
            }

            return(status4);
        }