using SqlSugar; using System; using System.Collections.Generic; using System.Text; namespace OrmTest { public class Unitdfasdfasfysa { public static void Init() { var db = NewUnitTest.Db; var clinicId = "1111"; db.CodeFirst.InitTables(); var rpDetailIds = new List() { "111", "22", }; var isAutoReg = true; // 1. 这种方式,直接写isAutoReg会报错 /* 生成sql: * SELECT TOP 1 1 FROM [CT_Recipe] [rp] WITH(NOLOCK) Inner JOIN [CT_RecipeDetail] [det] WITH(NOLOCK) ON (( [det].[RecipeId] = [rp].[RecipeId] ) AND ( [rp].[Status] = 2 )) Inner JOIN [Sys_Usage] [u] WITH(NOLOCK) ON ( [u].[UsageId] = [det].[UsageRouteId] ) WHERE (( [rp].[ClinicId] = N'1111' ) AND ([det].[RecipeDetId] IN ('111','22')) ) AND (((( [u].[Category] = 2 ) OR ( [u].[Category] = 3 )) OR ( [u].[Category] = 4 )) OR (( 1 AND( [det].[IsSkinTest] = 1 )) AND ( [det].[SkinTestSign] = 3 ))) */ try { var bb = db.Queryable((rp, det, u) => new object[] { JoinType.Inner, det.RecipeId == rp.RecipeId && rp.Status == 2, JoinType.Inner, u.UsageId == det.UsageRouteId, }) //.Where((rp, det, u) => rp.ClinicId == clinicId && rpDetailIds.Contains(det.RecipeDetId)) .Where((rp, det, u) => u.Category == 2 || u.Category == 3 || u.Category == 4 || (isAutoReg && det.IsSkinTest == 1 && det.SkinTestSign == 3)) .Any(); var bbb = db.Queryable((rp, det, u) => new object[] { JoinType.Inner, det.RecipeId == rp.RecipeId && rp.Status == 2, JoinType.Inner, u.UsageId == det.UsageRouteId, }) //.Where((rp, det, u) => rp.ClinicId == clinicId && rpDetailIds.Contains(det.RecipeDetId)) .Where((rp, det, u) => u.Category == 2 || u.Category == 3 || u.Category == 4 || (!isAutoReg && det.IsSkinTest == 1 && det.SkinTestSign == 3)) .Any(); } catch (Exception) { throw; } // 2. 写成isAutoReg == true 是可以正常生成 1=1条件 /*生成sql: * SELECT TOP 1 1 FROM [CT_Recipe] [rp] WITH(NOLOCK) Inner JOIN [CT_RecipeDetail] [det] WITH(NOLOCK) ON (( [det].[RecipeId] = [rp].[RecipeId] ) AND ( [rp].[Status] = 2 )) Inner JOIN [Sys_Usage] [u] WITH(NOLOCK) ON ( [u].[UsageId] = [det].[UsageRouteId] ) WHERE (( [rp].[ClinicId] = N'1111' ) AND ([det].[RecipeDetId] IN ('111','22')) ) AND (((( [u].[Category] = 2 ) OR ( [u].[Category] = 3 )) OR ( [u].[Category] = 4 )) OR ((( 1 = 1 ) AND ( [det].[IsSkinTest] = 1 )) AND ( [det].[SkinTestSign] = 3 ))) */ try { var bb = db.Queryable((rp, det, u) => new object[] { JoinType.Inner, det.RecipeId == rp.RecipeId && rp.Status == 2, JoinType.Inner, u.UsageId == det.UsageRouteId, }).Where((rp, det, u) => rp.ClinicId == clinicId && rpDetailIds.Contains(det.RecipeDetId)) .Where((rp, det, u) => u.Category == 2 || u.Category == 3 || u.Category == 4 || (isAutoReg == true && det.IsSkinTest == 1 && det.SkinTestSign == 3)) .Any(); } catch (Exception) { throw; } // 3. 写成isAutoReg == false 是可以正常生成 1=0条件 /*生成sql: * SELECT TOP 1 1 FROM [CT_Recipe] [rp] WITH(NOLOCK) Inner JOIN [CT_RecipeDetail] [det] WITH(NOLOCK) ON (( [det].[RecipeId] = [rp].[RecipeId] ) AND ( [rp].[Status] = 2 )) Inner JOIN [Sys_Usage] [u] WITH(NOLOCK) ON ( [u].[UsageId] = [det].[UsageRouteId] ) WHERE (( [rp].[ClinicId] = N'1111' ) AND ([det].[RecipeDetId] IN ('111','22')) ) AND (((( [u].[Category] = 2 ) OR ( [u].[Category] = 3 )) OR ( [u].[Category] = 4 )) OR ((( 1 = 0 ) AND ( [det].[IsSkinTest] = 1 )) AND ( [det].[SkinTestSign] = 3 ))) */ try { var bb = db.Queryable((rp, det, u) => new object[] { JoinType.Inner, det.RecipeId == rp.RecipeId && rp.Status == 2, JoinType.Inner, u.UsageId == det.UsageRouteId, }).Where((rp, det, u) => rp.ClinicId == clinicId && rpDetailIds.Contains(det.RecipeDetId)) .Where((rp, det, u) => u.Category == 2 || u.Category == 3 || u.Category == 4 || (isAutoReg == false && det.IsSkinTest == 1 && det.SkinTestSign == 3)) .Any(); } catch (Exception) { throw; } } /// /// 门诊处方明细 /// [SugarTable("UnitdfaaCT_RecipeDetail")] public class RecipeDetailEntity { /// /// 处方明细编号 /// [SugarColumn(IsPrimaryKey = true)] public string RecipeDetId { get; set; } /// /// 处方编号 /// public string RecipeId { get; set; } /// /// 处方内项目序号 /// public int Sort { get; set; } /// /// 处方取整方式 1.按次取整 2.按天取整 3.按实际发 4.医嘱取整 9.不自动计算 /// public int? SplitType { get; set; } /// /// 项目编号 /// public string ItemId { get; set; } /// /// 项目名称 /// public string ItemName { get; set; } /// /// 项目规格 /// public string ItemSpec { get; set; } /// /// 项目类型1.药品 2.项目 3项目组合 /// public int ItemType { get; set; } /// /// 组号(不分组,默认为0) /// public int GroupNo { get; set; } /// /// 组显示标志(开始、中间、结束,不分组默认为空) /// public string GroupTag { get; set; } /// /// 单次用量 /// public decimal SingleDose { get; set; } /// /// 剂量系数 /// public decimal DoseRate { get; set; } /// /// 剂量单位 /// public string DoseUnit { get; set; } /// /// 项目数量,最小单位 /// public decimal MiniUnitCount { get; set; } /// /// 项目单位、最小单位 /// public string MiniUnitName { get; set; } /// /// 门诊开药数量 /// public decimal ClinicUnitCount { get; set; } /// /// 门诊开药单位 /// public string ClinicUnitName { get; set; } /// /// 门诊开药单位系数 /// public int ClinicUnitRate { get; set; } /// /// 频次编号 /// public string FreqId { get; set; } /// /// 频次代码 /// public string FreqCode { get; set; } /// /// 频次名称 /// public string FreqName { get; set; } /// /// 执行次数 /// public int? FreqTimes { get; set; } /// /// 执行时间点 /// public string FreqExecPoints { get; set; } /// /// 药品给药途径编号 /// public string UsageRouteId { get; set; } /// /// 药品给药途径名称 /// public string UsageRouteName { get; set; } /// /// 执行天数(默认1) /// public int Days { get; set; } /// /// 每分钟滴速 /// public decimal? DroppingSpeedPerMinute { get; set; } /// /// 记速单位(类似d/min或者ml/h) /// public string SpeedRecordUnit { get; set; } /// /// 已经执行次数(记录输液、注射等单据打印次数) /// public int? ExecutedTimes { get; set; } /// /// 最后一次执行时间 /// public DateTime? LastExecutedTime { get; set; } /// /// 是否皮试药品 /// public int IsSkinTest { get; set; } /// /// 皮试标注 /// public int? SkinTestSign { get; set; } /// /// 是否抗菌药物(0否1是) /// public int? IsAntibacterials { get; set; } /// /// 中医处方-煎煮法(打碎、先煎、后下等)字典:2004 /// public string DecoctionWayId { get; set; } /// /// 中医处方-煎煮法名称 字典:2004 /// public string DecoctionWayName { get; set; } /// /// 执行科室编号 /// public string ExecDeptId { get; set; } /// /// 执行科室名称 /// public string ExecDeptName { get; set; } /// /// 已退数量 /// public decimal? ReturnClinicUnitCount { get; set; } /// /// 嘱托 /// public string Memo { get; set; } /// /// 美康药品处方明细唯一标识 /// public string MKIndex { get; set; } /// /// 中公网明细信息编号 /// public string ZgwDetailID { get; set; } /// /// 代煎费用关联草药处方编号 /// public string RelHerbalRecipeId { get; set; } /// /// 是否医保限制用药(0否1是) /// public int? IsMedUseLimit { get; set; } /// /// 医保限制审批标志(枚举:MedUseApprFlagEnum) /// public int? MedUseApprFlag { get; set; } /// /// 确费时间 /// public DateTime? ConfirmFeeTime { get; set; } /// /// 确费科室编号 /// public string ConfirmFeeDeptId { get; set; } /// /// 确费科室名称 /// public string ConfirmFeeDeptName { get; set; } /// /// 确费员工编号 /// public string ConfirmFeeEmployeeId { get; set; } /// /// 确费员工姓名 /// public string ConfirmFeeEmployeeName { get; set; } /// /// 手术描述 /// public string OperationMemo { get; set; } /// /// 手术申请编号 /// public string ApplyId { get; set; } /// /// 是否特殊费用 /// public int? IsSpecifiedPrice { get; set; } /// /// 数据标签编号(前端生成为值) /// public string TagId { get; set; } /// /// 是否可以编辑(枚举:BoolStatusEnum 0否1是) /// public int? IsCanEdit { get; set; } /// /// 剂量代码 /// public string DoseCode { get; set; } /// /// 给药科室编号 /// public string GiveDrugDeptId { get; set; } /// /// 给药科室名称 /// public string GiveDrugDeptName { get; set; } /// /// 门诊输液是否打印 /// public int? InfusionIsPrint { get; set; } /// /// 小包装包数 /// public int? SmallPackageCount { get; set; } /// /// 小包装取整后剂量代码 /// public string SmallPackageRoundingDoseCode { get; set; } /// /// 排序2 /// public int? Sort2 { get; set; } /// /// 医生确认保存标志 /// public int? DoctorConfirmSaved { get; set; } /// /// 配伍禁忌药品 /// public string CompatibleTabooDrugs { get; set; } } /// /// 门诊处方 /// [SugarTable("UnitdfaaCT_Recipe")] public class RecipeEntity { /// /// 处方编号 /// [SugarColumn(IsPrimaryKey = true)] public string RecipeId { get; set; } /// /// 门诊号 /// public string ClinicId { get; set; } /// /// 接诊编号 /// public string ReceiveId { get; set; } /// /// 患者ID /// public string PatientId { get; set; } /// /// 患者姓名 /// public string PatientName { get; set; } /// /// 数据类型 1.西成药 2.中草药 3.检查项目 5.检验项目 6.诊疗项目 99.门诊划价 /// public int DataType { get; set; } /// /// 处方类型 字典:2001 /// public string RecipeType { get; set; } /// /// 特殊处方标记(1急诊处方2儿科处方) /// public int? SpecialRecipeSign { get; set; } /// /// 处方类型名称 字典:2001 /// public string RecipeTypeName { get; set; } /// /// 中药-总剂数 /// public int? TotalPairCount { get; set; } /// /// 中药-每日剂数(默认1) /// public int? DayPairCount { get; set; } /// /// 草药处方剂型编号 /// public string DosageFormId { get; set; } /// /// 草药处方剂型名称 /// public string DosageFormName { get; set; } /// /// 中药类别(1饮片2颗粒剂3小包装) /// public int? CMDrugCategory { get; set; } /// /// 中药-采用剂型编号 字典:2002 /// public string UseDoseFormId { get; set; } /// /// 中药-采用剂型名称 字典:2002 /// public string UseDoseFormName { get; set; } /// /// 中药-用法编号 /// public string UsageId { get; set; } /// /// 中药-用法名称 /// public string UsageName { get; set; } /// /// 状态 1.已录入 2.已提交 /// public int Status { get; set; } /// /// 开方医生的科室编号 /// public string DrDeptId { get; set; } /// /// 开方医生的科室名称 /// public string DrDeptName { get; set; } /// /// 开药医生编号 /// public string DrEmployeeId { get; set; } /// /// 开药医生姓名 /// public string DrEmployeeName { get; set; } /// /// 机构编号 /// public string InputOrgId { get; set; } /// /// 录入科室编号 /// public string InputDeptId { get; set; } /// /// 录入科室名称 /// public string InputDeptName { get; set; } /// /// 录入职工编号 /// public string InputEmployeeId { get; set; } /// /// 录入职工姓名 /// public string InputEmployeeName { get; set; } /// /// 录入时间 /// public DateTime InputTime { get; set; } /// /// 是否需要审核处方(0否1是) /// public int IsNeedAudit { get; set; } /// /// 处方诊断编码 /// public string DiagCode { get; set; } /// /// 处方诊断名称 /// public string DiagName { get; set; } /// /// 批量挂号划价结算记录编号 /// public string BatchId { get; set; } /// /// 注意事项 /// public string Memo { get; set; } /// /// 是否打印(0否1是) /// public int? IsPrint { get; set; } /// /// 精麻毒处方代办人 /// public string SpecialRecipeAgent { get; set; } /// /// 精麻毒处方代办人身份证 /// public string SpecialRecipeAgentIdCard { get; set; } /// /// 中公网主信息编号 /// public string ZgwMainID { get; set; } /// /// 每日用量 /// public decimal? DecoctingDosage { get; set; } /// /// 代煎剂数 /// public int? DecoctPairCount { get; set; } /// /// 体检系统结算单号 /// public string PEISSettlementId { get; set; } /// /// 处方名称 /// public string RecipeName { get; set; } /// /// 是否外送处方 /// public int? IsDeliveryRecipe { get; set; } /// /// 开始时间 /// public DateTime? BeginTime { get; set; } /// /// 草药类型编号 /// public string HerbalTypeId { get; set; } /// /// 草药类型名称 /// public string HerbalTypeName { get; set; } /// /// 数据标签编号(前端生成为值) /// public string TagId { get; set; } /// /// 费别编号(关联费别表) /// public string SettlementTypeId { get; set; } /// /// 费别名称 /// public string SettlementTypeName { get; set; } /// /// 病种编码(字典:012011) /// public string DiseId { get; set; } /// /// 病种名称(字典:012011) /// public string DiseName { get; set; } /// /// 公费医疗-支付单位编号(字典:001040) /// public string PayCompanyId { get; set; } /// /// 公费医疗-支付单位名称(字典:001040) /// public string PayCompanyName { get; set; } /// /// 审核状态 /// public int AuditStatus { get; set; } /// /// 审核时间 /// public DateTime? AuditTime { get; set; } /// /// 审核结果 /// public string AuditResult { get; set; } /// /// 中草药对应药房规则编号 /// public string RuleId { get; set; } /// /// 中草药对应药房处方类型 /// public string PrescriptionType { get; set; } /// /// 是否签到(0否1是) /// public int IsSignIn { get; set; } /// /// 签到标识 /// public string SignInLogo { get; set; } /// /// 药品拿药序号 /// public string DrugSort { get; set; } /// /// 延长用药时间原因说明 /// public string ExtendedMedicationDescription { get; set; } /// /// 每日用量单位编号 /// public string DecoctingDosageUnitId { get; set; } /// /// 每日用量单位名称 /// public string DecoctingDosageUnitName { get; set; } /// /// 是否协定方 /// public int? IsAgreedParty { get; set; } /// /// 特殊药品每日序号 /// public string SpecialDrugDailySerialNum { get; set; } /// /// 是否是科研处方 /// public int? IsResearchRecipe { get; set; } /// /// 协定方是否可以编辑(枚举:BoolStatusEnum) /// public int? AgreedPartyIsCanEdit { get; set; } /// /// 优惠类型编号 /// public string DiscountTypeId { get; set; } /// /// 优惠类型名称 /// public string DiscountTypeName { get; set; } /// /// 是否双通道处方 /// public int? IsDualChannelRecipe { get; set; } /// /// 电子处方流转状态 ElectronicPrescriptionStatusEnum /// public int? ElectronicPrescriptionStatus { get; set; } /// /// 处方追溯码 /// public string MedTraceCode { get; set; } /// /// 医保处方编号 /// public string MedRecipeNo { get; set; } /// /// 预核验操作人ID /// public string PreVerificationEmployeeId { get; set; } /// /// 预核验操作人姓名 /// public string PreVerificationEmployeeName { get; set; } /// /// 预核验时间 /// public DateTime? PreVerificationTime { get; set; } /// /// 签名操作人 /// public string SignEmployeeId { get; set; } /// /// 签名操作人姓名 /// public string SignEmployeeName { get; set; } /// /// 签名时间 /// public DateTime? SignTime { get; set; } /// /// 上传操作人 /// public string UploadEmployeeId { get; set; } /// /// 上传操作人姓名 /// public string UploadEmployeeName { get; set; } /// /// 上传时间 /// public DateTime? UploadTime { get; set; } /// /// 撤销上传操作人 /// public string UnUploadEmployeeId { get; set; } /// /// 撤销上传操作人姓名 /// public string UnUploadEmployeeName { get; set; } /// /// 撤销上传时间 /// public DateTime? UnUploadTime { get; set; } /// /// 补录时间 /// public DateTime? SupplementTime { get; set; } } /// /// 药品用法表 /// [SugarTable("UnitdfaaSys_Usage")] public class UsageEntity { /// /// 用法编号 /// [SugarColumn(IsPrimaryKey = true)] public string UsageId { get; set; } /// /// 用法编码 /// public string UsageCode { get; set; } /// /// 用法名称 /// public string UsageName { get; set; } /// /// 允许处方类型(1西医2中医),多个逗号分隔 /// public string AllowUseRecipeTypes { get; set; } /// /// 分类(1口服2输液3注射4治疗5外用9其它) /// public int Category { get; set; } /// /// 机构编号(root系统内置) /// public string OrgId { get; set; } /// /// 排序 /// public int Sort { get; set; } /// /// 拼音 /// public string SpellCode { get; set; } /// /// 五笔 /// public string StrokeCode { get; set; } /// /// 状态(1:启用;2:停用) /// public int Status { get; set; } /// /// 是否删除(0否1是) /// public int IsDelete { get; set; } /// /// 备注 /// public string Memo { get; set; } /// /// 记速方式(类似滴速或者流速) /// public string SpeedRecordType { get; set; } /// /// 记速单位(类似d/min或者ml/h) /// public string SpeedRecordUnits { get; set; } /// /// 是否必填 /// public int? IsRequired { get; set; } /// /// 适用范围 /// public string ScopeOfApplication { get; set; } } } }