示例#1
0
        /// <summary>
        /// Add a parameter with a given name and value.
        /// </summary>
        /// <param name="name">The name of the parameter</param>
        /// <param name="value">The value of the parameter as a FHIR datatype or Resource</param>
        /// <returns>this (Parameters), so you can chain AddParameter calls</returns>
        public Parameters Add(string name, Base value)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var newParam = new ParameterComponent()
            {
                Name = name
            };

            if (value is Element)
            {
                newParam.Value = (Element)value;
            }
            else
            {
                newParam.Resource = (Resource)value;
            }

            Parameter.Add(newParam);

            return(this);
        }
        public void GivenIAddTheMedicationsParameter()
        {
            ParameterComponent param = new ParameterComponent();

            param.Name = FhirConst.GetStructuredRecordParams.kMedication;
            _httpContext.HttpRequestConfiguration.BodyParameters.Parameter.Add(param);
        }
        public void IAddThePrescriptionsPartParameter()
        {
            ParameterComponent param = new ParameterComponent();

            param.Name  = FhirConst.GetStructuredRecordParams.kPrescriptionIssues;
            param.Value = new FhirBoolean(true);
            _httpContext.HttpRequestConfiguration.BodyParameters.Parameter.Add(param);
        }
        public void IAddTheMedicationsDatePeriodPartParameter()
        {
            ParameterComponent param = new ParameterComponent();

            param.Name  = FhirConst.GetStructuredRecordParams.kMedicationDatePeriod;
            param.Value = TimePeriodHelper.GetTimePeriodFormatted("yyyy-MM-dd");
            _httpContext.HttpRequestConfiguration.BodyParameters.Parameter.Add(param);
        }
示例#5
0
        public void GivenIDuplicateParameter()
        {
            ParameterComponent param = new ParameterComponent();

            param.Name = FhirConst.GetStructuredRecordParams.kImmunisations;
            _httpContext.HttpRequestConfiguration.BodyParameters.Parameter.Add(param);

            ParameterComponent param1 = new ParameterComponent();

            param1.Name = FhirConst.GetStructuredRecordParams.kImmunisations;
            _httpContext.HttpRequestConfiguration.BodyParameters.Parameter.Add(param1);
        }
示例#6
0
        /// <summary>
        /// Returns the Value property of the requested parameter casted to the requested type
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="matchPrefix"></param>
        /// <returns></returns>
        public T GetSingleValue <T>(string name, bool matchPrefix = false) where T : Element
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            ParameterComponent p = Get(name, matchPrefix).SingleOrDefault();

            if (p == null)
            {
                return(null);
            }
            return(p.Value as T);
        }
示例#7
0
        public void GivenIAdd2InvalidParametersAndPartParameters()
        {
            Given($"I add the medication parameter with includePrescriptionIssues set to \"false\"");
            IEnumerable <Tuple <string, Base> > tuples = new Tuple <string, Base>[] {
                Tuple.Create("madeUp", (Base) new FhirString("madeUpValue1")),
                Tuple.Create(FhirConst.GetStructuredRecordParams.kProblemsSignificance, (Base) new FhirString("madeUpValue2"))
            };

            _httpContext.HttpRequestConfiguration.BodyParameters.Add("madeUpProblems", tuples);

            ParameterComponent param = new ParameterComponent();

            param.Name = "madeUpImmunisations";
            _httpContext.HttpRequestConfiguration.BodyParameters.Parameter.Add(param);
        }
示例#8
0
        /// <summary>
        /// Add a parameter with a given nanme and tuple value.
        /// </summary>
        /// <param name="name">The name of the parameter</param>
        /// <param name="tuples">The value of the parameter as a list of tuples of (name,FHIR datatype or Resource)</param>
        /// <returns>this (Parameters), so you can chain AddParameter calls</returns>
        public Parameters Add(string name, IEnumerable <Tuple <string, Base> > tuples)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (tuples == null)
            {
                throw new ArgumentNullException("tuples");
            }

            var newParam = new ParameterComponent()
            {
                Name = name
            };

            foreach (var tuple in tuples)
            {
                var newPart = new ParameterComponent()
                {
                    Name = tuple.Item1
                };
                newParam.Part.Add(newPart);

                if (tuple.Item2 is Element)
                {
                    newPart.Value = (Element)tuple.Item2;
                }
                else
                {
                    //TODO: Due to an error in the jan2015 version of DSTU2, this is not yet possible
                    //newPart.Resource = (Resource)tuple.Item2;
                    throw Error.NotImplemented("Jan 2015 DSTU2 does not support resource values for tuples parameters");
                }
            }

            Parameter.Add(newParam);

            return(this);
        }
示例#9
0
        /// <summary>
        /// Convert from ParameterComponent to PendingOperation Object.
        /// </summary>
        /// <param name="component">ParameterComponent.</param>
        /// <returns>PendingOperation.</returns>
        internal static PendingOperation FromParameterComponent(ParameterComponent component)
        {
            var operationTypeString = component.Part.First(x => x.Name == "type").Value.ToString();
            PatchOperationType operationType;

            try
            {
                operationType = (PatchOperationType)Enum.Parse(
                    typeof(PatchOperationType),
                    operationTypeString.ToUpper(new CultureInfo("en-US", false)));
            }
            catch (ArgumentException)
            {
                throw new InvalidOperationException($"Operation type of ${operationTypeString} is not valid.");
            }

            var path  = component.Part.First(x => x.Name == "path").Value.ToString();
            var name  = component.Part.FirstOrDefault(x => x.Name == "name")?.Value.ToString();
            var value = component.Part.FirstOrDefault(x => x.Name == "value");

            int?index       = int.TryParse(component.Part.FirstOrDefault(x => x.Name == "index")?.Value.ToString(), out int itmp) ? itmp : null;
            int?source      = int.TryParse(component.Part.FirstOrDefault(x => x.Name == "source")?.Value.ToString(), out int stmp) ? stmp : null;
            int?destination = int.TryParse(component.Part.FirstOrDefault(x => x.Name == "destination")?.Value.ToString(), out int dtmp) ? dtmp : null;

            return(new PendingOperation
            {
                Type = operationType,
                Parameter = component,
                Path = path,
                Name = name,
                Value = value,
                Index = index,
                Source = source,
                Destination = destination,
            }.Validate());
        }
示例#10
0
        public static Parameters ToParameters(this ImportRequest importRequest)
        {
            Parameters paramters = new Parameters();

            if (string.IsNullOrEmpty(importRequest.InputFormat))
            {
                paramters.Add(InputFormatParamterName, new FhirString(DefaultInputFormat));
            }
            else
            {
                paramters.Add(InputFormatParamterName, new FhirString(importRequest.InputFormat));
            }

            if (importRequest.InputSource != null)
            {
                paramters.Add(InputSourceParamterName, new FhirUri(importRequest.InputSource));
            }

            if (importRequest.Input != null)
            {
                foreach (InputResource importResource in importRequest.Input)
                {
                    ParameterComponent inputResourceComponent = new ParameterComponent()
                    {
                        Name = InputParamterName
                    };
                    paramters.Parameter.Add(inputResourceComponent);

                    if (!string.IsNullOrEmpty(importResource.Type))
                    {
                        inputResourceComponent.Part.Add(new ParameterComponent()
                        {
                            Name = TypeParamterName, Value = new FhirString(importResource.Type)
                        });
                    }

                    if (!string.IsNullOrEmpty(importResource.Etag))
                    {
                        inputResourceComponent.Part.Add(new ParameterComponent()
                        {
                            Name = EtagParamterName, Value = new FhirString(importResource.Etag)
                        });
                    }

                    if (importResource.Url != null)
                    {
                        inputResourceComponent.Part.Add(new ParameterComponent()
                        {
                            Name = UrlParamterName, Value = new FhirUri(importResource.Url)
                        });
                    }
                }
            }

            ParameterComponent storageDetailsParameterComponent = new ParameterComponent()
            {
                Name = StorageDetailParamterName
            };

            if (!string.IsNullOrWhiteSpace(importRequest.StorageDetail?.Type))
            {
                storageDetailsParameterComponent.Part.Add(new ParameterComponent()
                {
                    Name = TypeParamterName, Value = new FhirString(importRequest.StorageDetail.Type)
                });
            }

            paramters.Parameter.Add(storageDetailsParameterComponent);

            if (!string.IsNullOrEmpty(importRequest.Mode))
            {
                paramters.Add(ModeParamterName, new FhirString(importRequest.Mode));
            }

            if (importRequest.Force)
            {
                paramters.Add(ForceParamterName, new FhirBoolean(true));
            }

            return(paramters);
        }
示例#11
0
        public static ImportRequest ExtractImportRequest(this Parameters parameters)
        {
            ImportRequest importRequest = new ImportRequest();

            if (parameters.TryGetStringValue(InputFormatParamterName, out string inputFormat))
            {
                importRequest.InputFormat = inputFormat;
            }

            if (parameters.TryGetUriValue(InputSourceParamterName, out Uri uriValue))
            {
                importRequest.InputSource = uriValue;
            }

            var inputResources = new List <InputResource>();

            foreach (ParameterComponent paramComponent in parameters.Get(InputParamterName))
            {
                ParameterComponent typeParam = paramComponent.Part?.Where(p => TypeParamterName.Equals(p.Name, StringComparison.Ordinal))?.FirstOrDefault();
                ParameterComponent urlParam  = paramComponent.Part?.Where(p => UrlParamterName.Equals(p.Name, StringComparison.Ordinal))?.FirstOrDefault();
                ParameterComponent etagParam = paramComponent.Part?.Where(p => EtagParamterName.Equals(p.Name, StringComparison.Ordinal))?.FirstOrDefault();

                InputResource inputResource = new InputResource();

                if (typeParam.TryGetStringValue(out string type))
                {
                    inputResource.Type = type;
                }

                if (urlParam.TryGetUriValue(out Uri url))
                {
                    inputResource.Url = url;
                }

                if (etagParam.TryGetStringValue(out string etag))
                {
                    inputResource.Etag = etag;
                }

                inputResources.Add(inputResource);
            }

            importRequest.Input         = inputResources;
            importRequest.StorageDetail = new ImportRequestStorageDetail();

            ParameterComponent storageDetailsComponent = parameters.GetSingle(StorageDetailParamterName);
            ParameterComponent storageTypeParam        = storageDetailsComponent?.Part?.Where(p => TypeParamterName.Equals(p.Name, StringComparison.Ordinal))?.FirstOrDefault();

            if (storageTypeParam.TryGetStringValue(out string storageType))
            {
                importRequest.StorageDetail.Type = storageType;
            }
            else
            {
                importRequest.StorageDetail.Type = DefaultStorageDetailType;
            }

            if (parameters.TryGetStringValue(ModeParamterName, out string mode))
            {
                importRequest.Mode = mode;
            }

            if (parameters.TryGetBooleanValue(ForceParamterName, out bool force))
            {
                importRequest.Force = force;
            }

            return(importRequest);
        }