Beispiel #1
0
        private bool CopyToHl7Message(Hl7Message hl7Message, Hl7Comparator sourceComparator)
        {
            bool messagePopulated = true;

            // Check if both templates have been initialized correctly
            if ((this.Template == null) ||
                (sourceComparator.Template == null))
            {
                return(false);
            }

            // Iterate over this comparator
            foreach (Hl7ComparisonTag thisComparisonTag in this.Template.ComparisonTags)
            {
                // try to get the equivalent tag in the sourceComparator
                Hl7ComparisonTag sourceComparisonTag = sourceComparator.Template.ComparisonTags.Find(thisComparisonTag.Tag);
                if (sourceComparisonTag != null)
                {
                    System.String stringValue = sourceComparisonTag.DataFormat.ToHl7Format();
                    if (hl7Message != null)
                    {
                        // add the value
                        hl7Message.AddValue(sourceComparisonTag.Tag.Segment,
                                            sourceComparisonTag.Tag.FieldIndex,
                                            stringValue);
                    }
                }
            }

            return(messagePopulated);
        }
Beispiel #2
0
        public void FixMessage()
        {
            var message = scenarioContext.Get <string>("MessageString");

            message = Hl7Message.Fix(message);
            SetMessageString(message);
        }
Beispiel #3
0
        /// <summary>
        /// Handle the HL7 message update from the Image Manager Actor.
        /// </summary>
        /// <param name="message">HL7 message from Image Manager Actor.</param>
        public void HandleUpdateFromImageManagerActor(Hl7Message message)
        {
            switch (message.MessageType)
            {
            case "ADT":
            {
                switch (message.MessageSubType)
                {
                case "A08":
                    HandlePatientUpdate(message);
                    break;

                case "A40":
                    HandlePatientMerge(message);
                    break;
                }
            }
            break;

            case "ORM":
            {
                switch (message.MessageSubType)
                {
                case "O01":
                    HandleProcedureScheduled(message);
                    HandleProcedureUpdated(message);
                    break;
                }
            }
            break;

            default:
                break;
            }
        }
Beispiel #4
0
        public Task <string> Handle(Hl7Message message)
        {
            var ack = new ACK();
            var hl7 = _parser.Encode(ack);

            return(Task.FromResult(hl7));
        }
Beispiel #5
0
        /// <summary>
        /// Query message handler for the received Hl7 message - send a query response.
        /// </summary>
        /// <param name="hl7RequestMessage">Received HL7 message.</param>
        /// <returns>Hl7Message response.</returns>
        public override Hl7Message MessageHandler(Hl7Message hl7RequestMessage)
        {
            AdrMessage hl7ResponseMessage = new AdrMessage("A19");

            if (hl7RequestMessage is QryMessage)
            {
                QryMessage qryMessage = (QryMessage)hl7RequestMessage;

                // Try to get the ADR message from those stored
                hl7ResponseMessage = GetMatchingResponse(qryMessage.QRD[8]);
                if (hl7ResponseMessage == null)
                {
                    // return empty message
                    hl7ResponseMessage = new AdrMessage("A19");
                }

                // copy the QRD segment
                for (int i = 0; i < qryMessage.QRD.Count; i++)
                {
                    hl7ResponseMessage.QRD[i] = qryMessage.QRD[i];
                }
            }

            // fill in the MSA segment
            hl7ResponseMessage.MSA[1] = "AA";
            hl7ResponseMessage.MSA[2] = hl7RequestMessage.MessageControlId;

            return(hl7ResponseMessage);
        }
Beispiel #6
0
        public void ShouldThrowExceptionWhenThereAreTooManyParsingDelimiters()
        {
            //Arrange
            const string message = @"MSH|^~\ &|LIFTLAB||UBERMED||201701131234||ORU^R01|K113|P|";

            //Assert
            Assert.Throws <ArgumentException>(() => { Hl7Message.Parse(message); });
        }
Beispiel #7
0
        public void ShouldThrowExceptionWhenParsingDelimitersAreAlphanumeric()
        {
            //Arrange
            const string message = @"MSH|AB12|LIFTLAB||UBERMED||201701131234||ORU^R01|K113|P|";

            //Assert
            Assert.Throws <ArgumentException>(() => { Hl7Message.Parse(message); });
        }
Beispiel #8
0
        public void ParseMessage()
        {
            var message       = scenarioContext.Get <string>("MessageString");
            var parsedMessage = Hl7Message.Parse(message);

            parsedMessage.EnsureFullyParsed();
            scenarioContext["ParsedMessage"] = parsedMessage;
        }
Beispiel #9
0
        public void Add_hl7Message()
        {
            Hl7Message hl7Message = new Hl7Message();
            int        count      = attributeCollections.Count;

            attributeCollections.Add(hl7Message);
            Assert.That(count + 1, Is.EqualTo(attributeCollections.Count));
        }
Beispiel #10
0
        public Task <IMessage> Handle(
            Hl7Message message,
            CancellationToken cancellation = default)
        {
            var ack = new ACK();

            return(Task.FromResult <IMessage>(ack));
        }
Beispiel #11
0
        public void ShouldReadDelimitersFromMessage()
        {
            //Act
            var message = Hl7Message.Parse(MessageMshOnlyOtherFieldDelimiter);

            //Assert
            Assert.Equal('$', message.Encoding.FieldSeparator);
            Assert.Equal("RECEIVING_APPLICATION", message["MSH.4"].ToString());
        }
Beispiel #12
0
        public void Add_hl7Message_flags()
        {
            FlagsHl7Attribute flags      = new FlagsHl7Attribute();
            Hl7Message        hl7Message = new Hl7Message();
            int count = attributeCollections.Count;

            attributeCollections.Add(hl7Message, flags);
            Assert.That(count + 1, Is.EqualTo(attributeCollections.Count));
        }
Beispiel #13
0
        public static DvtkData.Dimse.DataSet Convert(Hl7Message message)
        {
            DvtkData.Dimse.DataSet dataset = new DvtkData.Dimse.DataSet("Transient");

            try
            {
                if (message != null)
                {
                    // iterate over all the segments in the HL7 message
                    ICollection segments = message.Segments.Values;
                    foreach (Hl7Segment hl7Segment in segments)
                    {
                        // iterate over all the fields in the HL7 segments
                        for (int i = 1; i < hl7Segment.Count; i++)
                        {
                            System.String hl7Value = hl7Segment[i];
                            if (hl7Value != System.String.Empty)
                            {
                                // check if there is an Hl7 Tag corresponding to the value in the DicomHl7Template
                                Hl7Tag         hl7Tag         = new Hl7Tag(hl7Segment[0], i);
                                DicomHl7TagMap dicomHl7TagMap = DicomHl7TagMapTemplate.FindTagMap(hl7Tag);
                                if (dicomHl7TagMap != null)
                                {
                                    System.String dicomValue = hl7Value;
                                    if (dicomHl7TagMap.ValueConvertor != null)
                                    {
                                        dicomValue = dicomHl7TagMap.ValueConvertor.FromHl7ToDicom(hl7Value, dicomHl7TagMap.Hl7ComponentIndex);
                                    }
                                    AddDicomAttribute(dataset, dicomHl7TagMap.DicomTagPath, dicomValue);
                                }

                                for (int componentIndex = 2; componentIndex < 7; componentIndex++)
                                {
                                    dicomHl7TagMap = DicomHl7TagMapTemplate.FindTagMap(hl7Tag, componentIndex);
                                    if (dicomHl7TagMap != null)
                                    {
                                        System.String dicomValue = hl7Value;
                                        if (dicomHl7TagMap.ValueConvertor != null)
                                        {
                                            dicomValue = dicomHl7TagMap.ValueConvertor.FromHl7ToDicom(hl7Value, dicomHl7TagMap.Hl7ComponentIndex);
                                        }
                                        AddDicomAttribute(dataset, dicomHl7TagMap.DicomTagPath, dicomValue);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine("HL7 to DICOM conversion exception: {0} - {1}", e.Message, e.StackTrace);
            }

            return(dataset);
        }
Beispiel #14
0
        public Task <IMessage> Handle(
            Hl7Message message,
            CancellationToken cancellation = default)
        {
            var controlId = message.Message.GetMessageControlId();
            var ack       = new ACK();

            ack.MSH.MessageControlID.Value = controlId;
            return(Task.FromResult <IMessage>(ack));
        }
Beispiel #15
0
        private void UpdateImageArchiveActor(Hl7Message message)
        {
            String            actorId           = GetFirstActorIdFromDicomServer(ActorTypeEnum.ImageArchive);
            ImageArchiveActor imageArchiveActor = (ImageArchiveActor)IheFramework.GetActor(new ActorName(ActorTypeEnum.ImageArchive, actorId));

            if (imageArchiveActor != null)
            {
                imageArchiveActor.HandleUpdateFromImageManagerActor(message);
            }
        }
Beispiel #16
0
        public void ShouldReturnTheMessageVersion()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            //Act
            var version = message.MessageVersion;

            //Assert
            Assert.Equal("2.3", version);
        }
Beispiel #17
0
        /// <summary>
        /// See the Dvtk.Comparator.Hl7Comparator.PopulateMessage method.
        /// </summary>
        /// <param name="hl7Message">See the Dvtk.Comparator.Hl7Comparator.PopulateMessage method.</param>
        /// <param name="hl7SourceComparator">See the Dvtk.Comparator.Hl7Comparator.PopulateMessage method.</param>
        /// <returns>See the Dvtk.Comparator.Hl7Comparator.PopulateMessage method.</returns>
        public bool PopulateHl7Message(Hl7Message hl7Message, Hl7Comparator hl7SourceComparator)
        {
            bool messagePopulated = false;

            if (_hl7Comparator != null)
            {
                messagePopulated = _hl7Comparator.PopulateMessage(hl7Message, hl7SourceComparator);
            }

            return(messagePopulated);
        }
Beispiel #18
0
        public bool SetUp(Hl7Message hl7Message)
        {
            System.String messageType    = hl7Message.MessageType;
            System.String messageSubType = hl7Message.MessageSubType;

            // Try to initialise a template
            _template = new Hl7ComparisonTemplate();
            bool setUpDone = _template.Initialize(messageType, messageSubType);

            return(setUpDone);
        }
Beispiel #19
0
        public void ShouldReturnNullForNotFoundFields()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            //Act
            var field = message["OBX.1"];

            //Assert
            Assert.Null(field);
        }
Beispiel #20
0
        public void ShouldReturnNullForNotFoundSegments()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            //Act
            var segment = message["OBX"];

            //Assert
            Assert.Null(segment);
        }
Beispiel #21
0
        public void ShouldReturnTheField()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            //Act
            var field = message["EVN.1"].ToString();

            //Assert
            Assert.Equal("A01", field);
        }
Beispiel #22
0
        public void ShouldReturnTheMessageType()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            //Act
            var controlId = message.MessageType;

            //Assert
            Assert.Equal("ADT^A01", controlId);
        }
Beispiel #23
0
        public void ShouldReturnTheMessageControlId()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            //Act
            var controlId = message.MessageControlId;

            //Assert
            Assert.Equal("934576120110613083617", controlId);
        }
Beispiel #24
0
        public void ShouldReturnTheProcessingId()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            //Act
            var processingId = message.ProcessingId;

            //Assert
            Assert.Equal("P", processingId);
        }
Beispiel #25
0
        public void GetSegmentsShouldReturnExpectedSegmentCount()
        {
            // Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            // Act
            var segments = message.Segments;

            // Assert
            Assert.Equal(4, segments.Count);
        }
Beispiel #26
0
        public void ShouldReturnTheSegment()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01Message);

            //Act
            var segment = message["EVN"].ToString();

            //Assert
            Assert.Equal("EVN|A01|20110613083617", segment);
        }
Beispiel #27
0
        public void ToStringReturnsOriginalStringWithoutTrailingPipes()
        {
            //Arrange
            var message = Hl7Message.Parse(AdtA01MessageNoTrailingSeparators);

            //Act
            var messageString = message.ToString();

            //Assert
            Assert.Equal(AdtA01MessageNoTrailingSeparators, messageString);
        }
Beispiel #28
0
        /// <summary>
        /// Default message handler for the received Hl7 message - just send an ACK.
        /// </summary>
        /// <param name="hl7RequestMessage">Received HL7 message.</param>
        /// <returns>Hl7Message response.</returns>
        public virtual Hl7Message MessageHandler(Hl7Message hl7RequestMessage)
        {
            // Set up an ACK message to return
            AckMessage hl7ResponseMessage = new AckMessage(hl7RequestMessage.MessageSubType);

            // fill in the MSA segment
            hl7ResponseMessage.MSA[1] = "AA";
            hl7ResponseMessage.MSA[2] = hl7RequestMessage.MessageControlId;

            return(hl7ResponseMessage);
        }
Beispiel #29
0
            public async Task WhenHandlingMessageThenReturnsResponse()
            {
                IMessageControlIdGenerator generator = DefaultMessageControlIdGenerator.Instance;
                var adt = new ADT_A01();

                adt.MSH.MessageControlID.Value = generator.NextId();

                var msg      = new Hl7Message(adt, "");
                var response = await _defaultHl7MessageMiddleware.Handle(msg).ConfigureAwait(false);

                Assert.NotNull(response);
            }
Beispiel #30
0
            public async Task WhenHandlingDischargeMessageThenReturnsResponse()
            {
                var parser = new PipeParser();
                var adt    = parser.Parse(@"MSH|^~\&|AccMgr|1|||20050112154645||ADT^A03|59912415|P|2.5.1||| EVN|A03|20050112154642|||||
PID|1||10006579^^^1^MRN^1||DUCK^DONALD^D||19241010|M||1|111^DUCK ST^^FOWL^CA^999990000^^M|1|8885551212|8885551212|1|2||40007716^^^AccMgr^VN^1|123121234|||||||||||NO
PV1|1|I|IN1^214^1^1^^^S|3||IN1^214^1|37^DISNEY^WALT^^^^^^AccMgr^^^^CI|||01||||1|||37^DISNEY^WALT^^^^^^AccMgr^^^^CI|2|40007716^^^AccMgr^VN|4||||||||||||||||1|||1||P|||20050110045253|20050112152000|3115.89|3115.89|||");

                var msg      = new Hl7Message(adt, "");
                var response = await _defaultHl7MessageMiddleware.Handle(msg).ConfigureAwait(false);

                Assert.NotNull(response);
            }