Esempio n. 1
0
        /// <summary>
        /// Notifies a remote system.
        /// </summary>
        /// <param name="workItem">The work item of the notification.</param>
        public void Notify <T>(NotificationQueueWorkItem <T> workItem) where T : IdentifiedData
        {
            IMessage notificationMessage = null;

            var patient = workItem.Event as Patient;

            MSH msh = null;
            PID pid = null;
            EVN evn = null;
            PV1 pv1 = null;

            switch (workItem.ActionType)
            {
            case ActionType.Create:
            case ActionType.DuplicatesResolved:
            case ActionType.Update:
            {
                tracer.TraceEvent(TraceEventType.Information, 0, "Received update notification");

                ADT_A05 message = new ADT_A05();

                msh = message.MSH;
                msh.MessageType.TriggerEvent.Value = "A31";

                pid = message.PID;

                evn = message.EVN;
                evn.EventTypeCode.Value = "A31";

                pv1 = message.PV1;
                notificationMessage = message;

                break;
            }

            default:
                throw new ArgumentOutOfRangeException($"Invalid notification type {workItem.ActionType}");
            }

            NotifierBase.UpdateMSH(msh, patient, this.TargetConfiguration);

            evn.RecordedDateTime.TimeOfAnEvent.Value = (TS)patient.CreationTime.DateTime;

            NotifierBase.UpdatePID(patient, pid, this.TargetConfiguration);

            pv1.PatientClass.Value = "N";

            var queueItem = new MessageQueueWorkItem(notificationMessage, this.TargetConfiguration);

            if (!queueItem.TrySend())
            {
                tracer.TraceEvent(TraceEventType.Warning, 0, "Unable to send message to remote endpoint: {0}", this.TargetConfiguration.ConnectionString);
                Hl7MessageQueue.Current.Enqueue(queueItem);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates a <see cref="PID"/> segment.
        /// </summary>
        /// <param name="patient">The patient to use to update the PID segment.</param>
        /// <param name="pid">The PID segment to update.</param>
        /// <param name="targetConfiguration">The target configuration.</param>
        internal static void UpdatePID(Patient patient, PID pid, TargetConfiguration targetConfiguration)
        {
            // ensure authenticated
            EnsureAuthenticated();

            tracer.TraceEvent(TraceEventType.Verbose, 0, "Start updating PID segment");

            if (patient.GenderConceptKey.HasValue)
            {
                UpdateGender(patient.GenderConceptKey.ToString(), pid);
            }

            if (patient.MultipleBirthOrder.HasValue)
            {
                if (patient.MultipleBirthOrder != 0)
                {
                    pid.BirthOrder.Value = patient.MultipleBirthOrder.ToString();
                }
                pid.MultipleBirthIndicator.Value = "Y";
            }

            if (patient.DateOfBirth.HasValue)
            {
                pid.DateTimeOfBirth.TimeOfAnEvent.Value = (TS)patient.DateOfBirth.Value;
            }

            if (patient.DeceasedDate.HasValue)
            {
                pid.PatientDeathDateAndTime.TimeOfAnEvent.Value = (TS)patient.DeceasedDate.Value;
                pid.PatientDeathIndicator.Value = "Y";
            }

            foreach (var address in patient.LoadCollection <EntityAddress>("Addresses"))
            {
                NotifierBase.UpdateAD(address, pid.GetPatientAddress(pid.PatientAddressRepetitionsUsed));
            }

            var pids = patient.LoadCollection <EntityIdentifier>("Identifiers").Where(item => assigningAuthorityRepositoryService.Find(a => a.DomainName == item.Authority.DomainName).FirstOrDefault() != null).ToArray();

            for (var i = 0; i < pids.Length; i++)
            {
                var patientIdentifier = pids[i];

                pid.GetPatientIdentifierList(i).ID.Value = patientIdentifier.Value;
                pid.GetPatientIdentifierList(i).AssigningAuthority.NamespaceID.Value     = patientIdentifier.Authority.DomainName;
                pid.GetPatientIdentifierList(i).AssigningAuthority.UniversalID.Value     = patientIdentifier.Authority.Oid;
                pid.GetPatientIdentifierList(i).AssigningAuthority.UniversalIDType.Value = "ISO";
                pid.GetPatientIdentifierList(i).IdentifierTypeCode.Value = "PI";
            }

            // Create the PI for the patient key
            var lastPid = pid.PatientIdentifierListRepetitionsUsed;

            pid.GetPatientIdentifierList(lastPid).ID.Value = patient.Key.ToString();
            pid.GetPatientIdentifierList(lastPid).AssigningAuthority.UniversalID.Value     = ApplicationContext.Current.Configuration?.Custodianship?.Id?.AssigningAuthority?.Oid;
            pid.GetPatientIdentifierList(lastPid).AssigningAuthority.UniversalIDType.Value = "ISO";
            pid.GetPatientIdentifierList(lastPid).IdentifierTypeCode.Value = "PI";

            foreach (var personLanguage in patient.LoadCollection <PersonLanguageCommunication>("LanguageCommunication").Where(l => l.IsPreferred))
            {
                pid.PrimaryLanguage.Identifier.Value = personLanguage.LanguageCode;
                //pid.PrimaryLanguage.NameOfCodingSystem.Value = "ISO639-1";
            }

            foreach (var mother in patient.LoadCollection <EntityRelationship>("Relationships").Where(r => (r.RelationshipTypeKey == EntityRelationshipTypeKeys.Mother ||
                                                                                                            r.RelationshipTypeKey == EntityRelationshipTypeKeys.NaturalMother) &&
                                                                                                      r.LoadProperty <Entity>("TargetEntity") is Person).Select(relationship => relationship.TargetEntity as Person))
            {
                mother.Identifiers.ForEach(c =>
                {
                    pid.GetMotherSIdentifier(pid.MotherSIdentifierRepetitionsUsed).ID.Value = c.Value;
                    pid.GetMotherSIdentifier(pid.MotherSIdentifierRepetitionsUsed).AssigningAuthority.NamespaceID.Value     = c.Authority.Oid;
                    pid.GetMotherSIdentifier(pid.MotherSIdentifierRepetitionsUsed).AssigningAuthority.UniversalIDType.Value = "ISO";
                    pid.GetPatientIdentifierList(pid.PatientIdentifierListRepetitionsUsed).IdentifierTypeCode.Value         = c.Authority.DomainName;
                });

                mother.Names.ForEach(c =>
                {
                    NotifierBase.UpdateXPN(c, pid.GetMotherSMaidenName(pid.MotherSMaidenNameRepetitionsUsed));
                });
            }

            foreach (var name in patient.LoadCollection <EntityName>("Names"))
            {
                NotifierBase.UpdateXPN(name, pid.GetPatientName(pid.PatientNameRepetitionsUsed));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Notifies a remote system.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="workItem">The work item of the notification.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        public void Notify <T>(NotificationQueueWorkItem <T> workItem) where T : IdentifiedData
        {
            IMessage notificationMessage;

            var patient = workItem.Event as Patient;

            MSH msh;
            PID pid;
            EVN evn;
            PV1 pv1;
            MRG mrg = null;

            switch (workItem.ActionType)
            {
            case ActionType.Create:
            {
                tracer.TraceEvent(TraceEventType.Information, 0, "Received create notification");

                var message = new ADT_A01();

                msh = message.MSH;
                msh.MessageType.MessageType.Value      = "ADT";
                msh.MessageType.MessageStructure.Value = "ADT_A01";
                msh.MessageType.TriggerEvent.Value     = "A01";

                pid = message.PID;

                evn = message.EVN;
                evn.EventTypeCode.Value = "A01";

                pv1 = message.PV1;
                notificationMessage = message;

                break;
            }

            case ActionType.DuplicatesResolved:
            {
                tracer.TraceEvent(TraceEventType.Information, 0, "Received duplicates resolved notification");

                var message = new ADT_A39();

                msh = message.MSH;
                msh.MessageType.MessageType.Value      = "ADT";
                msh.MessageType.MessageStructure.Value = "ADT_A40";
                msh.MessageType.TriggerEvent.Value     = "A40";

                pid = message.GetPATIENT(0).PID;

                evn = message.EVN;
                evn.EventTypeCode.Value = "A40";

                pv1 = message.GetPATIENT(0).PV1;
                mrg = message.GetPATIENT(0).MRG;
                notificationMessage = message;

                break;
            }

            case ActionType.Update:
            {
                tracer.TraceEvent(TraceEventType.Information, 0, "Received update notification");

                var message = new ADT_A01();

                msh = message.MSH;
                msh.MessageType.MessageType.Value      = "ADT";
                msh.MessageType.MessageStructure.Value = "ADT_A08";
                msh.MessageType.TriggerEvent.Value     = "A08";

                pid = message.PID;

                evn = message.EVN;
                evn.EventTypeCode.Value = "A08";

                pv1 = message.PV1;
                notificationMessage = message;

                break;
            }

            default:
                throw new ArgumentOutOfRangeException($"Invalid notification type {workItem.ActionType}");
            }

            NotifierBase.UpdateMSH(msh, patient, this.TargetConfiguration);

            evn.RecordedDateTime.TimeOfAnEvent.Value = (TS)patient.CreationTime.DateTime;

            NotifierBase.UpdatePID(patient, pid, this.TargetConfiguration);

            pv1.PatientClass.Value = "I";

            // TODO: populate the merge information
            if (mrg != null)
            {
            }

            var queueItem = new MessageQueueWorkItem(notificationMessage, this.TargetConfiguration);

            if (!queueItem.TrySend())
            {
                tracer.TraceEvent(TraceEventType.Warning, 0, "Unable to send message to remote endpoint: {0}", this.TargetConfiguration.ConnectionString);
                Hl7MessageQueue.Current.Enqueue(queueItem);
            }
        }