张保健 5 maanden geleden
bovenliggende
commit
a4d3a56686

+ 113 - 0
models/lis_model.go Bestand weergeven

@@ -79,6 +79,117 @@ func (DataUploadConfig) TableName() string {
79 79
 	return "data_upload_config"
80 80
 }
81 81
 
82
+type VYunjingPatientLabItems struct {
83
+	Id             	int64  	`gorm:"column:ID" json:"ID"`
84
+	Zyid			string  `gorm:"column:ZYID" json:"ZYID"`
85
+	Mzid     		string  `gorm:"column:MZID" json:"MZID"`
86
+	PatientId       string  `gorm:"column:PATIENT_ID" json:"PATIENT_ID"`
87
+	Sfzh 			string 	`gorm:"column:SFZH" json:"SFZH"`
88
+	PatientName     string 	`gorm:"column:PATIENT_NAME" json:"PATIENT_NAME"`
89
+	TestOrderNo		string 	`gorm:"column:TEST_ORDER_NO" json:"TEST_ORDER_NO"`
90
+	ItemType		string  `gorm:"column:ITEM_TYPE" json:"ITEM_TYPE"`
91
+	ItemTypeName    string  `gorm:"column:ITEM_TYPE_NAME" json:"ITEM_TYPE_NAME"`
92
+	ItemCode     	string  `gorm:"column:ITEM_CODE" json:"ITEM_CODE"`
93
+	ItemName    	string  `gorm:"column:ITEM_NAME" json:"ITEM_NAME"`
94
+	SubmitAt    	string  `gorm:"column:SUBMIT_AT" json:"SUBMIT_AT"`
95
+	CreateAt    	string  `gorm:"column:CREATE_AT" json:"CREATE_AT"`
96
+	DeptName    	string  `gorm:"column:DEPT_NAME" json:"DEPT_NAME"`
97
+}
98
+
99
+func (VYunjingPatientLabItems) TableName() string {
100
+	return "v_yunjing_patient_lab_items"
101
+}
102
+
103
+type VYunjingPatientLabAnti struct {
104
+	Id             	int64  	`gorm:"column:ID" json:"ID"`
105
+	Zyid			string  `gorm:"column:ZYID" json:"ZYID"`
106
+	Mzid     		string  `gorm:"column:MZID" json:"MZID"`
107
+	PatientId       string  `gorm:"column:PATIENT_ID" json:"PATIENT_ID"`
108
+	Sfzh 			string 	`gorm:"column:SFZH" json:"SFZH"`
109
+	PatientName     string 	`gorm:"column:PATIENT_NAME" json:"PATIENT_NAME"`
110
+	TestOrderNo		string 	`gorm:"column:TEST_ORDER_NO" json:"TEST_ORDER_NO"`
111
+	ResultDate		string 	`gorm:"column:RESULT_DATE" json:"RESULT_DATE"`
112
+	TestResult		string 	`gorm:"column:TEST_RESULT" json:"TEST_RESULT"`
113
+	Unit			string 	`gorm:"column:UNIT" json:"UNIT"`
114
+	ReferRange		string 	`gorm:"column:REFER_RANGE" json:"REFER_RANGE"`
115
+	AntiCode		string 	`gorm:"column:ANTI_CODE" json:"ANTI_CODE"`
116
+	AntiName		string 	`gorm:"column:ANTI_NAME" json:"ANTI_NAME"`
117
+	CreateAt    	string  `gorm:"column:CREATE_AT" json:"CREATE_AT"`
118
+
119
+}
120
+
121
+func (VYunjingPatientLabAnti) TableName() string {
122
+	return "v_yunjing_patient_lab_anti"
123
+}
124
+
125
+type PlugPlugcase struct {
126
+	Id             	int64  	`gorm:"column:ID" json:"ID"`
127
+	Oldserialno		string  `gorm:"column:oldSerialNo" json:"oldSerialNo"`
128
+	Serialno     	string  `gorm:"column:serialNo" json:"serialNo"`
129
+	Name         	string  `gorm:"column:name" json:"name"`
130
+	Gender 			string 	`gorm:"column:gender" json:"gender"`
131
+	Age          	int64 	`gorm:"column:age" json:"age"`
132
+	RegistrantmanId	int64 	`gorm:"column:registrantMan_id" json:"registrantMan_id"`
133
+	Mainindex		string  `gorm:"column:mainIndex" json:"mainIndex"`
134
+	Orddoctor     	string  `gorm:"column:ordDoctor" json:"ordDoctor"`
135
+	Ordloc     		string  `gorm:"column:ordLoc" json:"ordLoc"`
136
+	Birthday    	string  `gorm:"column:birthDay" json:"birthDay"`
137
+}
138
+
139
+func (PlugPlugcase) TableName() string {
140
+	return "plug_plugcase"
141
+}
142
+
143
+type PlugPlugcheckitem struct {
144
+	Id             	int64  	`gorm:"column:ID" json:"ID"`
145
+	Serialno		string  `gorm:"column:serialNo" json:"serialNo"`
146
+	Itemcode     	string  `gorm:"column:itemCode" json:"itemCode"`
147
+	State         	int64  	`gorm:"column:state" json:"state"`
148
+	Itemplug 		string 	`gorm:"column:itemPlug" json:"itemPlug"`
149
+	Checkitemid		string 	`gorm:"column:checkItemId" json:"checkItemId"`
150
+	Oldserialno		string 	`gorm:"column:oldSerialNo" json:"oldSerialNo"`
151
+	Applytime		string 	`gorm:"column:applyTime" json:"applyTime"`
152
+	Specimenname	string  `gorm:"column:specimenName" json:"specimenName"`
153
+	Checkitemname 	string  `gorm:"column:checkItemName" json:"checkItemName"`
154
+	Liscollectuser	string  `gorm:"column:LisCollectUser" json:"LisCollectUser"`
155
+	Liscollecttime	string  `gorm:"column:LisCollectTime" json:"LisCollectTime"`
156
+	Lissignuser    	string  `gorm:"column:LisSignUser" json:"LisSignUser"`
157
+	Lissigntime    	string  `gorm:"column:LissignTime" json:"LissignTime"`
158
+	Lisacceptuser   string  `gorm:"column:LisAcceptUser" json:"LisAcceptUser"`
159
+	Lisaccepttime   string  `gorm:"column:LisAcceptTime" json:"LisAcceptTime"`
160
+	Lisregisteruser	string  `gorm:"column:LisRegisterUser" json:"LisRegisterUser"`
161
+	Lisregistertime	string  `gorm:"column:LisRegisterTime" json:"LisRegisterTime"`
162
+	Lischeckuser    string  `gorm:"column:LisCheckUser" json:"LisCheckUser"`
163
+	Lischecktime    string  `gorm:"column:LisCheckTime" json:"LisCheckTime"`
164
+	Lisrefuseuser   string  `gorm:"column:LisRefuseUser" json:"LisRefuseUser"`
165
+	Lisrefusetime   string  `gorm:"column:LisRefuseTime" json:"LisRefuseTime"`
166
+	Lisstatus    	string  `gorm:"column:LisStatus" json:"LisStatus"`
167
+	Refusereason    string  `gorm:"column:RefuseReason" json:"RefuseReason"`
168
+}
169
+
170
+func (PlugPlugcheckitem) TableName() string {
171
+	return "plug_plugcheckitem"
172
+}
173
+
174
+type PlugPlugresult struct {
175
+	Id             		int64  	`gorm:"column:ID" json:"ID"`
176
+	Serialno			string  `gorm:"column:serialNo" json:"serialNo"`
177
+	Testitemname		string  `gorm:"column:testItemName" json:"testItemName"`
178
+	Itemcode			string  `gorm:"column:itemcode" json:"itemcode"`
179
+	Paritemno			string  `gorm:"column:parItemNo" json:"parItemNo"`
180
+	Reportvalueall		string  `gorm:"column:reportValueAll" json:"reportValueAll"`
181
+	Testitemdatetime	string  `gorm:"column:testItemDateTime" json:"testItemDateTime"`
182
+	Unit				string  `gorm:"column:unit" json:"unit"`
183
+	Refrange			string  `gorm:"column:refrange" json:"refrange"`
184
+	Resultstatus		string  `gorm:"column:resultStatus" json:"resultStatus"`
185
+	Itemorder			int64  	`gorm:"column:itemOrder" json:"itemOrder"`
186
+	Checker				string  `gorm:"column:checker" json:"checker"`
187
+}
188
+
189
+func (PlugPlugresult) TableName() string {
190
+	return "plug_plugresult"
191
+}
192
+
82 193
 type Schedules struct {
83 194
 	ID           int64 `gorm:"column:id" json:"id" form:"id"`
84 195
 	UserOrgId    int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
@@ -129,6 +240,7 @@ func (MiddlePatients) TableName() string {
129 240
 	return "xt_middle_patients"
130 241
 }
131 242
 
243
+
132 244
 type Patients struct {
133 245
 	ID              int64  `gorm:"column:id" json:"id" form:"id"`
134 246
 	UserOrgId       int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
@@ -331,6 +443,7 @@ type MiddleInspectionReference struct {
331 443
 	IsSync           int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
332 444
 	UTime            string `gorm:"column:u_time" json:"u_time" form:"u_time"`
333 445
 	SyncId           int64  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
446
+	ItemCode         string  `gorm:"column:item_code" json:"item_code" form:"item_code"`
334 447
 }
335 448
 
336 449
 func (MiddleInspectionReference) TableName() string {

+ 4 - 2
routers/router.go Bestand weergeven

@@ -28,6 +28,8 @@ func init() {
28 28
 
29 29
 	beego.Router("/api/syncshLis", &controllers.LisController{}, "get:SyncShLis")
30 30
 	beego.Router("/api/syncszblis", &controllers.LisController{}, "get:SyncSzblLis")
31
-	beego.Router("/api/test", &controllers.LisController{}, "get:SyncScpaLis")
32
-
31
+	beego.Router("/api/test", &controllers.LisController{}, "get:SyncTest")
32
+	beego.Router("/api/lis/gzjhxytx", &controllers.LisController{}, "get:SyncGzjhxytx")
33
+	beego.Router("/api/lis/scdckfyy", &controllers.LisController{}, "get:SyncSccdkfyyLis")
34
+	beego.Router("/api/lis/pajm", &controllers.LisController{}, "get:SyncPajmLis")
33 35
 }

+ 55 - 11
service/cron.go Bestand weergeven

@@ -25,6 +25,34 @@ func newWithSeconds() *cron.Cron {
25 25
 	return cron.New(cron.WithParser(secondParser), cron.WithChain())
26 26
 }
27 27
 
28
+// func BeginAutoSyncLis() {
29
+// 	utils.InfoLog("开启自动检验检查同步定时任务")
30
+// 	createLisSyncCronJob := newWithSeconds()
31
+
32
+// 	// specgzjh := "0 */1 * * * ?" // 每1分钟同步 广州暨华HIS医嘱
33
+// 	// createLisSyncCronJob.AddFunc(specgzjh, func() {
34
+// 	// 	// SyncGzjhyz()
35
+// 	// 	Synctfyz()
36
+// 	// })
37
+
38
+// 	specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
39
+// 	createLisSyncCronJob.AddFunc(specys, func() {
40
+// 		// SyncStsyLis()
41
+// 	})
42
+
43
+// 	specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
44
+// 	createLisSyncCronJob.AddFunc(specys1, func() {
45
+// 		// SyncCsnyLis()
46
+// 	})
47
+
48
+// 	spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
49
+// 	createLisSyncCronJob.AddFunc(spec, func() {
50
+// 		// SyncHbdyLis()
51
+// 	})
52
+
53
+// 	createLisSyncCronJob.Start()
54
+// }
55
+
28 56
 func BeginAutoSyncLis() {
29 57
 	utils.InfoLog("开启自动检验检查同步定时任务")
30 58
 	createLisSyncCronJob := newWithSeconds()
@@ -35,24 +63,40 @@ func BeginAutoSyncLis() {
35 63
 	// 	Synctfyz()
36 64
 	// })
37 65
 
38
-	specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
39
-	createLisSyncCronJob.AddFunc(specys, func() {
40
-		SyncScpaLis()
41
-	})
66
+	// specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
67
+	// createLisSyncCronJob.AddFunc(specys, func() {
68
+	// 	SyncTscyLis()
69
+	// })
42 70
 
43
-	specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
44
-	createLisSyncCronJob.AddFunc(specys1, func() {
45
-		// SyncCsnyLis()
46
-	})
71
+	// specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
72
+	// createLisSyncCronJob.AddFunc(specys1, func() {
73
+	// 	SyncCsnyLis()
74
+	// })
47 75
 
48
-	spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
49
-	createLisSyncCronJob.AddFunc(spec, func() {
50
-		// SyncHbdyLis()
76
+	// spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
77
+	// createLisSyncCronJob.AddFunc(spec, func() {
78
+	// 	SyncHbdyLis()
79
+	// })
80
+	
81
+	// spec2 := "0 50 2 * * ?" // 每天凌晨2点同步 龙岗二院
82
+	// createLisSyncCronJob.AddFunc(spec2, func() {
83
+	// 	SyncLisLgty()
84
+	// })
85
+
86
+	// spec3 := "0 50 3 * * ?" // 每天凌晨2点同步 广州暨华血液透析中心
87
+	// createLisSyncCronJob.AddFunc(spec3, func() {
88
+	// 	SyncLisGzjhtx()
89
+	// })
90
+
91
+	specgzjh := "0 0 */2 * * ?" // 每2个小时同步 汕头三优血液透析中心LIS
92
+	createLisSyncCronJob.AddFunc(specgzjh, func() {
93
+		SyncScpaLis()
51 94
 	})
52 95
 
53 96
 	createLisSyncCronJob.Start()
54 97
 }
55 98
 
99
+
56 100
 func AutoSyncLis() {
57 101
 	utils.TraceLog("检验检查任务开始执行")
58 102
 	org_id := int64(9538)

+ 524 - 0
service/gzjhtxzx_service.go Bestand weergeven

@@ -0,0 +1,524 @@
1
+package service
2
+
3
+import (
4
+	"IC/models"
5
+	"IC/utils"
6
+	"encoding/json"
7
+	"encoding/xml"
8
+	"github.com/astaxie/beego/httplib"
9
+	"net/url"
10
+	"strconv"
11
+	"strings"
12
+	"time"
13
+)
14
+
15
+type RequestResultGzjh struct {
16
+	Msg    string `json:"msg"`
17
+	ResultGzjh []struct {
18
+		AdviceId               int64   `json:"医嘱ID"`
19
+		OtherId                int64   `json:"相关ID"`
20
+		Source                 int     `json:"病人来源"`
21
+		PatientId              int64   `json:"病人ID"`
22
+		JzId                   int64   `json:"就诊ID"`
23
+		BabyId                 int     `json:"婴儿ID"`
24
+		PatientDepartmentId    int     `json:"病人科室ID"`
25
+		OrderId                int     `json:"次序"`
26
+		AdviceStatus           int     `json:"医嘱状态"`
27
+		AdviceType             int     `json:"医嘱类型"`
28
+		DiagnosisType          string  `json:"诊疗类型"`
29
+		DiagnosisItemId        int     `json:"诊疗项目ID"`
30
+		CheckMethd             string  `json:"检查方法"`
31
+		ChargeItemId           int     `json:"收费项目ID"`
32
+		Day                    int     `json:"天数"`
33
+		JiLiang                float64 `json:"剂量"`
34
+		YongLiang              string  `json:"用量"`
35
+		DanLiang               float64 `json:"单量"`
36
+		Shuliang               float64 `json:"数量"`
37
+		Advice                 string  `json:"医嘱"`
38
+		GeiYaoTuJing           string  `json:"给药途径"`
39
+		ShuoMing               string  `json:"说明"`
40
+		ZhiXingKeShiId         int     `json:"执行科室ID"`
41
+		ZhiXingKeShi           string  `json:"执行科室"`
42
+		PN                     string  `json:"P(+)或N(-)表示阳性或阴性"`
43
+		ZhiXingPinCi           string  `json:"执行频次"`
44
+		PinLvCiShu             int     `json:"频率次数"`
45
+		PinLvJianGe            int     `json:"频率间隔"`
46
+		JianGeDanWei           string  `json:"间隔单位"`
47
+		ZhiXingShiJianFangAn   string  `json:"执行时间方案"`
48
+		JiJiaTeXing            int     `json:"计价特性"`
49
+		ZhiXingXingZhi         int     `json:"执行性质"`
50
+		ZhiXingBiaoZhi         int     `json:"执行标记"`
51
+		KeFouFenLing           int     `json:"可否分零"`
52
+		JinJiBiaoZhi           int     `json:"紧急标志"`
53
+		KaiShiZhiXingShiJian   int64   `json:"开始执行时间"`
54
+		ZhiXingZhongZhiShiJian int64   `json:"执行终止时间"`
55
+		ShangCiZhiXingShiJian  int64   `json:"上次执行时间"`
56
+		KaiZhuKeShiId          int     `json:"开嘱科室ID"`
57
+		DoctorCode             string  `json:"医师编码"`
58
+		Doctor                 string  `json:"开嘱医师"`
59
+		AdviceTime             int64   `json:"开嘱时间"`
60
+		StopTime               int64   `json:"停嘱时间"`
61
+		ApplyId                int     `json:"申请ID"`
62
+		UploadLable            int     `json:"上传标志"`
63
+		CheckResult            int     `json:"审查结果"`
64
+		NoPrint                int     `json:"忽略打印"`
65
+		Summary                string  `json:"摘要"`
66
+		AdviceOrderId          int64   `json:"医嘱单id"`
67
+		GeiYaoKeShi            int     `json:"给药科室"`
68
+		GeiYaoXingZhi          int     `json:"给药性质"`
69
+		GroupNo                int     `json:"组号"`
70
+		Speed                  string  `json:"滴速"`
71
+		ShouRiCiShu            float64 `json:"首日次数"`
72
+		MoRiCiShu              float64 `json:"末日次数"`
73
+		AdviceDoctorId         int     `json:"开嘱医师ID"`
74
+		AdviceNurseId          int     `json:"开嘱护士ID"`
75
+		OperaId                int     `json:"操作员ID"`
76
+		Opera                  string  `json:"操作员"`
77
+		CheckTime              int64   `json:"审核时间"`
78
+		ReplyAdviceTime        int64   `json:"重整医嘱时间"`
79
+	} `json:"result"`
80
+	Code string `json:"code"`
81
+}
82
+
83
+type XmlKeyGzjh struct {
84
+	XMLName    xml.Name `xml:"string"`
85
+	StringName string   `xml:"name,attr"`
86
+	InnerText  string   `xml:",innerxml"`
87
+}
88
+
89
+// 获取艾迪康的key
90
+func GetGzjhAdKey(logid string, password string) (key string) {
91
+	Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/Login?"
92
+	apiurl := "logid=" + logid + "&password=" + password
93
+	apiurl = url.PathEscape(apiurl)
94
+	utils.InfoLog("apiUrl: %v", apiurl)
95
+	apiurl = Domain + apiurl
96
+	xmlKey := XmlKeyGzjh{}
97
+	httplib.Get(apiurl).ToXML(&xmlKey)
98
+	utils.InfoLog("xmlKey: %v", xmlKey)
99
+	return xmlKey.InnerText
100
+}
101
+
102
+type ADStringGzjh struct {
103
+	XMLName    xml.Name     `xml:"string" json:"string"`
104
+	NewDataSet rpnewDataSetGzjh `xml:"NewDataSet" json:"NewDataSetGzjh"`
105
+}
106
+
107
+type rpnewDataSetGzjh struct {
108
+	ListTable []rplisttableGzjh `xml:"listtable" json:"listtableGzjh"`
109
+}
110
+
111
+type rplisttableGzjh struct {
112
+	Id          string `xml:"Id" json:"Id"`
113
+	PatientName string `xml:"PatientName" json:"PatientName"`
114
+	Bgrq        string `xml:"Bgrq" json:"Bgrq"`
115
+	Instrument  string `xml:"Instrument" json:"Instrument"`
116
+	LisDate     string `xml:"LisDate" json:"LisDate"`
117
+	Sampleid    string `xml:"Sampleid" json:"Sampleid"`
118
+}
119
+
120
+type ReportListXml struct {
121
+	XMLName 		xml.Name `xml:"GetReportList"`
122
+	Key				string `xml:"Key"`
123
+	BeginDateTime	string `xml:"BeginDateTime"`
124
+	EndDateTime		string `xml:"EndDateTime"`
125
+	TypeDateTime	string `xml:"TypeDateTime"`
126
+	AgainFlag		string `xml:"AgainFlag"`
127
+}
128
+
129
+// 获取机构一段时间内检验检查列表
130
+func GetAdGetReportListGzjh(Key string, BeginDateTime string, EndDateTime string, TypeDateTime string, AgainFlag string) (key ADStringGzjh) {
131
+	Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetReportList"
132
+	var xmlKey ADStringGzjh
133
+	reportPost := httplib.Post(Domain)
134
+	reportPost.Param("Key",Key)
135
+	reportPost.Param("BeginDateTime",BeginDateTime)
136
+	reportPost.Param("EndDateTime",EndDateTime)
137
+	reportPost.Param("TypeDateTime",TypeDateTime)
138
+	reportPost.Param("AgainFlag",AgainFlag)
139
+	reportPost.Header("Content-Type", "application/xml")  
140
+	
141
+	xmlString,_ := reportPost.String()
142
+	xmlString = strings.Replace(xmlString, "&lt;", "<", -1)
143
+	xmlString = strings.Replace(xmlString, "&gt;", ">", -1)
144
+	xml.Unmarshal([]byte(xmlString), &xmlKey)
145
+	return xmlKey
146
+}
147
+
148
+type adkCheckGzjh struct {
149
+	ApplyId     string      	`json:"applyid"`
150
+	ReportNo    string      	`json:"reportno"`
151
+	PatName     string      	`json:"patname"`
152
+	Sex         string      	`json:"sex"`
153
+	Age         string      	`json:"age"`
154
+	DptName     string      	`json:"dptname"`
155
+	Testtype    string      	`json:"testtype"`
156
+	Testcode    string      	`json:"testcode"`
157
+	ExecuteTime string      	`json:"receivetime"`
158
+	Checktime   string      	`json:"checktime"`
159
+	Checkcode   string      	`json:"checkcode"`
160
+	Result      []adkResultGzjh `json:"result"`
161
+}
162
+
163
+func GetAdkInfoGzjh(key string, id string) (str []adkCheckGzjh, checkStr string) {
164
+	Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetJSONReportItemListById"
165
+
166
+	reportPost := httplib.Post(Domain)
167
+	reportPost.Param("Key",key)
168
+	reportPost.Param("id",id)
169
+	reportPost.Header("Content-Type", "application/xml")  
170
+	xmlKey := XmlKey{}
171
+	reportPost.ToXML(&xmlKey)
172
+	var checkJSON []adkCheckGzjh
173
+	json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
174
+	return checkJSON, xmlKey.InnerText
175
+}
176
+
177
+// 广州暨华血液透析中心Lis同步
178
+func SyncLisGzjhtx() (err error) {
179
+	// 第一步:获取艾迪康下发的Key
180
+	org_id := int64(10015)
181
+	login := "RH0046"
182
+	password := "Abc123123"
183
+	key := GetGzjhAdKey(login, password)
184
+	utils.InfoLog("key: %v", key)
185
+	// 第二步:获e取上一次同步的时间点
186
+	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
187
+	var sync_time int64
188
+	if syncLastInfo.ID > 0 {
189
+		sync_time = syncLastInfo.SyncTime + 86400
190
+	} else {
191
+		sync_time = 1672502400
192
+	}
193
+	nowTimes := time.Now().Unix()
194
+	// syncTimes := time.Unix(sync_time,0).Format("2006-01-02")
195
+	if sync_time < nowTimes {
196
+		for i := sync_time; i < nowTimes; i = i + 86400 {
197
+			tempsyncTimes := time.Unix(i, 0).Format("2006-01-02")
198
+			utils.InfoLog("tempsyncTimes:%v", tempsyncTimes)
199
+			adString := GetAdGetReportListGzjh(key, tempsyncTimes, tempsyncTimes, "2", "2")
200
+			listtable := adString.NewDataSet.ListTable
201
+			utils.InfoLog("listtable: %v", listtable)
202
+			if len(listtable) > 3 {
203
+				// 第三步:根据检查列表获取的ID来获取检验检查详情
204
+				for _, list := range listtable {
205
+					listId := list.Id
206
+					utils.InfoLog("listId: %v", listId)
207
+					checkInfo, checkStr := GetAdkInfoGzjh(key, listId)
208
+					utils.InfoLog("checkInfo: %v", checkInfo)
209
+					for _, info := range checkInfo {
210
+						// 根据姓名 去查询对应的patient_id
211
+						patient, _ := GetPatientIDGzjh(org_id, info.PatName)
212
+						utils.InfoLog("patient: %v", patient)
213
+						if patient.ID > 0 {
214
+							middleReportHandle := models.MiddleReportHandle{
215
+								OrgId:       org_id,
216
+								HisUserId:   strconv.FormatInt(patient.ID, 10),
217
+								ApplyNo:     info.ApplyId,
218
+								ReportId:    info.ReportNo,
219
+								Name:        info.PatName,
220
+								Sex:         info.Sex,
221
+								Age:         info.Age,
222
+								Dept:        info.DptName,
223
+								PatientId:   strconv.FormatInt(patient.ID, 10),
224
+								RequestTime: info.ExecuteTime,
225
+								ExecuteTime: info.ExecuteTime,
226
+								ReceiveTime: info.ExecuteTime,
227
+								CheckTime:   info.ExecuteTime,
228
+								ReportInfo:  checkStr,
229
+								CreatedTime: time.Now().Unix(),
230
+								UpdatedTime: time.Now().Unix(),
231
+							}
232
+							handleerr := CreateReportHandle(&middleReportHandle)
233
+							if handleerr != nil {
234
+								utils.ErrorLog("创建检验检查操作数据失败:%v", handleerr)
235
+								return
236
+							}
237
+
238
+							GzjhReportInfoHandle(info, org_id, patient.ID)
239
+						}
240
+					}
241
+				}
242
+				var syncInfo models.MiddleSyncInfo
243
+				syncInfo.OrgId = org_id
244
+
245
+				syncInfo.SyncTime = i
246
+				syncInfo.SyncResultType = 1
247
+				syncInfo.SyncRsultRemark = "同步成功"
248
+				syncInfo.SyncTotalNum = 0
249
+				syncInfo.SyncSuccessNum = 0
250
+				syncInfo.SyncInfo = ""
251
+				syncInfo.CreateTime = time.Now().Unix()
252
+				syncInfo.UpdateTime = time.Now().Unix()
253
+
254
+				cwderr := CreateSyncInfo(&syncInfo)
255
+				if cwderr != nil {
256
+					utils.ErrorLog("创建同步信息失败:%v", cwderr)
257
+					return
258
+				}
259
+			}
260
+		}
261
+
262
+	}
263
+	SyncToGzczjhtx()
264
+
265
+	return
266
+}
267
+
268
+// 根据姓名获取patient_id
269
+func GetPatientIDGzjh(org_id int64, patient_name string) (patient models.Patients, err error) {
270
+	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1 and name = ? ", org_id, patient_name).First(&patient).Error
271
+	return
272
+}
273
+
274
+func GetProjectInfoGzjh(item_id int64, org_id int64) (project_info models.MiddleInspectionReference, err error) {
275
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and item_id = ?", org_id, item_id).First(&project_info).Error
276
+	return
277
+}
278
+
279
+// 修改配置信息
280
+// func UpdateInspectionReference(InspectionReference *models.MiddleInspectionReference) error {
281
+// 	err := readMiddleDb.Model(&models.MiddleInspectionReference{}).Updates(&InspectionReference).Error
282
+// 	return err
283
+// }
284
+
285
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
286
+func GetGzzcjhProjectID(org_id int64, project_name string) (project_id int64, err error) {
287
+	var inspection_reference models.MiddleInspectionReference
288
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
289
+	if inspection_reference.ID > 0 {
290
+		return inspection_reference.ProjectId, err
291
+	} else {
292
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
293
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
294
+		if inspection_reference.ProjectId > 0 {
295
+			return inspection_reference.ProjectId + 1, err
296
+		} else {
297
+			return 1001501, err
298
+		}
299
+	}
300
+}
301
+
302
+// // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
303
+// func GetGzjhProjectID(org_id int64, project_name string) (project_id int64, err error) {
304
+// 	var inspection_reference models.MiddleInspectionReference
305
+// 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
306
+// 	if inspection_reference.ID > 0 {
307
+// 		return inspection_reference.ProjectId, err
308
+// 	} else {
309
+// 		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
310
+// 		if inspection_reference.ProjectId > 0 {
311
+// 			return inspection_reference.ProjectId + 1, err
312
+// 		} else {
313
+// 			return 116001, err
314
+// 		}
315
+// 	}
316
+// }
317
+
318
+func GzjhReportInfoHandle(CheckInfo adkCheckGzjh, org_id int64, patientId int64) {
319
+	// 1.先把所有的检查项弄出来
320
+	for _, info := range CheckInfo.Result {
321
+		// 根据project_id和item_id 判断该项是否存在
322
+		curitemcode, _ := strconv.ParseInt(info.Itemcode, 10, 64)
323
+		reference, _ := GetProjectInfoGzjh(curitemcode, org_id)
324
+		utils.InfoLog("info: %v", info)
325
+		utils.InfoLog("reference: %v", info)
326
+		if reference.ID > 0 {
327
+			if reference.ProjectId > 0 {
328
+				LgthYsSyncGzjh(info, reference.ProjectId, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
329
+			} else {
330
+				project_id := int64(0)
331
+				if len(info.Groupitemcode) > 0 {
332
+					// 对没有project信息的项目进行修改
333
+					project_id, _ = GetGzzcjhProjectID(org_id, info.Groupitemname)
334
+					reference.ProjectId = project_id
335
+					reference.ProjectName = info.Groupitemcode
336
+					reference.Project = info.Groupitemcode
337
+					// 修改配置信息
338
+					UpdateInspectionReference(&reference)
339
+				}
340
+				LgthYsSyncGzjh(info, project_id, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
341
+			}
342
+		} else {
343
+			project_id := int64(0)
344
+			if len(info.Groupitemcode) > 0 {
345
+				project_id, _ = GetGzzcjhProjectID(org_id, info.Groupitemname)
346
+			}
347
+			LgthYsSyncGzjh(info, project_id, curitemcode, org_id, patientId, CheckInfo.ExecuteTime)
348
+		}
349
+	}
350
+
351
+	// SyncLisGzjhtx()
352
+}
353
+
354
+type adkResultGzjh struct {
355
+	Testno        string `json:"testno"`
356
+	Reportno      string `json:"reportno"`
357
+	Itemord       string `json:"itemord"`
358
+	Itemcode      string `json:"itemcode"`
359
+	Itemname      string `json:"itemname"`
360
+	ItemEname     string `json:"itemename"`
361
+	Result        string `json:"result"`
362
+	Units         string `json:"units"`
363
+	Testdate      string `json:"testdate"`
364
+	Eqpname       string `json:"eqpname"`
365
+	Groupitemcode string `json:"groupitemcode"`
366
+	Groupitemname string `json:"groupitemname"`
367
+	Limit         string `json:"limit"`
368
+	Resultstate   string `json:"resultstate"`
369
+	Criticalflag  string `json:"criticalflag"`
370
+	Itemename     string `json:"itemename"`
371
+}
372
+
373
+// 从机构将数据同步到中间库
374
+func LgthYsSyncGzjh(report adkResultGzjh, project_id int64, item_id int64, org_id int64, patient_id int64, receivetime string) (*models.MiddleInspectionReference, error) {
375
+	tx := writeMiddleDb.Begin()
376
+	var inspection models.MiddleInspection
377
+	var inspection_reference models.MiddleInspectionReference
378
+	recordDateStr := receivetime
379
+
380
+	if len(receivetime) == 0 {
381
+		recordDateStr = time.Now().Format("2006-01-02 15:04")
382
+	}
383
+
384
+	record_date_str, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
385
+	record_date := record_date_str.Unix()
386
+	inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
387
+	// date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
388
+	// record_date,_ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
389
+	var total int
390
+	var RangeOptions string
391
+	var RangeMin string
392
+	var RangeMax string
393
+
394
+	// // 判断检查类型
395
+	ItemType := 1
396
+	Range := strings.Split(report.Limit, "-")
397
+	if len(Range) > 1 {
398
+		RangeMin = Range[0]
399
+		RangeMax = Range[1]
400
+		ItemType = 1
401
+	} else {
402
+		ItemType = 2
403
+		RangeOptions = report.Limit
404
+	}
405
+
406
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
407
+	if inspection_reference.ID > 0 {
408
+		ItemType = inspection_reference.RangeType
409
+	}
410
+	if total <= 0 {
411
+		inspection_reference.OrgId = org_id
412
+		inspection_reference.ProjectName = report.Groupitemname
413
+		inspection_reference.Project = report.Groupitemcode
414
+		inspection_reference.ProjectId = project_id
415
+		inspection_reference.ItemName = report.Itemname
416
+		inspection_reference.ItemNameAddition = report.ItemEname
417
+		inspection_reference.ItemId = item_id
418
+		inspection_reference.RangeType = ItemType
419
+		inspection_reference.RangeMin = RangeMin
420
+		inspection_reference.RangeMax = RangeMax
421
+		// inspection_reference.RangeValue = RangeValue
422
+		inspection_reference.RangeOptions = RangeOptions
423
+		inspection_reference.Unit = report.Units
424
+		inspection_reference.Status = 1
425
+		inspection_reference.CreatedTime = time.Now().Unix()
426
+		inspection_reference.UpdatedTime = time.Now().Unix()
427
+		inspection_reference.InspectDate = inspect_date
428
+		inspection_reference.UTime = inspect_date
429
+		err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
430
+		if err != nil {
431
+			tx.Rollback()
432
+		}
433
+	}
434
+
435
+	var itotal int
436
+	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, project_id, item_id, record_date, patient_id).Find(&inspection).Count(&itotal).Error
437
+	if itotal <= 0 {
438
+		report.Result = strings.Replace(report.Result, "&gt;", ">", -1)
439
+		report.Result = strings.Replace(report.Result, "&lt;", "<", -1)
440
+		inspection.PatientId = patient_id
441
+		inspection.OrgId = org_id
442
+		inspection.ProjectId = project_id
443
+		inspection.ItemName = inspection_reference.ItemName
444
+		inspection.ProjectName = inspection_reference.ProjectName
445
+		inspection.InspectType = ItemType
446
+		inspection.ItemId = item_id
447
+		inspection.InspectValue = report.Result
448
+		inspection.InspectDate = inspect_date
449
+		inspection.RecordDate = record_date
450
+		inspection.InspectTips = report.Resultstate
451
+		inspection.Status = 1
452
+		inspection.CreatedTime = time.Now().Unix()
453
+		inspection.UpdatedTime = time.Now().Unix()
454
+		inspection.UTime = inspect_date
455
+		inspection.HisUserId = strconv.FormatInt(patient_id, 10)
456
+		err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
457
+		if err != nil {
458
+			tx.Rollback()
459
+		}
460
+	}
461
+
462
+	// 	//处理检验检查操作表里同步条数和状态
463
+	// 	cur_num := Head.ReportInfoItemHandleNum + 1
464
+	// 	Head.ReportInfoItemHandleNum = cur_num
465
+	// 	handleType := 2
466
+	// 	if cur_num == Head.ReportInfoItemNum {
467
+	// 		handleType = 1
468
+	// 	}
469
+	// 	middleReportHandle := models.MiddleReportHandle{
470
+	// 		ID:							Head.ID,
471
+	// 		ReportInfoItemHandleNum:	cur_num,
472
+	// 		HandleType:					int64(handleType),
473
+	// 		UpdatedTime:				time.Now().Unix(),
474
+	// 	}
475
+	// 	err = UpdateReportHandleListyOrgID(&middleReportHandle)
476
+	// 	if err != nil {
477
+	// 		tx.Rollback()
478
+	// 	}
479
+	// }
480
+
481
+	tx.Commit()
482
+	return nil, err
483
+}
484
+
485
+
486
+// 根据姓名获取patient_id
487
+func GetPatientGzjhListGzjh(org_id int64, schedulesTime int64) (schedules []*models.DialysisSchedule, err error) {
488
+	err = readDb.Model(&models.DialysisSchedule{}).Where("user_org_id = ? and status = 1 and  schedule_date = ?", org_id, schedulesTime).Preload("Patients", "status = 1").Find(&schedules).Error
489
+	return
490
+}
491
+
492
+// 根据姓名获取admin_user_id
493
+func GetAdminUserIdGzjh(org_id int64, doctor_name string) (doctor models.UserAdminRole, err error) {
494
+	err = writeUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? and status = 1 and  user_name = ?", org_id, doctor_name).First(&doctor).Error
495
+	return
496
+}
497
+
498
+func GetPatientGzjhByOrgIdGzjh(org_id int64) (patientList []*models.Patients, err error) {
499
+	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patientList).Error
500
+	return
501
+}
502
+
503
+func SyncToGzczjhtx() {
504
+	utils.TraceLog("检验检查同步任务开始执行")
505
+	org_id := int64(10015)
506
+
507
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
508
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
509
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
510
+
511
+	// 第二步:将数据同步到业务库
512
+	if len(inspection_references) > 0 {
513
+		for _, inspection_reference := range inspection_references {
514
+			SyncInspectionReference(&inspection_reference)
515
+		}
516
+	}
517
+
518
+	if len(inspections) > 0 {
519
+		for _, inspection := range inspections {
520
+			SyncInspection(&inspection)
521
+		}
522
+	}
523
+	utils.SuccessLog("检验检查同步任务完成")
524
+}

+ 1 - 1
service/lis_service.go Bestand weergeven

@@ -104,7 +104,7 @@ func SyncInspection(data *models.MiddleInspection) error {
104 104
 	tx := writeDb.Begin()
105 105
 	var inspection models.Inspection
106 106
 	var total int
107
-	err = readDb.Model(&models.Inspection{}).Where("org_id = ? and project_id = ? and item_id = ? and patient_id =? and inspect_date=?  and status = 1", data.OrgId, data.ProjectId,data.ItemId,data.PatientId,data.InspectDate).Find(&inspection).Count(&total).Error
107
+	err = readDb.Model(&models.Inspection{}).Where("org_id = ? and project_id = ? and item_id = ? and patient_id =? and inspect_date=?  and status = 1", data.OrgId, data.ProjectId,data.ItemId,data.PatientId,data.RecordDate).Find(&inspection).Count(&total).Error
108 108
 	if total <= 0 {
109 109
 		inspection.OrgId = data.OrgId
110 110
 		inspection.PatientId = data.PatientId

+ 9 - 6
service/pajm_service.go Bestand weergeven

@@ -1,8 +1,6 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	"Data_Upload_Api/models/sz"
5
-	"Data_Upload_Api/service"
6 4
 	"IC/models"
7 5
 	"IC/utils"
8 6
 	_ "encoding/json"
@@ -29,7 +27,7 @@ type scpalis struct {
29 27
 	RangeValue   string `gorm:"column:range_value" json:"range_value"`
30 28
 	RangeOptions string `gorm:"column:range_options" json:"range_options"`
31 29
 	Unit         string `gorm:"column:unit" json:"unit"`
32
-	State        int64  `gorm:"column:state" json:"state"`
30
+	State        string  `gorm:"column:state" json:"state"`
33 31
 	CTime        int64  `gorm:"column:c_time" json:"c_time"`
34 32
 	UTime        int64  `gorm:"column:u_time" json:"u_time"`
35 33
 }
@@ -76,11 +74,16 @@ func GetScpaItemID(org_id int64, project_name string, item_name string, project_
76 74
 	}
77 75
 }
78 76
 
77
+func GetPatientPajmByOrgId(org_id int64) (patientList []*models.Patients, err error) {
78
+	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patientList).Error
79
+	return
80
+}
81
+
79 82
 // 四川蓬安济民透析中心Lis同步
80 83
 func SyncScpaLis() (err error) {
81 84
 	org_id := int64(9829)
82 85
 
83
-	org := &sz.DataUploadConfig{
86
+	org := &models.DataUploadConfig{
84 87
 		OrgId:  org_id,
85 88
 		DbHost: "192.168.0.254",
86 89
 		DbPort: "1433",
@@ -89,7 +92,7 @@ func SyncScpaLis() (err error) {
89 92
 		DbName: "nfjiminhis",
90 93
 	}
91 94
 
92
-	orgDb, err := service.CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
95
+	orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
93 96
 	if err != nil {
94 97
 		utils.ErrorLog("创建数据库连接失败:%v", err)
95 98
 		return
@@ -111,7 +114,7 @@ func SyncScpaLis() (err error) {
111 114
 	}
112 115
 	// 第二步:获取所有患者的病历号
113 116
 
114
-	patientList, _ := GetPatientGzjhByOrgId(org_id)
117
+	patientList, _ := GetPatientPajmByOrgId(org_id)
115 118
 	if len(patientList) > 0 {
116 119
 		for _, patient := range patientList {
117 120
 			if len(patient.IdCardNo) > 0 {

+ 345 - 0
service/sccdkfyy_service.go Bestand weergeven

@@ -0,0 +1,345 @@
1
+package service
2
+
3
+import (
4
+	"IC/models"
5
+	"IC/utils"
6
+	"github.com/jinzhu/gorm"
7
+	"strconv"
8
+	"strings"
9
+	"time"
10
+)
11
+
12
+// 四川城东康复医院Lis同步
13
+func SyncSccdkfyyLis() (err error) {
14
+	org_id := int64(10551)
15
+
16
+	org := &models.DataUploadConfig{
17
+		OrgId:  org_id,
18
+		DbHost: "192.168.1.5",
19
+		DbPort: "1433",
20
+		DbPass: "XTXT_User",
21
+		DbUser: "XTXT_User",
22
+		DbName: "ndlmis15",
23
+	}
24
+
25
+	orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
26
+	if err != nil {
27
+		utils.ErrorLog("创建数据库连接失败:%v", err)
28
+		return
29
+	}
30
+
31
+	// var sync_time int64
32
+	// sync_time = 1627747200
33
+
34
+	// scpaLis, _ := GetScpaLis(orgDb, sync_time,"512926196302182682")
35
+	// utils.InfoLog("IdCardNo:%v",scpaLis)
36
+
37
+	// 第一步:获取上一次同步的plug_plugcase的ID
38
+	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
39
+	var sync_time int64
40
+	if syncLastInfo.ID > 0 {
41
+		sync_time = syncLastInfo.SyncTime
42
+	} else {
43
+		sync_time = 0
44
+	}
45
+
46
+	sync_time_temp := time.Unix(sync_time, 0)
47
+	syncTimeStr := sync_time_temp.Format("2006-01-02 15:04:05")
48
+
49
+
50
+	// 第二步:获取时间内所有检验结果
51
+	sccdLis, _ := GetScdckfyyLis(orgDb, syncTimeStr)
52
+
53
+	if len(sccdLis) > 0 {
54
+		for _, item := range sccdLis {
55
+			printInfo, _ := GetPatientsInfoBySfzh(item.Sfzh, 10551)
56
+			if printInfo.ID == 0 {
57
+				continue
58
+			}
59
+			// result 里查询
60
+			antiRresult,_ := GetScCdkfyyAnti(orgDb,item.TestOrderNo)
61
+			if len(antiRresult) > 0  {
62
+				for _,anti := range antiRresult {
63
+					LgthScdckfyySync(anti,item, org_id, printInfo.ID)
64
+				}
65
+			}
66
+		}
67
+	}
68
+
69
+	// 第二步:获取所有患者的病历号
70
+
71
+	// patientList, _ := GetPatientGzjhByOrgId(org_id)
72
+	// if len(patientList) > 0 {
73
+	// 	for _, patient := range patientList {
74
+	// 		if len(patient.IdCardNo) > 0 {
75
+	// 			patient_id := patient.ID
76
+	// 			utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
77
+	// 			scdcCaseList, _ := GetScCdkfyyCase(orgDb, sync_time,lastId, patient.IdCardNo)
78
+	// 			// 如果存在纪录,再在plug_plugCheckitem里根据信息查询检验信息
79
+	// 			if len(scdcCaseList) > 0 {
80
+	// 				for _, info := range scdcCaseList {
81
+	// 					utils.InfoLog("Result:%v", info)
82
+	// 					scdcItemList,_ := GetScCdkfyyCheckItem(orgDb,info.Serialno)
83
+	// 					//根据item里的数据,查询检验结果
84
+	// 					if len(scdcItemList) > 0 {
85
+	// 						for _,item := range scdcItemList {
86
+	// 							resultList,_ := GetScCdkfyyResult(orgDb,item.Serialno,item.Itemcode)
87
+	// 							if len(resultList) > 0 {
88
+	// 								for _ ,resultinfo := range resultList{
89
+	// 									LgthScdckfyySync(resultinfo,item, org_id, patient_id)
90
+	// 								}
91
+	// 							}
92
+	// 						}
93
+	// 					}
94
+	// 				}
95
+	// 			}
96
+	// 		}
97
+	// 	}
98
+	// }
99
+	var syncInfo models.MiddleSyncInfo
100
+	syncInfo.OrgId = org_id
101
+	syncInfo.SyncTime = time.Now().Unix()
102
+	syncInfo.SyncResultType = 1
103
+	syncInfo.SyncRsultRemark = "同步成功"
104
+	syncInfo.SyncTotalNum = 0
105
+	syncInfo.SyncSuccessNum = 0
106
+	syncInfo.SyncInfo = ""
107
+	syncInfo.CreateTime = time.Now().Unix()
108
+	syncInfo.UpdateTime = time.Now().Unix()
109
+
110
+	cwderr := CreateSyncInfo(&syncInfo)
111
+	if cwderr != nil {
112
+		utils.ErrorLog("创建同步信息失败:%v", cwderr)
113
+		return
114
+	}
115
+	SyncToSccdkfyy()
116
+	return
117
+}
118
+
119
+func SyncToSccdkfyy() {
120
+	utils.TraceLog("检验检查同步任务开始执行")
121
+	org_id := int64(10551)
122
+
123
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
124
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
125
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
126
+
127
+	// 第二步:将数据同步到业务库
128
+	if len(inspection_references) > 0 {
129
+		for _, inspection_reference := range inspection_references {
130
+			SyncInspectionReference(&inspection_reference)
131
+		}
132
+	}
133
+
134
+	if len(inspections) > 0 {
135
+		for _, inspection := range inspections {
136
+			SyncInspection(&inspection)
137
+		}
138
+	}
139
+	utils.SuccessLog("检验检查同步任务完成")
140
+}
141
+
142
+func GetScCdkfyyAnti(rdb *gorm.DB, test_order_no string) (record []*models.VYunjingPatientLabAnti, err error) {
143
+	err = rdb.Model(&models.VYunjingPatientLabAnti{}).Where("TEST_ORDER_NO = ?", test_order_no).Find(&record).Error
144
+	return
145
+}
146
+
147
+func GetPatientsInfoBySfzh(sfzh string, org_id int64) (info models.Patients, err error) {
148
+	err = readDb.Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ?", sfzh, org_id).First(&info).Error
149
+	return
150
+}
151
+
152
+func GetScdckfyyLis(rdb *gorm.DB, synctime string) (record []*models.VYunjingPatientLabItems, err error) {
153
+	err = rdb.Model(&models.VYunjingPatientLabItems{}).Where("CREATE_AT >= ? ", synctime).Find(&record).Error
154
+	return
155
+}
156
+
157
+
158
+func SyncToScdckfyytx() {
159
+	utils.TraceLog("检验检查同步任务开始执行")
160
+	org_id := int64(10551)
161
+
162
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
163
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
164
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
165
+
166
+	// 第二步:将数据同步到业务库
167
+	if len(inspection_references) > 0 {
168
+		for _, inspection_reference := range inspection_references {
169
+			SyncInspectionReference(&inspection_reference)
170
+		}
171
+	}
172
+
173
+	if len(inspections) > 0 {
174
+		for _, inspection := range inspections {
175
+			SyncInspection(&inspection)
176
+		}
177
+	}
178
+	utils.SuccessLog("检验检查同步任务完成")
179
+}
180
+
181
+
182
+// 从机构将数据同步到中间库
183
+func LgthScdckfyySync(result *models.VYunjingPatientLabAnti, checkItem *models.VYunjingPatientLabItems, org_id int64, patient_id int64) (*models.MiddleInspectionReference, error) {
184
+	tx := writeMiddleDb.Begin()
185
+	var inspection models.MiddleInspection
186
+	var inspection_reference models.MiddleInspectionReference
187
+
188
+	timstr := strings.Split(checkItem.CreateAt, "T")
189
+	timstem := strings.Split(timstr[1], "Z")
190
+	recordDateStr := timstr[0] + " " + timstem[0]
191
+	utils.InfoLog("recordDateStr: %v", recordDateStr)
192
+
193
+	if len(recordDateStr) == 0 {
194
+		recordDateStr = time.Now().Format("2006-01-02 15:04")
195
+	}
196
+
197
+	
198
+
199
+	record_date_str, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
200
+	utils.InfoLog("record_date_str: %v", record_date_str)
201
+	record_date := record_date_str.Unix()
202
+	utils.InfoLog("record_date: %v", record_date)
203
+	inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
204
+	utils.InfoLog("inspect_date: %v", inspect_date)
205
+
206
+	var total int
207
+	var RangeOptions string
208
+	var RangeMin string
209
+	var RangeMax string
210
+
211
+	// // 判断检查类型
212
+	ItemType := 1
213
+	Range := strings.Split(result.ReferRange, "-")
214
+	if len(Range) > 1 {
215
+		RangeMin = Range[0]
216
+		RangeMax = Range[1]
217
+		ItemType = 1
218
+	} else {
219
+		ItemType = 2
220
+		RangeOptions = result.ReferRange
221
+	}
222
+
223
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_name = ? and item_name = ? and status = 1", org_id,checkItem.ItemTypeName,result.AntiName).Find(&inspection_reference).Count(&total).Error
224
+	if inspection_reference.ID > 0 {
225
+		ItemType = inspection_reference.RangeType
226
+	}
227
+	if total <= 0 {
228
+		//  如果配置表里没有相关配置,则创建project_id,item_id和相关配置信息
229
+		project_id, _ := GetSccdkfyyProjectID(org_id,checkItem.ItemTypeName)
230
+		item_id,_ := GetSccdkfyyItemID(org_id, checkItem.ItemTypeName, result.AntiName, project_id)
231
+
232
+		inspection_reference.OrgId = org_id
233
+		inspection_reference.ProjectName = checkItem.ItemTypeName
234
+		inspection_reference.Project = checkItem.ItemType
235
+		inspection_reference.ProjectId = project_id
236
+		inspection_reference.ItemName = result.AntiName
237
+		inspection_reference.ItemNameAddition = result.AntiName
238
+		inspection_reference.ItemId = item_id
239
+		inspection_reference.ItemCode = result.AntiName
240
+		inspection_reference.RangeType = ItemType
241
+		inspection_reference.RangeMin = RangeMin
242
+		inspection_reference.RangeMax = RangeMax
243
+		// inspection_reference.RangeValue = RangeValue
244
+		inspection_reference.RangeOptions = RangeOptions
245
+		inspection_reference.Unit = result.Unit
246
+		inspection_reference.Status = 1
247
+		inspection_reference.CreatedTime = time.Now().Unix()
248
+		inspection_reference.UpdatedTime = time.Now().Unix()
249
+		inspection_reference.InspectDate = inspect_date
250
+		inspection_reference.UTime = inspect_date
251
+		err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
252
+		if err != nil {
253
+			tx.Rollback()
254
+		}
255
+	}
256
+
257
+	var itotal int
258
+	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, inspection_reference.ProjectId, inspection_reference.ItemId, record_date, patient_id).Find(&inspection).Count(&itotal).Error
259
+	if itotal <= 0 {
260
+		result.TestResult = strings.Replace(result.TestResult, "&gt;", ">", -1)
261
+		result.TestResult = strings.Replace(result.TestResult, "&lt;", "<", -1)
262
+		inspection.PatientId = patient_id
263
+		inspection.OrgId = org_id
264
+		inspection.ProjectId = inspection_reference.ProjectId
265
+		inspection.ItemName = inspection_reference.ItemName
266
+		inspection.ProjectName = inspection_reference.ProjectName
267
+		inspection.InspectType = ItemType
268
+		inspection.ItemId = inspection_reference.ItemId
269
+		inspection.InspectValue = result.TestResult
270
+		inspection.InspectDate = inspect_date
271
+		inspection.RecordDate = record_date
272
+		inspection.InspectTips = result.AntiCode
273
+		inspection.Status = 1
274
+		inspection.CreatedTime = time.Now().Unix()
275
+		inspection.UpdatedTime = time.Now().Unix()
276
+		inspection.UTime = inspect_date
277
+		inspection.HisUserId = strconv.FormatInt(patient_id, 10)
278
+		err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
279
+		if err != nil {
280
+			tx.Rollback()
281
+		}
282
+	}
283
+	tx.Commit()
284
+	return nil, err
285
+}
286
+
287
+func GetProjectInfoSccdkfyy(item_id int64, org_id int64) (project_info models.MiddleInspectionReference, err error) {
288
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and item_id = ?", org_id, item_id).First(&project_info).Error
289
+	return
290
+}
291
+
292
+
293
+// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
294
+func GetSccdkfyyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
295
+	var inspection_reference models.MiddleInspectionReference
296
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
297
+	if inspection_reference.ID > 0 {
298
+		return inspection_reference.ItemId, err
299
+	} else {
300
+		err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
301
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
302
+		if inspection_reference.ItemId > 0 {
303
+			return inspection_reference.ItemId + 1, err
304
+		} else {
305
+			return project_id*100 + 1, err
306
+		}
307
+	}
308
+}
309
+
310
+
311
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
312
+func GetSccdkfyyProjectID(org_id int64, project_name string) (project_id int64, err error) {
313
+	var inspection_reference models.MiddleInspectionReference
314
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
315
+	if inspection_reference.ID > 0 {
316
+		return inspection_reference.ProjectId, err
317
+	} else {
318
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
319
+		if inspection_reference.ProjectId > 0 {
320
+			return inspection_reference.ProjectId + 1, err
321
+		} else {
322
+			return 1055101, err
323
+		}
324
+	}
325
+}
326
+
327
+func GetScCdkfyyResult(rdb *gorm.DB, serialNo string,parItemNo string) (record []*models.PlugPlugresult, err error) {
328
+	err = rdb.Model(&models.PlugPlugresult{}).Where("serialNo = ? and parItemNo = ?", serialNo,parItemNo).Find(&record).Error
329
+	return
330
+}
331
+
332
+func GetScCdkfyyCheckItem(rdb *gorm.DB, serialNo string) (record []*models.PlugPlugcheckitem, err error) {
333
+	err = rdb.Model(&models.PlugPlugcheckitem{}).Where("serialNo = ? ", serialNo).Find(&record).Error
334
+	return
335
+}
336
+
337
+func GetScCdkfyyCase(rdb *gorm.DB, startId int64,endId int64, hisuserid string) (record []*models.PlugPlugcase, err error) {
338
+	err = rdb.Model(&models.PlugPlugcase{}).Where("ID >= ? and ID <= ? and mainIndex = ?", startId,endId, hisuserid).Find(&record).Error
339
+	return
340
+}
341
+
342
+func GetScCdkfyyCaseMaxID(rdb *gorm.DB) (record models.PlugPlugcase, err error) {
343
+	err = rdb.Model(&models.PlugPlugcase{}).Select("TOP 1 *").Order("ID desc").Find(&record).Error
344
+	return
345
+}

+ 277 - 0
service/sy_service.go Bestand weergeven

@@ -0,0 +1,277 @@
1
+package service
2
+
3
+// 三优 检验检查对接
4
+import (
5
+	"IC/models"
6
+	"IC/utils"
7
+	_ "encoding/json"
8
+	_ "encoding/xml"
9
+	"github.com/jinzhu/gorm"
10
+	_ "github.com/jinzhu/gorm"
11
+	_"strconv"
12
+	"strings"
13
+	"time"
14
+	"fmt"
15
+)
16
+
17
+type stsylis struct {
18
+	Testno    	string  `gorm:"column:testno " json:"testno "`
19
+	Seqno    	string  `gorm:"column:seqno  " json:"seqno  "`
20
+	Itemno     	string  `gorm:"column:itemno " json:"itemno "`
21
+	Itemname  	string  `gorm:"column:itemname" json:"itemname"`
22
+	Testresult  string  `gorm:"column:testresult" json:"testresult"`
23
+	Result1  	string  `gorm:"column:result1" json:"result1"`
24
+	Result2     string  `gorm:"column:result2" json:"result2"`
25
+	Resultflag	string  `gorm:"column:resultflag" json:"resultflag"`
26
+	Units    	string  `gorm:"column:units" json:"units"`
27
+	Ranges     	string  `gorm:"column:ranges" json:"ranges"`
28
+	Resulttime	string  `gorm:"column:resulttime" json:"resulttime"`
29
+	Checkman   	string  `gorm:"column:checkman" json:"checkman"`
30
+	Testman 	string  `gorm:"column:testman" json:"testman"`
31
+	Lastmodify	string  `gorm:"column:lastmodify" json:"lastmodify"`
32
+	Instrument	string  `gorm:"column:instrument" json:"instrument"`
33
+	Sampleno	string  `gorm:"column:sampleno" json:"sampleno"`
34
+	Brdh        string  `gorm:"column:brdh" json:"brdh"`
35
+	Brxm        string  `gorm:"column:brxm" json:"brxm"`
36
+	Sfxmdh      string  `gorm:"column:sfxmdh" json:"sfxmdh"`
37
+	Sendflag    string  `gorm:"column:sendflag" json:"sendflag"`
38
+	Myid        string  `gorm:"column:myid" json:"myid"`
39
+	Uploadflag  string  `gorm:"column:uploadflag" json:"uploadflag"`
40
+}
41
+
42
+func (stsylis) TableName() string {
43
+	return "lis_reqresult"
44
+}
45
+
46
+func GetStsyLis(rdb *gorm.DB, synctime time.Time) (record []*stsylis, err error) {
47
+	err = rdb.Model(&stsylis{}).Where("resulttime >= ? ", synctime).Find(&record).Error
48
+	return
49
+}
50
+
51
+// 根据机构ID和患者姓名获取患者信息
52
+func GetUserInfoByName(org_id int64,name string) (patients models.Patients, err error) {
53
+	err = readDb.Model(&models.Patients{}).Where("user_org_id = ? and status = 1 and name = ?", org_id,name).First(&patients).Error
54
+	return
55
+}
56
+
57
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
58
+func GetStsyProjectID(org_id int64, project_name string,item_name string) (project_id int64, err error) {
59
+	var inspection_reference models.MiddleInspectionReference
60
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ?  and item_name = ? ", org_id, project_name, item_name).First(&inspection_reference).Error
61
+	if inspection_reference.ID > 0 {
62
+		return inspection_reference.ProjectId, err
63
+	} else {
64
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
65
+		if inspection_reference.ProjectId > 0 {
66
+			return inspection_reference.ProjectId + 1, err
67
+		} else {
68
+			return 1022301, err
69
+		}
70
+	}
71
+}
72
+
73
+// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
74
+func GetStsyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
75
+	var inspection_reference models.MiddleInspectionReference
76
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ? and item_name = ?", org_id, project_name, item_name).First(&inspection_reference).Error
77
+	if inspection_reference.ID > 0 {
78
+		return inspection_reference.ItemId, err
79
+	} else {
80
+		err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
81
+		if inspection_reference.ItemId > 0 {
82
+			return inspection_reference.ItemId + 1, err
83
+		} else {
84
+			return project_id*100 + 1, err
85
+		}
86
+	}
87
+}
88
+
89
+// 汕头三优血液透析中心
90
+func SyncStsyLis() (err error) {
91
+	org_id := int64(10223)
92
+
93
+	org := &models.DataUploadConfig{
94
+		OrgId:  org_id,
95
+		DbHost: "127.0.0.1",
96
+		DbPort: "1433",
97
+		DbPass: "Aa123456",
98
+		DbUser: "kyys",
99
+		DbName: "lis2022",
100
+	}
101
+
102
+	orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
103
+	if err != nil {
104
+		utils.ErrorLog("创建数据库连接失败:%v", err)
105
+		return
106
+	}
107
+
108
+	// var sync_time int64
109
+	// sync_time = 1627747200
110
+
111
+	// scpaLis, _ := GetScpaLis(orgDb, sync_time,"512926196302182682")
112
+	// utils.InfoLog("IdCardNo:%v",scpaLis)
113
+
114
+	// 第一步:获取上一次同步的时间点
115
+	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
116
+	var sync_time int64
117
+	if syncLastInfo.ID > 0 {
118
+		sync_time = syncLastInfo.SyncTime
119
+	} else {
120
+		sync_time = 1685548800
121
+	}
122
+
123
+	SyncTime := time.Unix(sync_time,0)
124
+
125
+	fmt.Println(SyncTime)
126
+	// 第二步:获取时间内所有检验结果
127
+	stsyLis, _ := GetStsyLis(orgDb, SyncTime)
128
+
129
+	if len(stsyLis) > 0 {
130
+		for _,LisInfo := range stsyLis{
131
+			brxm := LisInfo.Brxm
132
+			// 根据姓名获取患者ID
133
+			patient,_ := GetUserInfoByName(org_id,brxm)
134
+			if patient.ID > 0 {
135
+				project_id, _ := GetStsyProjectID(org_id, LisInfo.Instrument, LisInfo.Itemname)
136
+				item_id, _ := GetStsyItemID(org_id, LisInfo.Instrument, LisInfo.Itemname, project_id)
137
+				tx := writeMiddleDb.Begin()
138
+				var inspection models.MiddleInspection
139
+				var inspection_reference models.MiddleInspectionReference
140
+
141
+				timeLayout := "2006-01-02 15:04"
142
+				loc, _ := time.LoadLocation("Local")
143
+
144
+				tempTime := strings.Split(LisInfo.Lastmodify, "T")
145
+				tempTime1 := strings.Split(tempTime[1], ".")
146
+				tempRecord := tempTime[0] + " " + tempTime1[0]
147
+
148
+				recordTime, _ := time.ParseInLocation("2006-01-02 15:04:05", tempRecord, loc)
149
+				recordTimeInt := recordTime.Unix()
150
+				recordTimeStr := time.Unix(recordTimeInt,0).Format(timeLayout)
151
+
152
+				var total int
153
+				var RangeOptions string
154
+				var RangeMin string
155
+				var RangeMax string
156
+				var ItemType int
157
+				Range := strings.Split(LisInfo.Ranges, "--")
158
+				if len(Range) > 1 {
159
+					RangeMin = Range[0]
160
+					RangeMax = Range[1]
161
+					ItemType = 1
162
+				} else {
163
+					ItemType = 2
164
+					RangeOptions = LisInfo.Ranges
165
+				}
166
+
167
+				err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
168
+				if total <= 0 {
169
+					inspection_reference.OrgId = org_id
170
+					inspection_reference.ProjectName = LisInfo.Instrument
171
+					inspection_reference.Project = LisInfo.Instrument
172
+					inspection_reference.ProjectId = project_id
173
+					inspection_reference.ItemName = LisInfo.Itemname
174
+					// inspection_reference.ItemNameAddition = strconv.FormatInt(info.ItemId, 10)
175
+					inspection_reference.ItemId = item_id
176
+					inspection_reference.RangeType = ItemType
177
+					inspection_reference.RangeMin = RangeMin
178
+					inspection_reference.RangeMax = RangeMax
179
+					// inspection_reference.RangeValue = RangeValue
180
+					inspection_reference.RangeOptions = RangeOptions
181
+					inspection_reference.Unit = LisInfo.Units
182
+					inspection_reference.Status = 1
183
+					inspection_reference.CreatedTime = time.Now().Unix()
184
+					inspection_reference.UpdatedTime = time.Now().Unix()
185
+					inspection_reference.InspectDate = recordTimeStr
186
+					inspection_reference.UTime = recordTimeStr
187
+					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
188
+					if err != nil {
189
+						tx.Rollback()
190
+					}
191
+				}
192
+				var itotal int
193
+				err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and project_id = ? and item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, project_id, item_id, recordTimeInt, patient.ID).Find(&inspection).Count(&itotal).Error
194
+				if itotal <= 0 {
195
+					// inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
196
+					// inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)
197
+					inspection.PatientId = patient.ID
198
+					inspection.OrgId = org_id
199
+					inspection.ProjectId = project_id
200
+					inspection.ItemName = inspection_reference.ItemName
201
+					inspection.ProjectName = inspection_reference.ProjectName
202
+					inspection.InspectType = ItemType
203
+					inspection.ItemId = item_id
204
+					inspection.InspectValue = LisInfo.Testresult
205
+					inspection.InspectDate = recordTimeStr
206
+					inspection.RecordDate = recordTimeInt
207
+					// inspection.InspectTips = report.Resultstate
208
+					inspection.Status = 1
209
+					inspection.CreatedTime = time.Now().Unix()
210
+					inspection.UpdatedTime = time.Now().Unix()
211
+					// inspection.UTime = record_date.Format(timeLayout)
212
+					// inspection.HisUserId = strconv.FormatInt(patient_id, 10)
213
+					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
214
+					if err != nil {
215
+						tx.Rollback()
216
+					}
217
+				}
218
+				tx.Commit()
219
+			} else {
220
+				continue
221
+			}
222
+		}				
223
+	}
224
+	var syncInfo models.MiddleSyncInfo
225
+	syncInfo.OrgId = org_id
226
+	syncInfo.SyncTime = time.Now().Unix()
227
+	syncInfo.SyncResultType = 1
228
+	syncInfo.SyncRsultRemark = "同步成功"
229
+	syncInfo.SyncTotalNum = 0
230
+	syncInfo.SyncSuccessNum = 0
231
+	syncInfo.SyncInfo = ""
232
+	syncInfo.CreateTime = time.Now().Unix()
233
+	syncInfo.UpdateTime = time.Now().Unix()
234
+
235
+	cwderr := CreateSyncInfo(&syncInfo)
236
+	if cwderr != nil {
237
+		utils.ErrorLog("创建同步信息失败:%v", cwderr)
238
+		return
239
+	}
240
+	SyncToStsytx()
241
+	return
242
+}
243
+
244
+// func deleteMid(tx *gorm.DB) (err error) {
245
+// 	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock as t," +
246
+// 		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
247
+// 		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
248
+// 		"WHERE t1.user_org_id = t2.orgid)tmp " +
249
+// 		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
250
+// 		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
251
+// 	return
252
+// }
253
+
254
+
255
+func SyncToStsytx() {
256
+
257
+	utils.TraceLog("检验检查同步任务开始执行")
258
+	org_id := int64(10223)
259
+
260
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
261
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
262
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
263
+
264
+	// 第二步:将数据同步到业务库
265
+	if len(inspection_references) > 0 {
266
+		for _, inspection_reference := range inspection_references {
267
+			SyncInspectionReference(&inspection_reference)
268
+		}
269
+	}
270
+
271
+	if len(inspections) > 0 {
272
+		for _, inspection := range inspections {
273
+			SyncInspection(&inspection)
274
+		}
275
+	}
276
+	utils.SuccessLog("检验检查同步任务完成")
277
+}

+ 3 - 10
service/wfnfm_service.go Bestand weergeven

@@ -75,13 +75,6 @@ func FindDoctorAdviceOrderById(orgID int64,patientId int64, recordDate int64) (p
75 75
 	return
76 76
 }
77 77
 
78
-type DataUploadConfig struct {
79
-	DbHost         string `gorm:"column:db_host" json:"db_host"`
80
-	DbPort         string `gorm:"column:db_port" json:"db_port"`
81
-	DbUser         string `gorm:"column:db_user" json:"db_user"`
82
-	DbPass         string `gorm:"column:db_pass" json:"db_pass"`
83
-	DbName         string `gorm:"column:db_name" json:"db_name"`
84
-}
85 78
 
86 79
 func BatchCreateRecord(ps *models.EmrBloodDialyRecord, rdb *gorm.DB) (err error) {
87 80
 	err = rdb.Create(&ps).Error
@@ -100,7 +93,7 @@ func BatchCreateOrder(ps *models.EmrBloodDialyOrder, rdb *gorm.DB) (err error) {
100 93
 
101 94
 // 潍坊内分泌医院 同步健康数据上报
102 95
 func  EmrBloodDiaylOrder() {
103
-	org := &DataUploadConfig{
96
+	org := &models.DataUploadConfig{
104 97
 		DbHost:         "127.0.0.1",
105 98
 		DbPort:         "1433",
106 99
 		DbPass:         "Aa123456",
@@ -205,7 +198,7 @@ func  EmrBloodDiaylOrder() {
205 198
 
206 199
 // 潍坊内分泌医院 同步健康数据上报
207 200
 func  EmrBloodDiaylDetail() {
208
-	org := &DataUploadConfig{
201
+	org := &models.DataUploadConfig{
209 202
 		DbHost:         "localhost",
210 203
 		DbPort:         "1433",
211 204
 		DbPass:         "Aa123456",
@@ -303,7 +296,7 @@ func  EmrBloodDiaylDetail() {
303 296
 
304 297
 // 潍坊内分泌医院 同步健康数据上报
305 298
 func  EmrBloodDiaylRecord() {
306
-	org := &DataUploadConfig{
299
+	org := &models.DataUploadConfig{
307 300
 		DbHost:         "localhost",
308 301
 		DbPort:         "1433",
309 302
 		DbPass:         "Aa123456",

+ 2 - 25
service/ystx_service.go Bestand weergeven

@@ -200,7 +200,7 @@ func SyncLisYstx() (err error) {
200 200
 	// 第一步:获取艾迪康下发的Key
201 201
 	org_id := int64(9919)
202 202
 	login := "R26028"
203
-	password := "abc123"
203
+	password := "Abc123456@"
204 204
 	key := GetAdKey(login, password)
205 205
 	// 第二步:获取上一次同步的时间点
206 206
 	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
@@ -368,7 +368,7 @@ func YsReportInfoHandle(CheckInfo adkCheck, org_id int64, patientId int64) {
368 368
 		}
369 369
 	}
370 370
 
371
-	SyncToYstx()
371
+	SyncToGzczjhtx()
372 372
 }
373 373
 
374 374
 type adkResult struct {
@@ -502,29 +502,6 @@ func LgthYsSync(report adkResult, project_id int64, item_id int64, org_id int64,
502 502
 	return nil, err
503 503
 }
504 504
 
505
-func SyncToYstx() {
506
-	utils.TraceLog("检验检查同步任务开始执行")
507
-	org_id := int64(9919)
508
-
509
-	// 第一步:跟进org_id 去中间库查出需要同步的数据
510
-	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
511
-	inspections, _ := GetSyncInspectionByOrgId(org_id)
512
-
513
-	// 第二步:将数据同步到业务库
514
-	if len(inspection_references) > 0 {
515
-		for _, inspection_reference := range inspection_references {
516
-			SyncInspectionReference(&inspection_reference)
517
-		}
518
-	}
519
-
520
-	if len(inspections) > 0 {
521
-		for _, inspection := range inspections {
522
-			SyncInspection(&inspection)
523
-		}
524
-	}
525
-	utils.SuccessLog("检验检查同步任务完成")
526
-}
527
-
528 505
 // 根据姓名获取patient_id
529 506
 func GetPatientGzjhList(org_id int64, schedulesTime int64) (schedules []*models.DialysisSchedule, err error) {
530 507
 	err = readDb.Model(&models.DialysisSchedule{}).Where("user_org_id = ? and status = 1 and  schedule_date = ?", org_id, schedulesTime).Preload("Patients", "status = 1").Find(&schedules).Error

+ 37 - 0
tf日志/tf_20220808_log.txt Bestand weergeven

@@ -0,0 +1,37 @@
1
+记录日志
2
+
3
+
4
+2022-08-08 09:50:00 【 tftf入参 】:
5
+{"开嘱时间":"2022-08-08 09:49:00","病人来源":"1","身份证号":""}
6
+2022-08-08 09:50:00 【 tftf出参 】:
7
+{"msg":"成功","result":[],"code":"10000"}
8
+
9
+
10
+2022-08-08 09:51:00 【 tftf入参 】:
11
+{"开嘱时间":"2022-08-08 09:50:00","病人来源":"1","身份证号":""}
12
+2022-08-08 09:51:00 【 tftf出参 】:
13
+{"msg":"成功","result":[],"code":"10000"}
14
+
15
+
16
+2022-08-08 09:52:00 【 tftf入参 】:
17
+{"开嘱时间":"2022-08-08 09:51:00","病人来源":"1","身份证号":""}
18
+2022-08-08 09:52:00 【 tftf出参 】:
19
+{"msg":"成功","result":[],"code":"10000"}
20
+
21
+
22
+2022-08-08 09:53:00 【 tftf入参 】:
23
+{"开嘱时间":"2022-08-08 09:52:00","病人来源":"1","身份证号":""}
24
+2022-08-08 09:53:00 【 tftf出参 】:
25
+{"msg":"成功","result":[],"code":"10000"}
26
+
27
+
28
+2022-08-08 09:54:00 【 tftf入参 】:
29
+{"开嘱时间":"2022-08-08 09:53:00","病人来源":"1","身份证号":""}
30
+2022-08-08 09:54:00 【 tftf出参 】:
31
+{"msg":"成功","result":[],"code":"10000"}
32
+
33
+
34
+2022-08-08 09:55:00 【 tftf入参 】:
35
+{"开嘱时间":"2022-08-08 09:54:00","病人来源":"1","身份证号":""}
36
+2022-08-08 09:55:00 【 tftf出参 】:
37
+{"msg":"成功","result":[],"code":"10000"}

+ 43 - 0
tf日志/tf_20220809_log.txt Bestand weergeven

@@ -0,0 +1,43 @@
1
+记录日志
2
+
3
+
4
+2022-08-09 15:09:00 【 tftf入参 】:
5
+{"开嘱时间":"2022-08-09 15:09:00","病人来源":"1","身份证号":"999999190001018888"}
6
+2022-08-09 15:09:00 【 tftf出参 】:
7
+{"msg":"成功","result":[],"code":"10000"}
8
+
9
+
10
+2022-08-09 15:09:00 【 tftf入参 】:
11
+{"开嘱时间":"2022-08-09 15:09:00","病人来源":"1","身份证号":"430581200205182779"}
12
+2022-08-09 15:09:00 【 tftf出参 】:
13
+{"msg":"成功","result":[],"code":"10000"}
14
+
15
+
16
+2022-08-09 15:09:00 【 tftf入参 】:
17
+{"开嘱时间":"2022-08-09 15:09:00","病人来源":"1","身份证号":"350425200411242430"}
18
+2022-08-09 15:09:00 【 tftf出参 】:
19
+{"msg":"成功","result":[],"code":"10000"}
20
+
21
+
22
+2022-08-09 15:10:00 【 tftf入参 】:
23
+{"开嘱时间":"2022-08-09 15:10:00","病人来源":"1","身份证号":"999999190001019999"}
24
+2022-08-09 15:10:00 【 tftf出参 】:
25
+{"msg":"成功","result":[],"code":"10000"}
26
+
27
+
28
+2022-08-09 15:10:00 【 tftf入参 】:
29
+{"开嘱时间":"2022-08-09 15:10:00","病人来源":"1","身份证号":"999999190001018888"}
30
+2022-08-09 15:10:00 【 tftf出参 】:
31
+{"msg":"成功","result":[],"code":"10000"}
32
+
33
+
34
+2022-08-09 15:10:00 【 tftf入参 】:
35
+{"开嘱时间":"2022-08-09 15:10:00","病人来源":"1","身份证号":"430581200205182779"}
36
+2022-08-09 15:10:00 【 tftf出参 】:
37
+{"msg":"成功","result":[],"code":"10000"}
38
+
39
+
40
+2022-08-09 15:10:00 【 tftf入参 】:
41
+{"开嘱时间":"2022-08-09 15:10:00","病人来源":"1","身份证号":"350425200411242430"}
42
+2022-08-09 15:10:00 【 tftf出参 】:
43
+{"msg":"成功","result":[],"code":"10000"}

+ 85 - 0
tf日志/tf_20220810_log.txt Bestand weergeven

@@ -0,0 +1,85 @@
1
+记录日志
2
+
3
+
4
+2022-08-10 20:31:00 【 tftf入参 】:
5
+{"开嘱时间":"2022-08-10 20:31:00","病人来源":"1","身份证号":"350425200411242430"}
6
+2022-08-10 20:31:00 【 tftf出参 】:
7
+{"msg":"成功","result":[],"code":"10000"}
8
+
9
+
10
+2022-08-10 20:31:00 【 tftf入参 】:
11
+{"开嘱时间":"2022-08-10 20:31:00","病人来源":"1","身份证号":"35062319500804667X"}
12
+2022-08-10 20:31:00 【 tftf出参 】:
13
+{"msg":"成功","result":[],"code":"10000"}
14
+
15
+
16
+2022-08-10 20:32:00 【 tftf入参 】:
17
+{"开嘱时间":"2022-08-10 20:32:00","病人来源":"1","身份证号":"350623198802116616"}
18
+2022-08-10 20:32:00 【 tftf出参 】:
19
+{"msg":"成功","result":[],"code":"10000"}
20
+
21
+
22
+2022-08-10 20:32:00 【 tftf入参 】:
23
+{"开嘱时间":"2022-08-10 20:32:00","病人来源":"1","身份证号":"350425200411242430"}
24
+2022-08-10 20:32:00 【 tftf出参 】:
25
+{"msg":"成功","result":[],"code":"10000"}
26
+
27
+
28
+2022-08-10 20:32:00 【 tftf入参 】:
29
+{"开嘱时间":"2022-08-10 20:32:00","病人来源":"1","身份证号":"35062319500804667X"}
30
+2022-08-10 20:32:00 【 tftf出参 】:
31
+{"msg":"成功","result":[],"code":"10000"}
32
+
33
+
34
+2022-08-10 20:33:00 【 tftf入参 】:
35
+{"开嘱时间":"2022-08-10 20:33:00","病人来源":"1","身份证号":"350623198802116616"}
36
+2022-08-10 20:33:00 【 tftf出参 】:
37
+{"msg":"成功","result":[],"code":"10000"}
38
+
39
+
40
+2022-08-10 20:33:00 【 tftf入参 】:
41
+{"开嘱时间":"2022-08-10 20:33:00","病人来源":"1","身份证号":"350425200411242430"}
42
+2022-08-10 20:33:00 【 tftf出参 】:
43
+{"msg":"成功","result":[],"code":"10000"}
44
+
45
+
46
+2022-08-10 20:33:01 【 tftf入参 】:
47
+{"开嘱时间":"2022-08-10 20:33:00","病人来源":"1","身份证号":"35062319500804667X"}
48
+2022-08-10 20:33:01 【 tftf出参 】:
49
+{"msg":"成功","result":[],"code":"10000"}
50
+
51
+
52
+2022-08-10 20:37:00 【 tftf入参 】:
53
+{"开嘱时间":"2022-08-10 20:37:00","病人来源":"1","身份证号":"350623198802116616"}
54
+2022-08-10 20:37:00 【 tftf出参 】:
55
+{"msg":"成功","result":[],"code":"10000"}
56
+
57
+
58
+2022-08-10 20:37:00 【 tftf入参 】:
59
+{"开嘱时间":"2022-08-10 20:37:00","病人来源":"1","身份证号":"350425200411242430"}
60
+2022-08-10 20:37:00 【 tftf出参 】:
61
+{"msg":"成功","result":[],"code":"10000"}
62
+
63
+
64
+2022-08-10 20:37:00 【 tftf入参 】:
65
+{"开嘱时间":"2022-08-10 20:37:00","病人来源":"1","身份证号":"35062319500804667X"}
66
+2022-08-10 20:37:00 【 tftf出参 】:
67
+{"msg":"成功","result":[],"code":"10000"}
68
+
69
+
70
+2022-08-10 20:39:00 【 tftf入参 】:
71
+{"开嘱时间":"2022-08-10 20:39:00","病人来源":"1","身份证号":"350623198802116616"}
72
+2022-08-10 20:39:00 【 tftf出参 】:
73
+{"msg":"成功","result":[],"code":"10000"}
74
+
75
+
76
+2022-08-10 20:39:00 【 tftf入参 】:
77
+{"开嘱时间":"2022-08-10 20:39:00","病人来源":"1","身份证号":"350425200411242430"}
78
+2022-08-10 20:39:00 【 tftf出参 】:
79
+{"msg":"成功","result":[],"code":"10000"}
80
+
81
+
82
+2022-08-10 20:39:00 【 tftf入参 】:
83
+{"开嘱时间":"2022-08-10 20:39:00","病人来源":"1","身份证号":"35062319500804667X"}
84
+2022-08-10 20:39:00 【 tftf出参 】:
85
+{"msg":"成功","result":[],"code":"10000"}