Exemple #1
0
        /// <summary>
        /// Query data from the client registry
        /// </summary>
        public SVC.Messaging.FHIR.FhirQueryResult Query(System.Collections.Specialized.NameValueCollection parameters)
        {
            FhirQueryResult result = new FhirQueryResult();

            result.Details = new List <IResultDetail>();

            // Get query parameters
            var resourceProcessor = FhirMessageProcessorUtil.GetMessageProcessor(this.ResourceName);

            // Process incoming request

            NameValueCollection goodParameters = new NameValueCollection();

            for (int i = 0; i < parameters.Count; i++)
            {
                for (int v = 0; v < parameters.GetValues(i).Length; v++)
                {
                    if (!String.IsNullOrEmpty(parameters.GetValues(i)[v]))
                    {
                        goodParameters.Add(parameters.GetKey(i), MessageUtil.Escape(parameters.GetValues(i)[v]));
                    }
                }
            }
            parameters = goodParameters;

            var queryObject = resourceProcessor.ParseQuery(goodParameters, result.Details);

            result.Query = queryObject;

            // sanity check
#if !DEBUG
            if (result.Query.ActualParameters.Count == 0)
            {
                result.Outcome = ResultCode.Rejected;
                result.Details.Add(new ValidationResultDetail(ResultDetailType.Error, ApplicationContext.LocalizationService.GetString("MSGE077"), null, null));
            }
            else
#endif
            if (result.Details.Exists(o => o.Type == ResultDetailType.Error))
            {
                result.Outcome = ResultCode.Error;
                result.Details.Add(new ResultDetail(ResultDetailType.Error, ApplicationContext.LocalizationService.GetString("MSGE00A"), null, null));
            }
            else if (queryObject.Filter == null || result.Outcome != ResultCode.Accepted)
            {
                throw new InvalidOperationException("Could not process query parameters!");
            }
            else
            {
                result = DataUtil.Query(queryObject, result.Details);
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Update a patient
        /// </summary>
        public SVC.Messaging.FHIR.FhirOperationResult Update(string id, SVC.Messaging.FHIR.Resources.ResourceBase target, SVC.Core.Services.DataPersistenceMode mode)
        {
            // Create a registration event ... subject
            FhirOperationResult retVal = new FhirOperationResult();

            retVal.Details = new List <IResultDetail>();

            // Get query parameters
            var resourceProcessor = FhirMessageProcessorUtil.GetMessageProcessor(this.ResourceName);

            // Parse the incoming request
            if (target != null)
            {
                target.Id = id;
            }
            var storeContainer = resourceProcessor.ProcessResource(target, retVal.Details);

            if (storeContainer == null)
            {
                retVal.Outcome = ResultCode.AcceptedNonConformant;
            }
            else
            {
                // Now store the container
                try
                {
                    // HACK: Store the container
                    storeContainer = DataUtil.Update(storeContainer, id, mode, retVal.Details);

                    retVal.Outcome = ResultCode.Accepted;
                    retVal.Results = new List <ResourceBase>();
                    retVal.Results.Add(resourceProcessor.ProcessComponent(storeContainer, retVal.Details));
                }
                catch (MissingPrimaryKeyException e)
                {
                    retVal.Details.Add(new ResultDetail(ResultDetailType.Error, e.Message, e));
                    retVal.Outcome = ResultCode.TypeNotAvailable;
                    throw e;
                }
                catch (Exception e)
                {
                    retVal.Details.Add(new ResultDetail(ResultDetailType.Error, ApplicationContext.LocalizationService.GetString("DTPE001"), e));
                    retVal.Outcome = ResultCode.Error;
                }
            }
            return(retVal);
        }