Exemplo n.º 1
0
        public string[] ClinicHL7(string[] medications, out List <string[]> clinicPreIds)
        {
            var ids = new List <string[]> {
            };
            // 根据患者分组
            var prescriptionGroups = mongo.PrescriptionCollection.AsQueryable().Where(m => medications.Contains(m.UniqueId) && m.Patient.Clinic.SerialNumber.Length > 0).ToList().GroupBy(m => m.Patient);
            var data = prescriptionGroups.Select(g =>
            {
                //给MSH、PID、PV1 赋值 (Header)
                var propertie        = new List <string>();
                var patient          = g.Key;
                var headerProperties = new List <string>();
                ids.Add(g.Select(m => m.UniqueId).ToArray());

                //MSH|^~\&|SFRA||HIS||201808301922||OMP^O09|1462711203|P|2.4
                var msh = new HL7MessageMSH {
                    MessageType = "OMP^O09", MessageControl = g.FirstOrDefault().UniqueId,
                };
                var mshProperties = typeof(HL7MessageMSH).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(msh)).ToArray();
                var mshString     = string.Join("|", mshProperties);
                headerProperties.Add(mshString);

                //PID||0000014627|0000014627^^^^IDCard~^^^^PatientNO~0000014627^^^^IdentifyNO||陈文俊||19891031000000|M
                var pid = new HL7MessagePID
                {
                    PatientID             = patient.UniqueId,
                    PatientIdentifierList = $"{patient.UniqueId}^^^^IDCard{patient?.Hospitalization?.HospitalNumber}~^^^^PatientNO~{patient?.CertificateCode}^^^^IdentifyNO",
                    PatientName           = patient.DisplayName,
                    Birthday          = string.Format("{0:yyyyMMddHHmmss}", patient?.Birthday),
                    AdministrativeSex = patient.Gender == "男" ? "M" : "F",
                };
                var pidProperties = typeof(HL7MessagePID).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(pid)).ToArray();
                var pidString     = string.Join("|", pidProperties);
                headerProperties.Add(pidString);

                //PV1||O|||||||||||1|||||02|29120
                var pv1 = new HL7MessagePV1
                {
                    PatientClass         = "O",
                    ReAdmissionIndicator = g.ToArray().Length.ToString(),                     // 患者预支次数
                    PatientType          = "自费/医保",
                    VisitNumber          = string.Format("{0:yyyyMMddHHmmss}", DateTime.Now), //"就诊"
                };
                var pv1Properties = typeof(HL7MessagePV1).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(pv1)).ToArray();
                var pv1String     = string.Join("|", pv1Properties);
                headerProperties.Add(pv1String);
                var header = string.Join("\r\n", headerProperties);

                // body
                var body = g.SelectMany(m =>
                {
                    var bodyProperties = new List <string>();
                    var action         = mongo.ActionJournalCollection.AsQueryable().FirstOrDefault(a => a.TargetId == m.UniqueId);
                    var dateStr        = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);
                    //ORC|NW|1462711203CSS|256594|291200|||100&ml^&ONCE^^^^A||20180830192248|MDSD||100069|||||2008
                    var orc = new HL7MessageORC
                    {
                        PlacerOrderNumber     = $"{dateStr.Substring(10)}SFRA",                     // 1462711203CSS "CSS"意为手麻
                        FillerOrderNumber     = $"{dateStr.Substring(10)}",                         // 256594
                        PlacerGroupNumber     = $"{dateStr.Substring(6, 6)}",                       // 291200
                        QuantityTiming        = $@"{m.Goods?.Dosage}&{m.Goods.UsedUnit}^&ONCE^^^^A",
                        DateTimeofTransaction = string.Format("{0:yyyyMMddHHmmss}", m.CreatedTime), // 事务时间 20180830192248
                        EnteredBy             = action?.PrimaryUserId,                              //操作员ID MDSD
                        OrderingProvider      = m.DoctorId,                                         // 下单方提供者 100069
                        EnteringOrganization  = m.Doctor?.DepartmentId,                             //操作员所在科室
                        OrderingFacilityName  = m.Patient?.Hospitalization?.AdmittedDepartmentId,   //患者所在部门
                    };
                    var orcProperties = typeof(HL7MessageORC).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(orc)).ToArray();
                    var orcString     = string.Join("|", orcProperties);
                    bodyProperties.Add(orcString);

                    //RXO|Y00000002766^Y00000002766^d|1||^袋||||^^^&6000||||袋
                    var rxo = new HL7MessageRXO
                    {
                        RequestedGiveCode      = $"{m.GoodsId}^{m.GoodsId}^{(m.Goods?.Filter == nameof(Goods) ? "d" : "n")}",
                        RequestedGiveAmountMix = m.Qty.ToString(),
                        RequestedGiveUnits     = m.Goods?.UsedUnit,
                        DeliverToLocation      = $"^^^&{m.DepartmentDestinationId}", //发药部门
                        RequestedDispenseUnits = m.Goods?.UsedUnit,
                    };
                    var rxoProperties = typeof(HL7MessageRXO).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(rxo)).ToArray();
                    var rxoString     = string.Join("|", rxoProperties);
                    bodyProperties.Add(rxoString);

                    //RXR | 39
                    var rxr           = new HL7MessageRXR {
                    };
                    var rxrProperties = typeof(HL7MessageRXR).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(rxr)).ToArray();
                    var rxrString     = string.Join("|", rxrProperties);
                    bodyProperties.Add(rxrString);

                    //FT1||||||||||||^^2.76
                    var ft1 = new HL7MessageFT1 {
                        TransactionAmountUnit = $"^^{m.Goods.Price.ToString()}",
                    };
                    var ft1Properties = typeof(HL7MessageFT1).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(ft1)).ToArray();
                    var ft1String     = string.Join("|", ft1Properties);
                    bodyProperties.Add(ft1String);
                    return(bodyProperties);
                }).ToList();

                // 合并 header body
                propertie.Add(header);
                propertie.AddRange(body);
                return(string.Join("\r\n", propertie));
            }).ToArray();

            // 预支记录ID集合
            clinicPreIds = ids;
            return(data);
        }
Exemplo n.º 2
0
        public string[] HospitalizationHL7(string[] medications, out List <string[]> hospitalPreIds)
        {
            var ids        = new List <string[]> {
            };
            var properties = new List <string>();
            //m.Patient.Hospitalization.HospitalNumber.Length > 0 && m.FinishTime != null && m.FeeTime == null
            var prescriptionGroups = mongo.PrescriptionCollection.AsQueryable().Where(m => medications.Contains(m.UniqueId) && m.Patient.Hospitalization.HospitalNumber.Length > 0).ToList().GroupBy(m => m.Patient);
            var data = prescriptionGroups.Select(g =>
            {
                var propertie        = new List <string>();
                var patient          = g.Key;
                var headerProperties = new List <string>();
                ids.Add(g.Select(m => m.UniqueId).ToArray());

                //MSH|^~\&|SFRA||HIS||201809251223||RAS^O17|26898426016788|P|2.4
                var msh = new HL7MessageMSH {
                    MessageType = "RAS^O17", MessageControl = g.FirstOrDefault().UniqueId,
                };
                var mshProperties = typeof(HL7MessageMSH).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(msh)).ToArray();
                var mshString     = string.Join("|", mshProperties);
                headerProperties.Add(mshString);

                //PID||0000026898|0000026898^^^^IDCard~0000000082^^^^patientNo~432822195610096342^^^^IdentifyNO||刘三女||19561009000000|F|||||||||||||||湖南省郴州市
                var pid = new HL7MessagePID
                {
                    PatientID             = patient.UniqueId,
                    PatientIdentifierList = $"{patient.Clinic?.SerialNumber}^^^^IDCard~{patient.Hospitalization?.HospitalNumber}^^^^PatientNO~{patient?.CertificateCode}^^^^IdentifyNO",
                    PatientName           = patient.DisplayName,
                    Birthday          = string.Format("{0:yyyyMMddHHmmss}", patient?.Birthday),
                    AdministrativeSex = patient?.Gender == "男" ? "M" : "F",
                };
                var pidProperties = typeof(HL7MessagePID).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(pid)).ToArray();
                var pidString     = string.Join("|", pidProperties);
                headerProperties.Add(pidString);

                //PV1||I|9906^^^1127||||||||||2|||||01|38176
                var pv1 = new HL7MessagePV1
                {
                    PatientClass            = patient.Clinic.SerialNumber.Length > 0 ? "O" : "P",
                    AssignedPatientLocation = $"{patient.Hospitalization?.ResidedAreaId}^^{patient.Hospitalization?.BedNo}^{patient.Hospitalization?.AdmittedDepartmentId}",
                    ReAdmissionIndicator    = "就诊次数",
                    PatientType             = "自费/医保",
                    VisitNumber             = patient.UniqueId,//"就诊号码"
                };
                var pv1Properties = typeof(HL7MessagePV1).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(pv1)).ToArray();
                var pv1String     = string.Join("|", pv1Properties);
                headerProperties.Add(pv1String);
                var header = string.Join("\r\n", headerProperties);

                // body
                var body = g.SelectMany(m =>
                {
                    var bodyProperties = new List <string>();
                    var action         = mongo.ActionJournalCollection.AsQueryable().FirstOrDefault(a => a.TargetId == m.UniqueId);
                    var dateStr        = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);
                    //ORC|NW|2689842601CSS|256707|381760|||^&1^^^^A||20180925122348|MDSD||100082|||||3001||||^^1127
                    var orc = new HL7MessageORC
                    {
                        PlacerOrderNumber     = $"{dateStr.Substring(10)}SFRA",                                                     // 1462711203CSS
                        FillerOrderNumber     = $"{dateStr.Substring(10)}",                                                         // 256594
                        PlacerGroupNumber     = $"{dateStr.Substring(6, 6)}",                                                       // 291200
                        QuantityTiming        = $@"{m.Goods?.Dosage}&{m.Goods?.UsedUnit}^&ONCE^^^^A",
                        DateTimeofTransaction = Regex.Replace(m.CreatedTime.GetDateTimeFormats('s')[0].ToString(), @"[^0-9]+", ""), // 事务时间 20180830192248
                        EnteredBy             = m.DoctorId,                                                                         //操作员ID MDSD
                        OrderingProvider      = m.DoctorId,                                                                         // 下单方提供者 100069
                        EnteringOrganization  = m.Doctor?.DepartmentId,                                                             // 操作员所属科室
                        OrderingFacilityName  = m.Patient.Hospitalization?.AdmittedDepartmentId,                                    //患者所在部门
                    };
                    var orcProperties = typeof(HL7MessageORC).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(orc)).ToArray();
                    var orcString     = string.Join("|", orcProperties);
                    bodyProperties.Add(orcString);

                    //RXO|F00000005296^F00000005296^n|1||2小时|||||0|||2小时
                    var rxo = new HL7MessageRXO
                    {
                        RequestedGiveCode      = $"{m.GoodsId}^{m.GoodsId}^{(m.Goods?.Filter == nameof(Goods) ? "d" : "n")}",
                        RequestedGiveAmountMix = m.Qty.ToString(),                   //剂量?
                        RequestedGiveUnits     = m.Goods.UsedUnit,
                        DeliverToLocation      = $"^^^&{m.DepartmentDestinationId}", //发药部门
                        RequestedDispenseUnits = m.Goods?.UsedUnit,
                    };
                    var rxoProperties = typeof(HL7MessageRXO).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(rxo)).ToArray();
                    var rxoString     = string.Join("|", rxoProperties);
                    bodyProperties.Add(rxoString);

                    //RXA|0||20180925122348|20180925122348|0^0^5|1|^2小时|||000000|3001|||||||||2|A|20180925122348
                    var rxa = new HL7MessageRXA
                    {
                        GiveSubID             = "0",
                        StartDatetime         = string.Format("{0:yyyyMMddHHmmss}", m.CreatedTime),
                        EndDatetime           = string.Format("{0:yyyyMMddHHmmss}", m.FinishTime == null ? DateTime.Now: m.FinishTime),
                        AdministeredCode      = $"0^{(m.Goods.Filter == nameof(Goods) ? "3" : "5")}^5",
                        AdministeredAmount    = m.QtyActual.ToString(),
                        AdministeredUnits     = m.Goods.UsedUnit,
                        AdministeringProvider = m.DoctorId.ToString(),
                        AdministeredLocation  = m.Doctor?.DepartmentId, //"执行科室"
                        SystemntryTime        = string.Format("{0:yyyyMMddHHmmss}", m.FinishTime == null ? DateTime.Now : m.FinishTime),
                    };
                    var rxaProperties = typeof(HL7MessageRXA).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(rxa)).ToArray();
                    var rxaString     = string.Join("|", rxaProperties);
                    bodyProperties.Add(rxaString);

                    //RXR | 39
                    var rxr           = new HL7MessageRXR {
                    };
                    var rxrProperties = typeof(HL7MessageRXR).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(rxr)).ToArray();
                    var rxrString     = string.Join("|", rxrProperties);
                    bodyProperties.Add(rxrString);

                    var obxProperties = typeof(HL7MessageOBX).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(new HL7MessageOBX {
                    })).ToArray();
                    var obxString     = string.Join("|", obxProperties);
                    bodyProperties.Add(obxString);

                    //NTE|||1400
                    var net = new HL7MessageNET {
                        Comment = m.Goods?.Price.ToString(),
                    };
                    var netProperties = typeof(HL7MessageNET).GetProperties().Where(p => p.CanWrite).Select(o => o.GetValue(net)).ToArray();
                    var netString     = string.Join("|", netProperties);
                    bodyProperties.Add(netString);
                    return(bodyProperties);
                }).ToList();
                // 合并 header body
                propertie.Add(header);
                propertie.AddRange(body);
                return(string.Join("\r\n", propertie));
            }).ToArray();

            // 预支记录ID集合
            hospitalPreIds = ids;
            return(data);
        }