Exemplo n.º 1
0
        /// <summary>
        /// Perform an update of the specified patient
        /// </summary>
        protected virtual IMessage PerformUpdate(Hl7MessageReceivedEventArgs e, Bundle updateBundle)
        {
            try
            {
                var patient = updateBundle.Item.OfType <Patient>().FirstOrDefault(it => it.Tags.Any(t => t.TagKey == ".v2.segment" && t.Value == "PID"));
                if (patient == null)
                {
                    throw new ArgumentNullException(nameof(updateBundle), "Message did not contain a patient");
                }
                else if (!patient.Key.HasValue)
                {
                    throw new InvalidOperationException("Update can only be performed on existing patients. Ensure that a unique identifier exists on the update record");
                }
                var repoService = ApplicationServiceContext.Current.GetService <IRepositoryService <Bundle> >();
                if (repoService == null)
                {
                    throw new InvalidOperationException("Cannot find repository for Patient");
                }

                updateBundle = repoService.Save(updateBundle);
                AuditUtil.AuditUpdate(Core.Auditing.OutcomeIndicator.Success, null, updateBundle.Item.ToArray());

                // Create response message
                return(this.CreateACK(typeof(ACK), e.Message, "CA", $"{patient.Key} updated"));
            }
            catch
            {
                AuditUtil.AuditUpdate(Core.Auditing.OutcomeIndicator.MinorFail, null, updateBundle.Item.ToArray());
                throw;
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Send audit merge
 /// </summary>
 protected virtual void SendAuditMerge(OutcomeIndicator outcome, IMessage message, RecordMergeResult recordMergeResult)
 {
     if (recordMergeResult != null)
     {
         AuditUtil.AuditDelete(outcome, "ADT^A40", new Patient()
         {
             Key = recordMergeResult.Replaced.First()
         });
         AuditUtil.AuditUpdate(outcome, "ADT^A40", new Patient()
         {
             Key = recordMergeResult.Survivors.First()
         });
     }
     else
     {
         AuditUtil.AuditUpdate <IdentifiedData>(outcome, "ADT^A40");
     }
 }
        public virtual Object Update(Object data)
        {
            if ((this.Capabilities & ResourceCapabilityType.Update) == 0)
            {
                throw new NotSupportedException(this.m_localizationService.GetString("error.type.NotSupportedException"));
            }

            Bundle bundleData = data as Bundle;

            bundleData?.Reconstitute();
            var processData = bundleData?.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 entityData = processData as TResource;

                    var retVal = this.GetRepository().Save(entityData);
                    AuditUtil.AuditUpdate(Core.Auditing.OutcomeIndicator.Success, null, retVal);
                    return(retVal);
                }
                else
                {
                    this.m_tracer.TraceError("Invalid persistence type");
                    throw new ArgumentException(this.m_localizationService.GetString("error.rest.common.invalidPersistentType"));
                }
            }
            catch (Exception e)
            {
                AuditUtil.AuditUpdate(Core.Auditing.OutcomeIndicator.MinorFail, null, data);
                this.m_tracer.TraceError("Error updating resource");
                throw new Exception(this.m_localizationService.GetString("error.rest.common.updatingResource"), e);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Send audit update
 /// </summary>
 protected virtual void SendAuditUpdate(OutcomeIndicator outcome, IMessage message, IEnumerable <IdentifiedData> results)
 {
     AuditUtil.AuditUpdate(outcome, null, results?.ToArray());
 }