예제 #1
0
        /// <summary>
        /// Perform an admission operation
        /// </summary>
        protected virtual IMessage PerformAdmit(Hl7MessageReceivedEventArgs e, Bundle insertBundle)
        {
            try
            {
                var patient = insertBundle.Item.OfType <Patient>().FirstOrDefault(it => it.Tags.Any(t => t.TagKey == ".v2.segment" && t.Value == "PID"));
                if (patient == null)
                {
                    throw new ArgumentNullException(nameof(insertBundle), "Message did not contain a patient");
                }

                var repoService = ApplicationServiceContext.Current.GetService <IRepositoryService <Bundle> >();
                if (repoService == null)
                {
                    throw new InvalidOperationException("Cannot find repository for Patient");
                }

                insertBundle = repoService.Insert(insertBundle);

                AuditUtil.AuditCreate(Core.Auditing.OutcomeIndicator.Success, null, insertBundle.Item.ToArray());
                // Create response message
                return(this.CreateACK(typeof(ACK), e.Message, "CA", $"{patient.Key} created"));
            }
            catch
            {
                AuditUtil.AuditUpdate(Core.Auditing.OutcomeIndicator.MinorFail, null, insertBundle.Item.ToArray());
                throw;
            }
        }
        public virtual Object Create(Object data, bool updateIfExists)
        {
            if (data == null)
            {
                this.m_tracer.TraceError($"{nameof(data)} cannot be null");
                throw new ArgumentNullException(this.m_localizationService.FormatString("error.type.ArgumentNullException.param", new { param = nameof(data) }));
            }
            else if ((this.Capabilities & ResourceCapabilityType.Create) == 0 &&
                     (this.Capabilities & ResourceCapabilityType.CreateOrUpdate) == 0)
            {
                throw new NotSupportedException(this.m_localizationService.GetString("error.type.NotSupportedException"));
            }

            var bundle = data as Bundle;

            bundle?.Reconstitute();

            var processData = bundle?.GetFocalObject() ?? data;

            try
            {
                if (!(processData is TResource))
                {
                    this.m_tracer.TraceError($"Invalid data submission. Expected {typeof(TResource).FullName} but received {processData.GetType().FullName}. If you are submitting a bundle, ensure it has an entry point.");
                    throw new ArgumentException(this.m_localizationService.FormatString("error.rest.common.invalidDataSubmission", new
                    {
                        param  = typeof(TResource).FullName,
                        param1 = processData.GetType().FullName
                    }));
                }
                else if (processData is TResource)
                {
                    var resourceData = processData as TResource;
                    resourceData = updateIfExists ? this.GetRepository().Save(resourceData) : this.GetRepository().Insert(resourceData);

                    AuditUtil.AuditCreate(Core.Auditing.OutcomeIndicator.Success, null, resourceData);

                    return(resourceData);
                }
            }
            catch (Exception e)
            {
                AuditUtil.AuditCreate(Core.Auditing.OutcomeIndicator.MinorFail, null, data);
                this.m_tracer.TraceError($"Error creating {data}");
                throw new Exception(this.m_localizationService.FormatString("error.rest.common.errorCreatingParam", new { param = nameof(data) }), e);
            }
            this.m_tracer.TraceError($"Invalid data type: {nameof(data)}");
            throw new ArgumentException(nameof(data), this.m_localizationService.GetString("error.rest.common.invalidDataType"));
        }
예제 #3
0
 /// <summary>
 /// Send an audit of admit
 /// </summary>
 protected virtual void SendAuditAdmit(OutcomeIndicator outcomeIndicator, IMessage message, IEnumerable <IdentifiedData> results)
 {
     AuditUtil.AuditCreate(outcomeIndicator, null, results?.ToArray());
 }