예제 #1
0
 public bool ReceivePrescriptionClinic(string xml)
 {
     try
     {
         var cvtr = new SDSLBYConverter();
         var cvt  = cvtr.SDSLBYPrescriptions(xml);
         foreach (var item in cvt.Data)
         {
             mongo.PrescriptionCollection.FindOneAndReplace <Prescription>(x => x.UniqueId == item.UniqueId, item, new FindOneAndReplaceOptions <Prescription, Prescription> {
                 IsUpsert = true
             });
         }
         BaseConverter.WriteSyncLog(nameof(Prescription), DateTime.Now.Ticks.ToString(), xml);
         var cvtPatient = cvtr.SDSLBYPatients(xml);     //患者信息来自门诊处方
         foreach (var item in cvtPatient.Data)
         {
             mongo.PatientCollection.FindOneAndReplace <Patient>(x => x.UniqueId == item.UniqueId, item, new FindOneAndReplaceOptions <Patient, Patient> {
                 IsUpsert = true
             });
         }
         BaseConverter.WriteSyncLog(nameof(Patient), DateTime.Now.Ticks.ToString(), xml);
         return(true);
     }
     catch (Exception ex)
     {
         BaseConverter.WriteSyncLog(nameof(Prescription), SfraObject.GenerateId(), xml, ex);
         return(false);
     }
 }
예제 #2
0
        public async Task <LoginResult> LoginAsync(string user, string password, string terminal = null)
        {
            Terminal = terminal ?? Terminal;
            if (string.Equals(user, ServiceStartup.Kernel, StringComparison.OrdinalIgnoreCase))
            {
                var primary = new AuthorizedUserCache {
                    UniqueId = SfraObject.EmptyId(), LoginId = ServiceStartup.Kernel, DisplayName = "Kernel User", Kernel = true, Token = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")
                };
                await ServiceStartup.SetPrimaryAuthorizedAsync(Terminal, primary);

                return(new LoginResult {
                    Code = LoginCode.Ok, Jwt = primary.Token, Ip = Terminal,
                });
            }
            var find = mongo.UserCollection.AsQueryable().FirstOrDefault(u => u.LoginId.ToLower() == user.ToLower());
            var code = LoginCode.Ok;

            if (find == null)
            {
                code = LoginCode.NotExist;
            }
            else if (find.IsDisabled)
            {
                code = LoginCode.UserIsDenied;
            }
            else if (!find.CanPasswordAuth)
            {
                code = LoginCode.PwdAuthDenied;
            }
            else if (Helper.ComputeMd5Hash(password, find) != find.Password)
            {
                code = LoginCode.PasswordError;
            }
            return(await TryLoginAsync(code, find, Terminal));
        }
예제 #3
0
        public async Task <bool> ModifyEvaluateAsync([FromBody] Evaluate evaluate)
        {
            evaluate.UniqueId = evaluate.UniqueId ?? SfraObject.GenerateId();
            await mongo.EvaluateCollection.FindOneAndReplaceAsync <Evaluate>(x => x.UniqueId == evaluate.UniqueId, evaluate, new FindOneAndReplaceOptions <Evaluate, Evaluate> {
                IsUpsert = true
            });

            return(true);
        }
예제 #4
0
        public async Task <bool> ModifyKitAsync([FromBody] Kit kit)
        {
            kit.UniqueId = kit.UniqueId ?? SfraObject.GenerateId();
            await mongo.KitCollection.FindOneAndReplaceAsync <Kit>(x => x.UniqueId == kit.UniqueId, kit, new FindOneAndReplaceOptions <Kit, Kit> {
                IsUpsert = true
            });

            return(true);
        }
예제 #5
0
        public async Task <string> ModifyCategoryAsync([FromBody] GoodsCategory category)
        {
            category.UniqueId = category.UniqueId ?? SfraObject.GenerateId();
            await mongo.GoodsCategoryCollection.FindOneAndReplaceAsync <GoodsCategory>(x => x.UniqueId == category.UniqueId, category, new FindOneAndReplaceOptions <GoodsCategory, GoodsCategory> {
                IsUpsert = true
            });

            return(category.UniqueId);
        }
예제 #6
0
        public async Task <string> ModifyTerminalGoodsAsync([FromBody] TerminalGoods tg)
        {
            tg.UniqueId = tg.UniqueId ?? SfraObject.GenerateId();
            tg.Goods    = tg.Goods ?? mongo.GoodsCollection.AsQueryable().FirstOrDefault(f => f.UniqueId == tg.GoodsId);
            await mongo.TerminalGoodsCollection.FindOneAndReplaceAsync <TerminalGoods>(x => x.UniqueId == tg.UniqueId, tg, new FindOneAndReplaceOptions <TerminalGoods, TerminalGoods> {
                IsUpsert = true
            });

            return(tg.UniqueId);
        }
예제 #7
0
        public async Task <bool> ModifyCopyUsersKitAsync([FromBody] Kit[] kits)
        {
            var mm = mongo.KitCollection.AsQueryable().Where(k => !k.IsDisabled).ToList();

            foreach (var kit in kits)
            {
                var name = (kit.DisplayName ?? "").ToLower();
                if (!mm.Any(k => k.DisplayName.ToLower() == name && k.CreatorId == kit.CreatorId))
                {
                    kit.UniqueId = kit.UniqueId ?? SfraObject.GenerateId();
                    kit.Code     = kit.UniqueId;
                    await mongo.KitCollection.FindOneAndReplaceAsync <Kit>(x => x.UniqueId == kit.UniqueId, kit, new FindOneAndReplaceOptions <Kit, Kit> {
                        IsUpsert = true
                    });
                }
            }
            return(true);
        }
예제 #8
0
        public async Task <string> ModifyGoodsAsync([FromBody] Goods goods)
        {
            goods.UniqueId = goods.UniqueId ?? SfraObject.GenerateId();
            if (mongo.GoodsCollection.AsQueryable().Any(g => g.UniqueId == goods.UniqueId && g.IsSync))
            {
                return(null);
            }

            await mongo.GoodsCollection.FindOneAndReplaceAsync <Goods>(x => x.UniqueId == goods.UniqueId, goods, new FindOneAndReplaceOptions <Goods, Goods> {
                IsUpsert = true
            });

            // 把其它冗余数据也一并改掉
            await mongo.ExchangeCollection.UpdateManyAsync(e => e.GoodsId == goods.UniqueId, Builders <Exchange> .Update.Set(x => x.Goods, goods));

            await mongo.AllocationCollection.UpdateManyAsync(a => a.GoodsId == goods.UniqueId, Builders <Allocation> .Update.Set(x => x.Goods, goods));

            await mongo.PrescriptionCollection.UpdateManyAsync(p => p.GoodsId == goods.UniqueId, Builders <Prescription> .Update.Set(x => x.Goods, goods));

            await mongo.MedicationCollection.UpdateManyAsync(m => m.GoodsId == goods.UniqueId, Builders <Medication> .Update.Set(x => x.Goods, goods));

            await mongo.InternalAllocationCollection.UpdateManyAsync(i => i.GoodsId == goods.UniqueId, Builders <InternalAllocation> .Update.Set(x => x.Goods, goods));

            var tsfs = mongo.TransferCollection.AsQueryable().ToList();

            for (int i = 0; i < tsfs.Count; i++)
            {
                var tsf = tsfs[i];
                if ((tsf.TransferRecords ?? new List <Transfer.TransferRecord>()).All(t => t.GoodsId != goods.UniqueId))
                {
                    continue;
                }

                for (int j = 0; j < tsf.TransferRecords.Count; j++)
                {
                    await mongo.TransferCollection.UpdateOneAsync(t => t.UniqueId == tsf.UniqueId, Builders <Transfer> .Update.Set(x => x.TransferRecords[j].Goods, goods));
                }
            }
            await mongo.TerminalGoodsCollection.UpdateManyAsync(t => t.GoodsId == goods.UniqueId, Builders <TerminalGoods> .Update.Set(x => x.Goods, goods));

            return(goods.UniqueId);
        }
예제 #9
0
        public bool SupplyDict(string xml)
        {
            try
            {
                var cvtr = new BJFCConverter();
                var cvt = cvtr.BJFCConsumables(xml);
                foreach (var item in cvt.Data)
                {
                    mongo.GoodsCollection.FindOneAndReplace<Goods>(x => x.UniqueId == item.UniqueId, item, new FindOneAndReplaceOptions<Goods, Goods> { IsUpsert = true });
                }
                BaseConverter.WriteSyncLog(nameof(Goods), DateTime.Now.Ticks.ToString(), xml);

                return true;
            }
            catch (Exception ex)
            {
                BaseConverter.WriteSyncLog(nameof(Goods), SfraObject.GenerateId(), xml, ex);
                return false;
            }
        }
예제 #10
0
        public bool DoctorDict(string xml)
        {
            try
            {
                var cvtr = new BJFCConverter();
                var cvt = cvtr.BJFCEmps2Employees(xml);
                foreach (var item in cvt.Data)
                {
                    mongo.EmployeeCollection.FindOneAndReplace<Employee>(x => x.UniqueId == item.UniqueId, item, new FindOneAndReplaceOptions<Employee, Employee> { IsUpsert = true });
                }
                BaseConverter.WriteSyncLog(nameof(Employee), DateTime.Now.Ticks.ToString(), xml);

                return true;
            }
            catch (Exception ex)
            {
                BaseConverter.WriteSyncLog(nameof(Employee), SfraObject.GenerateId(), xml, ex);
                return false;
            }
        }
예제 #11
0
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                Run();
                SyncData();
            }
            catch (Exception ex)
            {
                Global.SchedulerLogger.Error(nameof(Run), ex);
            }

            void Run()
            {
                var ctrl  = new SyncDataInternal();
                var spans = Global.AppSettings["BJFC"]["DateSpan"].Values <int>().ToList();
                var begin = DateTime.Now.AddDays(spans[0]).Date;
                var end   = DateTime.Now.AddDays(spans[1] + 1).Date;

                ctrl.SyncOperationSchedule(Hospital.BJFC, null, begin, end);
            }

            void SyncData()
            {
                string directory = Global.AppSettings["BJFC"]["SyncDir"].Value <string>();

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                DirectoryInfo folder = new DirectoryInfo(directory);

                if (folder.GetFiles("*.xml").Length > 0)
                {
                    var    xmlDepts   = folder.GetFiles("Department_*.xml").OrderByDescending(d => d.CreationTime);
                    var    xmlDoctors = folder.GetFiles("Doctor_*.xml").OrderByDescending(d => d.CreationTime);
                    var    xmlSupply  = folder.GetFiles("Supply_*.xml").OrderByDescending(d => d.CreationTime);
                    var    xmlDrug    = folder.GetFiles("Drug_*.xml").OrderByDescending(d => d.CreationTime);
                    var    cvtr       = new BJFCConverter();
                    string xml;
                    foreach (var dept in xmlDepts)
                    {
                        using (StreamReader stream = new StreamReader(dept.FullName))
                        {
                            XmlTextReader rader  = new XmlTextReader(stream);
                            var           xmlDoc = new XmlDocument();
                            xmlDoc.Load(rader);
                            xml = xmlDoc.InnerXml;
                            try
                            {
                                var cvt = cvtr.BJFCDepartments(xml);
                                foreach (var item in cvt.Data)
                                {
                                    mongo.DepartmentCollection.FindOneAndReplace <Department>(x => x.UniqueId == item.UniqueId, item, new FindOneAndReplaceOptions <Department, Department> {
                                        IsUpsert = true
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                BaseConverter.WriteSyncLog(nameof(Department), SfraObject.GenerateId(), xml, ex);
                            }
                        }
                    }

                    foreach (var doctor in xmlDoctors)
                    {
                        using (StreamReader stream = new StreamReader(doctor.FullName))
                        {
                            XmlTextReader rader  = new XmlTextReader(stream);
                            var           xmlDoc = new XmlDocument();
                            xmlDoc.Load(rader);
                            xml = xmlDoc.InnerXml;
                            try
                            {
                                var cvt = cvtr.BJFCEmps2Employees(xml);
                                foreach (var item in cvt.Data)
                                {
                                    mongo.EmployeeCollection.FindOneAndReplace <Employee>(x => x.UniqueId == item.UniqueId, item, new FindOneAndReplaceOptions <Employee, Employee> {
                                        IsUpsert = true
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                BaseConverter.WriteSyncLog(nameof(Employee), SfraObject.GenerateId(), xml, ex);
                            }
                        }
                    }

                    foreach (var supply in xmlSupply)
                    {
                        using (StreamReader stream = new StreamReader(supply.FullName))
                        {
                            XmlTextReader rader  = new XmlTextReader(stream);
                            var           xmlDoc = new XmlDocument();
                            xmlDoc.Load(rader);
                            xml = xmlDoc.InnerXml;
                            try
                            {
                                var cvt = cvtr.BJFCConsumables(xml);
                                foreach (var item in cvt.Data)
                                {
                                    mongo.GoodsCollection.FindOneAndReplace <Goods>(x => x.UniqueId == item.UniqueId, item, new FindOneAndReplaceOptions <Goods, Goods> {
                                        IsUpsert = true
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                BaseConverter.WriteSyncLog(nameof(Goods), SfraObject.GenerateId(), xml, ex);
                            }
                        }
                    }

                    foreach (var drug in xmlDrug)
                    {
                        using (StreamReader stream = new StreamReader(drug.FullName))
                        {
                            XmlTextReader rader  = new XmlTextReader(stream);
                            var           xmlDoc = new XmlDocument();
                            xmlDoc.Load(rader);
                            xml = xmlDoc.InnerXml;
                            try
                            {
                                var cvt = cvtr.BJFCDrugs(xml);
                                foreach (var item in cvt.Data)
                                {
                                    mongo.GoodsCollection.FindOneAndReplace <Goods>(x => x.UniqueId == item.UniqueId, item, new FindOneAndReplaceOptions <Goods, Goods> {
                                        IsUpsert = true
                                    });
                                }
                            }
                            catch (Exception ex)
                            {
                                BaseConverter.WriteSyncLog(nameof(Goods), SfraObject.GenerateId(), xml, ex);
                            }
                        }
                    }
                    folder.Delete(true);
                }
            }
        }
예제 #12
0
        public bool reciveData(string xml)
        {
            try
            {
                var    code = 0;
                string msg  = null;

                var cvtr          = new SZGJConverter();
                var prescriptions = cvtr.SuZhouApply2Prescriptions(xml).Data;
                if (prescriptions.All(p => p.IsAddition))
                {
                    foreach (var p in prescriptions)
                    {
                        var medication = mongo.MedicationCollection.AsQueryable().First(m => !m.IsDisabled && m.Mode == ExchangeMode.Medication && m.DoctorId == p.DoctorId && m.PatientId == p.PatientId && m.GoodsId == p.GoodsId && m.QtyActual == p.Qty && m.PrescriptionId == null);
                        mongo.MedicationCollection.UpdateOne(x => x.UniqueId == medication.UniqueId, Builders <Medication> .Update.Set(o => o.PrescriptionId, p.UniqueId).Set(o => o.IsSynchronized, true));

                        p.QtyActual = medication.QtyActual;
                        p.Plans     = medication.Plans;
                        mongo.PrescriptionCollection.FindOneAndReplace <Prescription>(x => x.UniqueId == p.UniqueId, p, new FindOneAndReplaceOptions <Prescription, Prescription> {
                            IsUpsert = true
                        });
                    }
                    code = 0;
                    msg  = "先预支后补充的医嘱";
                }
                else
                {
                    if (prescriptions.Any(p => p.Qty != Math.Ceiling(p.Qty)))
                    {
                        // 2017-12-17 取药量为浮点数时医嘱发送到中心药房
                        code = 2;
                        msg  = "非整数医嘱";
                    }
                    else
                    {
                        // 临时医嘱,查询接收部门是否库存足够
                        var dst  = prescriptions.Select(p => p.DepartmentDestinationId).Where(p => !string.IsNullOrEmpty(p)).Distinct().FirstOrDefault();
                        var data = mongo.CustomerCollection.AsQueryable().Where(c => !c.IsDisabled).Select(cs => new
                        {
                            Cabinets      = cs.Cabinets.Where(c => c.DepartmentId == dst),
                            OutOfCabinets = cs.OutOfCabinets.Where(v => v.DepartmentId == dst),
                        }).ToList();
                        var fills  = data.SelectMany(d => d.Cabinets).Concat(data.SelectMany(d => d.OutOfCabinets)).SelectMany(c => c.Drawers).SelectMany(d => d.Boxes).SelectMany(b => b.Fills).ToList();
                        var unExes = mongo.PrescriptionCollection.AsQueryable().Where(p => !p.IsDisabled && p.DepartmentDestinationId == dst && p.FinishTime == null)
                                     .Select(p => new { p.GoodsId, p.BatchNumber, p.ExpiredDate, p.Mode, p.Qty, p.QtyActual, }).ToList();
                        if (prescriptions.All(p =>
                        {
                            var qty = fills.Where(f => f.GoodsId == p.GoodsId && f.ExpiredDate > DateTime.Now && (string.IsNullOrEmpty(p.BatchNumber) || f.BatchNumber == p.BatchNumber)).Sum(f => f.QtyExisted);
                            qty -= unExes.Where(e => e.GoodsId == p.GoodsId && (p.BatchNumber ?? string.Empty) == e.BatchNumber && e.Mode == ExchangeMode.CheckOut).Sum(e => e.Qty - e.QtyActual); // 取药
                            qty += unExes.Where(e => e.GoodsId == p.GoodsId && (p.BatchNumber ?? string.Empty) == e.BatchNumber && e.Mode == ExchangeMode.CheckIn).Sum(e => e.Qty - e.QtyActual);  // 退药
                            return(qty >= p.Qty);
                        }))
                        {
                            foreach (var p in prescriptions)
                            {
                                mongo.PrescriptionCollection.FindOneAndReplace <Prescription>(x => x.UniqueId == p.UniqueId, p, new FindOneAndReplaceOptions <Prescription, Prescription> {
                                    IsUpsert = true
                                });
                                mongo.PatientCollection.FindOneAndReplace <Patient>(x => x.UniqueId == p.Patient.UniqueId, p.Patient, new FindOneAndReplaceOptions <Patient, Patient> {
                                    IsUpsert = true
                                });
                            }

                            code = 0;
                            msg  = "临时医嘱库存充足";
                        }
                        else
                        {
                            code = 1;
                            msg  = "本地库存不足";
                        }
                    }
                }
                BaseConverter.WriteSyncLog(nameof(Prescription), $"{SfraObject.GenerateId()}_{msg}", xml);
                return(code == 0);
            }
            catch (Exception ex)
            {
                BaseConverter.WriteSyncLog(nameof(Prescription), SfraObject.GenerateId(), xml, ex);
                return(false);
            }
        }