/// <summary>
        /// 收费时判断医生站处状态
        /// </summary>
        /// <param name="prescriptions">处方对象</param>
        public void CheckDocPrsc(List <Prescription> prescriptions)
        {
            string obj = NewObject <CommonMethod>().GetOpConfig(OpConfigConstant.HasOpDSystem);

            if (Convert.ToInt32(obj) == 1)
            {
                List <Prescription> newpres    = prescriptions.Where((x, i) => prescriptions.FindIndex(z => z.DocPresHeadID == x.DocPresHeadID && z.DocPresHeadID > 0) == i).ToList();
                List <int>          presDocnos = new List <int>();
                for (int i = 0; i < newpres.Count; i++)
                {
                    //判断医生处方有没有修改,如果有修改,则抛出异常
                    OPD_PresDetail presDetail = NewObject <OPD_PresDetail>().getmodel(newpres[i].DocPresDetailID) as OPD_PresDetail;
                    if (presDetail == null)
                    {
                        throw new Exception("医生站处方有修改,请重新获取医生处方再收费");
                    }

                    if (newpres[i].DocPresDate != presDetail.PresDate)
                    {
                        throw new Exception("医生站处方有修改,请重新获取医生处方再收费");
                    }

                    presDocnos = prescriptions.Where(p => p.DocPresHeadID == newpres[i].DocPresHeadID).Select(p => p.DocPresNO).ToList();
                    NewObject <IOPManageDao>().UpdateDocPresStatus(newpres[i].DocPresHeadID, presDocnos, 1);
                }
            }
        }
        /// <summary>
        /// 更改处方注射次数
        /// </summary>
        /// <param name="presDetailId">处方明细Id</param>
        /// <param name="menuText">菜单显示名称</param>
        /// <param name="execTimes">执行次数</param>
        /// <returns>true成功</returns>
        public bool UpdatePresInjectTimes(int presDetailId, string menuText, int execTimes)
        {
            bool                  bRtn        = true;
            OPD_PresDetail        model       = (OPD_PresDetail)NewObject <OPD_PresDetail>().getmodel(presDetailId);
            int                   presHeadId  = model.PresHeadID;
            int                   presNo      = model.PresNO;
            int                   presGroupNo = model.GroupID;
            List <OPD_PresDetail> presList    = NewObject <OPD_PresDetail>().getlist <OPD_PresDetail>("PresHeadID=" + presHeadId + " and PresNO=" + presNo + " and GroupID=" + presGroupNo);

            foreach (OPD_PresDetail m in presList)
            {
                if (m.IsCharged == 0)
                {
                    m.Memo    = menuText;
                    m.ExecNum = execTimes;
                    this.BindDb(model);
                    int iRtn = model.save();
                    //修改关联费用数量
                    List <OPD_PresDetail> feeList = NewObject <OPD_PresDetail>().getlist <OPD_PresDetail>("LinkPresDetailID=" + m.PresDetailID);
                    foreach (OPD_PresDetail feeItem in feeList)
                    {
                        feeItem.Dosage       = m.ExecNum * feeItem.ExecNum;
                        feeItem.ChargeAmount = m.ExecNum * feeItem.ExecNum;
                        feeItem.PresAmount   = m.ExecNum * feeItem.ExecNum;
                        this.BindDb(feeItem);
                        feeItem.save();
                    }
                }
            }

            return(bRtn);
        }
        public ServiceResponseData GetInvoiceNOExaApplyHeadID()
        {
            try
            {
                int applyHeadID = requestData.GetData <int>(0);//医技申请头ID
                List <EXA_MedicalApplyDetail> applyDetails = NewObject <EXA_MedicalApplyDetail>().getlist <EXA_MedicalApplyDetail>(" ApplyHeadID=" + applyHeadID + " and  (ApplyStatus=1 or ApplyStatus=2) and IsReturns=0");
                if (applyDetails.Count == 0)
                {
                    throw new Exception("该处方没有正常的收费记录,不能退费");
                }

                int            presDetailId = Convert.ToInt32(applyDetails[0].PresDetailID);
                OPD_PresDetail presDetail   = NewObject <OPD_PresDetail>().getmodel(presDetailId) as OPD_PresDetail;
                if (presDetail == null)
                {
                    throw new Exception("该处方没有正常的收费记录,不能退费");
                }

                int presHeadID             = presDetail.PresHeadID; //门诊医生处方ID
                int presNO                 = presDetail.PresNO;     //门诊医生处方号
                List <OP_FeeItemHead> list = NewObject <OP_FeeItemHead>().getlist <OP_FeeItemHead>(" DocPresHeadID=" + presHeadID + " and DocPresNO=" + presNO + " and ChargeFlag=1 and ChargeStatus=0 and RegFlag=0");
                if (list.Count == 0)
                {
                    throw new Exception("该处方没有正常的收费记录,不能退费");
                }

                responseData.AddData(list[0].InvoiceNO);
                return(responseData);
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
        }
        /// <summary>
        /// 保存联动明细
        /// </summary>
        /// <param name="presDoctorID">处方医生Id</param>
        /// <param name="presDeptID">处方科室Id</param>
        /// <param name="oldLinkPresDetailId">原处方明细Id</param>
        /// <param name="newLinkPresDetailId">新处方明细Id</param>
        /// <param name="maxFeePresNo">最大费用处方号</param>
        /// <param name="currHeadId">当前头Id</param>
        /// <param name="hisHeadId">历史头Id</param>
        private void SaveLinkPresDetail(int presDoctorID, int presDeptID, int oldLinkPresDetailId, int newLinkPresDetailId, int maxFeePresNo, int currHeadId, int hisHeadId)
        {
            List <OPD_PresDetail> detailHisList = detailHisList = NewObject <OPD_PresDetail>().getlist <OPD_PresDetail>("PresHeadID=" + hisHeadId + " and LinkPresDetailID=" + oldLinkPresDetailId);

            foreach (OPD_PresDetail m in detailHisList)
            {
                decimal unitPrice = 0;
                //DataTable dtItems = NewObject<IOPDDao>().GetDrugItem(m.ItemID,m.ExecDeptID);
                //不能根据原有执行科室条件查询
                DataTable dtItems = NewObject <IOPDDao>().GetDrugItem(m.ItemID, -1);
                if (dtItems.Rows.Count <= 0)
                {
                    continue;
                }

                unitPrice = Convert.ToDecimal(dtItems.Rows[0]["UnitPrice"]);
                OPD_PresDetail currDetailModel = new OPD_PresDetail();
                this.BindDb(currDetailModel);
                currDetailModel.PresHeadID       = currHeadId;
                currDetailModel.PresNO           = m.PresNO + maxFeePresNo;
                currDetailModel.GroupID          = m.GroupID;
                currDetailModel.GroupSortNO      = m.GroupSortNO;
                currDetailModel.ItemID           = m.ItemID;
                currDetailModel.ItemName         = m.ItemName;
                currDetailModel.StatID           = m.StatID;
                currDetailModel.Spec             = m.Spec;
                currDetailModel.Dosage           = m.Dosage;
                currDetailModel.DosageUnit       = m.DosageUnit;
                currDetailModel.Factor           = m.Factor;
                currDetailModel.ChannelID        = m.ChannelID;
                currDetailModel.FrequencyID      = m.FrequencyID;
                currDetailModel.Entrust          = m.Entrust;
                currDetailModel.DoseNum          = m.DoseNum;
                currDetailModel.ChargeAmount     = m.ChargeAmount;
                currDetailModel.ChargeUnit       = m.ChargeUnit;
                currDetailModel.Price            = unitPrice;
                currDetailModel.Days             = m.Days;
                currDetailModel.DropSpec         = m.DropSpec;
                currDetailModel.IsAst            = m.IsAst;
                currDetailModel.AstResult        = string.Empty;
                currDetailModel.IsTake           = 0;
                currDetailModel.IsCharged        = 0;
                currDetailModel.IsCancel         = 0;
                currDetailModel.PresAmount       = m.PresAmount;
                currDetailModel.PresAmountUnit   = m.PresAmountUnit;
                currDetailModel.PresFactor       = m.PresFactor;
                currDetailModel.ExecNum          = 0;
                currDetailModel.Memo             = string.Empty;
                currDetailModel.PresDoctorID     = presDoctorID;
                currDetailModel.PresDeptID       = presDeptID;
                currDetailModel.ExecDeptID       = presDeptID;
                currDetailModel.PresDate         = DateTime.Now;
                currDetailModel.IsEmergency      = m.IsEmergency;
                currDetailModel.IsLunacyPosion   = m.IsLunacyPosion;
                currDetailModel.LinkPresDetailID = newLinkPresDetailId;
                currDetailModel.save();
            }
        }
Example #5
0
 /// <summary>
 /// 删除明细数据
 /// </summary>
 /// <param name="itemData">组合项目数据</param>
 /// <param name="dt">收费项目数据</param>
 public void DeleteData(DataTable itemData, DataTable dt)
 {
     if (dt != null)
     {
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             DataRow detaildr = itemData.Select("ExamItemID=" + dt.Rows[i]["ItemID"].ToString()).FirstOrDefault();
             if (detaildr == null)
             {
                 EXA_MedicalApplyDetail detail     = new EXA_MedicalApplyDetail();
                 OPD_PresDetail         presdetail = new OPD_PresDetail();
                 BindDb(detail);
                 detail.ApplyDetailID = Convert.ToInt32(dt.Rows[i]["ApplyDetailID"]);
                 detail.delete();
                 BindDb(presdetail);
                 presdetail.PresDetailID = Convert.ToInt32(dt.Rows[i]["PresDetailID"]);
                 presdetail.delete();
             }
         }
     }
 }
        /// <summary>
        /// 处方模板另存为
        /// </summary>
        /// <param name="newMould">处方模板头信息</param>
        /// <param name="presList">处方明细信息</param>
        /// <returns>true成功</returns>
        public bool AsSavePresTemplate(OPD_PresMouldHead newMould, List <OPD_PresDetail> presList)
        {
            BindDb(newMould);
            int mouId = newMould.save();

            foreach (OPD_PresDetail pres in presList)
            {
                OPD_PresMouldDetail newDetail  = new OPD_PresMouldDetail();
                OPD_PresDetail      presDetail = NewDao <IOPDDao>().GetPresDetail(pres.PresDetailID);
                newDetail.PresMouldHeadID = mouId;
                newDetail.PresNO          = 1;
                newDetail.Price           = presDetail.Price;
                newDetail.ChargeAmount    = presDetail.ChargeAmount;
                newDetail.ChannelID       = presDetail.ChannelID;
                newDetail.Days            = presDetail.Days;
                newDetail.Dosage          = presDetail.Dosage;
                newDetail.DosageUnit      = presDetail.DosageUnit;
                newDetail.DoseNum         = presDetail.DoseNum;
                newDetail.Entrust         = presDetail.Entrust;
                newDetail.ExecDeptID      = presDetail.ExecDeptID;
                newDetail.Factor          = presDetail.Factor;
                newDetail.FrequencyID     = presDetail.FrequencyID;
                newDetail.GroupID         = presDetail.GroupID;
                newDetail.GroupSortNO     = presDetail.GroupSortNO;
                newDetail.ItemID          = presDetail.ItemID;
                newDetail.ItemName        = presDetail.ItemName;
                newDetail.PresAmount      = presDetail.PresAmount;
                newDetail.PresAmountUnit  = presDetail.PresAmountUnit;
                newDetail.PresFactor      = presDetail.PresFactor;
                newDetail.Spec            = presDetail.Spec;
                newDetail.StatID          = presDetail.StatID;
                BindDb(newDetail);
                newDetail.save();
            }

            return(true);
        }
Example #7
0
        /// <summary>
        /// 保存医技申请
        /// </summary>
        /// <param name="head">申请头实体</param>
        /// <param name="itemData">项目数据</param>
        /// <param name="dt">明细数据</param>
        /// <returns>申请头id</returns>
        public int SaveMedicalApply(EXA_MedicalApplyHead head, DataTable itemData, DataTable dt)
        {
            DataRow dr = null;

            head.Remark = GetItemName(itemData);
            DeleteData(itemData, dt);
            if (dt != null)
            {
                head.ApplyHeadID = Convert.ToInt32(dt.Rows[0]["ApplyHeadID"].ToString());
            }

            this.BindDb(head);
            head.save();
            int          headid   = head.ApplyHeadID;
            OPD_PresHead presHead = new OPD_PresHead();

            if (head.SystemType == 0)
            {
                if (dt != null)
                {
                    presHead.PresHeadID = Convert.ToInt32(dt.Rows[0]["PresHeadID"].ToString());
                }

                presHead.MemberID  = head.MemberID;
                presHead.PatListID = head.PatListID;
                presHead.PresType  = 4;
                BindDb(presHead);
                int presheadid = presHead.save();
                NewObject <PrescriptionProcess>().UpdatePatCurrentDoctorID(head.PatListID, head.ApplyDoctorID, head.ApplyDeptID);
            }

            for (int i = 0; i < itemData.Rows.Count; i++)
            {
                dr = NewDao <IOPDDao>().GetPresNO().Rows[0];
                int             predetailid = 0;
                OPD_PresDetail  presdetail  = new OPD_PresDetail();
                IPD_OrderRecord orderRecord = new IPD_OrderRecord();
                DataRow         detaildr    = null;
                DataTable       orderdt     = NewDao <IOPDDao>().GetStatID(itemData.Rows[i]["ExamItemID"].ToString());
                if (dt != null)
                {
                    detaildr = dt.Select("ItemID=" + Convert.ToInt32(itemData.Rows[i]["ExamItemID"].ToString())).FirstOrDefault();
                }

                if (head.SystemType == 0)
                {
                    if (detaildr != null)
                    {
                        presdetail.PresDetailID = Convert.ToInt32(detaildr["PresDetailID"]);
                    }

                    if (head.ApplyType == 2)
                    {
                        presdetail.Price        = Convert.ToDecimal(itemData.Rows[i]["Price"].ToString()) * Convert.ToInt32(itemData.Rows[i]["Amount"].ToString());
                        presdetail.ChargeAmount = Convert.ToInt32(itemData.Rows[i]["Amount"].ToString());
                        presdetail.PresAmount   = Convert.ToInt32(itemData.Rows[i]["Amount"].ToString());
                    }
                    else
                    {
                        presdetail.Price        = Convert.ToDecimal(itemData.Rows[i]["Price"].ToString());
                        presdetail.ChargeAmount = 1;
                        presdetail.PresAmount   = 1;
                    }

                    presdetail.DoseNum    = 1;
                    presdetail.PresHeadID = presHead.PresHeadID;
                    presdetail.ItemID     = Convert.ToInt32(itemData.Rows[i]["ExamItemID"].ToString());
                    presdetail.ItemName   = itemData.Rows[i]["ExamItemName"].ToString();
                    presdetail.ExecDeptID = head.ExecuteDeptID;
                    presdetail.StatID     = Convert.ToInt32(orderdt.Rows[0]["StatID"]);
                    if (dr != null)
                    {
                        if (dr["PresNO"] == null || dr["PresNO"].ToString() == string.Empty)
                        {
                            presdetail.PresNO = 1;
                        }
                        else
                        {
                            presdetail.PresNO = Convert.ToInt32(dr["PresNO"]) + 1;
                        }
                    }

                    presdetail.IsEmergency    = 0;
                    presdetail.IsLunacyPosion = 0;
                    presdetail.PresDate       = head.ApplyDate;
                    presdetail.PresDeptID     = head.ApplyDeptID;
                    presdetail.PresDoctorID   = head.ApplyDoctorID;
                    BindDb(presdetail);
                    predetailid = presdetail.save();
                    if (presdetail.PresDetailID > 0)
                    {
                        predetailid = presdetail.PresDetailID;
                    }
                }
                else
                {
                    if (detaildr != null)
                    {
                        orderRecord.OrderID = Convert.ToInt32(detaildr["PresDetailID"]);
                    }

                    DataTable          ipPatlist          = NewDao <IOPDDao>().GetInBedPatient(head.PatListID);
                    SerialNumberSource serialNumberSource = NewObject <SerialNumberSource>();
                    string             groupID            = serialNumberSource.GetSerialNumber(SnType.医嘱组号);
                    orderRecord.GroupID       = Convert.ToInt32(groupID);
                    orderRecord.ExecDeptID    = head.ExecuteDeptID;
                    orderRecord.OrderCategory = 1;
                    orderRecord.CancelFlag    = 0;
                    orderRecord.DeleteFlag    = 0;
                    orderRecord.AstFlag       = -1;
                    orderRecord.DoseNum       = 1;
                    orderRecord.Dosage        = 1;
                    // orderRecord.DosageUnit = itemData.Rows[i][""].ToString();
                    orderRecord.OrderStatus = 1;
                    orderRecord.PatDeptID   = Convert.ToInt32(ipPatlist.Rows[0]["CurrDeptID"]);
                    orderRecord.WardID      = Convert.ToInt32(ipPatlist.Rows[0]["EnterWardID"]);
                    orderRecord.StatID      = Convert.ToInt32(orderdt.Rows[0]["StatID"]);
                    orderRecord.ItemID      = Convert.ToInt32(itemData.Rows[i]["ExamItemID"].ToString());
                    orderRecord.PresDeptID  = head.ApplyDeptID;
                    orderRecord.OrderDoc    = head.ApplyDoctorID;
                    orderRecord.ItemName    = itemData.Rows[i]["ExamItemName"].ToString();
                    orderRecord.Amount      = Convert.ToInt32(itemData.Rows[i]["Amount"].ToString());
                    orderRecord.OrderBdate  = head.CheckDate; //DateTime.Now; 20170418改成检查时间
                    if (head.ApplyType == 2)
                    {
                        orderRecord.ItemPrice = Convert.ToDecimal(itemData.Rows[i]["Price"].ToString()) * Convert.ToInt32(itemData.Rows[i]["Amount"].ToString());
                    }
                    else
                    {
                        orderRecord.ItemPrice = Convert.ToDecimal(itemData.Rows[i]["Price"].ToString());
                    }

                    orderRecord.ItemType  = 4;
                    orderRecord.PatListID = head.PatListID;
                    BindDb(orderRecord);
                    predetailid = orderRecord.save();
                    //插入费用明细
                    FeeItemDataSource feeDataSource = NewObject <FeeItemDataSource>();
                    DataTable         dtDetailItem  = feeDataSource.GetExamItemDetailDt(orderRecord.ItemID);

                    for (int index = 0; index < dtDetailItem.Rows.Count; index++)
                    {
                        int       feeitemId  = Convert.ToInt32(dtDetailItem.Rows[index]["ITEMID"]);
                        DataTable dtDrugItem = NewDao <IOPDDao>().GetFeeItemData(feeitemId);
                        decimal   amount     = Convert.ToDecimal(dtDetailItem.Rows[index]["ItemAmount"]);
                        DataRow[] rows       = dtDrugItem.Select(" ItemID=" + feeitemId);
                        if (rows.Length < 1)
                        {
                            continue;
                        }

                        IP_FeeItemGenerate feeItem = GenerateRecordFee(amount, 1, orderRecord, ipPatlist, rows[0]);
                        feeItem.FeeSource   = 1;
                        feeItem.CalCostMode = 0;
                        this.BindDb(feeItem);
                        feeItem.save();
                    }
                }

                EXA_MedicalApplyDetail detail = new EXA_MedicalApplyDetail();
                if (detaildr != null)
                {
                    detail.ApplyDetailID = Convert.ToInt32(detaildr["ApplyDetailID"]);
                }

                detail.SystemType   = head.SystemType;
                detail.PresDetailID = predetailid;
                detail.ApplyHeadID  = head.ApplyHeadID;
                detail.ItemID       = Convert.ToInt32(itemData.Rows[i]["ExamItemID"].ToString());
                detail.ItemName     = itemData.Rows[i]["ExamItemName"].ToString();
                detail.Price        = Convert.ToDecimal(itemData.Rows[i]["Price"].ToString());
                if (head.ApplyType == 2)
                {
                    detail.Amount   = Convert.ToInt32(itemData.Rows[i]["Amount"].ToString());
                    detail.TotalFee = Convert.ToDecimal(itemData.Rows[i]["Price"].ToString()) * detail.Amount;
                }
                else
                {
                    detail.Amount   = 1;
                    detail.TotalFee = Convert.ToDecimal(itemData.Rows[i]["Price"].ToString());
                }

                BindDb(detail);
                detail.save();
            }

            return(headid);
        }
        /// <summary>
        /// 生成明细
        /// </summary>
        /// <param name="presDoctorID">处方医生Id</param>
        /// <param name="presDeptID">处方科室Id</param>
        /// <param name="currHeadId">处方头</param>
        /// <param name="currPresNo">处方号</param>
        /// <param name="diffVal">处方号差值</param>
        /// <param name="m">模板</param>
        /// <param name="unitPrice">单位价格</param>
        /// <param name="currDetailModel">当前明细实体</param>
        /// <param name="presType">处方类型</param>
        private static void CreatePresDetail(int presDoctorID, int presDeptID, int currHeadId, int currPresNo, int diffVal, OPD_PresDetail m, decimal unitPrice, OPD_PresDetail currDetailModel, int presType)
        {
            currDetailModel.PresHeadID     = currHeadId;
            currDetailModel.PresNO         = currPresNo + m.PresNO - diffVal;
            currDetailModel.GroupID        = m.GroupID;
            currDetailModel.GroupSortNO    = m.GroupSortNO;
            currDetailModel.ItemID         = m.ItemID;
            currDetailModel.ItemName       = m.ItemName;
            currDetailModel.StatID         = m.StatID;
            currDetailModel.Spec           = m.Spec;
            currDetailModel.Dosage         = m.Dosage;
            currDetailModel.DosageUnit     = m.DosageUnit;
            currDetailModel.Factor         = m.Factor;
            currDetailModel.ChannelID      = m.ChannelID;
            currDetailModel.FrequencyID    = m.FrequencyID;
            currDetailModel.Entrust        = m.Entrust;
            currDetailModel.DoseNum        = m.DoseNum;
            currDetailModel.ChargeAmount   = m.ChargeAmount;
            currDetailModel.ChargeUnit     = m.ChargeUnit;
            currDetailModel.Price          = unitPrice;
            currDetailModel.Days           = m.Days;
            currDetailModel.DropSpec       = m.DropSpec;
            currDetailModel.IsAst          = m.IsAst;
            currDetailModel.AstResult      = string.Empty;
            currDetailModel.IsTake         = 0;
            currDetailModel.IsCharged      = 0;
            currDetailModel.IsCancel       = 0;
            currDetailModel.PresAmount     = m.PresAmount;
            currDetailModel.PresAmountUnit = m.PresAmountUnit;
            currDetailModel.PresFactor     = m.PresFactor;
            currDetailModel.ExecNum        = 0;
            currDetailModel.Memo           = string.Empty;
            currDetailModel.PresDoctorID   = presDoctorID;
            currDetailModel.PresDeptID     = presDeptID;
            if (presType == 3)
            {
                currDetailModel.ExecDeptID = presDeptID;
            }
            else
            {
                currDetailModel.ExecDeptID = m.ExecDeptID;
            }

            currDetailModel.PresDate       = DateTime.Now;
            currDetailModel.IsEmergency    = m.IsEmergency;
            currDetailModel.IsLunacyPosion = m.IsLunacyPosion;
            currDetailModel.save();
        }
        /// <summary>
        /// 拷贝处方
        /// </summary>
        /// <param name="presType">处方类型</param>
        /// <param name="currentPatId">当前病人id</param>
        /// <param name="hisPatListId">历史病人id</param>
        /// <param name="presDoctorID">处方医生Id</param>
        /// <param name="presDeptID">处方科室Id</param>
        /// <returns>true成功</returns>
        private bool CopyPres(int presType, int currentPatId, int hisPatListId, int presDoctorID, int presDeptID)
        {
            //检查历史是否有处方
            DataTable dtHisRecord = NewDao <IOPDDao>().GetPresInfo(presType, hisPatListId);

            if (dtHisRecord.Rows.Count > 0)
            {
                //检查当前是否有处方记录
                DataTable dtCurrentRecord = NewDao <IOPDDao>().GetPresInfo(presType, currentPatId);
                int       currHeadId      = 0;
                int       hisHeadId       = Convert.ToInt32(dtHisRecord.Rows[0]["PresHeadID"]);
                int       currPresNo      = 0;

                //判断当前病人是否有记录
                if (dtCurrentRecord.Rows.Count > 0)
                {
                    currHeadId = Convert.ToInt32(dtCurrentRecord.Rows[0]["PresHeadID"]);
                    currPresNo = Convert.ToInt32(dtCurrentRecord.Rows[dtCurrentRecord.Rows.Count - 1]["PresNO"]);
                }
                else
                {
                    //生成表头
                    OPD_PresHead presHisHead  = NewObject <OPD_PresHead>().getmodel(Convert.ToInt32(dtHisRecord.Rows[0]["PresHeadID"])) as OPD_PresHead;
                    OPD_PresHead presCurrHead = new OPD_PresHead();
                    presCurrHead.MemberID  = presHisHead.MemberID;
                    presCurrHead.PatListID = currentPatId;
                    presCurrHead.PresType  = presType;
                    this.BindDb(presCurrHead);
                    presCurrHead.save();
                    currHeadId = presCurrHead.PresHeadID;
                    currPresNo = 0;
                }

                List <OPD_PresDetail> detailHisList = null;

                //费用
                if (presType == 3)
                {
                    detailHisList = NewObject <OPD_PresDetail>().getlist <OPD_PresDetail>("PresHeadID=" + hisHeadId + " and LinkPresDetailID=0");
                }
                else
                {
                    detailHisList = NewObject <OPD_PresDetail>().getlist <OPD_PresDetail>("PresHeadID=" + hisHeadId);
                }

                int i       = 1;
                int diffVal = 0;

                //取得费用的最大处方号
                DataTable dtCurrentFeeRecord = NewDao <IOPDDao>().GetPresInfo(3, currentPatId);
                int       maxFeePresNo       = 0;
                if (presType == 1 || presType == 2)
                {
                    if (dtCurrentRecord.Rows.Count > 0)
                    {
                        maxFeePresNo = Convert.ToInt32(dtCurrentRecord.Rows[dtCurrentRecord.Rows.Count - 1]["PresNO"]);
                    }
                }

                foreach (OPD_PresDetail m in detailHisList)
                {
                    if (i == 1)
                    {
                        diffVal = m.PresNO - 1;
                    }

                    decimal unitPrice = 0;
                    if (presType == 1 || presType == 2)
                    {
                        //检查药品是否停用,和库存不足情况--直接过滤掉
                        DataTable dtItems = NewObject <IOPDDao>().GetDrugItem(m.ItemID, m.ExecDeptID);
                        if (dtItems.Rows.Count <= 0)
                        {
                            continue;
                        }

                        bool bRtn = NewObject <IOPDDao>().IsDrugStore(m.ExecDeptID, m.ItemID, m.ChargeAmount);
                        if (bRtn == false)
                        {
                            continue;
                        }

                        unitPrice = Convert.ToDecimal(dtItems.Rows[0]["UnitPrice"]);
                    }
                    else
                    {
                        DataTable dtItems = NewObject <IOPDDao>().GetDrugItem(m.ItemID, m.ExecDeptID);
                        if (dtItems.Rows.Count <= 0)
                        {
                            continue;
                        }

                        unitPrice = Convert.ToDecimal(dtItems.Rows[0]["UnitPrice"]);
                    }

                    OPD_PresDetail currDetailModel = new OPD_PresDetail();
                    this.BindDb(currDetailModel);
                    //生成处方明细
                    CreatePresDetail(presDoctorID, presDeptID, currHeadId, currPresNo, diffVal, m, unitPrice, currDetailModel, presType);
                    int newPresDetailId = currDetailModel.PresDetailID;
                    if (presType == 1 || presType == 2)
                    {
                        List <OPD_PresDetail> feeList = detailHisList = NewObject <OPD_PresDetail>().getlist <OPD_PresDetail>("LinkPresDetailID=" + m.PresDetailID);
                        if (feeList.Count > 0)
                        {
                            //生成关联动费用
                            CopyPresLinkFee(currentPatId, hisPatListId, presDoctorID, presDeptID, m.PresDetailID, newPresDetailId, maxFeePresNo);
                        }
                    }

                    i = i + 1;
                }
            }

            return(true);
        }
        /// <summary>
        /// 插入费用明细
        /// </summary>
        /// <param name="presType">处方类型</param>
        /// <param name="presHeadID">处方头ID</param>
        /// <param name="presDetail">处方明细实体</param>
        private void InsertFeePresDetail(int presType, int presHeadID, OPD_PresDetail presDetail)
        {
            Basic_Frequency frequency = (Basic_Frequency)NewObject <Basic_Frequency>().getmodel(presDetail.FrequencyID);
            int             execNum, cycleDay;

            Calculate(frequency.ExecuteCode, out execNum, out cycleDay);
            //根据用法获取关联费用
            DataTable dtFeeItems = NewDao <IOPDDao>().GetChannelFees(presDetail.ChannelID);

            foreach (DataRow row in dtFeeItems.Rows)
            {
                int calCostMode = Convert.ToInt32(row["CalCostMode"]);
                int totalAmount = 0;
                if (presType == 2)
                {
                    totalAmount = presDetail.DoseNum;
                }
                else
                {
                    if (presDetail.ExecNum > 0)
                    {
                        totalAmount = presDetail.ExecNum * Convert.ToInt32(row["ItemAmount"]);
                    }
                    else
                    {
                        if (calCostMode == 0)
                        {
                            totalAmount = execNum * presDetail.Days * Convert.ToInt32(row["ItemAmount"]);
                        }
                        else
                        {
                            totalAmount = presDetail.Days * Convert.ToInt32(row["ItemAmount"]);
                        }
                    }
                }

                OPD_PresDetail modelDetail = new OPD_PresDetail();
                modelDetail.Price = Convert.ToDecimal(row["UnitPrice"].ToString());

                modelDetail.PresHeadID     = presHeadID;
                modelDetail.ItemID         = Convert.ToInt32(row["ItemID"]);
                modelDetail.ItemName       = row["ItemName"].ToString();
                modelDetail.PresNO         = presDetail.PresNO;
                modelDetail.GroupID        = presDetail.GroupID;
                modelDetail.GroupSortNO    = 1;
                modelDetail.StatID         = Convert.ToInt32(row["StatID"]);
                modelDetail.Spec           = row["spec"].ToString();
                modelDetail.Dosage         = totalAmount;
                modelDetail.DosageUnit     = row["UnPickUnit"].ToString();
                modelDetail.Factor         = 1;
                modelDetail.FrequencyID    = 0;
                modelDetail.ChannelID      = 0;
                modelDetail.Entrust        = string.Empty;
                modelDetail.DoseNum        = 0;
                modelDetail.ChargeAmount   = totalAmount;
                modelDetail.ChargeUnit     = row["UnPickUnit"].ToString();
                modelDetail.Days           = 1;
                modelDetail.DropSpec       = string.Empty;
                modelDetail.IsAst          = 0;
                modelDetail.AstResult      = string.Empty;
                modelDetail.IsTake         = 0;
                modelDetail.IsCharged      = 0;
                modelDetail.IsCancel       = 0;
                modelDetail.PresAmount     = totalAmount;
                modelDetail.PresAmountUnit = row["UnPickUnit"].ToString();
                modelDetail.PresFactor     = 1;
                modelDetail.ExecNum        = Convert.ToInt32(row["ItemAmount"]);
                modelDetail.Memo           = "关联费用";
                if (Convert.ToInt32(row["ExecDeptId"]) == 0)
                {
                    modelDetail.ExecDeptID = presDetail.PresDeptID;
                }
                else
                {
                    modelDetail.ExecDeptID = Convert.ToInt32(row["ExecDeptId"]);
                }

                modelDetail.IsEmergency      = 0;
                modelDetail.IsLunacyPosion   = 0;
                modelDetail.PresDate         = presDetail.PresDate;
                modelDetail.PresDeptID       = presDetail.PresDeptID;
                modelDetail.PresDoctorID     = presDetail.PresDoctorID;
                modelDetail.LinkPresDetailID = presDetail.PresDetailID;
                BindDb(modelDetail);
                modelDetail.save();
            }
        }