D_Insert.sql 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. 
  2. IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[D_View_ReportStatsData]'))
  3. EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[D_View_ReportStatsData]
  4. AS
  5. SELECT
  6. convert(int,ReportClass) as ReportClass
  7. ,[HNumber] as [Base_HNumber] --住院号
  8. ,[VisitId] as [Base_VisitId] --住院次数
  9. ,( case when [LYFS] in (''a'',''1'',''A'') then ''a''
  10. when [LYFS] in (''b'',''2'',''B'') then ''b''
  11. when [LYFS] in (''c'',''3'') then ''c''
  12. when [LYFS] in (''d'',''4'') then ''d''
  13. when [LYFS] in (''e'',''5'') then ''e''
  14. when [LYFS] in (''f'',''9'',''oth'') then ''oth''
  15. else [LYFS] end) [Base_LYFS] --离院方式
  16. ,[RYDate] as [Base_RYDate]--入院时间
  17. ,[CYDate] as [Base_CYDate]--出院时间
  18. ,[BirthDate] as [Base_CSRQ]--出生日期
  19. ,Report_Leak.CYDept as [CYDept]--出院科室
  20. ,[ZGDoctor] as [ZGDoctor]--质控医生
  21. ,[BGName] --上报医师
  22. ,[DealReport] -- 未报
  23. ,[TotalFei] as [ZFY]--总费用
  24. ,null [CM_2_1] --手术后并发症
  25. ,null as Add_TJTime --提交时间
  26. ,[D_DeptDictMatch].UserDeptId as Add_OperDeptId --填报科室
  27. ,null as Add_UserName --填报员
  28. ,null as SBWorkDayCha --上报时间差
  29. ,null as ReportLeak_ID --数据管理与漏报关联关系
  30. ,null as status --状态
  31. FROM [Report_Leak]
  32. left outer join D_DeptDictMatch on D_DeptDictMatch.CYDept = Report_Leak.CYDept
  33. where DealReport in(0,2)and (IsDelete is null or IsDelete=0)
  34. union all
  35. SELECT
  36. ReportClass
  37. ,[Base_HNumber] as [Base_HNumber]--住院号
  38. ,[Base_VisitId] as [Base_VisitId]--住院次数
  39. ,( case when [Base_LYFS] in (''a'',''1'') then ''a''
  40. when [Base_LYFS] in (''b'',''2'') then ''b''
  41. when [Base_LYFS] in (''c'',''3'') then ''c''
  42. when [Base_LYFS] in (''d'',''4'') then ''d''
  43. when [Base_LYFS] in (''e'',''5'') then ''e''
  44. when [Base_LYFS] in (''f'',''9'',''oth'') then ''oth''
  45. else [Base_LYFS] end) [Base_LYFS] --离院方式--离院方式
  46. ,[Base_RYDate]as [Base_RYDate]--入院时间
  47. ,(case
  48. when REPORTCLASS in(44,45) and [Base_CYDate] is null
  49. then Add_TJTime -- HD、DPD提交时间
  50. when REPORTCLASS=51 and [Base_CYDate] is not null then
  51. Base_CYDate --OIT 出院时间
  52. when REPORTCLASS=51 and [Base_CYDate] is null and JSON_VALUE(DataInfo,''$."CM-0-2-4-2"'') is not null
  53. then JSON_VALUE(DataInfo,''$."CM-0-2-4-2"'') --OIT 填报页面出院时间
  54. when REPORTCLASS=51 and [Base_CYDate] is null and (JSON_VALUE(DataInfo,''$."CM-0-2-4-2"'') is null or JSON_VALUE(DataInfo,''$."CM-0-2-4-2"'') ='''' )
  55. then Add_TJTime --OIT提交时间
  56. else [Base_CYDate] end
  57. )
  58. as [Base_CYDate]--出院时间
  59. ,[Base_CSRQ] as [Base_CSRQ]--出生日期
  60. ,null as [CYDept] --出院科室
  61. ,[Base_ZGYSName] as [ZGDoctor]--质控医生
  62. ,[Base_BGName] as [BGName] --上报医生
  63. ,1 as [DealReport] --已报
  64. ,JSON_VALUE(DataInfo,''$."CM-6-1"'') as [ZFY]--总费用
  65. ,case when ReportClass=10 then JSON_VALUE(DataInfo,''$."CS-6-1-1"'')
  66. when ReportClass=39 then JSON_VALUE(DataInfo,''$."PACG-7-1-1"'')
  67. else JSON_VALUE(DataInfo,''$."CM-2-1"'')
  68. end as [CM_2_1] --手术后并发症
  69. ,Add_TJTime --提交时间
  70. ,Add_OperDeptId --填报科室
  71. ,Add_UserName --填报员
  72. ,SBWorkDayCha as SBWorkDayCha --上报时间差
  73. ,ReportLeak_ID --数据管理与漏报关联关系
  74. ,Status --状态
  75. FROM [D_MedicalRecord]
  76. where Status<>0 and (BackUpFlag is null or BackUpFlag=0)
  77. '
  78. if not exists(select * from syscolumns where id=object_id('D_Disease_Category') and name='DiseaseDifficulty')
  79. EXEC dbo.sp_executesql @statement = N'alter table D_Disease_Category add DiseaseDifficulty int NULL'
  80. --添加 标记锁定 权限
  81. if not exists (select * from [Q_Quanxian] where ID = 31)
  82. begin
  83. SET IDENTITY_INSERT [dbo].[Q_Quanxian] ON
  84. INSERT [dbo].[Q_Quanxian] ([Id], [QuanxianName], [Sort]) VALUES (31, N'标记锁定', 31)
  85. SET IDENTITY_INSERT [dbo].[Q_Quanxian] OFF
  86. end
  87. --D_MedicalRecord 添加锁定标记
  88. if not exists(select * from syscolumns where id=object_id('D_MedicalRecord') and name='IsLock')
  89. EXEC dbo.sp_executesql @statement = N'alter table D_MedicalRecord add IsLock bit NULL'
  90. --增加 sep和af重复优先上报af
  91. if not exists(select * from D_RepeatReportSetting where ReportClass =35 and RepeatReportClass=32)
  92. BEGIN
  93. INSERT [dbo].[D_RepeatReportSetting] ([ReportClass], [RepeatReportClass], [Icd9Code], [Icd10Code], [Enabled]) VALUES (35, 32, NULL, NULL, 0)
  94. END
  95. --是否开启预抽取
  96. if not exists(select * from Q_Options where Name='ReportLeakProExtract')
  97. BEGIN
  98. INSERT [dbo].[Q_Options] ([Name], [Value]) VALUES ('ReportLeakProExtract','True')
  99. END
  100. --添加疑似病种表
  101. if not exists(select * from sysobjects where id=object_id('D_SuspectRecord'))
  102. BEGIN
  103. EXEC dbo.sp_executesql @statement = N'
  104. SET ANSI_NULLS ON
  105. SET QUOTED_IDENTIFIER ON
  106. CREATE TABLE [dbo].[D_SuspectRecord](
  107. [ID] [int] IDENTITY(1,1) NOT NULL,
  108. [ReportClass] [int] NOT NULL,
  109. [HNumber] [nvarchar](50) NOT NULL,
  110. [VisitId] [int] NULL,
  111. [PatientName] [nvarchar](50) NULL,
  112. [Sex] [nvarchar](50) NULL,
  113. [BirthDate] [datetime] NULL,
  114. [Age] [nvarchar](50) NULL,
  115. [RYDate] [datetime] NULL,
  116. [CYDate] [datetime] NULL,
  117. [DoctorName] [nvarchar](50) NULL,
  118. [RYDept] [nvarchar](50) NULL,
  119. [JudgCondition] [nvarchar](max) NULL,
  120. [QualityPoint] [nvarchar](max) NULL,
  121. [GainDate] [datetime] NOT NULL,
  122. CONSTRAINT [PK_D_SuspectReport] PRIMARY KEY CLUSTERED
  123. (
  124. [ID] ASC
  125. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  126. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]'
  127. END
  128. --新增病种EAR
  129. if not exists(select * from D_Disease_Category where DCID=53)
  130. BEGIN
  131. SET IDENTITY_INSERT [dbo].[D_Disease_Category] ON
  132. INSERT [dbo].[D_Disease_Category] ([DCID], [DiseaseType], [DiseaseType_API], [DiseaseSystem], [DiseaseDescription], [SortID], [Enabled], [Num], [IsOpen], [DiseaseContent], [IsLeakOpen], [ByMonth_StartYear], [ByMonth_StartMonth], [ByMonth_CurrentYear], [ByMonth_CurrentMonth], [ByDay_StartDate], [ByDay_CurrentDate], [ByDay_LeakDay], [LastLeakDate], [HisDeptList], [HisDeptEnabled], [LeakExtractRuleEnabled], [LeakExtractRule], [IsNcisAutoOpen], [SystemDescription], [IsNcisChange], [DiseaseDifficulty]) VALUES (53, N'EAR', N'EAR', 4, N'主动脉腔内修复术', 53, 1, N'form-61', 1, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 1, 1, 0, NULL, NULL, NULL)
  133. SET IDENTITY_INSERT [dbo].[D_Disease_Category] OFF
  134. END
  135. --公告添加查看用户
  136. if not exists(select * from syscolumns where id=object_id('Report_InterAnnounce') and name='ToUserIds')
  137. EXEC dbo.sp_executesql @statement = N'alter table Report_InterAnnounce add ToUserIds [nvarchar](max) NULL'
  138. --治疗模式 a:门诊治疗 b:住院治疗
  139. if not exists(select * from syscolumns where id=object_id('Report_Leak') and name='OIT_0_2_1')
  140. EXEC dbo.sp_executesql @statement = N'alter table Report_Leak add OIT_0_2_1 [nvarchar](max) NULL'
  141. --新增病种
  142. if not exists(select * from D_Disease_Category where DCID=54)
  143. BEGIN
  144. SET IDENTITY_INSERT [dbo].[D_Disease_Category] ON
  145. INSERT [dbo].[D_Disease_Category] ([DCID], [DiseaseType], [DiseaseType_API], [DiseaseSystem], [DiseaseDescription], [SortID], [Enabled], [Num], [IsOpen], [DiseaseContent], [IsLeakOpen], [ByMonth_StartYear], [ByMonth_StartMonth], [ByMonth_CurrentYear], [ByMonth_CurrentMonth], [ByDay_StartDate], [ByDay_CurrentDate], [ByDay_LeakDay], [LastLeakDate], [HisDeptList], [HisDeptEnabled], [LeakExtractRuleEnabled], [LeakExtractRule], [IsNcisAutoOpen], [SystemDescription], [IsNcisChange], [DiseaseDifficulty]) VALUES (54, N'APTE', N'APTE', 1, N'急性肺血栓栓塞症', 54, 1, N'form-62', 1, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 1, 2, 0, NULL, NULL, NULL)
  146. SET IDENTITY_INSERT [dbo].[D_Disease_Category] OFF
  147. END
  148. --更新admin病种,
  149. if not exists(select * from Q_UserProfile where UserName='admin'and CID='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54')
  150. update Q_UserProfile
  151. set CID='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54'
  152. where UserName='admin'
  153. --EAR APTE 无需上报理由
  154. if not exists(select * from Report_NoReportNote where ReportClass=53)
  155. BEGIN
  156. INSERT [dbo].[Report_NoReportNote] ( [ReportClass], [Note], [Selected]) VALUES (53, N'参与临床药物与器械试验', 1)
  157. INSERT [dbo].[Report_NoReportNote] ( [ReportClass], [Note], [Selected]) VALUES (53, N'本次住院时间超过90天', 1)
  158. INSERT [dbo].[Report_NoReportNote] ( [ReportClass], [Note], [Selected]) VALUES (53, N'同一疾病30日内重复入院', 1)
  159. INSERT [dbo].[Report_NoReportNote] ( [ReportClass], [Note], [Selected]) VALUES (54, N'由外院住院诊疗后转入本院的病例', 1)
  160. INSERT [dbo].[Report_NoReportNote] ( [ReportClass], [Note], [Selected]) VALUES (54, N'18岁以下的病例', 1)
  161. INSERT [dbo].[Report_NoReportNote] ( [ReportClass], [Note], [Selected]) VALUES (54, N'同一疾病31日内重复入院', 1)
  162. INSERT [dbo].[Report_NoReportNote] ( [ReportClass], [Note], [Selected]) VALUES (54, N'本次住院超过90天', 1)
  163. END