Commit 06f62b3b by tangzhongyang

gx

Signed-off-by: tangzhongyang <2441037192@qq.com>
parent b23fcbbf
using Health.Api.Infrastructure.Enums;
using Health.Infra;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
namespace QueryPlatform.Api.Controllers
{
[Route("api/disease")]
[AllowAnonymous]
public class DiseaseController : ControllerBase
{
public DiseaseController()
{
}
//[HttpGet("{diseaseType}")]
//public ApiResponse<object> Get([FromRoute] string diseaseType, [FromQuery] string userId)
//{
// var diseaseTypes = EnumHelper.GetItems<DiseaseType>();
// if (diseaseTypes == null || !diseaseTypes.Select(t => t.Name).Contains(diseaseType))
// return new ApiResponse<object>(ResponseType.NotFound);
// diseaseType = diseaseTypes.FirstOrDefault(t => t.Name == diseaseType).Description;
// return new ApiResponse<object>();
//}
//[HttpPost]
//public ApiResponse Post()
//{
// return new ApiResponse();
//}
}
}
......@@ -155,30 +155,7 @@ public void PullData(int indexs,string DatabaseName,string tableName)
resourceQueries.PullData1(indexs, DatabaseName, tableName, "INPAT_ORDER");
resourceQueries.PullData1(indexs, DatabaseName, tableName, "INPAT_FEE");
}
/// <summary>
/// 药品疾病查询平台
/// </summary>
/// <returns></returns>
[HttpPost("Inquire")]
[AllowAnonymous]
public void Inquire(SYS_QueryConditions sYS_Query)
{
if(sYS_Query.icd.Length>1||sYS_Query.diseaseName.Length > 1 )
{
sYS_Query.type = 1; //疾病查询
resourceQueries.DiagInquire(sYS_Query.icd, sYS_Query.diseaseName);
}
else if (sYS_Query.drugName.Length > 1)
{
sYS_Query.type = 2; //药品查询
resourceQueries.DrugInquire(sYS_Query.drugName);
}
else if (sYS_Query.materialName.Length > 1)
{
sYS_Query.type = 3; //材料查询
resourceQueries.MaterialInquire(sYS_Query.materialName);
}
}
}
}
......@@ -2,6 +2,7 @@
using Health.Api.Infrastructure.Queries;
using Health.Api.Infrastructure.Queues;
using Microsoft.Extensions.Configuration;
using Health.Api.Infrastructure.Queries;
namespace Health.Api.Infrastructure.AutofacModules
{
......@@ -32,6 +33,10 @@ protected override void Load(ContainerBuilder builder)
builder.Register(c => new UserQueries(configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new ResourceQueries(Connection156, configConnectionString,Connection151,Connection152,Connection153,Connection154,Connection155,Connection158)).InstancePerLifetimeScope();
builder.Register(c => new DrugqueryQueries(Connection156, configConnectionString )).InstancePerLifetimeScope();
builder.Register(c => new HomeQueries(configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new AnalysisQueries(Connection156, configConnectionString )).InstancePerLifetimeScope();
}
}
}
......
......@@ -9,20 +9,47 @@ public class SYS_Hospital
public string DataLoginName { get; set; }
public string DataPassword { get; set; }
}
public class SYS_QueryConditions
public class 服务器
{
public string 服务器ip { get; set; }
public string 数据库账号 { get; set; }
public string 数据库密码 { get; set; }
}
public class hosid
{
public int id { get; set; }
}
public class jcid
{
//查询类型 1:疾病 or icd 2:drugName 3:材料
public int type { get; set; }
//icd
public int COUNT1 { get; set; }
public int COUNT2 { get; set; }
}
public class SYS_Drugquery
{
/// <summary>
/// 1 命中查询 2其他查询
/// </summary>
public int type1_2 { get; set; }
/// <summary>
/// ICD编码
/// </summary>
public string[] icd { get; set; }
//疾病
/// <summary>
/// 疾病名称
/// </summary>
public string[] diseaseName { get; set; }
//药品
/// <summary>
/// 药品
/// </summary>
public string[] drugName { get; set; }
//材料费
/// <summary>
/// 材料费
/// </summary>
public string[] materialName { get; set; }
}
/// <summary>
/// 项目,名称
/// </summary>
public string peojectName { get; set; }
}
}
......@@ -39,107 +39,79 @@ public ResourceQueries(string Connection156, string configConnectionString, stri
_Connection155 = Connection155;
_Connection158 = Connection158;
}
/// <summary>
/// 查询所有项目
/// </summary>
public IEnumerable<dynamic> ItemQuery()
{
using (DbConnection connection = new SqlConnection(_Connection156))
{
var query = @" SELECT ID, PROJECT_NAME, GENERIC_NAME, DISEASE_NAME, ICD,
COMPLETE_MARK, search_time
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_SEARCH_RECORD]
WHERE year(search_time)=year(GETDATE()) AND MONTH(search_time)=MONTH(GETDATE()) order by id DESC ";
return connection.Query(query).ToList();
}
DbConnection connection = new SqlConnection(_configConnectionString);
var query = @" SELECT ID, PROJECT_NAME, GENERIC_NAME, DISEASE_NAME, ICD,
COMPLETE_MARK, search_time
FROM [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] order by id DESC ";
return connection.Query(query).ToList();
}
/// <summary>
/// 停止正在查询项目
/// </summary>
public bool CancelProject(int id)
{
using (DbConnection connection = new SqlConnection(_Connection156))
{
//确定该项目在执行中
IEnumerable<dynamic> COMPLETE_MARK = connection.Query("select COMPLETE_MARK FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_SEARCH_RECORD] where COMPLETE_MARK =22 and id=" + id);
var result = false;//默认状态不成功
if (COMPLETE_MARK.Count() > 0)
throw new DomainException("该项目已经执行完毕,不能取消!!!");
else
return result = connection.Execute("update [SV_MEDIC_STATISTICS].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 31 where and COMPLETE_MARK != 22 id= " + id) > 0 ? true : false;
LOG("停止中","",id,"查询平台","");
}
return false;
DbConnection connection = new SqlConnection(_configConnectionString);
//确定该项目在执行中
IEnumerable<dynamic> COMPLETE_MARK = connection.Query("select COMPLETE_MARK FROM [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] where COMPLETE_MARK =22 and id=" + id);
if (COMPLETE_MARK.Count() > 0)
throw new DomainException("该项目已经执行完毕,不能取消!!!");
else
LOG("停止中", "", id, "查询平台", "");
return connection.Execute("update [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 31 where and COMPLETE_MARK != 22 id= " + id) > 0 ? true : false;
}
public (IEnumerable<dynamic>, IEnumerable<dynamic>) ShowMEDIC_AREA(int id, int paseIndex)
{
using (DbConnection connection = new SqlConnection(_Connection156))
{
IEnumerable<dynamic> sj = connection.Query($@"select*FROM(
DbConnection connection = new SqlConnection(_configConnectionString);
IEnumerable<dynamic> sj = connection.Query($@"select*FROM(
SELECT ROW_NUMBER() OVER(ORDER BY getdate())AS id,* FROM(
SELECT DISTINCT
[MEDIC_AREA]
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_AREA] WHERE INDEXS={id} AND MEDIC_AREA IS NOT NULL AND MEDIC_AREA<>''
FROM [SV_QueryPlatform_].[dbo].[MEDIC_AREA_{id}] WHERE INDEXS={id} AND MEDIC_AREA IS NOT NULL AND MEDIC_AREA<>''
)a
)b
WHERE id<={paseIndex}*10 and id>({paseIndex}-1)*10
").ToList();
IEnumerable<dynamic> zon = connection.Query($@" SELECT CAST(COUNT(*)AS MONEY)totalCount ,{paseIndex} paseIndex FROM(
IEnumerable<dynamic> zon = connection.Query($@" SELECT CAST(COUNT(*)AS MONEY)totalCount ,{paseIndex} paseIndex FROM(
SELECT DISTINCT
[MEDIC_AREA]
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_AREA] WHERE INDEXS={id} AND MEDIC_AREA IS NOT NULL AND MEDIC_AREA<>''
FROM [SV_QueryPlatform_].[dbo].[MEDIC_AREA_{id}] WHERE INDEXS={id} AND MEDIC_AREA IS NOT NULL AND MEDIC_AREA<>''
)a").ToList();
return (sj, zon);
}
return (null, null);
return (sj, zon);
}
public (IEnumerable<dynamic>, IEnumerable<dynamic>) ShowITEM_NAME(int id, int paseIndex)
{
using (DbConnection connection = new SqlConnection(_Connection156))
{
IEnumerable<dynamic> sj = connection.Query($@"select*FROM(
DbConnection connection = new SqlConnection(_configConnectionString);
IEnumerable<dynamic> sj = connection.Query($@"select*FROM(
SELECT ROW_NUMBER() OVER(ORDER BY getdate())AS id,* FROM(
SELECT DISTINCT
[ITEM_NAME]
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_AREA] WHERE INDEXS={id} AND ITEM_NAME IS NOT NULL AND ITEM_NAME<>''
FROM [SV_QueryPlatform_].[dbo].[MEDIC_AREA_{id}] WHERE INDEXS={id} AND ITEM_NAME IS NOT NULL AND ITEM_NAME<>''
)a
)b
WHERE id<={paseIndex}*10 and id>({paseIndex}-1)*10
").ToList();
IEnumerable<dynamic> zon = connection.Query($@" SELECT CAST(COUNT(*)AS MONEY)totalCount ,{paseIndex} paseIndex FROM(
IEnumerable<dynamic> zon = connection.Query($@" SELECT CAST(COUNT(*)AS MONEY)totalCount ,{paseIndex} paseIndex FROM(
SELECT DISTINCT
[ITEM_NAME]
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_AREA] WHERE INDEXS={id} AND ITEM_NAME IS NOT NULL AND ITEM_NAME<>''
FROM [SV_QueryPlatform_].[dbo].[MEDIC_AREA_{id}] WHERE INDEXS={id} AND ITEM_NAME IS NOT NULL AND ITEM_NAME<>''
)a").ToList();
return (sj, zon);
}
return (null, null);
}
/// <summary>
///报告展示(疾病展示所有,药品可以填写)
/// </summary>
public (IEnumerable<dynamic>, IEnumerable<dynamic>, string, string) ProjectReport(int id, string MEDIC_AREA, string item_name, string GENERIC_NAME, string PROJECT_NAME, string icd, string DISEASE_NAME)
{
bool result = deleteShow();
if (result)
result = addShow(id, MEDIC_AREA == "" ? null : MEDIC_AREA, item_name == "" ? null : item_name);
else
throw new DomainException("请重试!!!");
if (result)
return Show(id, MEDIC_AREA == "" ? null : MEDIC_AREA, GENERIC_NAME == "" ? null : GENERIC_NAME, PROJECT_NAME == "" ? null : PROJECT_NAME, icd == "" ? null : icd, DISEASE_NAME == "" ? null : DISEASE_NAME);
return (null, null, null, null);
return (sj, zon);
}
/// <summary>
/// 删除MEDIC_PERSON_INFORMATION_存储过程表的记录
/// </summary>
public bool deleteShow()
{
using (DbConnection connection = new SqlConnection(_Connection156))
{
bool a = connection.Execute("delete [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表]") >= 0 ? true : false;
return a;
}
return false;
DbConnection connection = new SqlConnection(_configConnectionString);
return connection.Execute("delete [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表]") >= 0 ? true : false;
}
/// <summary>
/// 添加本次查询的记录到 MEDIC_PERSON_INFORMATION_存储过程表
......@@ -161,126 +133,135 @@ public bool addShow(int id, string MEDIC_AREA, string ITEM_NAME)
ITEM_NAME = " ITEM_NAME LIKE '%" + ITEM_NAME.Replace(",", " %' or ITEM_NAME like '%") + "%'";
ITEM_NAME = "and (" + ITEM_NAME + ")";
}
using (DbConnection connection = new SqlConnection(_Connection156))
{
var AddQuery = $@"
insert into [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表]
(ID, HOS_ID, MASTER_INDEX, BIRTHDAY, SEX, PERSON_CODE, PERSON_ID, REG_CODE, REG_ID, REG_SOURCE, REG_TIME, AREA_ID, INDEXS, TYPE, DEPT_NAME, MEDIC_AREA)
SELECT a.* ,b.[MEDIC_AREA] FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION] a
left join [SV_MEDIC_STATISTICS].[dbo].[MEDIC_AREA] b on a.AREA_ID = b.ID AND a.INDEXS=b.INDEXS AND a.TYPE=b.TYPE
where({MEDIC_AREA}) {ITEM_NAME} and a.TYPE = 1 AND a.INDEXS IN(" + id + ")";
DbConnection connection = new SqlConnection(_configConnectionString);
return connection.Execute(AddQuery) >= 0 ? true : false;
}
return false;
var AddQuery = $@"
insert into [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表]
( HOS_ID, MASTER_INDEX, BIRTHDAY, SEX, PERSON_CODE, PERSON_ID, REG_CODE, REG_ID, REG_SOURCE, REG_TIME, AREA_ID, INDEXS, TYPE, DEPT_NAME, MEDIC_AREA)
SELECT a.HOS_ID,MASTER_INDEX,BIRTHDAY,SEX,PERSON_CODE,PERSON_ID,REG_CODE,REG_ID,REG_SOURCE,REG_TIME,AREA_ID,a.INDEXS,a.TYPE,DEPT_NAME,a.MEDIC_AREA
FROM [SV_QueryPlatform_].[dbo].[MEDIC_PERSON_INFORMATION_{id}] a
left join [SV_QueryPlatform_].[dbo].[MEDIC_AREA_{id}] b on a.AREA_ID = b.ID AND a.INDEXS=b.INDEXS AND a.TYPE=b.TYPE
where({MEDIC_AREA}) {ITEM_NAME} and a.TYPE = 1 AND a.INDEXS IN(" + id + ")";
return connection.Execute(AddQuery, commandTimeout: 60 * 60 * 5) >= 0 ? true : false;
}
/// <summary>
///报告展示(疾病展示所有,药品可以填写)
/// </summary>
public (IEnumerable<dynamic>, IEnumerable<dynamic>, string, string) ProjectReport(int id, string MEDIC_AREA, string item_name, string GENERIC_NAME, string PROJECT_NAME, string icd, string DISEASE_NAME)
{
bool result = deleteShow();
if (result)
result = addShow(id, MEDIC_AREA == "" ? null : MEDIC_AREA, item_name == "" ? null : item_name);
else
throw new DomainException("请重试!!!");
if (result)
return Show(id, MEDIC_AREA == "" ? null : MEDIC_AREA, GENERIC_NAME == "" ? null : GENERIC_NAME, PROJECT_NAME == "" ? null : PROJECT_NAME, icd == "" ? null : icd, DISEASE_NAME == "" ? null : DISEASE_NAME);
return (null, null, null, null);
}
/// <summary>
/// 展示结果
/// </summary>
public (IEnumerable<dynamic>, IEnumerable<dynamic>, string, string) Show(int id, string MEDIC_AREA, string GENERIC_NAME, string PROJECT_NAME, string icd, string DISEASE_NAME)
{
using (DbConnection connection = new SqlConnection(_Connection156))
{
var ShowQuery1 = "";
var ShowQuery2 = "";
ShowQuery1 = @"SELECT * FROM (
SELECT '总'n,COUNT(*)RS FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN (" + id + @")) S
union all
SELECT cast(N as nvarchar(10))n,COUNT(*)RS FROM (
SELECT DISTINCT YEAR([REG_TIME])N, HOS_ID,MASTER_INDEX
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN (" + id + @") AND YEAR(REG_TIME)>=2014
) S GROUP BY N
UNION ALL
SELECT '2013'N,COUNT(*)RS FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN(" + id + @")
AND YEAR(REG_TIME)<=2013 ) S
)S PIVOT (SUM(RS) FOR N IN ([2013],[2014],[2015],[2016],[2017],[2018],[2019],[2020],[总]))V";
DbConnection connection = new SqlConnection(_configConnectionString);
var ShowQuery1 = $@"SELECT * FROM (
SELECT '总'n,COUNT(*)RS FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX
FROM [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN ({id})) S
union all
SELECT cast(N as nvarchar(10))n,COUNT(*)RS FROM (
SELECT DISTINCT YEAR([REG_TIME])N, HOS_ID,MASTER_INDEX
FROM [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN ({id}) AND YEAR(REG_TIME)>=2014
) S GROUP BY N
UNION ALL
SELECT '2013'N,COUNT(*)RS FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX
FROM [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN({id})
AND YEAR(REG_TIME)<=2013 ) S
)S PIVOT (SUM(RS) FOR N IN ([2013],[2014],[2015],[2016],[2017],[2018],[2019],[2020],[2021],[总]))V";
ShowQuery2 = @"SELECT '医院区域'classification, PROVINCE hospital,COUNT(DISTINCT case when CODE is not null then code else HOS_ID end)hospitalsSUM,COUNT(*)patientSUM FROM (
var ShowQuery2 = $@"SELECT '医院区域'classification, PROVINCE hospital,COUNT(DISTINCT case when CODE is not null then code else HOS_ID end)hospitalsSUM,COUNT(*)patientSUM FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX,replace([Province],' ','')PROVINCE,CODE
FROM (SELECT DISTINCT HOS_ID,MASTER_INDEX
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN (" + id + @" )) A
JOIN [DB_SV_DATA_CONFIG].[DBO].[SYS_HOSPITAL] B ON A.HOS_ID=B.ID
) N GROUP BY PROVINCE
UNION ALL
SELECT '医院级别'JB,HOSLEVEL,COUNT(DISTINCT case when CODE is not null then code else HOS_ID end ),COUNT(*)RS FROM (
FROM [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN ({id})) A
JOIN [192.168.18.156].[DB_SV_DATA_CONFIG].[DBO].[SYS_HOSPITAL] B ON A.HOS_ID=B.ID
) N GROUP BY PROVINCE
UNION ALL
SELECT '医院级别'JB,HOSLEVEL,COUNT(DISTINCT case when CODE is not null then code else HOS_ID end ),COUNT(*)RS FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX,PROVINCE,CODE,
CASE WHEN HOSLEVEL LIKE '%三%' THEN '三级' WHEN HOSLEVEL LIKE '%二%' THEN '二级'
ELSE '一级' END HOSLEVEL,
HOSTYPE FROM (SELECT DISTINCT HOS_ID,MASTER_INDEX
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN (" + id + @" )) A
JOIN [DB_SV_DATA_CONFIG].[DBO].[SYS_HOSPITAL] B ON A.HOS_ID=B.ID
) N GROUP BY HOSLEVEL
UNION ALL
SELECT '医院类别'LB,HOSTYPE,COUNT(DISTINCT case when CODE is not null then code else HOS_ID end),COUNT(*)RS FROM (
FROM [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN ({id})) A
JOIN [192.168.18.156].[DB_SV_DATA_CONFIG].[DBO].[SYS_HOSPITAL] B ON A.HOS_ID=B.ID
) N GROUP BY HOSLEVEL
UNION ALL
SELECT '医院类别'LB,HOSTYPE,COUNT(DISTINCT case when CODE is not null then code else HOS_ID end),COUNT(*)RS FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX,CODE,
HOSTYPE FROM (SELECT DISTINCT HOS_ID,MASTER_INDEX
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN(" + id + @") ) A
JOIN [DB_SV_DATA_CONFIG].[DBO].[SYS_HOSPITAL] B ON A.HOS_ID=B.ID
) N GROUP BY HOSTYPE
UNION ALL
SELECT '总览'ZL,'医院数',COUNT(DISTINCT case when CODE is not null then code else HOS_ID end),COUNT(*)RS FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX,CODE,
FROM [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN({id}) ) A
JOIN [192.168.18.156].[DB_SV_DATA_CONFIG].[DBO].[SYS_HOSPITAL] B ON A.HOS_ID=B.ID
) N GROUP BY HOSTYPE
UNION ALL
SELECT '总览'ZL,'医院数',COUNT(DISTINCT case when CODE is not null then code else HOS_ID end),COUNT(*)RS FROM (
SELECT DISTINCT HOS_ID,MASTER_INDEX,CODE,
HOSTYPE FROM (SELECT DISTINCT HOS_ID,MASTER_INDEX
FROM [SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN(" + id + @") ) A
JOIN [DB_SV_DATA_CONFIG].[DBO].[SYS_HOSPITAL] B ON A.HOS_ID=B.ID
) N ";
IEnumerable<dynamic> yearfb = connection.Query(ShowQuery1);
IEnumerable<dynamic> dqfb = connection.Query(ShowQuery2).ToList();
var condition = "";
if (icd != "" && icd != null) condition = "ICD:" + icd;
if (DISEASE_NAME != "" && DISEASE_NAME != null) condition = condition + @"疾病名称:" + DISEASE_NAME;
if (GENERIC_NAME != "" && GENERIC_NAME != null) condition = condition + @"药品名称:" + GENERIC_NAME;
if (MEDIC_AREA != "" && MEDIC_AREA != null) condition = condition + @"产地:" + MEDIC_AREA;
FROM [SV_QueryPlatform].[dbo].[MEDIC_PERSON_INFORMATION_存储过程表] WHERE TYPE=1 AND INDEXS IN({id}) ) A
JOIN [192.168.18.156].[DB_SV_DATA_CONFIG].[DBO].[SYS_HOSPITAL] B ON A.HOS_ID=B.ID ) N ";
IEnumerable<dynamic> yearfb = connection.Query(ShowQuery1);
IEnumerable<dynamic> dqfb = connection.Query(ShowQuery2).ToList();
var condition = "";
if (!string.IsNullOrEmpty(icd)) condition = "ICD:" + icd;
if (!string.IsNullOrEmpty(DISEASE_NAME)) condition = condition + @"疾病名称:" + DISEASE_NAME;
if (!string.IsNullOrEmpty(GENERIC_NAME)) condition = condition + @"药品名称:" + GENERIC_NAME;
if (!string.IsNullOrEmpty(MEDIC_AREA)) condition = condition + @"产地:" + MEDIC_AREA;
return (yearfb, dqfb, condition, PROJECT_NAME);
return (yearfb, dqfb, condition, PROJECT_NAME);
}
return (null, null, null, null);
}
/// <summary>
/// 创建流水表
/// </summary>
public bool EstablishFlowDatabaseTable(string PROJECT_NAME, string sql, int id, string remarks)
{
using (DbConnection connection = new SqlConnection(_configConnectionString))
DbConnection connection = new SqlConnection(_configConnectionString);
int isfilter = 1;
if (connection.Query("select *from [SV_QueryPlatform].[dbo].[FlowReservoirStatus] where tableName like '%" + PROJECT_NAME + "%'").Count() > 0)
{
throw new DomainException(PROJECT_NAME + "流水库表已存在!");
}
else
{
int isfilter = 1;
if (connection.Query("select *from [SV_QueryPlatform].[dbo].[FlowReservoirStatus] where tableName like '%" + PROJECT_NAME + "%'").Count() > 0)
if (sql == "" || sql == null)
{
throw new DomainException(PROJECT_NAME + "流水库表已存在!");
isfilter = 0;
sql = $"SELECT distinct MASTER_INDEX,hos_id FROM[192.168.18.156].[SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION] WHERE indexs = {id} and TYPE = 1";
}
else
{
if (sql == "" || sql == null)
{
isfilter = 0;
sql = $"SELECT distinct MASTER_INDEX,hos_id FROM[192.168.18.156].[SV_MEDIC_STATISTICS].[dbo].[MEDIC_PERSON_INFORMATION] WHERE indexs = {id} and TYPE = 1";
}
if (connection.Execute($@"INSERT INTO[SV_QueryPlatform].[dbo].[FlowReservoirStatus]([tableName] ,[createDate] ,[state],indexs,isfilter,[sql],remarks)
if (connection.Execute($@"INSERT INTO[SV_QueryPlatform].[dbo].[FlowReservoirStatus]([tableName] ,[createDate] ,[state],indexs,isfilter,[sql],remarks)
select'{PROJECT_NAME}', getdate(), 0,{id} ,{isfilter},'INSERT INTO[SV_QueryPlatform].[dbo].[{PROJECT_NAME}]([MASTER_INDEX],[HOS_ID]){sql }','{remarks}'") > 0 ? true : false)
{
connection.Execute(@"CREATE TABLE [SV_QueryPlatform].[dbo].[" + PROJECT_NAME + "]([MASTER_INDEX][INT] NULL,[HOS_ID][INT] NULL) ON[PRIMARY]");
if (connection.Query(@"select * from[SV_QueryPlatform].sys.tables WHERE name = '" + PROJECT_NAME + "'").Count() > 0 ? true : false)
{
connection.Execute(@"CREATE TABLE [SV_QueryPlatform].[dbo].[" + PROJECT_NAME + "]([MASTER_INDEX][INT] NULL,[HOS_ID][INT] NULL) ON[PRIMARY]");
if (connection.Query(@"select * from[SV_QueryPlatform].sys.tables WHERE name = '" + PROJECT_NAME + "'").Count() > 0 ? true : false)
{
return connection.Execute("INSERT INTO [SV_QueryPlatform].[dbo].[" + PROJECT_NAME + "]([MASTER_INDEX],[HOS_ID])" + sql) > 0 ? true : false;
}
else
{
throw new DomainException("创建 [SV_QueryPlatform].[dbo].[" + PROJECT_NAME + "]流水库表成功,插入人群时报错!插入数据先病人再医院编码");
}
return connection.Execute("INSERT INTO [SV_QueryPlatform].[dbo].[" + PROJECT_NAME + "]([MASTER_INDEX],[HOS_ID])" + sql) > 0 ? true : false;
}
else
{
throw new DomainException("创建 [SV_QueryPlatform].[dbo].[" + PROJECT_NAME + "]流水库表失败");
throw new DomainException("创建 [SV_QueryPlatform].[dbo].[" + PROJECT_NAME + "]流水库表成功,插入人群时报错!插入数据先病人再医院编码");
}
}
else
{
throw new DomainException("创建 [SV_QueryPlatform].[dbo].[" + PROJECT_NAME + "]流水库表失败");
}
}
return false;
}
/// <summary>
/// 查询日志
......@@ -314,13 +295,13 @@ public IEnumerable<dynamic> QueryFlowDatabase()
/// <summary>
/// 日志
/// </summary>
public bool LOG(string LOG, string hos_code, int indexs, string? type, string? sql)
public void LOG(string LOG, string hos_code, int indexs, string? type, string? sql)
{
using (DbConnection connection = new SqlConnection(_configConnectionString))
{
sql = sql.Replace("'", "''");
return connection.Execute($@"INSERT INTO[SV_QueryPlatform].[dbo].[SYS_LOG]([INDEXS] ,hos_code,[createDate] ,[LOG],type,[错误sql])
select'{indexs}','{hos_code}', getdate(),'{LOG} ','{type}','{sql}'") > 0 ? true : false;
connection.Execute($@"INSERT INTO[SV_QueryPlatform].[dbo].[SYS_LOG]([INDEXS] ,hos_code,[createDate] ,[LOG],type,[错误sql])
select'{indexs}','{hos_code}', getdate(),'{LOG} ','{type}','{sql}'");
}
}
/// <summary>
......@@ -336,6 +317,7 @@ public string[] ShowSql(string TableName)
return A;
}
}
/// <summary>
/// 创建流水库
/// </summary>
......@@ -932,6 +914,8 @@ public void CheckTimeout()
}
}
}
/// <summary>
/// 拉取病人表
/// </summary>
......@@ -981,7 +965,7 @@ SELECT DISTINCT
pairs.TryAdd($"@{nameof(DatabaseName)}", DatabaseName);
pairs.TryAdd($"@{nameof(tableName)}", tableName);
pairs.TryAdd($"@{nameof(biao)}", biao);
var ITEM = "[@ExecOpenLink].[@ExecDatabase]";
//拉取病人表
configConnection.Execute($"UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET state =2 ,DataPullTime=getdate() WHERE indexs={indexs}");
......@@ -1005,7 +989,7 @@ SELECT DISTINCT
num = connection154.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.155")
num = connection155.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.156")
else if (hos.ExecOpenLink != "192.168.18.156")
num = connection156.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.158")
num = connection158.Execute(sql, commandTimeout: 60 * 60 * 5);
......@@ -1108,7 +1092,7 @@ SELECT DISTINCT
}
sql = sql.Replace("@paseIndex", paseIndex.ToString());
if (hos.ExecOpenLink == "192.168.18.151")
num = num+ connection151.Execute(sql, commandTimeout: 60 * 60 * 5);
num = num + connection151.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.152")
num = num + connection152.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.153")
......@@ -1117,12 +1101,12 @@ SELECT DISTINCT
num = num + connection154.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.155")
num = num + connection155.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.156")
else if (hos.ExecOpenLink != "192.168.18.156")
num = num + connection156.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.158")
num = num + connection158.Execute(sql, commandTimeout: 60 * 60 * 5);
configConnection.Execute($"UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET DataPullTime=getdate() WHERE indexs={indexs}");
// if (num >= 0 && i>1) { LOG($"{biao}" + paseIndex.ToString() + "/" + (count % 2000 > 0 ? (count / 2000) + 1 : count / 2000).ToString(), ITEM, indexs, "成功,返回行数:" + num, sql); }
// if (num >= 0 && i>1) { LOG($"{biao}" + paseIndex.ToString() + "/" + (count % 2000 > 0 ? (count / 2000) + 1 : count / 2000).ToString(), ITEM, indexs, "成功,返回行数:" + num, sql); }
paseIndex = paseIndex + 1;
......@@ -1147,175 +1131,9 @@ SELECT DISTINCT
}
//查询所有医院
public List<SYS_Hospital> showHospitals()
{
var sql = "";
using (DbConnection connection156 = new SqlConnection(_Connection156))
{
// sys_hospital156找医院
sql = @$"SELECT top 2
ExecOpenLink ,
ExecDatabase
FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital]
WHERE ExecOpenLink <>'' AND ExecOpenLink IS NOT NULL
AND ExecDatabase <>'' AND ExecDatabase IS NOT NULL
";
List<SYS_Hospital> hospitals = connection156.Query<SYS_Hospital>(sql).ToList();
return hospitals;
}
return null; ;
}
//判断是否取消
public int qx(int id)
{
using (DbConnection configConnection = new SqlConnection(_configConnectionString))
{
var sql = @$"SELECT COMPLETE_MARK FROM [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] where id ={id}";
int[] A = configConnection.Query<int>(sql).ToArray();
return A[0];
}
}
//Inquire
/// <summary>
/// diag查询平台
/// </summary>
public void DiagInquire(int type,string [] icd, string []diseaseName)
{
int indexs = -1;
int num = 0;
var sql = "";
var ITEM = "[@ExecOpenLink].[@ExecDatabase]";
//数组拼接条件
var icd_or_diseaseCondition = "";
foreach (var icdname in icd)
{
icd_or_diseaseCondition = icd_or_diseaseCondition + $"or icd like '%{icdname}%' ";
}
foreach (var disease in diseaseName)
{
icd_or_diseaseCondition = icd_or_diseaseCondition + $"or DISEASE_NAME like '%{disease}%' ";
}
icd_or_diseaseCondition = icd_or_diseaseCondition.Substring(2, icd_or_diseaseCondition.Length - 2);
//------------------------------查询------------------------//
//1.调医院
List<SYS_Hospital> hospitals = showHospitals();
using (DbConnection configConnection = new SqlConnection(_configConnectionString)) // DefaultConnection
using (DbConnection connection151 = new SqlConnection(_Connection151))
using (DbConnection connection152 = new SqlConnection(_Connection152))
using (DbConnection connection153 = new SqlConnection(_Connection153))
using (DbConnection connection154 = new SqlConnection(_Connection154))
using (DbConnection connection155 = new SqlConnection(_Connection155))
using (DbConnection connection156 = new SqlConnection(_Connection156))
using (DbConnection connection158 = new SqlConnection(_Connection158))
{
try
{
sql = " ";
//添加一条查询记录
connection156.Execute(sql, commandTimeout: 60 * 60 * 5);
sql = ShowSql($"SELECT_DIAG_{type}")[0];
Dictionary<string, object> pairs = new Dictionary<string, object> { };
foreach (var hos in hospitals)
{
pairs.Clear();
// 存在 // 不存在
pairs.TryAdd($"@{nameof(hos.ExecOpenLink)}", hos.ExecOpenLink);
pairs.TryAdd($"@{nameof(hos.ExecDatabase)}", hos.ExecDatabase);
pairs.TryAdd($"@{nameof(indexs)}", indexs);
// sql 数据源导出csv 导入csv 到connection
if (qx(indexs) != 31)
{
sql = sql.Replace("@condition", icd_or_diseaseCondition);
foreach (var item1 in pairs)
{
ITEM = ITEM.Replace(item1.Key, item1.Value.ToString());
sql = sql.Replace(item1.Key, item1.Value.ToString());
}
if (hos.ExecOpenLink == "192.168.18.151")
num = num + connection151.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.152")
num = num + connection152.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.153")
num = num + connection153.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.154")
num = num + connection154.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.155")
num = num + connection155.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.156")
num = num + connection156.Execute(sql, commandTimeout: 60 * 60 * 5);
else if (hos.ExecOpenLink == "192.168.18.158")
num = num + connection158.Execute(sql, commandTimeout: 60 * 60 * 5);
LOG($"查询成功,{num}行", $"{ITEM}", indexs, "查询平台", "");
}
else
{
configConnection.Execute("update [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23 where and COMPLETE_MARK != 22 id= " + indexs);
if (qx(indexs) == 23)//取消
{
LOG("停止成功", "", indexs, "查询平台", "");
}
}
}
configConnection.Execute("update [SV_MEDIC_STATISTICS].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 22 where and COMPLETE_MARK != 22 id= " + indexs);
LOG("查询结束", "", indexs, "查询平台", "");
}
catch (Exception e)
{
LOG($"查询失败", $"{ITEM}", indexs, "查询平台", sql);
}
}
}
//Inquire
/// <summary>
///Drug查询平台
/// </summary>
public void DrugInquire(int id,int type ,string[] drugName)
{
var sql = "";
//数组拼接条件
var drugCondition = "";
foreach (var drug in drugName)
{
drugCondition = drugCondition + $"or ITEM_NAME like '%{drug}%' ";
}
drugCondition=drugCondition.Substring(2, drugCondition.Length - 2);
List<SYS_Hospital> hospitals = showHospitals();
using (DbConnection configConnection = new SqlConnection(_configConnectionString)) // DefaultConnection
using (DbConnection connection151 = new SqlConnection(_Connection151))
using (DbConnection connection152 = new SqlConnection(_Connection152))
using (DbConnection connection153 = new SqlConnection(_Connection153))
using (DbConnection connection154 = new SqlConnection(_Connection154))
using (DbConnection connection155 = new SqlConnection(_Connection155))
using (DbConnection connection156 = new SqlConnection(_Connection156))
using (DbConnection connection158 = new SqlConnection(_Connection158))
{
}
}
}
}
//Inquire
/// <summary>
///Drug查询平台
/// </summary>
public void MaterialInquire(string[] materialName)
{
}
}
}
\ No newline at end of file
......@@ -26,6 +26,24 @@
</summary>
<returns></returns>
</member>
<member name="M:Health.Api.Controllers.AnalysisController.HosListInquire(System.Int32,System.String,System.Int32)">
<summary>
医院展示
</summary>
<returns></returns>
</member>
<member name="M:Health.Api.Controllers.AnalysisController.ParseInquire(System.String,System.Int32)">
<summary>
数据解析
</summary>
<returns></returns>
</member>
<member name="M:Health.Api.Controllers.DrugqueryController.Drugquery(Health.Api.Infrastructure.Modules.SYS_Drugquery)">
<summary>
查询病人疾病信息和药品信息//type1=疾病//type2药品
</summary>
<param name="sYS_Drugquery"></param>
</member>
<member name="M:Health.Api.Controllers.ResourceController.ItemQuery">
<summary>
查询当月项目
......@@ -89,12 +107,6 @@
</summary>
<returns></returns>
</member>
<member name="M:Health.Api.Controllers.ResourceController.Inquire(Health.Api.Infrastructure.Modules.SYS_QueryConditions)">
<summary>
查询平台
</summary>
<returns></returns>
</member>
<member name="M:Health.Api.Controllers.UserController.Info">
<summary>
用户信息
......@@ -216,6 +228,36 @@
解码中间件
</summary>
</member>
<member name="P:Health.Api.Infrastructure.Modules.SYS_Drugquery.type1_2">
<summary>
1 命中查询 2其他查询
</summary>
</member>
<member name="P:Health.Api.Infrastructure.Modules.SYS_Drugquery.icd">
<summary>
ICD编码
</summary>
</member>
<member name="P:Health.Api.Infrastructure.Modules.SYS_Drugquery.diseaseName">
<summary>
疾病名称
</summary>
</member>
<member name="P:Health.Api.Infrastructure.Modules.SYS_Drugquery.drugName">
<summary>
药品
</summary>
</member>
<member name="P:Health.Api.Infrastructure.Modules.SYS_Drugquery.materialName">
<summary>
材料费
</summary>
</member>
<member name="P:Health.Api.Infrastructure.Modules.SYS_Drugquery.peojectName">
<summary>
项目,名称
</summary>
</member>
<member name="P:Health.Api.Infrastructure.Modules.SYS_USER.IsDelete">
<summary>
true 删除 false 正常
......@@ -231,6 +273,52 @@
页行数 默认30
</summary>
</member>
<member name="M:Health.Api.Infrastructure.Queries.AnalysisQueries.HosListInquire(System.String,System.Int32)">
<summary>
医院展示
</summary>
</member>
<member name="M:Health.Api.Infrastructure.Queries.DrugqueryQueries.DrugqueryIndexs">
<summary>
获取到最大的那条记录id
</summary>
<returns></returns>
</member>
<member name="M:Health.Api.Infrastructure.Queries.DrugqueryQueries.Complete_MarkId(System.Int32)">
<summary>
获取到最大的那条记录Complete_MarkId
</summary>
<returns></returns>
</member>
<member name="M:Health.Api.Infrastructure.Queries.DrugqueryQueries.Countnum(System.String,System.Data.Common.DbConnection)">
<summary>
传入sql 连接 返回int
</summary>
<returns></returns>
</member>
<member name="M:Health.Api.Infrastructure.Queries.DrugqueryQueries.SqlAdd(Health.Api.Infrastructure.Modules.SYS_Drugquery,System.Int32)">
<summary>
插入查询记录表
</summary>
<param name="sYS_Drugquery"></param>
</member>
<member name="M:Health.Api.Infrastructure.Queries.DrugqueryQueries.Diseasequery(System.Int32,System.Int32,System.String[],System.String[],System.Int32)">
<summary>
查询疾病对应的病人信息
</summary>
<param name="type">类型1</param>
<param name="icd">ICD编码</param>
<param name="diseaseName">疾病名称</param>
<param name="type1_2">类型</param>
</member>
<member name="M:Health.Api.Infrastructure.Queries.DrugqueryQueries.Drugquery(System.Int32,System.Int32,System.String[],System.Int32)">
<summary>
查询药品信息
</summary>
<param name="type">类型2</param>
<param name="type1_2">他因</param>
<param name="drugName">药品名称</param>
</member>
<member name="M:Health.Api.Infrastructure.Queries.ResourceQueries.ItemQuery">
<summary>
查询所有项目
......@@ -241,11 +329,6 @@
停止正在查询项目
</summary>
</member>
<member name="M:Health.Api.Infrastructure.Queries.ResourceQueries.ProjectReport(System.Int32,System.String,System.String,System.String,System.String,System.String,System.String)">
<summary>
报告展示(疾病展示所有,药品可以填写)
</summary>
</member>
<member name="M:Health.Api.Infrastructure.Queries.ResourceQueries.deleteShow">
<summary>
删除MEDIC_PERSON_INFORMATION_存储过程表的记录
......@@ -256,6 +339,11 @@
添加本次查询的记录到 MEDIC_PERSON_INFORMATION_存储过程表
</summary>
</member>
<member name="M:Health.Api.Infrastructure.Queries.ResourceQueries.ProjectReport(System.Int32,System.String,System.String,System.String,System.String,System.String,System.String)">
<summary>
报告展示(疾病展示所有,药品可以填写)
</summary>
</member>
<member name="M:Health.Api.Infrastructure.Queries.ResourceQueries.Show(System.Int32,System.String,System.String,System.String,System.String,System.String)">
<summary>
展示结果
......@@ -296,11 +384,6 @@
拉取病人表
</summary>
</member>
<member name="M:Health.Api.Infrastructure.Queries.ResourceQueries.Inquire(System.Int32,System.String,System.String,System.String,System.String)">
<summary>
查询平台
</summary>
</member>
<member name="M:Health.Api.Infrastructure.Queries.UserStorage.Update(Health.Api.Infrastructure.Request.UserRequest)">
<summary>
修改密码
......
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Health.Api.Infrastructure;
//using Health.Api.Infrastructure.Models;
using Health.Api.Infrastructure.Modules;
using Health.Api.Infrastructure.Queries;
using Health.Api.Infrastructure.Request;
using Health.Infra;
namespace Health.Api.Controllers
{
[Authorize]
[Route("api/resource")]
[ApiController]
public class AnalysisController : Controller
{
private readonly AnalysisQueries _aQueries;
private readonly IMemoryCache _cache;
public AnalysisController(IMemoryCache cache,AnalysisQueries aQueries)
{
this._cache = cache;
this._aQueries = aQueries;
}
/// <summary>
/// 医院展示
/// </summary>
/// <returns></returns>
[HttpPost("HosListInquire")]
[AllowAnonymous]
public (IEnumerable<dynamic>, IEnumerable<dynamic>) HosListInquire(int paseIndex, string hos_name, int hos_id)
{
return _aQueries.HosListInquire(paseIndex, hos_name, hos_id);
}
/// <summary>
/// 数据解析
/// </summary>
/// <returns></returns>
[HttpPost("ParseInquire")]
[AllowAnonymous]
public void ParseInquire(string zxr, int hosid)
{
int id = _aQueries.JX_SCJXJL(hosid, zxr);//1.生成解析记录
_aQueries.JX_GXID(id, hosid);//更新reg_id,master_index
_aQueries.JX_DIC_DIAG(id, hosid);//更新标准库里DIC_DIAG_SUMMARY里的标准字段
_aQueries.JX_DIC_FEE(id, hosid);//新建费用查询字典表
_aQueries.JX_ADD_DA_Disease(id, hosid);//未匹配上的诊断导入到DA_Disease表中
_aQueries.JX_DIC_DRUG_ATC(id, hosid);//匹配更新标准库 DIC_DRUG_ATC的标准字段
_aQueries.JX_ADD_DA_Drug(id, hosid);//未匹配上的导入 [dbo].[DA_Drug] 做处理
//对导入的药品跑权重
_aQueries.JX_DRUG_DATA_QZ(id, hosid);
//对导入的诊断做处理,剔除无效字符
_aQueries.JX_DA_DIAGNOSIS_DATA(id, hosid);
//新导入的诊断跑权重,生成标准科室,标准一级诊断,标准二级诊断
_aQueries.JX_DIAGNOSIS_DATA_QZ(id, hosid);
}
}
}
using Health.Api.Infrastructure.Modules;
using Health.Api.Infrastructure.Queries;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Caching.Memory;
using System.Data.Common;
namespace Health.Api.Controllers
{
public class DrugqueryController : Controller
{
private readonly IMemoryCache _cache;
private readonly ResourceQueries resourceQueries;
private readonly DrugqueryQueries drugqueryQueries;
public DrugqueryController(
IMemoryCache cache,
ResourceQueries resourceQueries,
DrugqueryQueries drugqueryQueries)
{
this._cache = cache;
this.resourceQueries = resourceQueries;
this.drugqueryQueries = drugqueryQueries;
}
/// <summary>
/// 查询病人疾病信息和药品信息//type1=疾病//type2药品
/// </summary>
/// <param name="sYS_Drugquery"></param>
[HttpPost("Drugquery")]
[AllowAnonymous]
public void Drugquery(SYS_Drugquery sYS_Drugquery)
{
int type = 0;
if ((sYS_Drugquery.icd!=null || sYS_Drugquery.diseaseName!=null) && sYS_Drugquery.drugName==null && sYS_Drugquery.materialName==null)
{
type = 1;//1疾病
int num =drugqueryQueries.SqlAdd(sYS_Drugquery, type);
drugqueryQueries.Diseasequery(type, sYS_Drugquery.type1_2, sYS_Drugquery.icd,sYS_Drugquery.diseaseName,num);
}
else if (sYS_Drugquery.drugName!=null && sYS_Drugquery.diseaseName == null && sYS_Drugquery.icd == null && sYS_Drugquery.materialName == null)
{
type = 2;//2药品
int num = drugqueryQueries.SqlAdd(sYS_Drugquery, type);
drugqueryQueries.Drugquery(type, sYS_Drugquery.type1_2, sYS_Drugquery.drugName,num);
}
else if(sYS_Drugquery.materialName!=null && sYS_Drugquery.diseaseName==null && sYS_Drugquery.icd == null && sYS_Drugquery.drugName == null)
{
type = 3;//3材料
int num = drugqueryQueries.SqlAdd(sYS_Drugquery, type);
drugqueryQueries.Drugquery(type, sYS_Drugquery.type1_2, sYS_Drugquery.materialName,num);
}
else
{
throw new DomainException("只能单类型查询!!");
}
}
}
}
using Microsoft.AspNetCore.Mvc;
namespace Health.Api.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}
using Dapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
//using Health.Api.Infrastructure.Models;
using Health.Api.Infrastructure.Modules;
using Health.Api.Infrastructure.Request;
using Health.Infra;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Threading.Tasks;
using static UtilExtensions;
namespace Health.Api.Infrastructure.Queries
{
public class AnalysisQueries
{
private readonly string _Connection156;
private readonly string _configConnectionString;
//private List<Common> a;
bool state = true;
public AnalysisQueries(string Connection156, string configConnectionString)
{
_Connection156 = Connection156;
_configConnectionString = configConnectionString;
}
//Inquire
/// <summary>
///医院展示
/// </summary>
public IEnumerable<dynamic> HosListInquire(string hos_name, int hos_id)
{
using (DbConnection connection = new SqlConnection(_Connection156))
{
string where = " ";
if (!string.IsNullOrEmpty(hos_name))
{
where = where + " and [HosName] like '%" + hos_name + "%'";
}
if (hos_id != 0)
{
where = where + " and id =" + hos_id;
}
var query = @" SELECT [ID] 编号,[CODE] 编码,[HosName] 医院名称,[HosLevel] 医院等级,[HosType] 医院类型,[ExecOpenLink] 服务器,[ExecDatabase] 数据库, Replace([Province],' ','') 省份, Replace([Region],' ','') 市, Replace([City],' ','') 区
FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] where id<>1 " + where;
return connection.Query(query).ToList();
}
}
public (IEnumerable<dynamic>, IEnumerable<dynamic>) HosListInquire(int paseIndex, string hos_name, int hos_id)
{
using (DbConnection connection = new SqlConnection(_Connection156))
{
string where = " ";
if (!string.IsNullOrEmpty(hos_name))
{
where = where + " and [HosName] like '%" + hos_name + "%'";
}
if (hos_id != 0)
{
where = where + " and id =" + hos_id;
}
IEnumerable<dynamic> sj = connection.Query($@"select*FROM(
SELECT ROW_NUMBER() OVER(ORDER BY getdate())AS id,* FROM(
SELECT DISTINCT
[ID] 编号,[CODE] 编码,[HosName] 医院名称,[HosLevel] 医院等级,[HosType] 医院类型,[ExecOpenLink] 服务器,[ExecDatabase] 数据库, Replace([Province],' ','') 省份,
Replace([Region],' ','') 市, Replace([City],' ','') 区
FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] WHERE id<>1 { where} )a )b WHERE id<={paseIndex}*10 and id>({paseIndex} - 1)*10 ").ToList();
IEnumerable<dynamic> zon = connection.Query($@" SELECT CAST(COUNT(*)AS MONEY)totalCount ,{paseIndex} paseIndex FROM(
SELECT DISTINCT *
FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] WHERE id<>1 " + where + ")a").ToList();
return (sj, zon);
}
return (null, null);
}
private void updatezt(int id, int hos_id, string status, string log)
{
using (DbConnection configConnection = new SqlConnection(_configConnectionString))
{
configConnection.Execute(@$"update [SV_QueryPlatform].[dbo].[解析任务] set [status]='{status}',[updatedate]=getdate(),log='{log}' where hos_id={hos_id} and id={id}");
}
}
//1.解析执行sql
private void JX_zx(string sql, int hos_id, int id, SYS_Hospital hos)
{
DbConnection configConnection = new SqlConnection(_configConnectionString);
服务器 fwq = configConnection.Query<服务器>($"SELECT [服务器ip],[数据库账号],[数据库密码] FROM[SV_QueryPlatform].[dbo].[服务器] where[服务器ip] ='{hos.ExecOpenLink}'").FirstOrDefault();
var msConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", hos.ExecOpenLink, hos.ExecDatabase, fwq.数据库账号, fwq.数据库密码);
// DefaultConnection
using (DbConnection conn = new SqlConnection(msConnectionString))
{
try
{
conn.Execute(sql, commandTimeout: 60 * 60 * 12);
}
catch (Exception e)
{
configConnection.Execute(@$"update [SV_QueryPlatform].[dbo].[解析任务] set [status]='失败',[updatedate]=getdate() where hos_id={hos_id} and id={id}");
}
}
}
//1.解析执行sql返回数字
private int JX_zx_int(string sql, int hos_id, int id, SYS_Hospital hos)
{
DbConnection configConnection = new SqlConnection(_configConnectionString);
服务器 fwq = configConnection.Query<服务器>($"SELECT [服务器ip],[数据库账号],[数据库密码] FROM[SV_QueryPlatform].[dbo].[服务器] where[服务器ip] ='{hos.ExecOpenLink}'").FirstOrDefault();
var msConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", hos.ExecOpenLink, hos.ExecDatabase, fwq.数据库账号, fwq.数据库密码);
// DefaultConnection
using (DbConnection conn = new SqlConnection(msConnectionString))
{
try
{
return conn.Query<hosid>(sql).FirstOrDefault().id;
}
catch (Exception e)
{
configConnection.Execute(@$"update [SV_QueryPlatform].[dbo].[解析任务] set [status]='失败',[updatedate]=getdate(),log=[status]+{sql} where hos_id={hos_id} and id={id}");
}
return 0;
}
}
//生成一条解析记录
public int JX_SCJXJL(int hos_id, string czr)
{
var sql = "";
using (DbConnection configConnection = new SqlConnection(_configConnectionString)) // DefaultConnection
{
sql = @$" insert into [dbo].[解析任务]( [updatedate], [status], [ksdate], [hos_id], [czr])VALUES(getdate(),'开始解析',getdate(),{hos_id},'{czr}') ";
configConnection.Execute(sql, commandTimeout: 60 * 60 * 10);
return configConnection.Query<hosid>($@" select max(id)id from [dbo].[解析任务] where hos_id={hos_id} ").FirstOrDefault().id;
}
return 0;
}
//1.更新id org_code m_index
public void JX_GXID(int id, int hos_id)
{
var sql = "";
SYS_Hospital hos = new SYS_Hospital();
using (DbConnection connection156 = new SqlConnection(_Connection156))
{
updatezt(id, hos_id, "处理org_code", "");
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
}
sql = @$" update [{hos.ExecDatabase}].[dbo].[ASSAY_REPORT] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[DIC_DEPT] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[DIC_DIAG] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[DIC_DRUG] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[DIC_EMP] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[DIC_FEE] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[EXEC_REPORT] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[INPAT_DIAG] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[INPAT_FEE] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[INPAT_ORDER] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[INPAT_REG_INFO] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[OUT_DIAG] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[OUT_FEE] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[OUT_PRES] set org_code={hos_id} where org_code<>{hos_id}
update [{hos.ExecDatabase}].[dbo].[OUT_REG_INFO] set org_code={hos_id} where org_code<>{hos_id}";
updatezt(id, hos_id, "处理org_code", sql);
JX_zx(sql, hos_id, id, hos);
sql = $@"
SELECT (
SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[OUT_REG_INFO] A JOIN [{hos.ExecDatabase}].[dbo].[PUB_PATIENT] b ON A.PERSON_CODE=b.PERSON_CODE WHERE A.PERSON_ID!=b.PERSON_ID OR A.PERSON_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[OUT_DIAG] A JOIN [{hos.ExecDatabase}].[dbo].OUT_REG_INFO b ON A.REG_CODE=b.REG_CODE WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[OUT_FEE]A JOIN [{hos.ExecDatabase}].[dbo].OUT_REG_INFO b ON A.REG_CODE=b.REG_CODE WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[OUT_PRES]A JOIN [{hos.ExecDatabase}].[dbo].OUT_REG_INFO b ON A.REG_code=b.reg_code WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[inpat_REG_INFO] A JOIN [{hos.ExecDatabase}].[dbo].[PUB_PATIENT] b ON b.PERSON_CODE=a.PERSON_CODE WHERE A.PERSON_ID!=b.PERSON_ID OR A.PERSON_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[inpat_diag] A JOIN [{hos.ExecDatabase}].[dbo].[inpat_reg_info] b ON b.REG_CODE=a.REG_CODE WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[inpat_order] A JOIN [{hos.ExecDatabase}].[dbo].[inpat_reg_info] b ON b.REG_CODE=a.REG_CODE WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[inpat_fee] A JOIN [{hos.ExecDatabase}].[dbo].[inpat_reg_info] b ON b.REG_CODE=a.REG_CODE WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[ops_info] A JOIN [{hos.ExecDatabase}].[dbo].[inpat_reg_info] b ON b.REG_CODE=a.REG_CODE WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].EXEC_REPORT A JOIN [{hos.ExecDatabase}].[dbo].OUT_REG_INFO B ON a.REG_CODE=B.REG_CODE and REG_Source=1 WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[EXEC_REPORT] A JOIN [{hos.ExecDatabase}].[dbo].INPAT_REG_INFO B ON a.REG_CODE=B.REG_CODE and REG_Source=2 WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[ASSAY_REPORT] A JOIN [{hos.ExecDatabase}].[dbo].[OUT_REG_INFO] B ON a.REG_CODE=B.REG_CODE and REG_Source=1 WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[ASSAY_REPORT] A JOIN [{hos.ExecDatabase}].[dbo].[INPAT_REG_INFO] B ON a.REG_CODE=B.REG_CODE and REG_Source=2 WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[NIS_RECORD] A JOIN [{hos.ExecDatabase}].[dbo].[OUT_REG_INFO] B ON a.REG_CODE=B.REG_CODE and REG_Source=1 WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)+(SELECT COUNT(1) FROM [{hos.ExecDatabase}].[dbo].[NIS_RECORD] A JOIN [{hos.ExecDatabase}].[dbo].[INPAT_REG_INFO] B ON a.REG_CODE=B.REG_CODE and REG_Source=2 WHERE A.REG_ID!=b.REG_ID OR A.REG_ID IS NULL
)id";
updatezt(id, hos_id, "检查id是否更新", sql);
//判断id是否修
//判断MASTER_INDEX是否修改
sql = $@"SELECT COUNT(1)id FROM [{hos.ExecDatabase}].[dbo].PUB_PATIENT
where MASTER_INDEX is null";
updatezt(id, hos_id, "更新MASTER_INDEX", "判断MASTER_INDEX是否修改" + sql.Replace("'", "''"));
if (JX_zx_int(sql, hos_id, id, hos) > 0 && hos.ExecDatabase.Length == 13)
{
sql = $@" IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'PATIENT')
DROP TABLE [{hos.ExecDatabase}].dbo.PATIENT
IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'PATIENT_NOTNULL')
DROP TABLE [{hos.ExecDatabase}].dbo.PATIENT_NOTNULL
IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'PATIENT_STORE1')
DROP TABLE [{hos.ExecDatabase}].dbo.PATIENT_STORE1
IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'PATIENT_STORE2')
DROP TABLE [{hos.ExecDatabase}].dbo.PATIENT_STORE2
CREATE TABLE [{hos.ExecDatabase}].dbo.PATIENT (PERSON_ID INT,ID_CARD NVARCHAR(max),CARD_ID NVARCHAR(max),NEWPERSON_ID INT)
CREATE TABLE [{hos.ExecDatabase}].dbo.PATIENT_NOTNULL(PERSON_ID INT,CODE NVARCHAR(50),NEWPERSON_ID INT)
CREATE TABLE [{hos.ExecDatabase}].dbo.PATIENT_STORE1(PERSON_ID INT,CODE NVARCHAR(50),NEWPERSON_ID INT)
CREATE TABLE [{hos.ExecDatabase}].dbo.PATIENT_STORE2(PERSON_ID INT,CODE NVARCHAR(50),NEWPERSON_ID INT)
CREATE NONCLUSTERED INDEX [INDEX_PATIENT] ON [{hos.ExecDatabase}].[dbo].[PATIENT]
([ID_CARD] ASC, [CARD_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX_PATIENT_NOTNULL] ON [{hos.ExecDatabase}].[dbo].[PATIENT_NOTNULL] ([CODE] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX_PATIENT_STORE1] ON [{hos.ExecDatabase}].[dbo].[PATIENT_STORE1] ([CODE] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX_PATIENT_STORE2] ON [{hos.ExecDatabase}].[dbo].[PATIENT_STORE2] ([CODE] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX1_PATIENT_NOTNULL] ON [{hos.ExecDatabase}].[dbo].[PATIENT_NOTNULL]([PERSON_ID] ASC, [CODE] ASC, [NEWPERSON_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX1_PATIENT_STORE1] ON [{hos.ExecDatabase}].[dbo].[PATIENT_STORE1] ([PERSON_ID] ASC, [CODE] ASC, [NEWPERSON_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX1_PATIENT_STORE2] ON [{hos.ExecDatabase}].[dbo].[PATIENT_STORE2] ([PERSON_ID] ASC, [CODE] ASC, [NEWPERSON_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX2_PATIENT] ON [{hos.ExecDatabase}].[dbo].[PATIENT] ([PERSON_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX2_PATIENT_NOTNULL] ON [{hos.ExecDatabase}].[dbo].[PATIENT_NOTNULL] ([PERSON_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX2_PATIENT_STORE1] ON [{hos.ExecDatabase}].[dbo].[PATIENT_STORE1] ([PERSON_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
CREATE NONCLUSTERED INDEX [INDEX2_PATIENT_STORE2] ON [{hos.ExecDatabase}].[dbo].[PATIENT_STORE2] ([PERSON_ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)";
updatezt(id, hos_id, "更新MASTER_INDEX", "创建需要使用的表" + sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
//判断病人表中主索引列是否有值
sql = @$" SELECT CASE WHEN MAX(MASTER_INDEX) IS NULL THEN 0 ELSE MAX(MASTER_INDEX) END id FROM [{hos.ExecDatabase}].[DBO].PUB_PATIENT where MASTER_INDEX is not null; ";
updatezt(id, hos_id, "更新MASTER_INDEX", "判断病人表中主索引列是否有值" + sql.Replace("'", "''"));
int COUNT = JX_zx_int(sql, hos_id, id, hos);
sql = @$" SELECT COUNT(1) id FROM [{hos.ExecDatabase}].[DBO].PUB_PATIENT where MASTER_INDEX is null ";
int COUNT_ROW = JX_zx_int(sql, hos_id, id, hos);
if (COUNT_ROW != 0)
{
//将病人的医保号和身份证号集中放在一张表中
sql = $@"truncate TABLE [{hos.ExecDatabase}].[DBO].PATIENT
truncate TABLE [{hos.ExecDatabase}].[DBO].PATIENT_NOTNULL
truncate TABLE [{hos.ExecDatabase}].[DBO].PATIENT_STORE1
truncate TABLE [{hos.ExecDatabase}].[DBO].PATIENT_STORE2
insert into [{hos.ExecDatabase}].[DBO].PATIENT(PERSON_ID,ID_CARD,CARD_ID,NEWPERSON_ID)
SELECT TAB.PERSON_ID, CAST(ID_CARD AS NVARCHAR(100))ID_CARD, CARD_ID ,NULL NEWPERSON_ID FROM
(SELECT PERSON_ID,ID_CARD FROM [{hos.ExecDatabase}].[DBO].PUB_PATIENT WHERE [MASTER_INDEX] IS NULL ) TAB
LEFT JOIN (SELECT PERSON_ID, CARD_ID FROM (SELECT DJ.PERSON_ID, CARD_ID FROM [{hos.ExecDatabase}].[DBO].[OUT_REG_INFO] DJ GROUP BY DJ.PERSON_ID, CARD_ID
UNION
SELECT DJ.PERSON_ID, CARD_ID FROM [{hos.ExecDatabase}].[DBO].[INPAT_REG_INFO] DJ GROUP BY DJ.PERSON_ID,CARD_ID) TA ) TAB1
ON TAB.PERSON_ID=TAB1.PERSON_ID GROUP BY TAB.PERSON_ID,ID_CARD,CARD_ID;";
updatezt(id, hos_id, "更新MASTER_INDEX", "将病人的医保号和身份证号集中放在一张表中" + sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
//获取最大的master_index的值
sql = @$" select case when max(NEWPERSON_ID) is null then 0 else max(NEWPERSON_ID) end id from [{hos.ExecDatabase}].[dbo].[PATIENT]";
updatezt(id, hos_id, "更新MASTER_INDEX", "获取最大的master_index的值" + sql.Replace("'", "''"));
int mark = JX_zx_int(sql, hos_id, id, hos);
//置空不符合规范的身份证号和医保号
//更新无医保号且无身份证号的病人
sql = $@"IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'tablea')
DROP TABLE [{hos.ExecDatabase}].dbo.tablea
UPDATE [{hos.ExecDatabase}].[dbo].PATIENT SET ID_CARD = NULL WHERE ID_CARD NOT LIKE '[0-9]%' OR LEN(ID_CARD)<=15 OR ID_CARD LIKE '%8888%' OR ID_CARD LIKE '%0000%'
UPDATE [{hos.ExecDatabase}].[dbo].PATIENT SET CARD_ID = NULL WHERE CARD_ID NOT LIKE '[0-9]%' OR LEN(CARD_ID)<6
create table [{hos.ExecDatabase}].[dbo].tablea (id int primary key identity({COUNT + mark + 1},1),[code] nvarchar(200))
insert into [{hos.ExecDatabase}].[dbo].tablea(code)
select distinct person_id from [{hos.ExecDatabase}].[dbo].[PATIENT] WHERE ID_CARD IS NULL AND CARD_ID IS NULL
update [{hos.ExecDatabase}].[dbo].[PATIENT] set NEWPERSON_ID = b.id from [{hos.ExecDatabase}].[dbo].tablea b where [{hos.ExecDatabase}].[dbo].[PATIENT].PERSON_ID = b.code
insert into [{hos.ExecDatabase}].[dbo].PATIENT_NOTNULL(PERSON_ID,CODE,NEWPERSON_ID)
select PERSON_ID,ID_CARD CODE, NEWPERSON_ID from [{hos.ExecDatabase}].[dbo].PATIENT WHERE NEWPERSON_ID IS NULL
UNION ALL
select PERSON_ID,CARD_ID CODE, NEWPERSON_ID from [{hos.ExecDatabase}].[dbo].PATIENT WHERE NEWPERSON_ID IS NULL
drop table [{hos.ExecDatabase}].[dbo].tablea";
updatezt(id, hos_id, "更新MASTER_INDEX", "置空不符合规范的身份证号和医保号&&更新无医保号且无身份证号的病人" + sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
//递归更新身份证或者医保号相同的主索引
sql = $@"IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'table2')
DROP TABLE [{hos.ExecDatabase}].dbo.table2
create table [{hos.ExecDatabase}].[DBO].table2 (id int primary key identity({mark + 1},1),[code] nvarchar(200))
insert into [{hos.ExecDatabase}].[DBO].PATIENT_STORE1(PERSON_ID,CODE,NEWPERSON_ID)select PERSON_ID,CODE, NEWPERSON_ID from [{hos.ExecDatabase}].[DBO].PATIENT_NOTNULL
DECLARE @COUNT INT WHILE 1=1
BEGIN
truncate table [{hos.ExecDatabase}].[DBO].PATIENT_STORE2
insert into [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 (PERSON_ID,CODE,NEWPERSON_ID) select A.PERSON_ID,B.CODE,B.PERSON_ID NEWPERSON_ID from [{hos.ExecDatabase}].[DBO].PATIENT_STORE1 A JOIN [{hos.ExecDatabase}].[DBO].PATIENT_NOTNULL B ON A.CODE = B.CODE GROUP BY A.PERSON_ID,B.PERSON_ID,b.CODE
insert into [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 (PERSON_ID,CODE,NEWPERSON_ID) select A.PERSON_ID,B.CODE,B.PERSON_ID NEWPERSON_ID from [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 A JOIN [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 B ON A.NEWPERSON_ID = B.PERSON_ID GROUP BY A.PERSON_ID,B.PERSON_ID,b.CODE
SELECT @COUNT=COUNT(1) FROM [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 A LEFT JOIN [{hos.ExecDatabase}].[DBO].PATIENT_STORE1 B ON A.PERSON_ID = B.PERSON_ID and A.NEWPERSON_ID = B.NEWPERSON_ID AND A.CODE = B.CODE WHERE B.PERSON_ID IS NULL
IF @COUNT=0 BREAK
truncate table [{hos.ExecDatabase}].[DBO].PATIENT_STORE1
INSERT INTO [{hos.ExecDatabase}].[DBO].PATIENT_STORE1 (PERSON_ID,CODE,NEWPERSON_ID) SELECT PERSON_ID,CODE,NEWPERSON_ID FROM [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 GROUP BY PERSON_ID,CODE,NEWPERSON_ID
END
insert into [{hos.ExecDatabase}].[DBO].table2(code) SELECT DISTINCT A.NEWPERSON_ID FROM [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 A ORDER BY NEWPERSON_ID
UPDATE [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 SET NEWPERSON_ID = b.id from [{hos.ExecDatabase}].[DBO].table2 b where [{hos.ExecDatabase}].[DBO].[PATIENT_STORE2].NEWPERSON_ID = b.code
update [{hos.ExecDatabase}].[DBO].[PATIENT] set NEWPERSON_ID = b.NEWPERSON_ID from (SELECT PERSON_ID,MIN(NEWPERSON_ID) NEWPERSON_ID FROM [{hos.ExecDatabase}].[DBO].PATIENT_STORE2 GROUP BY PERSON_ID) b where [{hos.ExecDatabase}].[DBO].[PATIENT].PERSON_ID = b.PERSON_ID
drop table [{hos.ExecDatabase}].dbo.table2";
updatezt(id, hos_id, "更新MASTER_INDEX", "递归更新身份证或者医保号相同的主索引" + sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
sql = $@"UPDATE [{hos.ExecDatabase}].dbo.PATIENT SET NEWPERSON_ID = B.MASTER_INDEX FROM (SELECT A.NEWPERSON_ID,B.MASTER_INDEX FROM [{hos.ExecDatabase}].dbo.PATIENT A JOIN [{hos.ExecDatabase}].dbo.PUB_PATIENT B ON A.ID_CARD = B.ID_CARD WHERE B.MASTER_INDEX IS NOT NULL AND B.ID_CARD LIKE '[0-9]%' AND LEN(B.ID_CARD)>=15 AND B.ID_CARD NOT LIKE '%8888%' AND B.ID_CARD NOT LIKE '%0000%' GROUP BY A.NEWPERSON_ID,B.MASTER_INDEX) B WHERE PATIENT.NEWPERSON_ID = B.NEWPERSON_ID
UPDATE [{hos.ExecDatabase}].dbo.PATIENT SET NEWPERSON_ID = B.MASTER_INDEX FROM (SELECT A.NEWPERSON_ID,B.MASTER_INDEX FROM [{hos.ExecDatabase}].dbo.PATIENT A JOIN ( SELECT B.CARD_ID,MASTER_INDEX FROM [{hos.ExecDatabase}].dbo.[PUB_PATIENT] A LEFT JOIN [{hos.ExecDatabase}].dbo.OUT_REG_INFO B ON A.PERSON_CODE = B.PERSON_CODE WHERE A.MASTER_INDEX IS NOT NULL AND A.ID_CARD LIKE '[0-9]%' AND LEN(A.ID_CARD)>=15 AND A.ID_CARD NOT LIKE '%8888%' AND A.ID_CARD NOT LIKE '%0000%' AND B.CARD_ID LIKE '[0-9]%' AND LEN(B.CARD_ID)>=6 AND B.CARD_ID IS NOT NULL UNION SELECT B.CARD_ID,MASTER_INDEX FROM [{hos.ExecDatabase}].dbo.[PUB_PATIENT] A LEFT JOIN [{hos.ExecDatabase}].dbo.INPAT_REG_INFO B ON A.PERSON_CODE = B.PERSON_CODE WHERE A.MASTER_INDEX IS NOT NULL AND A.ID_CARD LIKE '[0-9]%' AND LEN(A.ID_CARD)>=15 AND A.ID_CARD NOT LIKE '%8888%' AND A.ID_CARD NOT LIKE '%0000%' AND B.CARD_ID LIKE '[0-9]%' AND LEN(B.CARD_ID)>=6 AND B.CARD_ID IS NOT NULL ) B ON A.CARD_ID = B.CARD_ID GROUP BY A.NEWPERSON_ID,B.MASTER_INDEX ) B WHERE PATIENT.NEWPERSON_ID = B.NEWPERSON_ID";
updatezt(id, hos_id, "更新MASTER_INDEX", "同步ID_CARD或医保号相同的病人主索引.." + sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
sql = $@"UPDATE [{hos.ExecDatabase}].dbo.PUB_PATIENT SET MASTER_INDEX=NEWPERSON_ID FROM (SELECT [PERSON_ID],NEWPERSON_ID FROM [{hos.ExecDatabase}].dbo.PATIENT GROUP BY [PERSON_ID], NEWPERSON_ID) TAB,[{hos.ExecDatabase}].dbo.PUB_PATIENT B WHERE B.PERSON_ID=TAB.PERSON_ID;
";
updatezt(id, hos_id, "更新MASTER_INDEX", "将数据更新回病人登记表.." + sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
sql = $@"DROP TABLE[{ hos.ExecDatabase}].dbo.PATIENT
DROP TABLE[{ hos.ExecDatabase}].dbo.PATIENT_NOTNULL
DROP TABLE[{ hos.ExecDatabase}].dbo.PATIENT_STORE1
DROP TABLE[{ hos.ExecDatabase}].dbo.PATIENT_STORE2";
updatezt(id, hos_id, "更新MASTER_INDEX", "删除临时表.." + sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
}
}
}
public void JX_DIC_DIAG(int id, int hos_id)
{
var sql = "";
SYS_Hospital hos = new SYS_Hospital();
using (DbConnection connection156 = new SqlConnection(_Connection156))
{
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
}
sql = @$" IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'DIC_DIAG_SUMMARY')
drop table [{hos.ExecDatabase}].[dbo].[DIC_DIAG_SUMMARY];
CREATE TABLE [{hos.ExecDatabase}].[dbo].[DIC_DIAG_SUMMARY](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DISEASE_NAME] [nvarchar](500) NULL,
[ICD] [nvarchar](50) NULL,
[ICD_CODE] [nvarchar](50) NULL,
[I_DEPT_NAME] [nvarchar](100) NULL,
[F_DIAG] [nvarchar](200) NULL,
[S_DIAG] [nvarchar](200) NULL
);
IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'DIC_DIAG_GATHER')
drop table [{hos.ExecDatabase}].[dbo].[DIC_DIAG_GATHER];
CREATE TABLE [dbo].[DIC_DIAG_GATHER](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DISEASE_NAME] [nvarchar](500) NULL,
[ICD_ID] INT NULL,
[I_ICD_CODE] [nvarchar](50) NULL,
[I_DEPT_NAME] [nvarchar](100) NULL,
[DIAGNOSIS] [nvarchar](200) NULL,
[DISEASE] [nvarchar](200) NULL
);
INSERT INTO [{hos.ExecDatabase}].[dbo].[DIC_DIAG_SUMMARY]([DISEASE_NAME],[ICD])select disease_name,max(icd) from [{hos.ExecDatabase}].[dbo].[OUT_DIAG]where disease_name IS NOT NULL AND disease_name !='' group by disease_name union select disease_name,max(icd) from [{hos.ExecDatabase}].[dbo].[INPAT_DIAG]where disease_name IS NOT NULL AND disease_name !='' group by disease_name";
updatezt(id, hos_id, "创建诊断项目汇总表", sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
//复制DA_Disease这张表
var fwq = "";
if (hos.ExecOpenLink != "192.168.18.156")
{
fwq = "[192.168.18.156].";
}
sql = @$"SELECT * into [{hos.ExecDatabase}].dbo.DA_Disease FROM {fwq}[SV_DATA_CONFIG].[dbo].[DA_Disease];
SELECT * into [{hos.ExecDatabase}].dbo.DA_DISEASE_ICD FROM {fwq}[SV_DATA_CONFIG].[dbo].[DA_DISEASE_ICD];
SELECT * into [{hos.ExecDatabase}].dbo.DIC_ICD FROM {fwq}[SV_DATA_CONFIG].[dbo].[DIC_ICD];";
updatezt(id, hos_id, "复制DA_Disease这张表", sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
//匹配诊断
sql = @$"UPDATE [{hos.ExecDatabase}].[dbo].[DIC_DIAG_SUMMARY]
SET ICD_CODE = d.I_ICD,[F_DIAG] = d.I_CLASS_DISEASE,
[S_DIAG] = d.I_DISEASE, [I_DEPT_NAME] = d.I_DEPARTMENT FROM [{hos.ExecDatabase}].[dbo].[DIC_DIAG_SUMMARY] t,
[{hos.ExecDatabase}].[dbo].[DA_Disease] d WHERE t.DISEASE_NAME = d.[HOSPITAL_DISEASE] and(isnull(d.HOSPITAL_DISEASE, '') <> '');
insert into [{hos.ExecDatabase}].[dbo].[DIC_DIAG_GATHER](DISEASE_NAME,ICD_ID, I_ICD_CODE,I_DEPT_NAME,DIAGNOSIS,DISEASE)
select [DISEASE_NAME],d.id ICD_ID,d.icd I_ICD_CODE,[DEPARTMENT] I_DEPT_NAME,[DIAGNOSIS],[DISEASE] from
(select distinct [DISEASE_NAME] from [{hos.ExecDatabase}].[dbo].[DIC_DIAG_SUMMARY] ) a
left join [{hos.ExecDatabase}].[dbo].[DA_Disease] b on a.DISEASE_NAME=b.[HOSPITAL_DISEASE]
left join [{hos.ExecDatabase}].[dbo].[DA_DISEASE_ICD] c on b.id=c.DISEASE_ID
left join [{hos.ExecDatabase}].[dbo].[DIC_ICD] d on c.ICD_ID=d.ID
DROP TABLE [{hos.ExecDatabase}].[dbo].DA_Disease;
DROP TABLE [{hos.ExecDatabase}].[dbo].DA_DISEASE_ICD;
DROP TABLE[{hos.ExecDatabase}].[dbo]. DIC_ICD
";
updatezt(id, hos_id, "更新DIC_DIAG_GATHER", sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
//
}
public void JX_DIC_FEE(int id, int hos_id)
{
var sql = "";
SYS_Hospital hos = new SYS_Hospital();
using (DbConnection connection156 = new SqlConnection(_Connection156))
{
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
}
sql = @$" IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'DIC_FEE_SUMMARY')
drop table [{hos.ExecDatabase}].[dbo].[DIC_FEE_SUMMARY];
CREATE TABLE [{hos.ExecDatabase}].[dbo].[DIC_FEE_SUMMARY](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ITEM_NAME] [nvarchar](200) NULL,
[CATEGORY] [nvarchar](200) NULL,
[I_TYPE_NAME] [nvarchar](200) NULL,
[MEDIC_AREA] [nvarchar](200) NULL
);
";
updatezt(id, hos_id, "DIC_FEE_SUMMARY表的生成", sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
var fwq = "";
if (hos.ExecOpenLink != "192.168.18.156")
{
fwq = "[192.168.18.156].";
}
//复制DA_Disease这张表
sql = @$" INSERT INTO [dbo].[DIC_FEE_SUMMARY]([ITEM_NAME],MEDIC_AREA,CATEGORY,I_TYPE_NAME)
SELECT t2.item_name,t2.medic_area,t2.category,t1.insurance_category FROM {fwq}[DB_SV_Data_Config].dbo.DA_Hos_Category t1 RIGHT JOIN (
SELECT category,item_name,medic_area FROM [dbo].[OUT_FEE] WHERE ITEM_NAME IS NOT NULL AND ITEM_NAME !='' GROUP BY category,item_name,medic_area
UNION
SELECT category,item_name,medic_area FROM [dbo].INPAT_FEE WHERE ITEM_NAME IS NOT NULL AND ITEM_NAME !='' GROUP BY category,item_name,medic_area) t2
ON t1.category = t2.category";
updatezt(id, hos_id, "从费用中取出不重复的费用", sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
}
public void JX_ADD_DA_Disease(int id, int hos_id)
{
var sql = "";
SYS_Hospital hos = new SYS_Hospital();
using (DbConnection connection156 = new SqlConnection(_Connection156))
{
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
}
var fwq = "";
if (hos.ExecOpenLink != "192.168.18.156")
{
fwq = "[192.168.18.156].";
}
sql = @$" insert into {fwq}[SV_DATA_CONFIG].[dbo].[DA_Disease](HospitalID,[HOSPITAL_DISEASE],[IS_FILTER])
select DISTINCT {hos_id} ,DISEASE_NAME ,0 from [{hos.ExecDatabase}].[dbo].[DIC_DIAG_GATHER] A
LEFT JOIN {fwq}[SV_DATA_CONFIG].[dbo].[DA_Disease] B ON A.DISEASE_NAME=B.HOSPITAL_DISEASE WHERE B.ID IS NULL;
";
updatezt(id, hos_id, "插入标准诊断到诊断字典【累增】", sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
}
public void JX_DIC_DRUG_ATC(int id, int hos_id)
{
var sql = "";
SYS_Hospital hos = new SYS_Hospital();
using (DbConnection connection156 = new SqlConnection(_Connection156))
{
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
}
var fwq = "";
if (hos.ExecOpenLink != "192.168.18.156")
{
fwq = "[192.168.18.156].";
}
sql = @$" IF EXISTS(SELECT * FROM [{hos.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'DIC_DRUG_ATC')
drop table [{hos.ExecDatabase}].[dbo].[DIC_DRUG_ATC];
CREATE TABLE [dbo].[DIC_DRUG_ATC](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ITEM_NAME] [nvarchar](200) NULL,
[TYPE_NAME] [nvarchar](200) NULL,
[I_ITEM_NAME] [nvarchar](200) NULL,
[ATC_CODE] [nvarchar](50) NULL,
[MEDIC_AREA] [nvarchar](200) NULL
);
SELECT * into dbo.DA_Hos_Category FROM {fwq}[DB_SV_Data_Config].[dbo].[DA_Hos_Category]
INSERT INTO [dbo].[DIC_DRUG_ATC](
[ITEM_NAME],MEDIC_AREA,TYPE_NAME)
SELECT DISTINCT ITEM_NAME,MEDIC_AREA,[Keyword]
FROM [DBO].[OUT_FEE] A,[dbo].[DA_Hos_Category] C
WHERE A.CATEGORY=C.CATEGORY AND C.insurance_category LIKE '%%' and a.ITEM_NAME is not null
UNION
SELECT DISTINCT ITEM_NAME,MEDIC_AREA,[Keyword]
FROM [DBO].[INPAT_FEE] A,[dbo].[DA_Hos_Category] C
WHERE A.CATEGORY=C.CATEGORY AND C.insurance_category LIKE '%%' and a.ITEM_NAME is not null
drop table DA_Hos_Category;
SELECT * into dbo.DA_Drug FROM {fwq}[SV_DATA_CONFIG].[dbo].[DA_Drug]
update [dbo].[DIC_DRUG_ATC]
set I_ITEM_NAME=b.CommonName,ATC_CODE=b.ATC
from [dbo].[DIC_DRUG_ATC] a,
{fwq}[SV_DATA_CONFIG].[dbo].[DA_Drug] b
where b.CommonName is not null and b.DrugName=a.ITEM_NAME;
DROP TABLE DA_Drug";
updatezt(id, hos_id, "创建诊断项目汇总表", sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
}
public void JX_ADD_DA_Drug(int id, int hos_id)
{
var sql = "";
SYS_Hospital hos = new SYS_Hospital();
using (DbConnection connection156 = new SqlConnection(_Connection156))
{
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
}
var fwq = "";
if (hos.ExecOpenLink != "192.168.18.156")
{
fwq = "[192.168.18.156].";
}
sql = @$" insert into {fwq}[SV_DATA_CONFIG].[dbo].[DA_Drug](HospitalID,[DrugName],[IsExec],[MEDIC_AREA],[ORIGINALDRUGTYPE])
select DISTINCT {hos_id},ITEM_NAME,NULL,MEDIC_AREA,[TYPE_NAME] from (
SELECT distinct ITEM_NAME,a.MEDIC_AREA,[TYPE_NAME]
FROM [dbo].[DIC_DRUG_ATC] a
left join (select distinct drugname,medic_area from {fwq}[SV_DATA_CONFIG].[dbo].[DA_Drug] ) b on a.ITEM_NAME=b.DrugName and a.medic_area=b.medic_area
where a.medic_area is not null and b.drugname is null
union
SELECT distinct ITEM_NAME,a.MEDIC_AREA,[TYPE_NAME]
FROM [dbo].[DIC_DRUG_ATC] a
left join (select distinct drugname,medic_area from {fwq}[SV_DATA_CONFIG].[dbo].[DA_Drug] ) b on a.ITEM_NAME=b.DrugName
where a.medic_area is null and b.drugname is null ) m
";
updatezt(id, hos_id, "将未匹配到的药品插入到DA_Drug表中【累增】", sql.Replace("'", "''"));
JX_zx(sql, hos_id, id, hos);
}
public void JX_DRUG_DATA_QZ(int id, int hos_id)
{
var sql = "";
int num = 0;
SYS_Hospital hos = new SYS_Hospital();
using (DbConnection configConnection = new SqlConnection(_configConnectionString)) // DefaultConnection
using (DbConnection connection156 = new SqlConnection(_Connection156))
{
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
sql = @$" select count(1)from [SV_QueryPlatform].[dbo].[权重执行sql] where type ='药品' ";
num = configConnection.Query<int>(sql).FirstOrDefault();
int i = 1;
updatezt(id, hos_id, "更新药品权重", sql.Replace("'", "''"));
for (i = 1; i < num + 1; i++)
{
sql = @$" select execsql from [SV_QueryPlatform].[dbo].[权重执行sql] where type ='药品' and id={i} ";
string zxsql = configConnection.Query<string>(sql).FirstOrDefault();
connection156.Execute(sql, commandTimeout: 60 * 60 * 12);
}
sql = @$" update SV_DATA_CONFIG.[dbo].[DA_Drug] set ISEXEC = 0 where ISEXEC is null ;
update SV_DATA_CONFIG.[dbo].[DA_Drug] set iscompletion = 0 where iscompletion is null";
connection156.Query<int>(sql).FirstOrDefault();
}
}
public void JX_DA_DIAGNOSIS_DATA(int id, int hos_id)
{
var sql = "";
SYS_Hospital hos = new SYS_Hospital();
DbConnection configConnection = new SqlConnection(_configConnectionString);
DbConnection connection156 = new SqlConnection(_Connection156);
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
sql = @$" UPDATE [SV_DATA_CONFIG].[dbo].[DA_Disease] SET [FILTER_DISEASE] = HOSPITAL_DISEASE where IS_FILTER = 0 ;
update [SV_DATA_CONFIG].[dbo].DA_DISEASE set FILTER_DISEASE = replace(FILTER_DISEASE,CHAR(13),'') where IS_FILTER = 0 and CHARINDEX(CHAR(13),FILTER_DISEASE) > 0;
update [SV_DATA_CONFIG].[dbo].DA_DISEASE set FILTER_DISEASE = replace(FILTER_DISEASE,CHAR(9),'') where IS_FILTER = 0 and CHARINDEX(CHAR(19),FILTER_DISEASE) > 0;
update [SV_DATA_CONFIG].[dbo].DA_DISEASE set FILTER_DISEASE = replace(FILTER_DISEASE,CHAR(10),'') where IS_FILTER = 0 and CHARINDEX(CHAR(10),FILTER_DISEASE) > 0;";
updatezt(id, hos_id, "剔除起始位 DA_Diagnosis_Data type=2的无效字符", sql.Replace("'", "''"));
connection156.Execute(sql, commandTimeout: 60 * 60 * 12);
sql = @$" select ' update [SV_DATA_CONFIG].[dbo].DA_DISEASE
set FILTER_DISEASE = replace(FILTER_DISEASE,'''+[data]+''','''+[REPLACE]+''')
where IS_FILTER = 0 and CHARINDEX('''+[data]+''',FILTER_DISEASE) > 0 ' from 特殊字符替换 ";
string[] zxsqls = configConnection.Query<string>(sql).ToArray();
foreach (var item in zxsqls)
{
connection156.Execute(item, commandTimeout: 60 * 60 * 12);
}
sql = @$" update [SV_DATA_CONFIG].[dbo].DA_DISEASE set FILTER_DISEASE = REPLACE( FILTER_DISEASE,substring(FILTER_DISEASE,
charindex('(',FILTER_DISEASE),charindex(')',FILTER_DISEASE) - charindex('(',FILTER_DISEASE) +1),'')
where IS_FILTER = 0 and charindex(')',FILTER_DISEASE) > 0 and charindex('(',FILTER_DISEASE) > 0 and charindex(')',FILTER_DISEASE) >
charindex('(',FILTER_DISEASE)
update [SV_DATA_CONFIG].[dbo].DA_DISEASE set I_DEPARTMENT = t2.DEPARTMENT,I_CLASS_DISEASE = t2.DIAGNOSIS,
I_ICD = t2.icd,I_DISEASE = t2.DISEASE,IS_EXEC =1 , EXEC_DATE = getdate(),REMARK ='ICD全文匹配'
from SV_DATA_CONFIG.dbo.DA_DISEASE t1 join SV_DATA_CONFIG.dbo.DIC_ICD t2
on t1.filter_disease = t2.DISEASE and t2.STATE = 1 where t1.IS_FILTER = 0;
update [SV_DATA_CONFIG].[dbo].DA_DISEASE set I_DEPARTMENT = t2.DEPARTMENT,I_CLASS_DISEASE = t2.DIAGNOSIS,
I_ICD = t2.icd,I_DISEASE = t2.DISEASE,IS_EXEC =1 , EXEC_DATE = getdate(),REMARK ='ICD全文匹配'
from SV_DATA_CONFIG.dbo.DA_DISEASE t1 join SV_DATA_CONFIG.dbo.DIC_ICD t2
on t1.HOSPITAL_DISEASE = t2.DISEASE and t2.STATE = 1 where t1.IS_FILTER = 0
UPDATE [SV_DATA_CONFIG].[dbo].[DA_Disease] SET IS_FILTER = 1 WHERE IS_FILTER = 0
";
connection156.Execute(sql, commandTimeout: 60 * 60 * 12);
}
public void JX_DIAGNOSIS_DATA_QZ(int id, int hos_id)
{
var sql = "";
SYS_Hospital hos = new SYS_Hospital();
DbConnection configConnection = new SqlConnection(_configConnectionString);
DbConnection connection156 = new SqlConnection(_Connection156.Replace("DB_SV_Data_Config", "SV_DATA_CONFIG"));
sql = @$" SELECT DISTINCT ExecOpenLink , ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE id ={hos_id}; ";
hos = connection156.Query<SYS_Hospital>(sql).FirstOrDefault();
sql = @$" insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,2450 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压心脏病伴心力衰竭%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,2454 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压肾脏病不伴有肾衰竭%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,2460 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压(肾性)%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,2471 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%继发性高血压%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,2472 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%肾血管性高血压%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,26069 as icd_id from dbo.da_disease where 1=1 and (hospital_disease='48 47急性冠周炎') ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33928 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压(原发性)%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33928 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%特发性(原发性)高血压%' and hospital_disease not like '%?%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33928 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%特发性高血压%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33929 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%原发性高血压%' and hospital_disease not like '%?%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33930 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压1%' and hospital_disease not like '%?%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33930 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压Ⅰ%' and hospital_disease not like '%?%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33931 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压2%' and hospital_disease not like '%?%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33931 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压Ⅱ%' and hospital_disease not like '%?%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33931 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压3%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33933 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压3%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33933 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压Ⅲ%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33934 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%单纯收缩期高血压%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33935 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压急症%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33936 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%难治性高血压%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33937 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%低肾素性高血压%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33938 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压亚急症%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33940 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%肾萎缩伴有高血压%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33941 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压心脏和肾脏病同时伴有(充血性)心力衰竭和肾衰竭%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33942 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压心脏和肾脏病伴有(充血性)心力衰竭%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33943 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压心脏病不伴有(充血性)心力衰竭%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33944 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压性心力衰竭%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
insert into da_disease_icd(disease_id,icd_id) select tab.disease_id,tab.icd_id from ( select id as disease_id,33946 as icd_id from dbo.da_disease where 1=1 and ( hospital_disease like '%高血压心脏病伴心力衰竭%' and hospital_disease not like '%?%' and hospital_disease not like '%待排%' ) ) tab left join da_disease_icd t1 on t1.disease_id = tab.disease_id and t1.icd_id = tab.icd_id where t1.id is null
update da_disease set i_department='风湿科',i_class_disease='风湿热,未提及心脏受累',i_icd='I00.x01',i_disease='风湿性关节炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '风湿性关节炎%'update da_disease set i_department='风湿科',i_class_disease='风湿热,未提及心脏受累',i_icd='I00.x01',i_disease='风湿性关节炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '风湿性关节炎%' and is_exec is null
update da_disease set i_department='风湿科',i_class_disease='风湿热,未提及心脏受累',i_icd='I00.x01',i_disease='风湿性关节炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '关节炎%'update da_disease set i_department='风湿科',i_class_disease='风湿热,未提及心脏受累',i_icd='I00.x01',i_disease='风湿性关节炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '关节炎%' and is_exec is null
update da_disease set i_department='风湿科',i_class_disease='风湿热,未提及心脏受累',i_icd='I00.x01',i_disease='风湿性关节炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '急性风湿性关节炎%'update da_disease set i_department='风湿科',i_class_disease='风湿热,未提及心脏受累',i_icd='I00.x01',i_disease='风湿性关节炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '急性风湿性关节炎%' and is_exec is null
update da_disease set i_department='风湿科',i_class_disease='脊椎关节强硬',i_icd='M47.822',i_disease='颈椎病',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '颈椎病%'update da_disease set i_department='风湿科',i_class_disease='脊椎关节强硬',i_icd='M47.822',i_disease='颈椎病',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '颈椎病%' and is_exec is null
update da_disease set i_department='风湿科',i_class_disease='脊椎关节强硬',i_icd='M47.822',i_disease='颈椎病',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and hospital_disease like '颈椎病%'update da_disease set i_department='风湿科',i_class_disease='脊椎关节强硬',i_icd='M47.822',i_disease='颈椎病',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and hospital_disease like '颈椎病%' and is_exec is null
update da_disease set i_department='风湿科',i_class_disease='其他脊椎病',i_icd='M48.921',i_disease='颈椎退行性病变',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '颈椎退行性病变%'update da_disease set i_department='风湿科',i_class_disease='其他脊椎病',i_icd='M48.921',i_disease='颈椎退行性病变',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '颈椎退行性病变%' and is_exec is null
update da_disease set i_department='骨科',i_class_disease='其他椎间盘疾患',i_icd='M51.202',i_disease='腰椎间盘突出',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '腰椎间盘突出%'update da_disease set i_department='骨科',i_class_disease='其他椎间盘疾患',i_icd='M51.202',i_disease='腰椎间盘突出',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '腰椎间盘突出%' and is_exec is null
update da_disease set i_department='骨科',i_class_disease='腰椎和骨盆关节和韧带脱位,扭伤和劳损',i_icd='S33.501',i_disease='腰部扭伤',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '腰部扭伤%'update da_disease set i_department='骨科',i_class_disease='腰椎和骨盆关节和韧带脱位,扭伤和劳损',i_icd='S33.501',i_disease='腰部扭伤',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '腰部扭伤%' and is_exec is null
update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '右上肺炎%'update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '右上肺炎%' and is_exec is null
update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '右下肺炎%'update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '右下肺炎%' and is_exec is null
update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '左上肺炎%'update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '左上肺炎%' and is_exec is null
update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '左下肺炎%' and is_exec is null
update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '左下肺炎%'update da_disease set i_department='呼吸科',i_class_disease='肺炎,病原体未特指',i_icd='J18',i_disease='肺炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '左下肺炎%' and is_exec is null
update da_disease set i_department='呼吸科',i_class_disease='慢性阻塞性肺病',i_icd='J44.103',i_disease='慢性阻塞性肺病伴急性加重',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like 'AECOPD%'update da_disease set i_department='呼吸科',i_class_disease='慢性阻塞性肺病',i_icd='J44.103',i_disease='慢性阻塞性肺病伴急性加重',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like 'AECOPD%' and is_exec is null
update da_disease set i_department='呼吸科',i_class_disease='慢性阻塞性肺病',i_icd='J44.901',i_disease='慢性阻塞性肺病',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like 'COPD%'update da_disease set i_department='呼吸科',i_class_disease='慢性阻塞性肺病',i_icd='J44.901',i_disease='慢性阻塞性肺病',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like 'COPD%' and is_exec is null
update da_disease set i_department='口腔科',i_class_disease='龈炎和牙周疾病',i_icd='K05.203',i_disease='急性牙周炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like 'a牙周炎%'update da_disease set i_department='口腔科',i_class_disease='龈炎和牙周疾病',i_icd='K05.203',i_disease='急性牙周炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like 'a牙周炎%' and is_exec is null
update da_disease set i_department='泌尿外科',i_class_disease='前列腺炎性疾病',i_icd='N41.001',i_disease='急性前列腺炎',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '急性前列腺炎%' and is_exec is null
update da_disease set i_department='泌尿外科',i_class_disease='前列腺炎性疾病',i_icd='N41.101',i_disease='慢性前列腺炎',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '慢性前列腺炎%' and is_exec is null
update da_disease set i_department='泌尿外科',i_class_disease='前列腺炎性疾病',i_icd='N41.901',i_disease='前列腺炎',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '前列腺炎%' and is_exec is null
update da_disease set i_department='普外科',i_class_disease='结肠恶性肿瘤',i_icd='C18.2',i_disease='升结肠恶性肿瘤',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and hospital_disease like '%升结肠恶性肿瘤%'
update da_disease set i_department='普外科',i_class_disease='结肠恶性肿瘤',i_icd='C18.3',i_disease='结肠肝曲恶性肿瘤',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and hospital_disease like '%结肠肝曲恶性肿瘤%'
update da_disease set i_department='普外科',i_class_disease='结肠恶性肿瘤',i_icd='C18.4',i_disease='横结肠恶性肿瘤',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and hospital_disease like '%横结肠恶性肿瘤%'
update da_disease set i_department='普外科',i_class_disease='结肠恶性肿瘤',i_icd='C18.5',i_disease='结肠脾曲恶性肿瘤',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and hospital_disease like '%结肠脾曲恶性肿瘤%'
update da_disease set i_department='普外科',i_class_disease='结肠恶性肿瘤',i_icd='C18.6',i_disease='降结肠恶性肿瘤',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and hospital_disease like '%降结肠恶性肿瘤%'
update da_disease set i_department='消化科',i_class_disease='霍乱',i_icd='A00',i_disease='霍乱',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '霍乱%' and filter_disease not like '%接触%' and filter_disease not like '%%' and filter_disease not like '%疫苗%'update da_disease set i_department='消化科',i_class_disease='霍乱',i_icd='A00',i_disease='霍乱',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '霍乱%' and filter_disease not like '%接触%' and filter_disease not like '%%' and filter_disease not like '%疫苗%' and is_exec is null
update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25',i_disease='胃溃疡',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '胃溃疡%'update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25',i_disease='胃溃疡',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '胃溃疡%' and is_exec is null
update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25.301',i_disease='急性胃溃疡',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '急性胃溃疡%'update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25.301',i_disease='急性胃溃疡',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '急性胃溃疡%' and is_exec is null
update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25.401',i_disease='胃溃疡伴出血',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '胃溃疡伴出血%'update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25.401',i_disease='胃溃疡伴出血',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '胃溃疡伴出血%' and is_exec is null
update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25.501',i_disease='胃溃疡伴穿孔',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '胃溃疡伴穿孔%'update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25.501',i_disease='胃溃疡伴穿孔',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '胃溃疡伴穿孔%' and is_exec is null
update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25.701',i_disease='慢性胃溃疡',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '慢性胃溃疡%'update da_disease set i_department='消化科',i_class_disease='胃溃疡',i_icd='K25.701',i_disease='慢性胃溃疡',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and filter_disease like '慢性胃溃疡%' and is_exec is null
update da_disease set i_department='消化科',i_class_disease='胃炎和十二指肠炎',i_icd='K29',i_disease='胃炎和十二指肠炎',is_exec=1,exec_date=getdate(),remark='后台人工处理' where 1=1 and hospital_disease like '胃炎%' and is_exec is null
update da_disease set i_department='心内科',i_class_disease='高血压病',i_icd='I10.x04',i_disease='高血压I期',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '高血压%' and hospital_disease like '%高血压1%' and is_exec is null
update da_disease set i_department='心内科',i_class_disease='高血压病',i_icd='I10.x04',i_disease='高血压I期',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '高血压%' and hospital_disease like '%高血压I%' and is_exec is null
update da_disease set i_department='心内科',i_class_disease='高血压病',i_icd='I10.x04',i_disease='高血压I期',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '高血压%' and hospital_disease like '%高血压1%' and is_exec is null
update da_disease set i_department='心内科',i_class_disease='高血压病',i_icd='I10.x05',i_disease='高血压Ⅱ期',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '高血压%' and hospital_disease like '%高血压3%' and is_exec is null
update da_disease set i_department='心内科',i_class_disease='高血压病',i_icd='I10.x05',i_disease='高血压Ⅱ期',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '高血压%' and hospital_disease like '%高血压II%' and is_exec is null
update da_disease set i_department='心内科',i_class_disease='高血压病',i_icd='I10.x05',i_disease='高血压Ⅱ期',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '高血压%' and hospital_disease like '%高血压2%' and is_exec is null
update da_disease set i_department='心内科',i_class_disease='高血压病',i_icd='I10.x06',i_disease='高血压Ⅲ期',is_exec=1,exec_date=getdate() where 1=1 and filter_disease like '高血压%' and hospital_disease like '%高血压3%' and is_exec is null
";
connection156.Execute(sql, commandTimeout: 60 * 60 * 12);
sql = $@"update SV_DATA_CONFIG.dbo.da_disease set i_department=t2.DEPARTMENT,i_class_disease=t2.DIAGNOSIS,i_icd=t2.ICD,i_disease=t2.DISEASE,is_exec=2,exec_date=getdate(),
REMARK = 'sql脚本执行' FROM SV_DATA_CONFIG.dbo.DA_Disease T1 JOIN (select distinct DEPARTMENT,ICD,diagnosis,disease from SV_DATA_CONFIG.dbo.DIC_ICD where state = 1 ) T2 ON
T1.filter_disease like '%'+t2.disease+'%' and t1.hospital_disease like '%'+t2.disease+'%' where t1.is_exec is null ;
INSERT INTO SV_DATA_CONFIG.[dbo].[DA_DISEASE_ICD] (DISEASE_ID,ICD_ID)
SELECT A.ID,B.ID FROM SV_DATA_CONFIG.DBO.DA_Disease A
JOIN SV_DATA_CONFIG.DBO.DIC_ICD B ON A.I_ICD = B.ICD
WHERE A.IS_EXEC = 2 AND A.I_ICD IS NOT NULL;
update SV_DATA_CONFIG.DBO.DA_Disease set is_exec = 1 where IS_EXEC = 2;
update SV_DATA_CONFIG.dbo.DA_Disease set IS_EXEC = 0 where IS_EXEC is null ;";
connection156.Execute(sql, commandTimeout: 60 * 60 * 12);
}
}
}
using Dapper;
using Health.Api.Infrastructure.Modules;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
namespace Health.Api.Infrastructure.Queries
{
public class DrugqueryQueries
{
private readonly string _Connection156;
private readonly string _configConnectionString;
//private List<Common> a;
bool state = true;
public DrugqueryQueries(string Connection156, string configConnectionString)
{
_Connection156 = Connection156;
_configConnectionString = configConnectionString;
}
//查询所有医院
public List<SYS_Hospital> showHospitals()
{
DbConnection connection156 = new SqlConnection(_Connection156);
// sys_hospital156找医院
var sql = @$"SELECT
ExecOpenLink ,
ExecDatabase
FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital]
WHERE ExecOpenLink <>'' AND ExecOpenLink IS NOT NULL
AND ExecDatabase <>'' AND ExecDatabase IS NOT NULL
";
return connection156.Query<SYS_Hospital>(sql).ToList();
}
/// <summary>
/// 获取到最大的那条记录id
/// </summary>
/// <returns></returns>
public int DrugqueryIndexs()
{
var indexs = "";
using (DbConnection configConnection = new SqlConnection(_configConnectionString))
{
indexs = @$"SELECT max(id) id FROM [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD]";
int a = configConnection.Query<int>(indexs).FirstOrDefault();
return a;
}
return 0;
}
/// <summary>
/// 获取到最大的那条记录Complete_MarkId
/// </summary>
/// <returns></returns>
public int Complete_MarkId(int Indexs)
{
DbConnection configConnection = new SqlConnection(_configConnectionString);
return configConnection.Query<int>(@$"select COMPLETE_MARK from [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] where id={Indexs} ").FirstOrDefault();
}
/// <summary>
///传入sql 连接 返回int
/// </summary>
/// <returns></returns>
public int Countnum(string sql, DbConnection configConnection)
{
int c = configConnection.Query<int>(sql).FirstOrDefault();
return c;
}
/// <summary>
/// 插入查询记录表
/// </summary>
/// <param name="sYS_Drugquery"></param>
public int SqlAdd(SYS_Drugquery sYS_Drugquery, int type)
{
string peojectName = sYS_Drugquery.peojectName;
string drugName = "";
string diseaseName = "";
string icd = "";
string lx = "";
if (type == 1)
{
lx = "疾病"; if (sYS_Drugquery.diseaseName != null) foreach (var item in sYS_Drugquery.diseaseName) { diseaseName = string.Join(",", sYS_Drugquery.diseaseName); }
if (sYS_Drugquery.icd != null) foreach (var item in sYS_Drugquery.icd) { icd = string.Join(",", sYS_Drugquery.icd); }
}
else if (type == 2) { lx = "药品"; foreach (var item in sYS_Drugquery.drugName) { drugName = string.Join(",", sYS_Drugquery.drugName); } }
else if (type == 3) { lx = "材料"; foreach (var item in sYS_Drugquery.materialName) { drugName = string.Join(",", sYS_Drugquery.materialName); } }
DbConnection connection = new SqlConnection(_configConnectionString);
var sql = @$"INSERT INTO [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD]([HOS_TYPE],[PROJECT_NAME],[GENERIC_NAME],[COMMODITY_NAME],[DISEASE_NAME],[ICD],
[COMPLETE_MARK],[search_time],type ,[TYPE1_2] )
VALUES(0,'{peojectName}','{ drugName}',null,'{diseaseName}',
'{icd}',21,getdate(),'{lx}','{sYS_Drugquery.type1_2}')";
connection.Execute(sql, commandTimeout: 60 * 60 * 5);
sql = @$"select max(id) from [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD]
where PROJECT_NAME='{peojectName}' and GENERIC_NAME='{drugName}' and DISEASE_NAME='{diseaseName}'
and icd='{icd}' and type='{lx}' and [TYPE1_2]='{sYS_Drugquery.type1_2}'";
int num = connection.Query<int>(sql).FirstOrDefault();
//添加一条查询记录
sql = $@"CREATE TABLE [SV_QueryPlatform_].[dbo].[MEDIC_PERSON_INFORMATION_{num}](
[ID] [int] IDENTITY(1,1) NOT NULL,
[HOS_ID] [int] NULL,
[MASTER_INDEX] [int] NULL,
[BIRTHDAY] [datetime2](7) NULL,
[SEX] [nvarchar](50) NULL,
[PERSON_CODE] [nvarchar](50) NULL,
[PERSON_ID] [int] NULL,
[REG_CODE] [nvarchar](50) NULL,
[REG_ID] [int] NULL,
[REG_SOURCE] [nvarchar](50) NULL,
[REG_TIME] [datetime2](7) NULL,
[AREA_ID] [int] NULL,
[INDEXS] [int] NULL,
[TYPE] [int] NULL,
[DEPT_NAME] [nvarchar](50) NULL,
[MEDIC_AREA] [nvarchar](max) NULL,
CONSTRAINT [PK_MEDIC_PERSON_INFORMATIONaa_{num}] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] ";
connection.Execute(sql, commandTimeout: 60 * 60 * 5);
sql = $@"CREATE TABLE [SV_QueryPlatform_].[dbo].[MEDIC_AREA_{num}](
[ID] [int] IDENTITY(1,1) NOT NULL,
[HOS_ID] [int] NULL,
[ITEM_NAME] [nvarchar](500) NULL,
[MEDIC_AREA] [nvarchar](50) NULL,
[TYPE] [int] NULL,
[INDEXS] [nvarchar](50) NULL,
[MEDIC_NAME] [nvarchar](50) NULL
) ON [PRIMARY]";
connection.Execute(sql, commandTimeout: 60 * 60 * 5);
return num;
}
/// <summary>
/// 查询疾病对应的病人信息
/// </summary>
/// <param name="type">类型1</param>
/// <param name="icd">ICD编码</param>
/// <param name="diseaseName">疾病名称</param>
/// <param name="type1_2">类型</param>
public void Diseasequery(int type, int type1_2, string[] icd, string[] diseaseName, int Indexs)
{
var sql = "";
int num = 0;
int CompleteMar = 0;
var icd_or_diseaseCondition = "";
if (icd != null)
{
foreach (var icdname in icd)
{
if (!string.IsNullOrEmpty(icdname))
icd_or_diseaseCondition = icd_or_diseaseCondition + $"or icd like '%{icdname}%'";
}
}
if (diseaseName != null)
{
foreach (var disease in diseaseName)
{
if (!string.IsNullOrEmpty(disease))
icd_or_diseaseCondition = icd_or_diseaseCondition + $"or DISEASE_NAME like '%{disease}%'";
}
}
icd_or_diseaseCondition = icd_or_diseaseCondition.Substring(2, icd_or_diseaseCondition.Length - 2);
DbConnection configConnection = new SqlConnection(_configConnectionString);
List<SYS_Hospital> hos = configConnection.Query<SYS_Hospital>(@$"SELECT ExecOpenLink ,ExecDatabase FROM [192.168.18.156].[DB_SV_Data_Config].[dbo].[SYS_Hospital] WHERE ExecOpenLink <>'' AND ExecOpenLink IS NOT NULL AND ExecDatabase <>'' AND ExecDatabase IS NOT NULL ").ToList();
服务器 fwq = new 服务器();
var msConnectionString = "";
var countsql = 0;
foreach (var item in hos)
{
//统计执行的多少家医院
countsql++;
var fwqsql = $"SELECT [服务器ip],[数据库账号],[数据库密码] FROM [SV_QueryPlatform].[dbo].[服务器] where [服务器ip] ='{item.ExecOpenLink}'";
fwq = configConnection.Query<服务器>(fwqsql).FirstOrDefault();
msConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", item.ExecOpenLink, item.ExecDatabase, fwq.数据库账号, fwq.数据库密码);
var sql2 = "";
using (DbConnection conn = new SqlConnection(msConnectionString))
{
//获取MEDIC_SEARCH_RECORD表的id和COMPLETE_MARK
CompleteMar = Complete_MarkId(Indexs);
if (CompleteMar == 23)
{
throw new DomainException("查询失败!!");
}
if (CompleteMar == 31)
{
throw new DomainException("查询取消!!");
}
try
{
//判断状态 21在执行
if (CompleteMar == 21)
{
if (Countnum($@"SELECT count(*) FROM {item.ExecDatabase}.dbo.SYSOBJECTS WHERE NAME = 'DIC_DIAG_SUMMARY'", conn) > 0)
{
if (Countnum($@"SELECT count(*) a FROM {item.ExecDatabase}.[dbo].[DIC_DIAG_SUMMARY] where {icd_or_diseaseCondition} ", conn) > 0)
{
sql2 = $@" IF EXISTS(SELECT * FROM [{item.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'MEDIC_PERSON_INFORMATION_{Indexs}')
drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs};
SELECT C.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,A.REG_CODE,A.REG_ID,1 REG_SOURCE,A.REG_TIME, {Indexs}Indexs,a.org_Code hos_id,C.BIRTHDAY,C.SEX,1 TYPE,A.DEPT_NAME into [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs} FROM
{item.ExecDatabase}.[DBO].OUT_REG_INFO A ,
(SELECT DISTINCT REG_ID FROM
{item.ExecDatabase}.[DBO].OUT_DIAG WHERE {icd_or_diseaseCondition}) B,
{item.ExecDatabase}.[DBO].PUB_PATIENT C WHERE A.REG_ID=B.REG_ID AND A.PERSON_ID=C.PERSON_ID
UNION ALL
SELECT C.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,A.REG_CODE,A.REG_ID,2 REG_SOURCE,A.INHOS_TIME,{Indexs},a.org_Code hos_id,C.BIRTHDAY,C.SEX,1 TYPE,A.OUT_DEPT_NAME FROM
{item.ExecDatabase}.[DBO].INPAT_REG_INFO A , (SELECT DISTINCT REG_ID FROM {item.ExecDatabase}.[DBO].INPAT_DIAG WHERE {icd_or_diseaseCondition}) B,
{item.ExecDatabase}.[DBO].PUB_PATIENT C
WHERE A.REG_ID=B.REG_ID AND A.PERSON_ID=C.PERSON_ID";
conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
sql2 = $@" insert into [SV_QueryPlatform_].[dbo].MEDIC_PERSON_INFORMATION_{Indexs }
( [HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],
[REG_TIME], AREA_ID,[INDEXS],[TYPE],[DEPT_NAME] )
SELECT [HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],
[REG_TIME],null AREA_ID,[INDEXS],[TYPE],[DEPT_NAME]
From [{item.ExecOpenLink}].[{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}";
num = num + configConnection.Execute(sql2, commandTimeout: 60 * 60 * 5);
//LOG($"查询成功,{num}行", $"{ITEM}", Indexs, "查询平台", "");
if (type1_2 == 2)
{
sql2 = $@"IF EXISTS(SELECT * FROM [{item.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'MEDIC_PERSON_INFORMATION_{Indexs}_2')
drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}_2;
SELECT A.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,B.REG_CODE,B.REG_ID,1 REG_SOURCE,B.REG_TIME,A.BIRTHDAY,A.SEX,2 TYPE, {Indexs} Indexs , b.org_code hos_id,B.DEPT_NAME into [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}_2
FROM {item.ExecDatabase}.[DBO].PUB_PATIENT A, {item.ExecDatabase}.[DBO].OUT_REG_INFO B,
(SELECT DISTINCT MASTER_INDEX FROM {item.ExecDatabase}.[DBO].[MEDIC_PERSON_INFORMATION_{Indexs}] WHERE INDEXS= {Indexs} AND HOS_ID = cast(right('{item.ExecDatabase}',3)as int)) C
WHERE A.PERSON_ID=B.PERSON_ID AND A.MASTER_INDEX=C.MASTER_INDEX
UNION ALL
SELECT A.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,B.REG_CODE,B.REG_ID,2 REG_SOURCE,B.INHOS_TIME,A.BIRTHDAY,A.SEX,2 TYPE,{Indexs} , b.org_code,B.OUT_DEPT_NAME
FROM {item.ExecDatabase}.[DBO].PUB_PATIENT A, {item.ExecDatabase}.[DBO].INPAT_REG_INFO B,
(SELECT DISTINCT MASTER_INDEX FROM {item.ExecDatabase}.[DBO].[MEDIC_PERSON_INFORMATION_{Indexs}] WHERE INDEXS={Indexs} AND HOS_ID = cast(right('{item.ExecDatabase}',3)as int)) C
WHERE A.PERSON_ID=B.PERSON_ID AND A.MASTER_INDEX=C.MASTER_INDEX ;";
conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
sql2 = $@"INSERT INTO [SV_QueryPlatform_].[dbo].[MEDIC_PERSON_INFORMATION_{Indexs}]([HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],[REG_TIME],AREA_ID,[INDEXS],[TYPE],[DEPT_NAME])
select [HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],[REG_TIME],null,
[INDEXS],[TYPE],[DEPT_NAME]
From [{item.ExecOpenLink}].[{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}_2";
num = num + configConnection.Execute(sql2, commandTimeout: 60 * 60 * 5);
sql2 = $@" DELETE FROM M FROM [SV_QueryPlatform_].[dbo].[MEDIC_PERSON_INFORMATION_{Indexs}] M
INNER JOIN (SELECT * FROM [SV_QueryPlatform_].[dbo].[MEDIC_PERSON_INFORMATION_{Indexs}] WHERE INDEXS = {Indexs}
AND HOS_ID =cast(right('{item.ExecDatabase}',3)as int) AND TYPE = 1) N
ON M.INDEXS = N.INDEXS AND M.HOS_ID = N.HOS_ID AND M.MASTER_INDEX = N.MASTER_INDEX
AND M.PERSON_ID = N.PERSON_ID AND M.REG_ID = N.REG_ID
AND M.REG_SOURCE = N.REG_SOURCE AND M.TYPE = 2 ;";
num = num + configConnection.Execute(sql2, commandTimeout: 60 * 60 * 5);
sql2 = $@" drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}_2;";
num = num + conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
// LOG($"查询成功,{num}行", $"{ITEM}", Indexs, "查询平台", "");
}
sql2 = $@" drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}; ";
num = num + conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
}
}
}
}
catch (Exception e)
{
configConnection.Execute(@$"update [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate(),log='{sql2.Replace("'", "''")}' where COMPLETE_MARK != 22 and id= " + Indexs);
}
}
}
if (countsql == hos.Count)
{
configConnection.Execute("update [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 22,END_TIME=getdate() where COMPLETE_MARK != 22 and id= " + Indexs);
}
else
{
configConnection.Execute("update [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate() where COMPLETE_MARK != 22 and id= " + Indexs);
}
}
/// <summary>
/// 查询药品信息
/// </summary>
/// <param name="type">类型2</param>
/// <param name="type1_2">他因</param>
/// <param name="drugName">药品名称</param>
public void Drugquery(int type, int type1_2, string[] drugName , int Indexs)
{
var sql = "";
int num = 0;
int CompleteMar = 0;
var drugs = "";
if (drugName != null)
{
foreach (var drug in drugName)
{
if (!string.IsNullOrEmpty(drug))
drugs = drugs + $"or item_name like '%{drug}%'";
}
}
drugs = drugs.Substring(2, drugs.Length - 2);
DbConnection configConnection = new SqlConnection(_configConnectionString);
List<SYS_Hospital> hos = configConnection.Query<SYS_Hospital>(@$"SELECT ExecOpenLink ,ExecDatabase FROM [192.168.18.156].[DB_SV_Data_Config].[dbo].[SYS_Hospital] WHERE ExecOpenLink <>'' AND ExecOpenLink IS NOT NULL AND ExecDatabase <>'' AND ExecDatabase IS NOT NULL ").ToList();
服务器 fwq = new 服务器();
var msConnectionString = "";
var countsql = 0;
var sql2 = "";
foreach (var item in hos)
{
//统计执行的多少家医院
countsql++;
var fwqsql = $"SELECT [服务器ip],[数据库账号],[数据库密码] FROM [SV_QueryPlatform].[dbo].[服务器] where[服务器ip] ='{item.ExecOpenLink}'";
fwq = configConnection.Query<服务器>(fwqsql).FirstOrDefault();
msConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", item.ExecOpenLink, item.ExecDatabase, fwq.数据库账号, fwq.数据库密码);
using (DbConnection conn = new SqlConnection(msConnectionString))
{
CompleteMar = Complete_MarkId(Indexs);
if (CompleteMar == 23)
{
throw new DomainException("查询失败!!");
}
if (CompleteMar == 31)
{
throw new DomainException("查询停止!!");
}
try
{
//判断状态 21在执行
if (CompleteMar == 21)
{
if (Countnum($@"SELECT count(*) FROM {item.ExecDatabase}.dbo.SYSOBJECTS WHERE NAME = 'DIC_FEE_SUMMARY'", conn) > 0)
{
if (Countnum($@"SELECT count(*) a FROM {item.ExecDatabase}.[dbo].[DIC_FEE_SUMMARY] where {drugs} ", conn) > 0)
{
//药品信息查询语句
foreach (var drug in drugName)
{
sql2 = $@"insert into [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] (
[HOS_ID] ,[ITEM_NAME] ,[MEDIC_NAME],[MEDIC_AREA],[INDEXS] )
select cast(right('{item.ExecDatabase}',3)as int) hos_id,ITEM_NAME,
'{drug}'MEDIC_NAME,medic_area medic_area,{Indexs} INDEXS from {item.ExecDatabase}.[dbo].[DIC_FEE_SUMMARY]
WHERE [ITEM_NAME] like '%{drug}%' GROUP BY ITEM_NAME,MEDIC_AREA ";
conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
}
if (Countnum($@"SELECT count(*) FROM [SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}]
where hos_id=cast(right('{item.ExecDatabase}',3)as int) and indexs={Indexs}", configConnection) > 0)
{
var sql3 = $@"IF EXISTS(SELECT * FROM [{item.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'MEDIC_PERSON_INFORMATION_{Indexs}')
drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs};
SELECT C.MASTER_INDEX MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,A.REG_CODE,A.REG_ID,'1'REG_SOURCE,A.REG_TIME,B.ID AREA_ID, {Indexs} INDEXS,cast(right('{item.ExecDatabase}',3)as int) HOS_ID,C.BIRTHDAY,C.SEX,1 TYPE,A.DEPT_NAME into [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs} FROM
{item.ExecDatabase}.[DBO].OUT_REG_INFO A, (SELECT DISTINCT REG_ID,D.ID FROM {item.ExecDatabase}.[DBO].OUT_FEE E,
(SELECT * FROM [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] WHERE INDEXS={Indexs} AND (MEDIC_AREA IS NULL OR MEDIC_AREA ='')) D
WHERE HOS_ID = cast(right('{item.ExecDatabase}',3)as int) AND E.ITEM_NAME=D.ITEM_NAME
UNION ALL
SELECT DISTINCT REG_ID,D.ID FROM {item.ExecDatabase}.[DBO].OUT_FEE E,
(SELECT * FROM [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] WHERE INDEXS= {Indexs} AND MEDIC_AREA IS NOT NULL AND MEDIC_AREA!='') D
WHERE HOS_ID = cast(right('{item.ExecDatabase}',3)as int) AND E.ITEM_NAME=D.ITEM_NAME AND E.MEDIC_AREA=D.MEDIC_AREA ) B,{item.ExecDatabase}.[DBO].PUB_PATIENT C
WHERE A.REG_ID=B.REG_ID AND A.PERSON_ID=C.PERSON_ID
UNION ALL
SELECT C.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,A.REG_CODE,A.REG_ID,2 REG_SOURCE,A.INHOS_TIME,B.ID,{Indexs} ,cast(right('{item.ExecDatabase}',3)as int),C.BIRTHDAY,C.SEX,1,A.OUT_DEPT_NAME FROM
{item.ExecDatabase}.[DBO].INPAT_REG_INFO A,
(SELECT DISTINCT REG_ID,D.ID FROM {item.ExecDatabase}.[DBO].INPAT_FEE E,
(SELECT * FROM [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] WHERE INDEXS= {Indexs} AND (MEDIC_AREA IS NULL OR MEDIC_AREA ='')) D
WHERE HOS_ID = cast(right('{item.ExecDatabase}',3)as int) AND E.ITEM_NAME=D.ITEM_NAME
UNION ALL
SELECT DISTINCT REG_ID,D.ID FROM [DBO].INPAT_FEE E,
(SELECT * FROM [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] WHERE INDEXS= {Indexs} AND MEDIC_AREA IS NOT NULL AND MEDIC_AREA!='') D
WHERE HOS_ID = cast(right('{item.ExecDatabase}',3)as int) AND E.ITEM_NAME=D.ITEM_NAME AND E.MEDIC_AREA=D.MEDIC_AREA) B, [DBO].PUB_PATIENT C WHERE A.REG_ID=B.REG_ID AND A.PERSON_ID=C.PERSON_ID";
num = num + conn.Execute(sql3, commandTimeout: 60 * 60 * 5);
sql2 = $@"insert into [SV_QueryPlatform_].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}([HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],[REG_TIME],AREA_ID,[INDEXS],[TYPE],[DEPT_NAME])
SELECT [HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],[REG_TIME], AREA_ID,[INDEXS],[TYPE],[DEPT_NAME] From [{item.ExecOpenLink}].[{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}";
num = num + configConnection.Execute(sql2, commandTimeout: 60 * 60 * 5);
}
if (type1_2 == 2)
{
sql2 = $@"IF EXISTS(SELECT * FROM [{item.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'MEDIC_PERSON_INFORMATION_{Indexs}_2')
drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}_2;
SELECT A.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,B.REG_CODE,B.REG_ID,1 REG_SOURCE,B.REG_TIME,A.BIRTHDAY,A.SEX,2 TYPE, {Indexs} Indexs , b.org_code hos_id,B.DEPT_NAME into [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}_2
FROM {item.ExecDatabase}.[DBO].PUB_PATIENT A, {item.ExecDatabase}.[DBO].OUT_REG_INFO B,
(SELECT DISTINCT MASTER_INDEX FROM {item.ExecDatabase}.[DBO].[MEDIC_PERSON_INFORMATION_{Indexs}] WHERE INDEXS= {Indexs} AND HOS_ID = cast(right('{item.ExecDatabase}',3)as int)) C
WHERE A.PERSON_ID=B.PERSON_ID AND A.MASTER_INDEX=C.MASTER_INDEX
UNION ALL
SELECT A.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,B.REG_CODE,B.REG_ID,2 REG_SOURCE,B.INHOS_TIME,A.BIRTHDAY,A.SEX,2 TYPE,{Indexs} , b.org_code,B.OUT_DEPT_NAME
FROM {item.ExecDatabase}.[DBO].PUB_PATIENT A, {item.ExecDatabase}.[DBO].INPAT_REG_INFO B,
(SELECT DISTINCT MASTER_INDEX FROM {item.ExecDatabase}.[DBO].[MEDIC_PERSON_INFORMATION_{Indexs}] WHERE INDEXS={Indexs} AND HOS_ID = cast(right('{item.ExecDatabase}',3)as int)) C
WHERE A.PERSON_ID=B.PERSON_ID AND A.MASTER_INDEX=C.MASTER_INDEX;";
conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
sql2 = $@"INSERT INTO [SV_QueryPlatform_].[dbo].[MEDIC_PERSON_INFORMATION_{Indexs}]([HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],[REG_TIME],AREA_ID,[INDEXS],[TYPE],[DEPT_NAME])
select [HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],[REG_TIME],null,[INDEXS],[TYPE],[DEPT_NAME] From [{item.ExecOpenLink}].[{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}_2";
num = num + configConnection.Execute(sql2, commandTimeout: 60 * 60 * 5);
sql2 = $@" DELETE FROM M FROM [SV_QueryPlatform_].[dbo].[MEDIC_PERSON_INFORMATION_{Indexs}] M
INNER JOIN (SELECT * FROM [SV_QueryPlatform_].[dbo].[MEDIC_PERSON_INFORMATION_{Indexs}] WHERE INDEXS = {Indexs}
AND HOS_ID =cast(right('{item.ExecDatabase}',3)as int) AND TYPE = 1) N
ON M.INDEXS = N.INDEXS AND M.HOS_ID = N.HOS_ID AND M.MASTER_INDEX = N.MASTER_INDEX
AND M.PERSON_ID = N.PERSON_ID AND M.REG_ID = N.REG_ID
AND M.REG_SOURCE = N.REG_SOURCE AND M.TYPE = 2 ;";
num = num + configConnection.Execute(sql2, commandTimeout: 60 * 60 * 5);
sql2 = $@" drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}_2;";
num = num + conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
}
sql2 = $@" drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}; ";
num = num + conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
}
}
}
}
catch (Exception e)
{
configConnection.Execute($"update [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate(),log='{ sql2.Replace("'", "''")}' where COMPLETE_MARK != 22 and id= " + Indexs);
}
}
}
//判断是否查完全部医院
if (countsql == hos.Count)
{
configConnection.Execute("update [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 22,END_TIME=getdate() where COMPLETE_MARK != 22 and id= " + Indexs);
}
configConnection.Execute("update [SV_QueryPlatform].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate() where COMPLETE_MARK != 22 and id= " + Indexs);
}
}
}
namespace Health.Api.Infrastructure.Queries
{
public class HomeQueries
{
private readonly string _configConnectionString;
//private List<Common> a;
bool state = true;
public HomeQueries( string configConnectionString)
{
_configConnectionString = configConnectionString;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment