Пример #1
0
        public static string GenerateInpatientTransferMessage(InpatientTransferMessageModel messageData, out string messageControlId)
        {
            string messageDateTime = DateTime.Now.ToString("yyyyMMddHHmmss");

            messageControlId = Guid.NewGuid().ToString();

            ADT_A02 adtMessage = new ADT_A02();

            adtMessage.MSH.FieldSeparator.Value                   = "|";
            adtMessage.MSH.EncodingCharacters.Value               = "^~\\&";
            adtMessage.MSH.SendingApplication.NamespaceID.Value   = Environment.GetEnvironmentVariable("OutboundInterface_SendingApplicationName");
            adtMessage.MSH.ReceivingApplication.NamespaceID.Value = "PCS_IN";
            adtMessage.MSH.DateTimeOfMessage.TimeOfAnEvent.Value  = messageDateTime;
            adtMessage.MSH.MessageType.MessageType.Value          = "ADT";
            adtMessage.MSH.MessageType.TriggerEvent.Value         = "A08";
            adtMessage.MSH.MessageControlID.Value                 = messageControlId;
            adtMessage.MSH.ProcessingID.ProcessingID.Value        = "P";
            adtMessage.MSH.VersionID.VersionID.Value              = "2.4";
            adtMessage.MSH.AcceptAcknowledgmentType.Value         = "NE";
            adtMessage.MSH.ApplicationAcknowledgmentType.Value    = "AL";
            adtMessage.MSH.CountryCode.Value = string.Empty;

            adtMessage.EVN.EventTypeCode.Value = "A08";
            adtMessage.EVN.EventOccurred.TimeOfAnEvent.Value = messageDateTime;

            adtMessage.PID.PatientID.ID.Value = messageData.MRN;
            adtMessage.PID.PatientID.AssigningAuthority.NamespaceID.Value = "PAS";
            adtMessage.PID.PatientID.IdentifierTypeCode.Value             = "PAS";
            var pid3 = adtMessage.PID.GetPatientIdentifierList(0);

            pid3.ID.Value = string.Empty;

            adtMessage.PV1.SetIDPV1.Value     = "1";
            adtMessage.PV1.PatientClass.Value = messageData.PatinetClassCode;
            if (!string.IsNullOrEmpty(messageData.WardCode))
            {
                adtMessage.PV1.AssignedPatientLocation.PointOfCare.Value = messageData.WardCode;
                adtMessage.PV1.AssignedPatientLocation.Room.Value        = string.IsNullOrEmpty(messageData.BayCode) ? "\"\"" : messageData.BayCode;
                adtMessage.PV1.AssignedPatientLocation.Bed.Value         = string.IsNullOrEmpty(messageData.BedCode) ? "\"\"" : messageData.BedCode;
            }

            var consultingDoctor = adtMessage.PV1.GetConsultingDoctor(0);

            string[] consultingDocName = messageData.ConsultingDoctorName.Split(' ');
            consultingDoctor.IDNumber.Value           = messageData.ConsultingDoctorGMCCode;
            consultingDoctor.FamilyName.Surname.Value = messageData.ConsultingDoctorName;
            consultingDoctor.DegreeEgMD.Value         = messageData.ConsultingDoctorPASId;


            var hospitalServiceComp = adtMessage.PV1.HospitalService.ExtraComponents.getComponent(0);
            var compValue           = new NHapi.Model.V23.Datatype.ST(adtMessage);

            compValue.Value          = messageData.SpecialtyCode;
            hospitalServiceComp.Data = compValue;

            //adtMessage.PV1.HospitalService.Value = messageData.SpecialtyCode;
            adtMessage.PV1.PatientType.Value    = messageData.PatinetClassCode.Equals("I") ? "1" : "2";
            adtMessage.PV1.VisitNumber.ID.Value = messageData.VisitNumber;
            adtMessage.PV1.AdmitDateTime.TimeOfAnEvent.Value = messageData.BedTransferDateTime == null ? null : ((DateTime)messageData.BedTransferDateTime).ToString("yyyyMMddHHmmss");

            adtMessage.PV2.ExpectedDischargeDateTime.TimeOfAnEvent.Value = messageData.ExpectedDischargeDate;

            PipeParser pipeParser = new PipeParser();

            return(pipeParser.Encode(adtMessage));
        }
        public string GenerateInpatientTransferMessage(string encounterId)
        {
            string messageControlId = null;
            string mrnpid           = _configuration["SynapseCore:Settings:MRN_ID_TYPE"];
            string empipid          = _configuration["SynapseCore:Settings:EMPI_ID_TYPE"];
            string sql = "select ebenc.wardcode, beds.baycode, beds.bedcode, to_char(ebenc.edd, 'YYYYMMDDHH24MISS') as edd, enc.visitnumber, " +
                         "enc.consultingdoctortext, exenc.consultingdoctorgmccode, exenc.consultingdoctorpasid, exenc.specialtycode, " +
                         "enc.person_id, enc.encounter_id, enc.patientclasscode, mrnpid.idnumber as mrn, nhspid.idnumber as empi, " +
                         "ebenc.bedtransferdatetime " +
                         "from entitystorematerialised.local_eboards_encounter ebenc " +
                         "inner join entitystorematerialised.core_encounter enc on enc.encounter_id = ebenc.encounter_id " +
                         "left outer join entitystorematerialised.extended_encounter exenc on enc.encounter_id = exenc.encounter_id " +
                         "left outer join entitystorematerialised.meta_wardbaybed beds on beds.wardbaybed_id = ebenc.bedcode " +
                         "left outer join entitystorematerialised.core_personidentifier mrnpid on enc.person_id = mrnpid.person_id and mrnpid.idtypecode = '" + mrnpid + "' " +
                         "left outer join entitystorematerialised.core_personidentifier nhspid on enc.person_id = nhspid.person_id and nhspid.idtypecode = '" + empipid + "' " +
                         "where enc.encounter_id = @encounter_id";

            var selectParamList = new List <KeyValuePair <string, object> >()
            {
                new KeyValuePair <string, object>("encounter_id", encounterId)
            };

            DataSet ds = new DataSet();

            ds = DataServices.DataSetFromSQL(sql, selectParamList);
            DataTable dt = ds.Tables[0];

            if (dt.Rows.Count > 0)
            {
                InpatientTransferMessageModel messageData = new InpatientTransferMessageModel()
                {
                    BayCode = Convert.ToString(dt.Rows[0]["baycode"]),
                    BedCode = Convert.ToString(dt.Rows[0]["bedcode"]),
                    ConsultingDoctorGMCCode = Convert.ToString(dt.Rows[0]["consultingdoctorgmccode"]),
                    ConsultingDoctorName    = Convert.ToString(dt.Rows[0]["consultingdoctortext"]),
                    ConsultingDoctorPASId   = Convert.ToString(dt.Rows[0]["consultingdoctorpasid"]),
                    EMPI                  = Convert.ToString(dt.Rows[0]["empi"]),
                    Encounter_id          = Convert.ToString(dt.Rows[0]["encounter_id"]),
                    ExpectedDischargeDate = Convert.ToString(dt.Rows[0]["edd"]),
                    MRN = Convert.ToString(dt.Rows[0]["mrn"]),
                    PatinetClassCode    = Convert.ToString(dt.Rows[0]["patientclasscode"]),
                    Person_Id           = Convert.ToString(dt.Rows[0]["person_id"]),
                    SpecialtyCode       = Convert.ToString(dt.Rows[0]["specialtycode"]),
                    VisitNumber         = Convert.ToString(dt.Rows[0]["visitnumber"]),
                    WardCode            = Convert.ToString(dt.Rows[0]["wardcode"]),
                    BedTransferDateTime = (dt.Rows[0]["bedtransferdatetime"] == DBNull.Value ? null : (DateTime?)Convert.ToDateTime(dt.Rows[0]["bedtransferdatetime"]))
                };

                var hl7Message = HL7MessageServices.GenerateInpatientTransferMessage(messageData, out messageControlId);

                OutboundMessageStore store = new OutboundMessageStore()
                {
                    EMPINumber              = Convert.ToString(dt.Rows[0]["empi"]),
                    Encounter_Id            = Convert.ToString(dt.Rows[0]["encounter_id"]),
                    HospitalNumber          = Convert.ToString(dt.Rows[0]["mrn"]),
                    Message                 = hl7Message,
                    Message_Id              = Guid.NewGuid().ToString(),
                    OutboundMessageStore_Id = Guid.NewGuid().ToString(),
                    Person_Id               = Convert.ToString(dt.Rows[0]["person_id"]),
                    SendStatus              = 0
                };

                InsertOutboundMessage(store);
            }


            return(messageControlId);
        }