예제 #1
0
        private ACK InitAcknowledgment(HL7Header hl7Header)
        {
            ACK reply = new ACK();

            Identifier serverApplication = hl7Header.ReceivingApplication;
            Identifier serverFacility    = hl7Header.ReceivingFacility;
            //Identifier sendingApplication = PixRegistryConfigration.ReceivingApplication;
            //Identifier sendingFacility = PixRegistryConfigration.ReceivingFacility;
            Identifier sendingApplication = hl7Header.SendingApplicaiton;
            Identifier sendingFacility    = hl7Header.SendingFacility;

            string @event = hl7Header.TriggerEvent;

            PopulateMSH(
                reply.MSH,
                "ACK",
                @event,
                hl7Header.MessageControlId,
                serverApplication,
                serverFacility,
                sendingApplication,
                sendingFacility);

            return(reply);
        }
예제 #2
0
        private Boolean IsHeaderValid(HL7Header _header)
        {
            Boolean bErr = false;

            var data = _header.MSHSegment.Version;

            Assert.AreNotSame("2.3", data);
            data = _header.MSHSegment.SendingFacility;
            Assert.AreNotSame("PTOX", data);

            return(bErr);
        }
예제 #3
0
        public byte[] ProcessMessage(byte[] request)
        {
            string msgIn = Encoding.UTF8.GetString(request);

            var parser = new PipeParser();

            IMessage  msg    = parser.Parse(msgIn, "2.3.1");
            HL7Header header = new HL7Header(msg);

            ACK reply = InitAcknowledgment(header);
            XdsPatientServiceImpl patientService = new XdsPatientServiceImpl();

            PID pid231;

            try
            {
                LogAdapter.Logger.Info(string.Format("Process HL7 event {0}", header.TriggerEvent));
                //Platform.Log(LogLevel.Info, "Process HL7 event {0}", header.TriggerEvent);
                switch (header.TriggerEvent)
                {
                case "A01":
                case "A04":
                case "A05":     // Insert Patient
                {
                    pid231 = (PID)msg.GetStructure("PID");
                    PatientIdentifier patientIdentifier = GetPatientIdentifier(pid231);
                    var patientInfo = new PatientInfo()
                    {
                        PatientIdent = patientIdentifier
                    };

                    //if (!PixRegistryConfigration.IsValidDomain(patient.AssigningAuthority))
                    //{
                    //    PopulateErr(reply.ERR, "PID", "1", "3", "204", "Unknown Key Identifier", "Domain don't accept.");
                    //    throw new HL7Exception("Unknown Key Identifier", ErrorCode.UnknownKeyIdentifier, ErrorSeverity.E);
                    //}

                    AnalyzePID(pid231, ref patientInfo);
                    patientService.CreatePatient(patientInfo);
                    break;
                }

                case "A08":     // Update Patient
                {
                    pid231 = (PID)msg.GetStructure("PID");
                    PatientIdentifier patientIdentifier = GetPatientIdentifier(pid231);
                    var patientInfo = new PatientInfo()
                    {
                        PatientIdent = patientIdentifier
                    };

                    //if (!PixRegistryConfigration.IsValidDomain(patient.AssigningAuthority))
                    //{
                    //    PopulateErr(reply.ERR, "PID", "1", "3", "204", "Unknown Key Identifier", "Domain don't accept.");
                    //    throw new HL7Exception("Unknown Key Identifier", ErrorCode.UnknownKeyIdentifier, ErrorSeverity.E);
                    //}

                    AnalyzePID(pid231, ref patientInfo);
                    patientService.UpdatePatient(patientInfo);
                    break;
                }

                //case "A40": // Merge Patient
                //    {
                //        ADT_A40_PATIENT allPatient = (ADT_A40_PATIENT)msg.GetStructure("PATIENT");
                //        PatientIdentifier patient = GetPatientIdentifier(allPatient.PID);
                //        PatientIdentifier mergePatient = GetMrgPatientIdentifier(allPatient.MRG);

                //        //if (!PixRegistryConfigration.IsValidDomain(patient.AssigningAuthority))
                //        //{
                //        //    PopulateErr(reply.ERR, "PID", "1", "3", "204", "Unknown Key Identifier", "Domain don't accept.");
                //        //    throw new HL7Exception("Unknown Key Identifier", ErrorCode.UnknownKeyIdentifier, ErrorSeverity.E);
                //        //}

                //        patientService.MergePatient(patient, mergePatient);
                //        break;
                //    }

                default:
                {
                    const string ErrorMsg =
                        "Unexpected request to XDS-Registry. Valid message type are ADT^A01, ADT^A04, ADT^A05, ADT^A08, ADT^A40";
                    LogAdapter.Logger.Error(ErrorMsg);
                    //Platform.Log(LogLevel.Warn, ErrorMsg);
                    throw new Exception(ErrorMsg);
                }
                }

                PopulateMSA(reply.MSA, "AA", header.MessageControlId);
            }
            catch (HL7Exception ex)
            {
                LogAdapter.Logger.TraceException(ex);
                //Platform.Log(LogLevel.Warn, ex);
                PopulateMSA(reply.MSA, "AE", header.MessageControlId);
            }
            catch (PatientDonotExistException ex)
            {
                LogAdapter.Logger.TraceException(ex);
                //Platform.Log(LogLevel.Warn, ex);
                PopulateMSA(reply.MSA, "AE", header.MessageControlId);
                PopulateErr(reply.ERR, "PID", "1", "3", "204", "Unknown Key Identifier", ex.Message);
            }
            catch (Exception ex)
            {
                LogAdapter.Logger.TraceException(ex);
                //Platform.Log(LogLevel.Warn, ex);
                PopulateMSA(reply.MSA, "AE", header.MessageControlId);
                PopulateErr(reply.ERR, string.Empty, string.Empty, string.Empty, "207", "Application internal error", ex.Message);
            }

            return(Encoding.UTF8.GetBytes(parser.Encode(reply)));
        }