张保健 5 месяцев назад
Родитель
Сommit
9be80b40f4
9 измененных файлов: 1486 добавлений и 261 удалений
  1. 18 0
      controllers/lis.go
  2. 107 80
      models/lis_model.go
  3. 5 3
      routers/router.go
  4. 34 64
      service/cron.go
  5. 86 48
      service/lis_service.go
  6. 2 7
      service/pajm_service.go
  7. 1008 0
      service/sssy_service.go
  8. 33 34
      service/sy_service.go
  9. 193 25
      service/tscyyy_service.go

+ 18 - 0
controllers/lis.go Просмотреть файл

@@ -35,6 +35,15 @@ func (c *LisController) Schedule() {
35 35
 
36 36
 }
37 37
 
38
+// 石狮盛誉LIS同步
39
+func (c *LisController) SyncSssy() {
40
+	service.SyncToSssytx()
41
+	c.ServeSuccessJSON(map[string]interface{}{
42
+		"resultList": "12345",
43
+	})
44
+	return
45
+}
46
+
38 47
 func (c *LisController) SyncTest() {
39 48
 	// 获取备份库里所有的医嘱信息
40 49
 	// service.EmrBloodDiaylOrder()
@@ -64,6 +73,15 @@ func (c *LisController) SyncTscyLis() {
64 73
 	return
65 74
 }
66 75
 
76
+// 唐山朝阳医院LIS
77
+func (c *LisController) SyncTscyVipLis() {
78
+	service.SyncTscyVipLis()
79
+	c.ServeSuccessJSON(map[string]interface{}{
80
+		"resultList": "12345",
81
+	})
82
+	return
83
+}
84
+
67 85
 func (c *LisController) SyncShLis() {
68 86
 	// 获取备份库里所有的医嘱信息
69 87
 

+ 107 - 80
models/lis_model.go Просмотреть файл

@@ -80,20 +80,20 @@ func (DataUploadConfig) TableName() string {
80 80
 }
81 81
 
82 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"`
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 97
 }
98 98
 
99 99
 func (VYunjingPatientLabItems) TableName() string {
@@ -101,21 +101,20 @@ func (VYunjingPatientLabItems) TableName() string {
101 101
 }
102 102
 
103 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
-
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"`
119 118
 }
120 119
 
121 120
 func (VYunjingPatientLabAnti) TableName() string {
@@ -123,17 +122,17 @@ func (VYunjingPatientLabAnti) TableName() string {
123 122
 }
124 123
 
125 124
 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"`
125
+	Id              int64  `gorm:"column:ID" json:"ID"`
126
+	Oldserialno     string `gorm:"column:oldSerialNo" json:"oldSerialNo"`
127
+	Serialno        string `gorm:"column:serialNo" json:"serialNo"`
128
+	Name            string `gorm:"column:name" json:"name"`
129
+	Gender          string `gorm:"column:gender" json:"gender"`
130
+	Age             int64  `gorm:"column:age" json:"age"`
131
+	RegistrantmanId int64  `gorm:"column:registrantMan_id" json:"registrantMan_id"`
132
+	Mainindex       string `gorm:"column:mainIndex" json:"mainIndex"`
133
+	Orddoctor       string `gorm:"column:ordDoctor" json:"ordDoctor"`
134
+	Ordloc          string `gorm:"column:ordLoc" json:"ordLoc"`
135
+	Birthday        string `gorm:"column:birthDay" json:"birthDay"`
137 136
 }
138 137
 
139 138
 func (PlugPlugcase) TableName() string {
@@ -141,30 +140,30 @@ func (PlugPlugcase) TableName() string {
141 140
 }
142 141
 
143 142
 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"`
143
+	Id              int64  `gorm:"column:ID" json:"ID"`
144
+	Serialno        string `gorm:"column:serialNo" json:"serialNo"`
145
+	Itemcode        string `gorm:"column:itemCode" json:"itemCode"`
146
+	State           int64  `gorm:"column:state" json:"state"`
147
+	Itemplug        string `gorm:"column:itemPlug" json:"itemPlug"`
148
+	Checkitemid     string `gorm:"column:checkItemId" json:"checkItemId"`
149
+	Oldserialno     string `gorm:"column:oldSerialNo" json:"oldSerialNo"`
150
+	Applytime       string `gorm:"column:applyTime" json:"applyTime"`
151
+	Specimenname    string `gorm:"column:specimenName" json:"specimenName"`
152
+	Checkitemname   string `gorm:"column:checkItemName" json:"checkItemName"`
153
+	Liscollectuser  string `gorm:"column:LisCollectUser" json:"LisCollectUser"`
154
+	Liscollecttime  string `gorm:"column:LisCollectTime" json:"LisCollectTime"`
155
+	Lissignuser     string `gorm:"column:LisSignUser" json:"LisSignUser"`
156
+	Lissigntime     string `gorm:"column:LissignTime" json:"LissignTime"`
157
+	Lisacceptuser   string `gorm:"column:LisAcceptUser" json:"LisAcceptUser"`
158
+	Lisaccepttime   string `gorm:"column:LisAcceptTime" json:"LisAcceptTime"`
159
+	Lisregisteruser string `gorm:"column:LisRegisterUser" json:"LisRegisterUser"`
160
+	Lisregistertime string `gorm:"column:LisRegisterTime" json:"LisRegisterTime"`
161
+	Lischeckuser    string `gorm:"column:LisCheckUser" json:"LisCheckUser"`
162
+	Lischecktime    string `gorm:"column:LisCheckTime" json:"LisCheckTime"`
163
+	Lisrefuseuser   string `gorm:"column:LisRefuseUser" json:"LisRefuseUser"`
164
+	Lisrefusetime   string `gorm:"column:LisRefuseTime" json:"LisRefuseTime"`
165
+	Lisstatus       string `gorm:"column:LisStatus" json:"LisStatus"`
166
+	Refusereason    string `gorm:"column:RefuseReason" json:"RefuseReason"`
168 167
 }
169 168
 
170 169
 func (PlugPlugcheckitem) TableName() string {
@@ -172,18 +171,18 @@ func (PlugPlugcheckitem) TableName() string {
172 171
 }
173 172
 
174 173
 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"`
174
+	Id               int64  `gorm:"column:ID" json:"ID"`
175
+	Serialno         string `gorm:"column:serialNo" json:"serialNo"`
176
+	Testitemname     string `gorm:"column:testItemName" json:"testItemName"`
177
+	Itemcode         string `gorm:"column:itemcode" json:"itemcode"`
178
+	Paritemno        string `gorm:"column:parItemNo" json:"parItemNo"`
179
+	Reportvalueall   string `gorm:"column:reportValueAll" json:"reportValueAll"`
180
+	Testitemdatetime string `gorm:"column:testItemDateTime" json:"testItemDateTime"`
181
+	Unit             string `gorm:"column:unit" json:"unit"`
182
+	Refrange         string `gorm:"column:refrange" json:"refrange"`
183
+	Resultstatus     string `gorm:"column:resultStatus" json:"resultStatus"`
184
+	Itemorder        int64  `gorm:"column:itemOrder" json:"itemOrder"`
185
+	Checker          string `gorm:"column:checker" json:"checker"`
187 186
 }
188 187
 
189 188
 func (PlugPlugresult) TableName() string {
@@ -240,7 +239,6 @@ func (MiddlePatients) TableName() string {
240 239
 	return "xt_middle_patients"
241 240
 }
242 241
 
243
-
244 242
 type Patients struct {
245 243
 	ID              int64  `gorm:"column:id" json:"id" form:"id"`
246 244
 	UserOrgId       int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
@@ -252,6 +250,8 @@ type Patients struct {
252 250
 	ContactName     string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
253 251
 	Gender          int64  `gorm:"column:gender" json:"gender" form:"gender"`
254 252
 	Birthday        int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
253
+	Phone           string `gorm:"column:phone" json:"phone" form:"phone"`
254
+	Age             int64  `gorm:"column:age" json:"age"`
255 255
 }
256 256
 
257 257
 func (Patients) TableName() string {
@@ -412,8 +412,10 @@ type MiddleInspection struct {
412 412
 	UTime        string `gorm:"column:u_time" json:"u_time" form:"u_time"`
413 413
 	IsSync       int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
414 414
 	// SyncItemId int64 `gorm:"column:sync_item_id" json:"sync_item_id" form:"sync_item_id"`
415
-	HisUserId string `gorm:"column:his_user_id" json:"his_user_id" form:"his_user_id"`
416
-	SyncId    int64  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
415
+	HisUserId    string `gorm:"column:his_user_id" json:"his_user_id" form:"his_user_id"`
416
+	SyncId       int64  `gorm:"column:sync_id" json:"sync_id" form:"sync_id"`
417
+	SysProjectId int64  `gorm:"column:sys_project_id" json:"sys_project_id" form:"sys_project_id"`
418
+	SysItemId    int64  `gorm:"column:sys_item_id" json:"sys_item_id" form:"sys_item_id"`
417 419
 }
418 420
 
419 421
 func (MiddleInspection) TableName() string {
@@ -443,7 +445,9 @@ type MiddleInspectionReference struct {
443 445
 	IsSync           int    `gorm:"column:is_sync" json:"is_sync" form:"is_sync"`
444 446
 	UTime            string `gorm:"column:u_time" json:"u_time" form:"u_time"`
445 447
 	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"`
448
+	ItemCode         string `gorm:"column:item_code" json:"item_code" form:"item_code"`
449
+	XtProjectId      int64  `gorm:"column:xt_project_id" json:"xt_project_id" form:"xt_project_id"`
450
+	XtItemId         int64  `gorm:"column:xt_item_id" json:"xt_item_id" form:"xt_item_id"`
447 451
 }
448 452
 
449 453
 func (MiddleInspectionReference) TableName() string {
@@ -560,3 +564,26 @@ type VMItemProjectList struct {
560 564
 func (VMItemProjectList) TableName() string {
561 565
 	return "xt_his_project_list"
562 566
 }
567
+
568
+type HisLabelPrintStatusInfo struct {
569
+	ID                 int64    `gorm:"column:id" json:"id" form:"id"`
570
+	PatientId          int64    `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
571
+	Ctime              int64    `gorm:"column:ctime" json:"ctime" form:"ctime"`
572
+	Mtime              int64    `gorm:"column:mtime" json:"mtime" form:"mtime"`
573
+	Status             int64    `gorm:"column:status" json:"status" form:"status"`
574
+	IsCombinationPrint int64    `gorm:"column:is_combination_print" json:"is_combination_print" form:"is_combination_print"`
575
+	RecordDate         string   `gorm:"column:record_date" json:"record_date" form:"record_date"`
576
+	ItemIds            string   `gorm:"column:item_ids" json:"item_ids" form:"item_ids"`
577
+	UserOrgId          int64    `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
578
+	ProjectIds         string   `gorm:"column:project_ids" json:"project_ids" form:"project_ids"`
579
+	DoctorId           int64    `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
580
+	Ids                string   `gorm:"column:ids" json:"ids" form:"ids"`
581
+	IsTeam             int64    `gorm:"column:is_team" json:"is_team" form:"is_team"`
582
+	IsPrint            int64    `gorm:"column:is_print" json:"is_print" form:"is_print"`
583
+	Patient            Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
584
+	ApplyCode          string   `gorm:"column:apply_code" json:"apply_code" form:"apply_code"`
585
+}
586
+
587
+func (HisLabelPrintStatusInfo) TableName() string {
588
+	return "his_label_print_status_info"
589
+}

+ 5 - 3
routers/router.go Просмотреть файл

@@ -29,7 +29,9 @@ func init() {
29 29
 	beego.Router("/api/syncshLis", &controllers.LisController{}, "get:SyncShLis")
30 30
 	beego.Router("/api/syncszblis", &controllers.LisController{}, "get:SyncSzblLis")
31 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")
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")
35
+	beego.Router("/api/lis/sssy", &controllers.LisController{}, "get:SyncSssy")
36
+	beego.Router("/api/lis/tscyvip", &controllers.LisController{}, "get:SyncTscyVipLis")
35 37
 }

+ 34 - 64
service/cron.go Просмотреть файл

@@ -25,78 +25,48 @@ 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
-
56 28
 func BeginAutoSyncLis() {
57 29
 	utils.InfoLog("开启自动检验检查同步定时任务")
58 30
 	createLisSyncCronJob := newWithSeconds()
59 31
 
60
-	// specgzjh := "0 */1 * * * ?" // 每1分钟同步 广州暨华HIS医嘱
61
-	// createLisSyncCronJob.AddFunc(specgzjh, func() {
62
-	// 	// SyncGzjhyz()
63
-	// 	Synctfyz()
64
-	// })
65
-
66
-	// specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
67
-	// createLisSyncCronJob.AddFunc(specys, func() {
68
-	// 	SyncTscyLis()
69
-	// })
70
-
71
-	// specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
72
-	// createLisSyncCronJob.AddFunc(specys1, func() {
73
-	// 	SyncCsnyLis()
74
-	// })
75
-
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()
32
+	specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
33
+	createLisSyncCronJob.AddFunc(specys, func() {
34
+		SyncTscyLis()
35
+	})
36
+
37
+	specys1 := "0 10 */2 * * ?" // 每两个小时同步长沙南雅医院
38
+	createLisSyncCronJob.AddFunc(specys1, func() {
39
+		SyncCsnyLis()
40
+	})
41
+
42
+	spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
43
+	createLisSyncCronJob.AddFunc(spec, func() {
44
+		SyncHbdyLis()
45
+	})
46
+
47
+	spec2 := "0 50 2 * * ?" // 每天凌晨2点同步 龙岗二院
48
+	createLisSyncCronJob.AddFunc(spec2, func() {
49
+		SyncLisLgty()
50
+	})
51
+
52
+	spec3 := "0 50 3 * * ?" // 每天凌晨2点同步 广州暨华血液透析中心
53
+	createLisSyncCronJob.AddFunc(spec3, func() {
54
+		SyncLisGzjhtx()
55
+	})
56
+
57
+	spec4 := "0 20 3 * * ?" // 每天凌晨同步 石狮盛誉血液透析中心
58
+	createLisSyncCronJob.AddFunc(spec4, func() {
59
+		SyncSYData2()
60
+	})
61
+
62
+	spec5 := "0 20 4 * * ?" // 每天凌晨同步 石狮盛誉血液透析中心
63
+	createLisSyncCronJob.AddFunc(spec5, func() {
64
+		SyncTscyVipLis()
94 65
 	})
95 66
 
96 67
 	createLisSyncCronJob.Start()
97 68
 }
98 69
 
99
-
100 70
 func AutoSyncLis() {
101 71
 	utils.TraceLog("检验检查任务开始执行")
102 72
 	org_id := int64(9538)
@@ -171,7 +141,7 @@ func AutoSyncLis() {
171 141
 				}
172 142
 				// utils.InfoLog("同步信息详情:%v",syncInfo)
173 143
 				continue
174
-			} 
144
+			}
175 145
 
176 146
 			// 第四部:将同步过来的数据插入到中间库对应的表
177 147
 			syncSuccessNum := 0

+ 86 - 48
service/lis_service.go Просмотреть файл

@@ -3,28 +3,28 @@ package service
3 3
 import (
4 4
 	"IC/models"
5 5
 	"IC/utils"
6
-	_"strconv"
6
+	_ "IC/utils"
7
+	_ "fmt"
8
+	_ "github.com/jinzhu/gorm"
9
+	_ "strconv"
7 10
 	"strings"
8 11
 	"time"
9
-	_"IC/utils"
10
-	_"fmt"
11
-	_"github.com/jinzhu/gorm"
12 12
 )
13 13
 
14 14
 // 获取备份库所有的医嘱信息
15
-func GetAllAdvice() (Advice []models.DoctorAdvice,err error) {
15
+func GetAllAdvice() (Advice []models.DoctorAdvice, err error) {
16 16
 	err = backupDb.Model(&models.DoctorAdvice{}).Offset(100000).Limit(10000).Find(&Advice).Error
17 17
 	return
18 18
 }
19 19
 
20 20
 // 获取备份库所有的医嘱信息
21
-func GetScheduless(id int64) (schedule models.Schedules,err error) {
22
-	err = tempwriteDb.Model(&models.Schedules{}).Where("id = ?",id).First(&schedule).Error
21
+func GetScheduless(id int64) (schedule models.Schedules, err error) {
22
+	err = tempwriteDb.Model(&models.Schedules{}).Where("id = ?", id).First(&schedule).Error
23 23
 	return
24 24
 }
25 25
 
26
-func UpdateSchedule(id int64,status int64) error{
27
-	err := writeDb.Model(&models.Schedules{}).Where("id = ? ", id).Updates(map[string]interface{}{"status":status}).Error
26
+func UpdateSchedule(id int64, status int64) error {
27
+	err := writeDb.Model(&models.Schedules{}).Where("id = ? ", id).Updates(map[string]interface{}{"status": status}).Error
28 28
 	return err
29 29
 }
30 30
 
@@ -34,23 +34,23 @@ func SyncAdvice(Advice *models.DoctorAdvice) error {
34 34
 	return err
35 35
 }
36 36
 
37
-// 查找有字段的机构 
38
-func GetfiledConfigOrg() (FiledConfig []models.FiledConfig,err error) {
37
+// 查找有字段的机构
38
+func GetfiledConfigOrg() (FiledConfig []models.FiledConfig, err error) {
39 39
 	db := readDb.Begin()
40 40
 	err = db.Table("xt_filed_config").Group("org_id").Select("org_id,module,filed_name").Where("org_id > 0").Scan(&FiledConfig).Error
41 41
 	return
42 42
 }
43 43
 
44
-// 查询系统字段 
45
-func GetfiledConfigSys() (FiledConfig []models.FiledConfig,err error) {
44
+// 查询系统字段
45
+func GetfiledConfigSys() (FiledConfig []models.FiledConfig, err error) {
46 46
 	err = readDb.Model(&models.FiledConfig{}).Where("org_id = 0").Find(&FiledConfig).Error
47
-	return 
47
+	return
48 48
 }
49 49
 
50 50
 // 跟进查询条件查询结果
51
-func GetfiledConfigByOrgId(org_id int64,module int64,filed_name string)(FiledConfig models.FiledConfig,err error) {
52
-	err = readDb.Model(&models.FiledConfig{}).Where("org_id = ? and module = ? and filed_name = ?",org_id,module,filed_name).First(&FiledConfig).Error
53
-	return 
51
+func GetfiledConfigByOrgId(org_id int64, module int64, filed_name string) (FiledConfig models.FiledConfig, err error) {
52
+	err = readDb.Model(&models.FiledConfig{}).Where("org_id = ? and module = ? and filed_name = ?", org_id, module, filed_name).First(&FiledConfig).Error
53
+	return
54 54
 }
55 55
 
56 56
 // 创建一条字段数据详情
@@ -64,7 +64,46 @@ func SyncInspectionReference(data *models.MiddleInspectionReference) error {
64 64
 	tx := writeDb.Begin()
65 65
 	var inspection_reference models.InspectionReference
66 66
 	var total int
67
-	err = readDb.Model(&models.InspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ?  and status = 1", data.OrgId, data.ProjectId,data.ItemId).Find(&inspection_reference).Count(&total).Error
67
+	err = readDb.Model(&models.InspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ?  and status = 1", data.OrgId, data.ProjectId, data.ItemId).Find(&inspection_reference).Count(&total).Error
68
+	if total <= 0 {
69
+		inspection_reference.OrgId = data.OrgId
70
+		inspection_reference.ProjectName = data.ProjectName
71
+		inspection_reference.Project = data.ProjectName
72
+		inspection_reference.ProjectId = data.ProjectId
73
+		inspection_reference.ItemName = data.ItemName
74
+		inspection_reference.ItemId = data.ItemId
75
+		inspection_reference.RangeType = data.RangeType
76
+		inspection_reference.RangeMin = data.RangeMin
77
+		inspection_reference.RangeMax = data.RangeMax
78
+		inspection_reference.RangeValue = data.RangeValue
79
+		inspection_reference.RangeOptions = data.RangeOptions
80
+		inspection_reference.Unit = data.Unit
81
+		inspection_reference.Status = 1
82
+		inspection_reference.CreatedTime = time.Now().Unix()
83
+		inspection_reference.UpdatedTime = time.Now().Unix()
84
+
85
+		err := tx.Model(&models.InspectionReference{}).Create(&inspection_reference).Error
86
+		if err != nil {
87
+			tx.Rollback()
88
+		}
89
+
90
+		data.IsSync = 1
91
+		data.SyncId = inspection_reference.ID
92
+		data.UpdatedTime = time.Now().Unix()
93
+		ierr := writeMiddleDb.Save(&data).Error
94
+		if ierr != nil {
95
+			tx.Rollback()
96
+		}
97
+	}
98
+	tx.Commit()
99
+	return err
100
+}
101
+
102
+func SyncInspectionReferenceTwo(data *models.MiddleInspectionReference) error {
103
+	tx := writeDb.Begin()
104
+	var inspection_reference models.InspectionReference
105
+	var total int
106
+	err = readDb.Model(&models.InspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ?  and status = 1", data.OrgId, data.XtProjectId, data.XtItemId).Find(&inspection_reference).Count(&total).Error
68 107
 	if total <= 0 {
69 108
 		inspection_reference.OrgId = data.OrgId
70 109
 		inspection_reference.ProjectName = data.ProjectName
@@ -104,7 +143,7 @@ func SyncInspection(data *models.MiddleInspection) error {
104 143
 	tx := writeDb.Begin()
105 144
 	var inspection models.Inspection
106 145
 	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.RecordDate).Find(&inspection).Count(&total).Error
146
+	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 147
 	if total <= 0 {
109 148
 		inspection.OrgId = data.OrgId
110 149
 		inspection.PatientId = data.PatientId
@@ -139,13 +178,13 @@ func SyncInspection(data *models.MiddleInspection) error {
139 178
 }
140 179
 
141 180
 // 跟进org_id获取未同步的检验检查选项信息
142
-func GetSyncInspectionReferenceByOrgId(org_id int64) (InspectionReferences []models.MiddleInspectionReference,err error) {
181
+func GetSyncInspectionReferenceByOrgId(org_id int64) (InspectionReferences []models.MiddleInspectionReference, err error) {
143 182
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&InspectionReferences).Error
144 183
 	return
145 184
 }
146 185
 
147 186
 // 跟进org_id获取未同步的检验检查信息
148
-func GetSyncInspectionByOrgId(org_id int64) (Inspection []models.MiddleInspection,err error) {
187
+func GetSyncInspectionByOrgId(org_id int64) (Inspection []models.MiddleInspection, err error) {
149 188
 	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and status = 1 and is_sync = 0", org_id).Find(&Inspection).Error
150 189
 	return
151 190
 }
@@ -169,48 +208,48 @@ func CreateReportHandle(report *models.MiddleReportHandle) error {
169 208
 }
170 209
 
171 210
 // 根据机构ID获取该机构检验检查操作表里状态为0的数据
172
-func GetReportHandleListyOrgID(org_id int64) (report_handle_list []models.MiddleReportHandle ,err error){
173
-	err = readMiddleDb.Model(&models.MiddleReportHandle{}).Where("org_id = ?  and  handle_type = 0 ",  org_id).Find(&report_handle_list).Error
211
+func GetReportHandleListyOrgID(org_id int64) (report_handle_list []models.MiddleReportHandle, err error) {
212
+	err = readMiddleDb.Model(&models.MiddleReportHandle{}).Where("org_id = ?  and  handle_type = 0 ", org_id).Find(&report_handle_list).Error
174 213
 	return
175 214
 }
176 215
 
177 216
 // 根据机构ID修改检验检查操作表里的数据
178
-func UpdateReportHandleListyOrgID(report_handle *models.MiddleReportHandle)  error{
217
+func UpdateReportHandleListyOrgID(report_handle *models.MiddleReportHandle) error {
179 218
 	err := writeMiddleDb.Model(&models.MiddleReportHandle{}).Updates(&report_handle).Error
180 219
 	return err
181 220
 }
182 221
 
183 222
 // 跟进机构ID获取该机构所有病人的his_user_id
184
-func GetHisUserIdByOrgID(org_id int64) (patients []models.MiddlePatients ,err error) {
223
+func GetHisUserIdByOrgID(org_id int64) (patients []models.MiddlePatients, err error) {
185 224
 	err = readMiddleDb.Model(&models.MiddlePatients{}).Where("user_org_id = ? and status = 1", org_id).Find(&patients).Error
186 225
 	return
187 226
 }
188 227
 
189 228
 // 根据机构ID获取该机构上次同步信息
190
-func GetSyncTimeByOrgID(org_id int64,his_user_id string) (sync_info models.MiddleSyncInfo ,err error){
191
-	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ?  and  his_user_id =? ",  org_id,his_user_id).Last(&sync_info).Error
229
+func GetSyncTimeByOrgID(org_id int64, his_user_id string) (sync_info models.MiddleSyncInfo, err error) {
230
+	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ?  and  his_user_id =? ", org_id, his_user_id).Last(&sync_info).Error
192 231
 	return
193 232
 }
194 233
 
195 234
 // 根据机构ID获取该机构上次同步信息
196
-func GetSyncTimeByOrgIDForYs(org_id int64) (sync_info models.MiddleSyncInfo ,err error){
197
-	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ? ",  org_id).Last(&sync_info).Error
235
+func GetSyncTimeByOrgIDForYs(org_id int64) (sync_info models.MiddleSyncInfo, err error) {
236
+	err = readMiddleDb.Model(&models.MiddleSyncInfo{}).Where("org_id = ? ", org_id).Last(&sync_info).Error
198 237
 	return
199 238
 }
200 239
 
201 240
 // 根据机构ID和His_useer_id获取该患者最后一条同步检查数据
202
-func GetInspectionLastInfoByOrgID(org_id int64,his_user_id string) (inspectionLastInfo models.MiddleInspection ,err error){
203
-	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ?  and  his_user_id =? ",  org_id,his_user_id).Order("created_time desc").First(&inspectionLastInfo).Error
241
+func GetInspectionLastInfoByOrgID(org_id int64, his_user_id string) (inspectionLastInfo models.MiddleInspection, err error) {
242
+	err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ?  and  his_user_id =? ", org_id, his_user_id).Order("created_time desc").First(&inspectionLastInfo).Error
204 243
 	return
205 244
 }
206 245
 
207 246
 // 从机构将数据同步到中间库
208
-func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleInspectionReference,*models.MiddleInspection,error) {
247
+func Sync(data *models.TBLISItem, org_id int64, patient_id int64) (*models.MiddleInspectionReference, *models.MiddleInspection, error) {
209 248
 	tx := writeMiddleDb.Begin()
210 249
 	var inspection models.MiddleInspection
211 250
 	var inspection_reference models.MiddleInspectionReference
212 251
 	recordDateStr := data.UTime
213
-	if len(data.UTime) == 0 { 
252
+	if len(data.UTime) == 0 {
214 253
 		recordDateStr = time.Now().Format("2006-01-02 15:04")
215 254
 	}
216 255
 	record_date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
@@ -223,17 +262,17 @@ func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleIn
223 262
 	} else {
224 263
 		data.ItemType = 1
225 264
 		if len(data.RangeMax) > 0 {
226
-			Range := strings.Split(data.RangeMax,"-")
265
+			Range := strings.Split(data.RangeMax, "-")
227 266
 			if len(Range) > 1 {
228 267
 				data.RangeMin = Range[0]
229
-				data.RangeMax = Range[1] 
268
+				data.RangeMax = Range[1]
230 269
 			} else {
231 270
 				data.RangeMin = Range[0]
232 271
 			}
233 272
 		}
234 273
 	}
235 274
 
236
-	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, data.ProjectId,data.ItemId).Find(&inspection_reference).Count(&total).Error
275
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project_id = ? and item_id = ? and status = 1", org_id, data.ProjectId, data.ItemId).Find(&inspection_reference).Count(&total).Error
237 276
 	if total <= 0 && len(data.ProjectName) > 0 {
238 277
 		inspection_reference.OrgId = org_id
239 278
 		inspection_reference.ProjectName = data.ProjectName
@@ -258,7 +297,7 @@ func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleIn
258 297
 		}
259 298
 	}
260 299
 
261
-	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, data.ProjectId,data.ItemId,record_date.Unix(),patient_id).Find(&inspection).Count(&itotal).Error
300
+	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, data.ProjectId, data.ItemId, record_date.Unix(), patient_id).Find(&inspection).Count(&itotal).Error
262 301
 	if itotal <= 0 {
263 302
 		inspection.PatientId = patient_id
264 303
 		inspection.OrgId = org_id
@@ -286,22 +325,21 @@ func Sync(data *models.TBLISItem,org_id int64,patient_id int64)(*models.MiddleIn
286 325
 	}
287 326
 
288 327
 	tx.Commit()
289
-	return &inspection_reference,&inspection,err
328
+	return &inspection_reference, &inspection, err
290 329
 }
291 330
 
292
-//GetPatientList 返回患者的列表
293
-func GetList(his_user_id []interface{},syncTimes string) (lis []*models.TBLISItem,  err error) {
294
-	err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id in (?)  ",syncTimes,his_user_id).Find(&lis).Error
331
+// GetPatientList 返回患者的列表
332
+func GetList(his_user_id []interface{}, syncTimes string) (lis []*models.TBLISItem, err error) {
333
+	err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id in (?)  ", syncTimes, his_user_id).Find(&lis).Error
295 334
 	return
296 335
 }
297 336
 
298
-//GetPatientList 返回患者的列表
299
-func GetListByHisUserID(his_user_id string,syncTimes string,selectType int64) (lis []*models.TBLISItem,err error) {
337
+// GetPatientList 返回患者的列表
338
+func GetListByHisUserID(his_user_id string, syncTimes string, selectType int64) (lis []*models.TBLISItem, err error) {
300 339
 	if selectType == 1 {
301
-	 	err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND patient_name = ?  ",syncTimes,his_user_id).Find(&lis).Error
302
-	 } else {
303
-		err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id = ? ",syncTimes,his_user_id).Find(&lis).Error
304
-	 }
340
+		err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND patient_name = ?  ", syncTimes, his_user_id).Find(&lis).Error
341
+	} else {
342
+		err = readRemoteDb.Model(&models.TBLISItem{}).Where("u_time > ? AND his_user_id = ? ", syncTimes, his_user_id).Find(&lis).Error
343
+	}
305 344
 	return
306 345
 }
307
-

+ 2 - 7
service/pajm_service.go Просмотреть файл

@@ -27,7 +27,7 @@ type scpalis struct {
27 27
 	RangeValue   string `gorm:"column:range_value" json:"range_value"`
28 28
 	RangeOptions string `gorm:"column:range_options" json:"range_options"`
29 29
 	Unit         string `gorm:"column:unit" json:"unit"`
30
-	State        string  `gorm:"column:state" json:"state"`
30
+	State        int64  `gorm:"column:state" json:"state"`
31 31
 	CTime        int64  `gorm:"column:c_time" json:"c_time"`
32 32
 	UTime        int64  `gorm:"column:u_time" json:"u_time"`
33 33
 }
@@ -74,11 +74,6 @@ func GetScpaItemID(org_id int64, project_name string, item_name string, project_
74 74
 	}
75 75
 }
76 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
-
82 77
 // 四川蓬安济民透析中心Lis同步
83 78
 func SyncScpaLis() (err error) {
84 79
 	org_id := int64(9829)
@@ -114,7 +109,7 @@ func SyncScpaLis() (err error) {
114 109
 	}
115 110
 	// 第二步:获取所有患者的病历号
116 111
 
117
-	patientList, _ := GetPatientPajmByOrgId(org_id)
112
+	patientList, _ := GetPatientGzjhByOrgId(org_id)
118 113
 	if len(patientList) > 0 {
119 114
 		for _, patient := range patientList {
120 115
 			if len(patient.IdCardNo) > 0 {

Разница между файлами не показана из-за своего большого размера
+ 1008 - 0
service/sssy_service.go


+ 33 - 34
service/sy_service.go Просмотреть файл

@@ -6,37 +6,37 @@ import (
6 6
 	"IC/utils"
7 7
 	_ "encoding/json"
8 8
 	_ "encoding/xml"
9
+	"fmt"
9 10
 	"github.com/jinzhu/gorm"
10 11
 	_ "github.com/jinzhu/gorm"
11
-	_"strconv"
12
+	_ "strconv"
12 13
 	"strings"
13 14
 	"time"
14
-	"fmt"
15 15
 )
16 16
 
17 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"`
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 40
 }
41 41
 
42 42
 func (stsylis) TableName() string {
@@ -49,13 +49,13 @@ func GetStsyLis(rdb *gorm.DB, synctime time.Time) (record []*stsylis, err error)
49 49
 }
50 50
 
51 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
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 54
 	return
55 55
 }
56 56
 
57 57
 // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
58
-func GetStsyProjectID(org_id int64, project_name string,item_name string) (project_id int64, err error) {
58
+func GetStsyProjectID(org_id int64, project_name string, item_name string) (project_id int64, err error) {
59 59
 	var inspection_reference models.MiddleInspectionReference
60 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 61
 	if inspection_reference.ID > 0 {
@@ -120,17 +120,17 @@ func SyncStsyLis() (err error) {
120 120
 		sync_time = 1685548800
121 121
 	}
122 122
 
123
-	SyncTime := time.Unix(sync_time,0)
123
+	SyncTime := time.Unix(sync_time, 0)
124 124
 
125 125
 	fmt.Println(SyncTime)
126 126
 	// 第二步:获取时间内所有检验结果
127 127
 	stsyLis, _ := GetStsyLis(orgDb, SyncTime)
128 128
 
129 129
 	if len(stsyLis) > 0 {
130
-		for _,LisInfo := range stsyLis{
130
+		for _, LisInfo := range stsyLis {
131 131
 			brxm := LisInfo.Brxm
132 132
 			// 根据姓名获取患者ID
133
-			patient,_ := GetUserInfoByName(org_id,brxm)
133
+			patient, _ := GetUserInfoByName(org_id, brxm)
134 134
 			if patient.ID > 0 {
135 135
 				project_id, _ := GetStsyProjectID(org_id, LisInfo.Instrument, LisInfo.Itemname)
136 136
 				item_id, _ := GetStsyItemID(org_id, LisInfo.Instrument, LisInfo.Itemname, project_id)
@@ -147,7 +147,7 @@ func SyncStsyLis() (err error) {
147 147
 
148 148
 				recordTime, _ := time.ParseInLocation("2006-01-02 15:04:05", tempRecord, loc)
149 149
 				recordTimeInt := recordTime.Unix()
150
-				recordTimeStr := time.Unix(recordTimeInt,0).Format(timeLayout)
150
+				recordTimeStr := time.Unix(recordTimeInt, 0).Format(timeLayout)
151 151
 
152 152
 				var total int
153 153
 				var RangeOptions string
@@ -190,7 +190,7 @@ func SyncStsyLis() (err error) {
190 190
 					}
191 191
 				}
192 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
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, recordTimeStr, patient.ID).Find(&inspection).Count(&itotal).Error
194 194
 				if itotal <= 0 {
195 195
 					// inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
196 196
 					// inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)
@@ -219,7 +219,7 @@ func SyncStsyLis() (err error) {
219 219
 			} else {
220 220
 				continue
221 221
 			}
222
-		}				
222
+		}
223 223
 	}
224 224
 	var syncInfo models.MiddleSyncInfo
225 225
 	syncInfo.OrgId = org_id
@@ -251,7 +251,6 @@ func SyncStsyLis() (err error) {
251 251
 // 	return
252 252
 // }
253 253
 
254
-
255 254
 func SyncToStsytx() {
256 255
 
257 256
 	utils.TraceLog("检验检查同步任务开始执行")

+ 193 - 25
service/tscyyy_service.go Просмотреть файл

@@ -4,11 +4,10 @@ import (
4 4
 	"IC/models"
5 5
 	"IC/utils"
6 6
 	_ "IC/utils"
7
-	_"bytes"
7
+	_ "bytes"
8 8
 	"encoding/json"
9 9
 	_ "encoding/json"
10
-	_"encoding/xml"
11
-	_"fmt"
10
+	_ "encoding/xml"
12 11
 	_ "fmt"
13 12
 	"github.com/astaxie/beego/httplib"
14 13
 	_ "github.com/jinzhu/gorm"
@@ -18,25 +17,24 @@ import (
18 17
 	"time"
19 18
 )
20 19
 
21
-
22 20
 type tscylis struct {
23 21
 	HisUserId    string `json:"his_user_id"`
24 22
 	PatientName  string `json:"patient_name"`
25
-	ProjectId    string  `json:"project_id"`
23
+	ProjectId    string `json:"project_id"`
26 24
 	ProjectName  string `json:"project_name"`
27
-	InspectDate  string  `json:"inspect_date"`
28
-	ItemId       string  `json:"item_id"`
25
+	InspectDate  string `json:"inspect_date"`
26
+	ItemId       string `json:"item_id"`
29 27
 	ItemName     string `json:"item_name"`
30
-	ItemType     string  `json:"item_type"`
28
+	ItemType     string `json:"item_type"`
31 29
 	ItemValue    string `json:"item_value"`
32 30
 	RangeMin     string `json:"range_min"`
33 31
 	RangeMax     string `json:"range_max"`
34 32
 	RangeValue   string `json:"range_value"`
35 33
 	RangeOptions string `json:"range_options"`
36 34
 	Unit         string `json:"unit"`
37
-	State        string  `json:"state"`
38
-	CTime        string  `json:"c_time"`
39
-	UTime        string  `json:"u_time"`
35
+	State        string `json:"state"`
36
+	CTime        string `json:"c_time"`
37
+	UTime        string `json:"u_time"`
40 38
 }
41 39
 
42 40
 type tscyLisResult struct {
@@ -53,8 +51,6 @@ func GetTscyLis(sync_time string, his_user_id string) (str tscyLisResult, checkS
53 51
 	if err != nil {
54 52
 		utils.InfoLog("err:%v", err)
55 53
 	}
56
-	utils.InfoLog("str:%v", strs)
57
-
58 54
 	var checkJSON tscyLisResult
59 55
 	json.Unmarshal([]byte(strs), &checkJSON)
60 56
 	// utils.InfoLog("checkJSON:%v", checkJSON)
@@ -77,19 +73,35 @@ func GetTscyProjectID(org_id int64, project_name string) (project_id int64, err
77 73
 	}
78 74
 }
79 75
 
76
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
77
+func GetTscyVipProjectID(org_id int64, project_name string) (project_id int64, err error) {
78
+	var inspection_reference models.MiddleInspectionReference
79
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
80
+	if inspection_reference.ID > 0 {
81
+		return inspection_reference.ProjectId, err
82
+	} else {
83
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
84
+		if inspection_reference.ProjectId > 0 {
85
+			return inspection_reference.ProjectId + 1, err
86
+		} else {
87
+			return 1056201, err
88
+		}
89
+	}
90
+}
91
+
80 92
 // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
81
-func GetTscyItemID(org_id int64,project_name string,item_name string,project_id int64) (item_id int64 ,err error) {
93
+func GetTscyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
82 94
 	var inspection_reference models.MiddleInspectionReference
83
-	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
95
+	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
84 96
 	if inspection_reference.ID > 0 {
85
-		return inspection_reference.ItemId,err
97
+		return inspection_reference.ItemId, err
86 98
 	} else {
87
-		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
88
-		utils.InfoLog("inspection_reference: %v",inspection_reference)
99
+		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
100
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
89 101
 		if inspection_reference.ItemId > 0 {
90
-			return inspection_reference.ItemId + 1,err
102
+			return inspection_reference.ItemId + 1, err
91 103
 		} else {
92
-			return project_id * 100 + 1 ,err
104
+			return project_id*100 + 1, err
93 105
 		}
94 106
 	}
95 107
 }
@@ -135,7 +147,7 @@ func SyncTscyLis() (err error) {
135 147
 						// 根据project_id和item_id 判断该项是否存在
136 148
 						project_id := int64(0)
137 149
 						// if info.ProjectId > 0 {
138
-							project_id, _ = GetTscyProjectID(org_id, info.ProjectName)
150
+						project_id, _ = GetTscyProjectID(org_id, info.ProjectName)
139 151
 						// } else {
140 152
 						// 	continue
141 153
 						// }
@@ -146,7 +158,7 @@ func SyncTscyLis() (err error) {
146 158
 						var inspection models.MiddleInspection
147 159
 						var inspection_reference models.MiddleInspectionReference
148 160
 
149
-						record_date,_ := strconv.ParseInt(info.InspectDate, 10, 64)
161
+						record_date, _ := strconv.ParseInt(info.InspectDate, 10, 64)
150 162
 
151 163
 						if record_date == 0 {
152 164
 							record_date = time.Now().Unix()
@@ -166,12 +178,12 @@ func SyncTscyLis() (err error) {
166 178
 						ItemType := info.ItemType
167 179
 						// Range := strings.Split(info.RangeValue, "-")
168 180
 						// if len(Range) > 1 {
169
-							RangeMin = info.RangeMin
170
-							RangeMax = info.RangeMax
181
+						RangeMin = info.RangeMin
182
+						RangeMax = info.RangeMax
171 183
 						// 	ItemType = 1
172 184
 						// } else {
173 185
 						// 	ItemType = 2
174
-							RangeOptions = info.RangeOptions
186
+						RangeOptions = info.RangeOptions
175 187
 						// }
176 188
 
177 189
 						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
@@ -280,3 +292,159 @@ func SyncToTscytx() {
280 292
 	}
281 293
 	utils.SuccessLog("检验检查同步任务完成")
282 294
 }
295
+
296
+// 唐山朝阳医院Vip区透析中心Lis同步
297
+func SyncTscyVipLis() (err error) {
298
+	org_id := int64(10562)
299
+	// 第一步:获取上一次同步的时间点
300
+	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
301
+	var sync_time int64
302
+	if syncLastInfo.ID > 0 {
303
+		sync_time = syncLastInfo.SyncTime
304
+	} else {
305
+		sync_time = 1651334400
306
+	}
307
+	// 第二步:获取所有患者的病历号
308
+
309
+	patientList, _ := GetPatientGzjhByOrgId(org_id)
310
+	if len(patientList) > 0 {
311
+		for _, patient := range patientList {
312
+			if len(patient.IdCardNo) > 0 || len(patient.DialysisNo) > 0 {
313
+				// 上次同步时间转换为接口需要的格式
314
+				patient_id := patient.ID
315
+				utils.InfoLog("IdCardNo:%v", patient.IdCardNo)
316
+				gzjhLis, _ := GetTscyLis(strconv.FormatInt(sync_time, 10), patient.IdCardNo)
317
+
318
+				if len(gzjhLis.Result) > 0 {
319
+					for _, info := range gzjhLis.Result {
320
+						// 根据project_id和item_id 判断该项是否存在
321
+						project_id := int64(0)
322
+						project_id, _ = GetTscyVipProjectID(org_id, info.ProjectName)
323
+
324
+						item_id, _ := GetTscyItemID(org_id, info.ProjectName, info.ItemName, project_id)
325
+
326
+						tx := writeMiddleDb.Begin()
327
+						var inspection models.MiddleInspection
328
+						var inspection_reference models.MiddleInspectionReference
329
+
330
+						record_date, _ := strconv.ParseInt(info.InspectDate, 10, 64)
331
+
332
+						if record_date == 0 {
333
+							record_date = time.Now().Unix()
334
+						}
335
+						inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
336
+						var total int
337
+						var RangeOptions string
338
+						var RangeMin string
339
+						var RangeMax string
340
+
341
+						// // 判断检查类型
342
+						ItemType := info.ItemType
343
+						RangeMin = info.RangeMin
344
+						RangeMax = info.RangeMax
345
+
346
+						RangeOptions = info.RangeOptions
347
+						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
348
+
349
+						if total <= 0 {
350
+							inspection_reference.OrgId = org_id
351
+							inspection_reference.ProjectName = info.ProjectName
352
+							inspection_reference.Project = info.ProjectName
353
+							inspection_reference.ProjectId = project_id
354
+							inspection_reference.ItemName = info.ItemName
355
+							inspection_reference.ItemNameAddition = info.ItemId
356
+							inspection_reference.ItemId = item_id
357
+							inspection_reference.RangeType, _ = strconv.Atoi(ItemType)
358
+							inspection_reference.RangeMin = RangeMin
359
+							inspection_reference.RangeMax = RangeMax
360
+							// inspection_reference.RangeValue = RangeValue
361
+							inspection_reference.RangeOptions = RangeOptions
362
+							inspection_reference.Unit = info.Unit
363
+							inspection_reference.Status = 1
364
+							inspection_reference.CreatedTime = time.Now().Unix()
365
+							inspection_reference.UpdatedTime = time.Now().Unix()
366
+							inspection_reference.InspectDate = inspect_date
367
+							inspection_reference.UTime = inspect_date
368
+							err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
369
+							if err != nil {
370
+								tx.Rollback()
371
+							}
372
+						}
373
+
374
+						var itotal int
375
+						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
376
+						if itotal <= 0 {
377
+							info.ItemValue = strings.Replace(info.ItemValue, "&gt;", ">", -1)
378
+							info.ItemValue = strings.Replace(info.ItemValue, "&lt;", "<", -1)
379
+							inspection.PatientId = patient_id
380
+							inspection.OrgId = org_id
381
+							inspection.ProjectId = project_id
382
+							inspection.ItemName = inspection_reference.ItemName
383
+							inspection.ProjectName = inspection_reference.ProjectName
384
+							inspection.InspectType, _ = strconv.Atoi(ItemType)
385
+							inspection.ItemId = item_id
386
+							inspection.InspectValue = info.ItemValue
387
+							inspection.InspectDate = inspect_date
388
+							inspection.RecordDate = record_date
389
+							// inspection.InspectTips = report.Resultstate
390
+							inspection.Status = 1
391
+							inspection.CreatedTime = time.Now().Unix()
392
+							inspection.UpdatedTime = time.Now().Unix()
393
+							inspection.UTime = inspect_date
394
+							inspection.HisUserId = strconv.FormatInt(patient_id, 10)
395
+							err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
396
+							if err != nil {
397
+								tx.Rollback()
398
+							}
399
+						}
400
+
401
+						tx.Commit()
402
+					}
403
+				}
404
+			} else {
405
+				continue
406
+			}
407
+		}
408
+	}
409
+	var syncInfo models.MiddleSyncInfo
410
+	syncInfo.OrgId = org_id
411
+	syncInfo.SyncTime = time.Now().Unix()
412
+	syncInfo.SyncResultType = 1
413
+	syncInfo.SyncRsultRemark = "同步成功"
414
+	syncInfo.SyncTotalNum = 0
415
+	syncInfo.SyncSuccessNum = 0
416
+	syncInfo.SyncInfo = ""
417
+	syncInfo.CreateTime = time.Now().Unix()
418
+	syncInfo.UpdateTime = time.Now().Unix()
419
+
420
+	cwderr := CreateSyncInfo(&syncInfo)
421
+	if cwderr != nil {
422
+		utils.ErrorLog("创建同步信息失败:%v", cwderr)
423
+		return
424
+	}
425
+	SyncToTscyVip()
426
+	return
427
+}
428
+
429
+func SyncToTscyVip() {
430
+	utils.TraceLog("检验检查同步任务开始执行")
431
+	org_id := int64(10562)
432
+
433
+	// 第一步:跟进org_id 去中间库查出需要同步的数据
434
+	inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
435
+	inspections, _ := GetSyncInspectionByOrgId(org_id)
436
+
437
+	// 第二步:将数据同步到业务库
438
+	if len(inspection_references) > 0 {
439
+		for _, inspection_reference := range inspection_references {
440
+			SyncInspectionReference(&inspection_reference)
441
+		}
442
+	}
443
+
444
+	if len(inspections) > 0 {
445
+		for _, inspection := range inspections {
446
+			SyncInspection(&inspection)
447
+		}
448
+	}
449
+	utils.SuccessLog("检验检查同步任务完成")
450
+}