Browse Source

Merge branch 'master' of http://git.shengws.com/zhangbj/IC

28169 1 month ago
parent
commit
ac2aba2963

+ 1 - 1
conf/app.conf View File

@@ -1,5 +1,5 @@
1 1
 appname = IC
2
-httpport = 9818
2
+httpport = 9859
3 3
 runmode = prod
4 4
 
5 5
 copyrequestbody = true

+ 10 - 2
main.go View File

@@ -15,7 +15,7 @@ func init() {
15 15
 }
16 16
 
17 17
 func main() {
18
-	//service.BeginAutoSyncLis()
18
+	service.BeginAutoSyncLis()
19 19
 	//service.SyncStsyLis() //  汕头三优  打开程序马上运行LIS同步
20 20
 	//service.SyncLisSgyhs() //  韶关源和盛  打开程序马上运行LIS同步
21 21
 	//service.SyncLisPljx(10597) //  揭阳景熹透析中心  打开程序马上运行LIS同步
@@ -27,6 +27,14 @@ func main() {
27 27
 	//service.SyncSclsyyyyyz(orgDb) // 深圳五洲医院  打开程序马上运行LIS同步
28 28
 	//service.SyncGzkyLis() // 广州康允 打开程序马上运行LIS同步
29 29
 	//service.SyncLisZqshtx() // 肇庆三鹤 打开程序马上运行LIS同步
30
-	//service.SyncBjncHis()
30
+	//service.SyncScyyyyLis() // 四川乐生友谊医院 打开程序马上运行LIS同步
31
+	//service.SyncGxlsskyz() // 广西灵山盛康 医嘱
32
+	//service.SyncSzxdyyLis() // 山西朔州现代医院  打开程序马上运行LIS同步
33
+	//service.SyncSzxdyyyz() // 山西朔州现代医院  打开程序马上运行医嘱同步
34
+	//service.SyncSHLisFunc() // 舒和LIS对接
35
+	//service.SyncLisLaxk() //乐安祥康LIS对接
36
+	//service.SyncLisPljx(10597) // 揭阳LIS对接
37
+	//service.SyncLisPljx(10599) // 揭阳LIS对接
38
+	service.SyncLisGzky(0) // 广州康允血液透析中心LIS对接
31 39
 	beego.Run()
32 40
 }

+ 1 - 0
models/lis_model.go View File

@@ -333,6 +333,7 @@ type Inspection struct {
333 333
 	Status       int64  `gorm:"column:status" json:"status" form:"status"`
334 334
 	CreatedTime  int64  `gorm:"column:created_time" json:"created_time" form:"created_time"`
335 335
 	UpdatedTime  int64  `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
336
+	SgnTreat     int64  `gorm:"column:sgn_treat" json:"sgn_treat" form:"sgn_treat"`
336 337
 }
337 338
 
338 339
 func (Inspection) TableName() string {

+ 90 - 0
models/report_result.go View File

@@ -118,3 +118,93 @@ type HisLabelPrintInfo struct {
118 118
 func (HisLabelPrintInfo) TableName() string {
119 119
 	return "his_label_print_info"
120 120
 }
121
+
122
+type XtHisProjectTeam struct {
123
+	ID          int64   `gorm:"column:id" json:"id" form:"id"`
124
+	ProjectTeam string  `gorm:"column:project_team" json:"project_team" form:"project_team"`
125
+	Price       float64 `gorm:"column:price" json:"price" form:"price"`
126
+	Pinyin      string  `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
127
+	Wubi        string  `gorm:"column:wubi" json:"wubi" form:"wubi"`
128
+	TubeColor   int64   `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
129
+	TeamType    int64   `gorm:"column:team_type" json:"team_type" form:"team_type"`
130
+	Remark      string  `gorm:"column:remark" json:"remark" form:"remark"`
131
+	UserOrgId   int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
132
+	Status      int64   `gorm:"column:status" json:"status" form:"status"`
133
+	CreatedTime int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
134
+	UpdatedTime int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
135
+	ProjectId   string  `gorm:"column:project_id" json:"project_id" form:"project_id"`
136
+	ItemId      string  `gorm:"column:item_id" json:"item_id" form:"item_id"`
137
+	Sort        int64   `gorm:"column:sort" json:"sort" form:"sort"`
138
+}
139
+
140
+func (XtHisProjectTeam) TableName() string {
141
+	return "xt_his_project_team"
142
+}
143
+
144
+type XtHisProjectList struct {
145
+	ID           int64        `gorm:"column:id" json:"id" form:"id"`
146
+	Number       int64        `gorm:"column:number" json:"number" form:"number"`
147
+	UserOrgId    int64        `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
148
+	ProjectId    int64        `gorm:"column:project_id" json:"project_id" form:"project_id"`
149
+	Status       int64        `gorm:"column:status" json:"status" form:"status"`
150
+	CreatedTime  int64        `gorm:"column:created_time" json:"created_time" form:"created_time"`
151
+	UpdatedTime  int64        `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
152
+	TeamId       int64        `gorm:"column:team_id" json:"team_id" form:"team_id"`
153
+	Type         int64        `gorm:"column:type" json:"type" form:"type"`
154
+	XtHisProject XtHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
155
+	PN           string       `gorm:"-" json:"pn" form:"pn"`
156
+}
157
+
158
+func (XtHisProjectList) TableName() string {
159
+	return "xt_his_project_list"
160
+}
161
+
162
+type XtHisProject struct {
163
+	ID                          int64   `gorm:"column:id" json:"id" form:"id"`
164
+	ProjectName                 string  `gorm:"column:project_name" json:"project_name" form:"project_name"`
165
+	Pinyin                      string  `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
166
+	Wubi                        string  `gorm:"column:wubi" json:"wubi" form:"wubi"`
167
+	Price                       float64 `gorm:"column:price" json:"price" form:"price"`
168
+	Unit                        string  `gorm:"column:unit" json:"unit" form:"unit"`
169
+	CostClassify                int64   `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
170
+	ExecutiveSection            int64   `gorm:"column:executive_section" json:"executive_section" form:"executive_section"`
171
+	MedicalCoverage             int64   `gorm:"column:medical_coverage" json:"medical_coverage" form:"medical_coverage"`
172
+	StatisticalClassification   int64   `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
173
+	DiseaseDirectory            int64   `gorm:"column:disease_directory" json:"disease_directory" form:"disease_directory"`
174
+	IsRecord                    int64   `gorm:"column:is_record" json:"is_record" form:"is_record"`
175
+	MedicalCode                 string  `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
176
+	TubeColor                   int64   `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
177
+	MedicalStatus               int64   `gorm:"column:medical_status" json:"medical_status" form:"medical_status"`
178
+	Remark                      string  `gorm:"column:remark" json:"remark" form:"remark"`
179
+	Sign                        int64   `gorm:"column:sign" json:"sign" form:"sign"`
180
+	DefaultNumber               string  `gorm:"column:default_number" json:"default_number" form:"default_number"`
181
+	IsDefault                   int64   `gorm:"column:is_default" json:"is_default" form:"is_default"`
182
+	IsCharge                    int64   `gorm:"column:is_charge" json:"is_charge" form:"is_charge"`
183
+	IsEstimate                  int64   `gorm:"column:is_estimate" json:"is_estimate" form:"is_estimate"`
184
+	IsWorkload                  int64   `gorm:"column:is_workload" json:"is_workload" form:"is_workload"`
185
+	Sort                        string  `gorm:"column:sort" json:"sort" form:"sort"`
186
+	DoctorAdvice                int64   `gorm:"column:doctor_advice" json:"doctor_advice" form:"doctor_advice"`
187
+	UserOrgId                   int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
188
+	Status                      int64   `gorm:"column:status" json:"status" form:"status"`
189
+	CreatedTime                 int64   `gorm:"column:created_time" json:"created_time" form:"created_time"`
190
+	UpdatedTime                 int64   `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
191
+	SingleDose                  string  `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
192
+	ExecutionFrequency          string  `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
193
+	DeliveryWay                 string  `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
194
+	NumberDays                  string  `gorm:"column:number_days" json:"number_days" form:"number_days"`
195
+	Total                       string  `gorm:"column:total" json:"total" form:"total"`
196
+	Category                    int64   `gorm:"column:category" json:"category" form:"category"`
197
+	IsMark                      int64   `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
198
+	SpecailProject              int64   `gorm:"column:specail_project" json:"specail_project" form:"specail_project"`
199
+	SocialSecurityDirectoryCode string  `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
200
+	RecordDate                  int64   `gorm:"column:record_date" json:"record_date" form:"record_date"`
201
+	IsPrint                     int64   `gorm:"column:is_print" json:"is_print" form:"is_print"`
202
+	FirstLetter                 string  `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
203
+	Bbx01                       string  `gorm:"column:bbx01" json:"bbx01" form:"bbx01"`
204
+	Bby01                       string  `gorm:"column:bby01" json:"bby01" form:"bby01"`
205
+	ZuobiaoId                   string  `gorm:"column:zuobiao_id" json:"zuobiao_id" form:"zuobiao_id"`
206
+}
207
+
208
+func (XtHisProject) TableName() string {
209
+	return "xt_his_project"
210
+}

+ 45 - 19
service/cron.go View File

@@ -1,14 +1,14 @@
1 1
 package service
2 2
 
3 3
 import (
4
+	"IC/models"
5
+	"IC/utils"
4 6
 	"encoding/json"
5 7
 	_ "fmt"
8
+	_ "github.com/jinzhu/gorm"
9
+	"github.com/robfig/cron/v3"
6 10
 	_ "strings"
7 11
 	"time"
8
-
9
-	"IC/models"
10
-	"IC/utils"
11
-	_ "github.com/jinzhu/gorm"
12 12
 )
13 13
 
14 14
 // cron表达式 https://www.cnblogs.com/zuxingyu/p/6023919.html
@@ -19,15 +19,15 @@ func init() {
19 19
 }
20 20
 
21 21
 // 返回一个支持至 秒 级别的 cron
22
-//func newWithSeconds() *cron.Cron {
23
-//	secondParser := cron.NewParser(cron.Second | cron.Minute |
24
-//		cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
25
-//	return cron.New(cron.WithParser(secondParser), cron.WithChain())
26
-//}
22
+func newWithSeconds() *cron.Cron {
23
+	secondParser := cron.NewParser(cron.Second | cron.Minute |
24
+		cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
25
+	return cron.New(cron.WithParser(secondParser), cron.WithChain())
26
+}
27 27
 
28 28
 func BeginAutoSyncLis() {
29 29
 	utils.InfoLog("开启自动检验检查同步定时任务")
30
-	//createLisSyncCronJob := newWithSeconds()
30
+	createLisSyncCronJob := newWithSeconds()
31 31
 
32 32
 	//orgDb, err := gorm.Open(oracle.Open("oracle://zjybase:zjybase@10.0.0.248:1521/orcl"), &gorm.Config{})
33 33
 	//
@@ -35,6 +35,12 @@ func BeginAutoSyncLis() {
35 35
 	//	utils.InfoLog("创建数据库连接失败:%v", err)
36 36
 	//}
37 37
 
38
+	//orgDb, err := gorm.Open(oracle.Open("oracle://BSLIS52:zhsoft@172.9.200.3:1521/JYK"), &gorm.Config{})
39
+	//
40
+	//if err != nil {
41
+	//	utils.InfoLog("syncTimeStr:%v", err)
42
+	//}
43
+
38 44
 	//specys := "0 0 */1 * * ?" // 每天凌晨3点同步 唐山朝阳医院
39 45
 	//createLisSyncCronJob.AddFunc(specys, func() {
40 46
 	//	SyncTscyLis()
@@ -47,7 +53,7 @@ func BeginAutoSyncLis() {
47 53
 	//
48 54
 	//spec := "0 50 1 * * ?" // 每天凌晨1点同步 监利大院的
49 55
 	//createLisSyncCronJob.AddFunc(spec, func() {
50
-	//	SyncHbdyLis()
56
+	//SyncHbdyLis()
51 57
 	//})
52 58
 	//
53 59
 	//spec2 := "0 50 2 * * ?" // 每天凌晨2点同步 龙岗二院
@@ -80,9 +86,9 @@ func BeginAutoSyncLis() {
80 86
 	//	SyncLisSzwz()
81 87
 	//})
82 88
 
83
-	//spec8 := "0 25 */3 * * ?" // 每个小时同步一次 汕头三优透析中心LIS对接,本地部署的
89
+	//spec8 := "0 25 */12 * * ?" // 每个小时同步一次 汕头三优透析中心LIS对接,本地部署的
84 90
 	//createLisSyncCronJob.AddFunc(spec8, func() {
85
-	SyncStsyLis()
91
+	//	SyncStsyLis()
86 92
 	//})
87 93
 
88 94
 	//spec9 := "0 57 * * * ?" // 每个小时同步一次 遵化仁爱医院LIS对接,本地部署的
@@ -95,12 +101,12 @@ func BeginAutoSyncLis() {
95 101
 	//	SyncLisSgyhs()
96 102
 	//})
97 103
 
98
-	//spec11 := "0 20 */2 * * ?" // 每个小时同步一次 揭阳景熹LIS对接,本地部署的
104
+	//spec11 := "0 20 */12 * * ?" // 每个小时同步一次 揭阳景熹LIS对接,本地部署的
99 105
 	//createLisSyncCronJob.AddFunc(spec11, func() {
100 106
 	//	SyncLisPljx(10597)
101 107
 	//})
102
-
103
-	//spec12 := "0 40 */2 * * ?" // 每个小时同步一次 普宁景熹LIS对接,本地部署的
108
+	//
109
+	//spec12 := "0 40 */12 * * ?" // 每个小时同步一次 普宁景熹LIS对接,本地部署的
104 110
 	//createLisSyncCronJob.AddFunc(spec12, func() {
105 111
 	//	SyncLisPljx(10599)
106 112
 	//})
@@ -122,7 +128,7 @@ func BeginAutoSyncLis() {
122 128
 
123 129
 	//spec16 := "0 20 */2 * * ?" // 每个小时同步一次 深圳五洲医院,本地部署的
124 130
 	//createLisSyncCronJob.AddFunc(spec16, func() {
125
-	//	SyncLisSzwz()
131
+	//	SyncLisSzwz(orgDb)
126 132
 	//})
127 133
 
128 134
 	//spec17 := "0 20 */2 * * ?" // 每个小时同步一次 湖南嘉禾恒佳医院,本地部署的
@@ -132,7 +138,7 @@ func BeginAutoSyncLis() {
132 138
 
133 139
 	//spec18 := "1 * * * * ?" // 每个30秒同步一次 四川乐山友谊医院医嘱对接,本地部署的
134 140
 	//createLisSyncCronJob.AddFunc(spec18, func() {
135
-	//	SyncSclsyyyyyz(orgDb)
141
+	//SyncSclsyyyyyz(orgDb)
136 142
 	//})
137 143
 
138 144
 	//spec19 := "* 35 */4 * * ?" // 每个2个小时同步一次 四川乐山友谊医院LIS对接,本地部署的
@@ -150,7 +156,27 @@ func BeginAutoSyncLis() {
150 156
 	//	SyncBjncHis()
151 157
 	//})
152 158
 
153
-	//createLisSyncCronJob.Start()
159
+	//spec22 := "1 * * * * ?" // 每个30秒同步一次 广西灵山盛康医嘱对接,本地部署的
160
+	//createLisSyncCronJob.AddFunc(spec22, func() {
161
+	//	SyncGxlsskyz()
162
+	//})
163
+
164
+	//spec23 := "1 * * * * ?" // 每个30秒同步一次 朔州现代医院医嘱对接,本地部署的
165
+	//createLisSyncCronJob.AddFunc(spec23, func() {
166
+	//	SyncSzxdyyyz()
167
+	//})
168
+
169
+	//spec24 := "* 25 */2 * * ?" // 每个2个小时同步一次 四川乐山友谊医院LIS对接,本地部署的
170
+	//createLisSyncCronJob.AddFunc(spec24, func() {
171
+	//	SyncSzxdyyLis()
172
+	//})
173
+
174
+	//spec25 := "* 10 */2 * * ?" // 每个30秒同步一次 朔州现代医院医嘱对接,本地部署的
175
+	//createLisSyncCronJob.AddFunc(spec25, func() {
176
+	//	SyncSHLisFunc()
177
+	//})
178
+
179
+	createLisSyncCronJob.Start()
154 180
 }
155 181
 
156 182
 func AutoSyncLis() {

+ 710 - 216
service/gzky_service.go View File

@@ -1,260 +1,217 @@
1 1
 package service
2 2
 
3
-// 广州康允血液透析中心 检验检查对接
4 3
 import (
5 4
 	"IC/models"
6 5
 	"IC/utils"
6
+	_ "IC/utils"
7
+	"encoding/json"
7 8
 	_ "encoding/json"
8
-	_ "encoding/xml"
9
-	"fmt"
10
-	"github.com/jinzhu/gorm"
9
+	"encoding/xml"
10
+	_ "fmt"
11
+	"github.com/astaxie/beego/httplib"
11 12
 	_ "github.com/jinzhu/gorm"
12
-	_ "strconv"
13
+	"net/url"
14
+	"strconv"
13 15
 	"strings"
14 16
 	"time"
15 17
 )
16 18
 
17
-type gzkylis struct {
18
-	Finputdate           string `gorm:"column:F_InputDate" json:"F_InputDate"`
19
-	Fname                string `gorm:"column:F_Name" json:"F_Name"`
20
-	Fsex                 string `gorm:"column:F_Sex" json:"F_Sex"`
21
-	Fage                 string `gorm:"column:F_Age" json:"F_Age"`
22
-	Fhospnaturalitem     string `gorm:"column:F_HospNaturalItem" json:"F_HospNaturalItem"`
23
-	Fhospnaturalitemname string `gorm:"column:F_HospNaturalItemName" json:"F_HospNaturalItemName"`
24
-	Fhospitem            string `gorm:"column:F_HospItem" json:"F_HospItem"`
25
-	Fhospitemname        string `gorm:"column:F_HospItemName" json:"F_HospItemName"`
26
-	Fresult              string `gorm:"column:F_Result" json:"F_Result"`
27
-	Funit                string `gorm:"column:F_Unit" json:"F_Unit"`
28
-	Fhint                string `gorm:"column:F_Hint" json:"F_Hint"`
29
-	Freference           string `gorm:"column:F_Reference" json:"F_Reference"`
30
-	Frecordtime          string `gorm:"column:F_RecordTime" json:"F_RecordTime"`
19
+// 广州康允血液透析中心 检验检查对接
20
+
21
+type XmlKeyGzky struct {
22
+	XMLName    xml.Name `xml:"string"`
23
+	StringName string   `xml:"name,attr"`
24
+	InnerText  string   `xml:",innerxml"`
31 25
 }
32 26
 
33
-func (gzkylis) TableName() string {
34
-	return "V_KM_LIS_Result"
27
+// 获取艾迪康的key
28
+func GetAdKeyGzky(logid string, password string) (key string) {
29
+	Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/Login?"
30
+	apiurl := "logid=" + logid + "&password=" + password
31
+	apiurl = url.PathEscape(apiurl)
32
+	apiurl = Domain + apiurl
33
+	XmlKeyGzky := XmlKeyGzky{}
34
+	httplib.Get(apiurl).ToXML(&XmlKeyGzky)
35
+	return XmlKeyGzky.InnerText
35 36
 }
36 37
 
37
-func GetGzkyLis(rdb *gorm.DB, synctime string) (record []*gzkylis, err error) {
38
-	err = rdb.Model(&gzkylis{}).Where("F_RecordTime >= ? ", synctime).Find(&record).Error
39
-	return
38
+type ADStringGzky struct {
39
+	XMLName        xml.Name         `xml:"string" json:"string"`
40
+	NewDataSetGzky rpnewDataSetGzky `xml:"NewDataSet" json:"NewDataSet"`
40 41
 }
41 42
 
42
-// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
43
-func GetGzkyProjectID(org_id int64, project_name string) (project_id int64, err error) {
44
-	var inspection_reference models.MiddleInspectionReference
45
-	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?  ", org_id, project_name).First(&inspection_reference).Error
46
-	if inspection_reference.ID > 0 {
47
-		return inspection_reference.ProjectId, err
48
-	} else {
49
-		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
50
-		if inspection_reference.ProjectId > 0 {
51
-			return inspection_reference.ProjectId + 1, err
52
-		} else {
53
-			return 1056701, err
54
-		}
55
-	}
43
+type rpnewDataSetGzky struct {
44
+	ListTableGzky []rplisttableGzky `xml:"listtable" json:"listtable"`
56 45
 }
57 46
 
58
-// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
59
-func GetGzkyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
60
-	var inspection_reference models.MiddleInspectionReference
61
-	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
62
-	if inspection_reference.ID > 0 {
63
-		return inspection_reference.ItemId, err
64
-	} else {
65
-		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
66
-		if inspection_reference.ItemId > 0 {
67
-			return inspection_reference.ItemId + 1, err
68
-		} else {
69
-			return project_id*100 + 1, err
70
-		}
71
-	}
47
+type rplisttableGzky struct {
48
+	Id              string `xml:"Id" json:"Id"`
49
+	ReportType      string `xml:"ReportType" json:"ReportType"`
50
+	AdiconBarcode   string `xml:"AdiconBarcode" json:"AdiconBarcode"`
51
+	PatientName     string `xml:"PatientName" json:"PatientName"`
52
+	Bgrq            string `xml:"Bgrq" json:"Bgrq"`
53
+	Instrument      string `xml:"Instrument" json:"Instrument"`
54
+	LisDate         string `xml:"LisDate" json:"LisDate"`
55
+	Sampleid        string `xml:"Sampleid" json:"Sampleid"`
56
+	CustomerBarcode string `xml:"CustomerBarcode" json:"CustomerBarcode"`
57
+	Repno           string `xml:"Repno" json:"Repno"`
58
+	// PdfFileName		string `xml:"PdfFileName" json:"PdfFileName"`
59
+	// DownFlag		string `xml:"DownFlag" json:"DownFlag"`
60
+	// DownDate		string `xml:"DownDate" json:"DownDate"`
61
+	Sjrq string `xml:"Sjrq" json:"Sjrq"`
62
+	// Sjys		string `xml:"Sjys" json:"Sjys"`
63
+	// Brnl		string `xml:"Brnl" json:"Brnl"`
64
+	// Brxb		string `xml:"Brxb" json:"Brxb"`
65
+	Bbzl string `xml:"bbzl" json:"bbzl"`
66
+	// Bzlbid		string `xml:"Bzlbid" json:"Bzlbid"`
67
+	// PDFFileType		string `xml:"PDFFileType" json:"PDFFileType"`
68
+	// PageType		string `xml:"PageType" json:"PageType"`
69
+	PatientNo string `xml:"PatientNo" json:"PatientNo"`
70
+	// SfzId		string `xml:"SfzId" json:"SfzId"`
71
+	// CertificatesType		string `xml:"CertificatesType" json:"CertificatesType"`
72
+	// Nationality		string `xml:"Nationality" json:"Nationality"`
73
+	// SerialNumber		string `xml:"SerialNumber" json:"SerialNumber"`
74
+	// Str1		string `xml:"Str1" json:"Str1"`
75
+	// Str2		string `xml:"Str2" json:"Str2"`
76
+	// Str3		string `xml:"Str3" json:"Str3"`
77
+	// Str4		string `xml:"Str4" json:"Str4"`
78
+	// Str5		string `xml:"Str5" json:"Str5"`
79
+	// TWBG		string `xml:"TWBG" json:"TWBG"`
72 80
 }
73 81
 
74
-// 汕头三优血液透析中心
75
-func SyncGzkyLis() (err error) {
76
-	org_id := int64(10567)
82
+// 获取机构一段时间内检验检查列表
83
+func GetAdGetReportListGzky(Key string, BeginDateTime string, EndDateTime string, TypeDateTime string, AgainFlag string) (key ADStringGzky) {
84
+	Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetReportList"
85
+	//apiurl := "Key=" + Key + "&BeginDateTime=" + BeginDateTime + "&EndDateTime=" + EndDateTime + "&TypeDateTime=" + TypeDateTime + "&AgainFlag=" + AgainFlag
86
+	//apiurl = url.PathEscape(apiurl)
87
+	//apiurl = Domain + apiurl
88
+	//utils.InfoLog("url0: %v", apiurl)
89
+	var xmlKey ADStringGzky
90
+	req := httplib.Post(Domain)
91
+	req.Param("Key", Key)
92
+	req.Param("BeginDateTime", BeginDateTime)
93
+	req.Param("EndDateTime", EndDateTime)
94
+	req.Param("TypeDateTime", TypeDateTime)
95
+	req.Param("AgainFlag", AgainFlag)
96
+	xmlString, _ := req.String()
97
+	xmlString = strings.Replace(xmlString, "&lt;", "<", -1)
98
+	xmlString = strings.Replace(xmlString, "&gt;", ">", -1)
99
+	xml.Unmarshal([]byte(xmlString), &xmlKey)
100
+	return xmlKey
101
+}
77 102
 
78
-	org := &models.DataUploadConfig{
79
-		OrgId:  org_id,
80
-		DbHost: "127.0.0.1",
81
-		DbPort: "1433",
82
-		DbPass: "1Q2W3e4r!@#$",
83
-		DbUser: "kyy",
84
-		DbName: "kmdb",
85
-	}
103
+type AdkCheckGzky struct {
104
+	Cgbg AdkSResultGzky `json:"常规报告"`
105
+}
86 106
 
87
-	orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
88
-	if err != nil {
89
-		utils.ErrorLog("创建数据库连接失败:%v", err)
90
-		return
91
-	}
107
+type AdkSResultGzky struct {
108
+	Item []AdkItemGzky `json:"item"`
109
+}
92 110
 
93
-	// var sync_time int64
94
-	// sync_time = 1627747200
111
+type AdkItemGzky struct {
112
+	Adiconbarcode   string `json:"AdiconBarcode"`
113
+	Patientname     string `json:"PatientName"`
114
+	Sex             string `json:"Sex"`
115
+	Age             string `json:"Age"`
116
+	Reportdate      string `json:"ReportDate"`
117
+	Itemcode        string `json:"ItemCode"`
118
+	ItemnameCn      string `json:"ItemName_CN"`
119
+	ItemnameEn      string `json:"ItemName_EN"`
120
+	Result          string `json:"Result"`
121
+	Resulthint      string `json:"ResultHint"`
122
+	Resultreference string `json:"ResultReference"`
123
+	Resultunit      string `json:"ResultUnit"`
124
+	Zhmc            string `json:"zhmc"`
125
+}
126
+
127
+func GetAdkInfoGzky(key string, id string) (str AdkCheckGzky, checkStr string) {
128
+	Domain := "http://183.63.151.26:8081/AdWebService_new/ADReportWebService.asmx/GetJSONReportItemListByAdiconBarocde?"
129
+	//apiurl := "key=" + key + "&AdiconBarocde=" + id
130
+	//apiurl = url.PathEscape(apiurl)
131
+	//apiurl = Domain + apiurl
132
+	//utils.InfoLog("url1: %v", apiurl)
133
+	xmlKey := XmlKeyGzky{}
134
+	rep := httplib.Post(Domain)
135
+	rep.Param("Key", key)
136
+	rep.Param("AdiconBarcode", id)
137
+	rep.ToXML(&xmlKey)
138
+	utils.InfoLog("InnerText: %v", xmlKey.InnerText)
139
+	var checkJSON AdkCheckGzky
140
+	json.Unmarshal([]byte(xmlKey.InnerText), &checkJSON)
95 141
 
96
-	// scpaLis, _ := GetScpaLis(orgDb, sync_time,"512926196302182682")
97
-	// utils.InfoLog("IdCardNo:%v",scpaLis)
142
+	return checkJSON, xmlKey.InnerText
143
+}
98 144
 
99
-	// 第一步:获取上一次同步的时间点
145
+// 广州康允透析中心Lis同步
146
+func SyncLisGzky(flag int64) (err error) {
147
+	// 第一步:获取艾迪康下发的Key
148
+	org_id := int64(10567)
149
+	login := "RH0395"
150
+	password := "abc123456"
151
+	key := GetAdKeyGzky(login, password)
152
+	utils.InfoLog("key:%v", key)
153
+	// 第二步:获取上一次同步的时间点
100 154
 	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
101 155
 	var sync_time int64
102 156
 	if syncLastInfo.ID > 0 {
103
-		sync_time = syncLastInfo.SyncTime
157
+		sync_time = syncLastInfo.SyncTime - 60*60*24*3
104 158
 	} else {
105
-		sync_time = 1685548800
159
+		sync_time = 1730390400
106 160
 	}
107 161
 
108
-	SyncTime := time.Unix(sync_time, 0)
109
-	syncTimeStr := SyncTime.Format("2006-01-02 15:04:05")
110
-
111
-	fmt.Println(SyncTime)
112
-	// 第二步:获取时间内所有检验结果
113
-	gzkyLis, _ := GetGzkyLis(orgDb, syncTimeStr)
114
-
115
-	if len(gzkyLis) > 0 {
116
-		for _, LisInfo := range gzkyLis {
117
-			utils.InfoLog("LisInfo:%v", LisInfo)
118
-			utils.InfoLog("患者姓名:%v", LisInfo.Fname)
119
-			brxm := LisInfo.Fname
120
-			// 根据姓名获取患者ID
121
-			patient, _ := GetUserInfoByName(org_id, brxm)
122
-			if patient.ID > 0 {
123
-				project_id, _ := GetGzkyProjectID(org_id, LisInfo.Fhospnaturalitemname)
124
-				item_id, _ := GetGzkyItemID(org_id, LisInfo.Fhospnaturalitemname, LisInfo.Fhospitemname, project_id)
125
-				tx := writeMiddleDb.Begin()
126
-				var inspection models.MiddleInspection
127
-				var inspection_reference models.MiddleInspectionReference
128
-
129
-				tempTime := strings.Split(LisInfo.Frecordtime, "T")
130
-				utils.InfoLog("tempTime1:%v", tempTime[0])
131
-				utils.InfoLog("tempTime2:%v", tempTime[1])
132
-				tempTime1 := strings.Split(tempTime[1], "Z")
133
-				tempRecord := tempTime[0] + " " + tempTime1[0]
134
-
135
-				utils.InfoLog("tempTime3:%v", tempRecord)
136
-
137
-				recordTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", tempRecord)
138
-				utils.InfoLog("tempTime4:%v", recordTime)
139
-				inspect_date := recordTime.Format("2006-01-02 15:04")
140
-				recordTimeStr, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", inspect_date)
141
-				recordTimeInt := recordTimeStr.Unix()
142
-				utils.InfoLog("tempTime5:%v", recordTimeInt)
143
-				utils.InfoLog("tempTime6:%v", recordTimeStr)
144
-
145
-				var total int
146
-				var RangeOptions string
147
-				var RangeMin string
148
-				var RangeMax string
149
-				var ItemType int
150
-				typeFlag := strings.Contains(LisInfo.Freference, "阴性")
151
-				if typeFlag {
152
-					ItemType = 2
153
-					RangeMin = LisInfo.Freference
154
-					RangeOptions = LisInfo.Fhint
155
-				} else {
156
-					Range := strings.Split(LisInfo.Freference, "-")
157
-					if len(Range) > 1 {
158
-						RangeMin = Range[0]
159
-						RangeMax = Range[1]
160
-						ItemType = 1
161
-					} else {
162
-						ItemType = 2
163
-						RangeMin = LisInfo.Freference
164
-					}
165
-					RangeOptions = LisInfo.Fhint
166
-				}
162
+	if flag > 0 {
163
+		sync_time = 1730390400
164
+	}
167 165
 
168
-				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
169
-				if total <= 0 {
170
-					inspection_reference.OrgId = org_id
171
-					inspection_reference.ProjectName = LisInfo.Fhospnaturalitemname
172
-					inspection_reference.Project = LisInfo.Fhospnaturalitem
173
-					inspection_reference.ProjectId = project_id
174
-					inspection_reference.ItemName = LisInfo.Fhospitemname
175
-					inspection_reference.ItemNameAddition = LisInfo.Fhospitem
176
-					inspection_reference.ItemId = item_id
177
-					inspection_reference.RangeType = ItemType
178
-					inspection_reference.RangeMin = RangeMin
179
-					inspection_reference.RangeMax = RangeMax
180
-					inspection_reference.RangeValue = LisInfo.Freference
181
-					inspection_reference.RangeOptions = RangeOptions
182
-					inspection_reference.Unit = LisInfo.Funit
183
-					inspection_reference.Status = 1
184
-					inspection_reference.CreatedTime = time.Now().Unix()
185
-					inspection_reference.UpdatedTime = time.Now().Unix()
186
-					inspection_reference.InspectDate = tempRecord
187
-					inspection_reference.UTime = tempRecord
188
-					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
189
-					if err != nil {
190
-						tx.Rollback()
166
+	nowTimes := time.Now().Unix()
167
+	// syncTimes := time.Unix(sync_time,0).Format("2006-01-02")
168
+	if sync_time < nowTimes {
169
+		for i := sync_time; i < nowTimes; i = i + 86400 {
170
+			tempsyncTimes := time.Unix(i, 0).Format("2006-01-02")
171
+			adString := GetAdGetReportListGzky(key, tempsyncTimes, tempsyncTimes, "2", "1")
172
+			listtable := adString.NewDataSetGzky.ListTableGzky
173
+			if len(listtable) >= 1 {
174
+				// 第三步:根据检查列表获取的ID来获取检验检查详情
175
+				for _, list := range listtable {
176
+					listId := list.AdiconBarcode
177
+					checkInfo, _ := GetAdkInfoGzky(key, listId)
178
+					//utils.InfoLog("checkStr: %v", checkStr)
179
+					for _, info := range checkInfo.Cgbg.Item {
180
+						// 根据姓名 去查询对应的patient_id
181
+						patient, _ := GetPatientID(org_id, info.Patientname)
182
+						utils.InfoLog("patient: %v", patient)
183
+						if patient.ID > 0 {
184
+							GzkyReportInfoHandle(info, org_id, patient.ID)
185
+						}
191 186
 					}
192 187
 				}
193
-				var itotal int
194
-				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
195
-				if itotal <= 0 {
196
-					// inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
197
-					// inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)
198
-					inspection.PatientId = patient.ID
199
-					inspection.OrgId = org_id
200
-					inspection.ProjectId = project_id
201
-					inspection.ItemName = inspection_reference.ItemName
202
-					inspection.ProjectName = inspection_reference.ProjectName
203
-					inspection.InspectType = ItemType
204
-					inspection.ItemId = item_id
205
-					inspection.InspectValue = LisInfo.Fresult
206
-					inspection.InspectDate = inspect_date
207
-					inspection.RecordDate = recordTimeInt
208
-					inspection.InspectTips = LisInfo.Fhint
209
-					inspection.Status = 1
210
-					inspection.CreatedTime = time.Now().Unix()
211
-					inspection.UpdatedTime = time.Now().Unix()
212
-					// inspection.UTime = record_date.Format(timeLayout)
213
-					// inspection.HisUserId = strconv.FormatInt(patient_id, 10)
214
-					inspection.SysProjectId = inspection_reference.XtProjectId
215
-					inspection.SysItemId = inspection_reference.XtItemId
216
-					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
217
-					if err != nil {
218
-						tx.Rollback()
219
-					}
188
+				var syncInfo models.MiddleSyncInfo
189
+				syncInfo.OrgId = org_id
190
+
191
+				syncInfo.SyncTime = i
192
+				syncInfo.SyncResultType = 1
193
+				syncInfo.SyncRsultRemark = "同步成功"
194
+				syncInfo.SyncTotalNum = 0
195
+				syncInfo.SyncSuccessNum = 0
196
+				syncInfo.SyncInfo = ""
197
+				syncInfo.CreateTime = time.Now().Unix()
198
+				syncInfo.UpdateTime = time.Now().Unix()
199
+
200
+				cwderr := CreateSyncInfo(&syncInfo)
201
+				if cwderr != nil {
202
+					utils.ErrorLog("创建同步信息失败:%v", cwderr)
203
+					return
220 204
 				}
221
-				tx.Commit()
222
-			} else {
223
-				continue
224 205
 			}
225 206
 		}
207
+
226 208
 	}
227
-	var syncInfo models.MiddleSyncInfo
228
-	syncInfo.OrgId = org_id
229
-	syncInfo.SyncTime = time.Now().Unix()
230
-	syncInfo.SyncResultType = 1
231
-	syncInfo.SyncRsultRemark = "同步成功"
232
-	syncInfo.SyncTotalNum = 0
233
-	syncInfo.SyncSuccessNum = 0
234
-	syncInfo.SyncInfo = ""
235
-	syncInfo.CreateTime = time.Now().Unix()
236
-	syncInfo.UpdateTime = time.Now().Unix()
237
-
238
-	cwderr := CreateSyncInfo(&syncInfo)
239
-	if cwderr != nil {
240
-		utils.ErrorLog("创建同步信息失败:%v", cwderr)
241
-		return
242
-	}
243
-	SyncToGzkytx()
209
+	SyncToGzky()
210
+	TreatSgnForGzky(10567)
244 211
 	return
245 212
 }
246 213
 
247
-// func deleteMid(tx *gorm.DB) (err error) {
248
-// 	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock as t," +
249
-// 		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
250
-// 		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
251
-// 		"WHERE t1.user_org_id = t2.orgid)tmp " +
252
-// 		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
253
-// 		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
254
-// 	return
255
-// }
256
-
257
-func SyncToGzkytx() {
214
+func SyncToGzky() {
258 215
 
259 216
 	utils.TraceLog("检验检查同步任务开始执行")
260 217
 	org_id := int64(10567)
@@ -287,7 +244,6 @@ func SyncGzkyInspection(data *models.MiddleInspection) error {
287 244
 	var total int
288 245
 	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
289 246
 	if total <= 0 {
290
-
291 247
 		inspection.OrgId = data.OrgId
292 248
 		inspection.PatientId = data.PatientId
293 249
 		inspection.ProjectName = data.ProjectName
@@ -319,3 +275,541 @@ func SyncGzkyInspection(data *models.MiddleInspection) error {
319 275
 	tx.Commit()
320 276
 	return err
321 277
 }
278
+
279
+// 同步到正式库后,确认透前肾功能和透后肾功能
280
+// 计算KT/V 和 URR
281
+func TreatSgnForGzky(org_id int64) error {
282
+	tx := writeDb.Begin()
283
+	var inspection []models.Inspection
284
+	err = readDb.Model(&models.Inspection{}).Where("org_id = ? and project_id = 15 and sgn_treat = 0  and status = 1", org_id).Find(&inspection).Error
285
+	if len(inspection) > 0 {
286
+		for _, insp := range inspection {
287
+			var inspectionInfo models.Inspection
288
+			err = readDb.Model(&models.Inspection{}).Where("org_id = ? and patient_id = ? and project_id = 15 and item_id = ? and inspect_date = ? and sgn_treat = 0  and status = 1", org_id, insp.PatientId, insp.ItemId, insp.InspectDate).First(&inspectionInfo).Error
289
+			if inspectionInfo.ID > 0 {
290
+				// 查询前面两天是否有数据,有的话,当前数据有透后数据
291
+				startData := inspectionInfo.InspectDate - 60*60*48
292
+				var inspectionBefore models.Inspection
293
+				err = readDb.Model(&models.Inspection{}).Where("org_id = ? and patient_id = ? and project_id = 15 and item_id = ? and inspect_date >= ? and inspect_date < ? and sgn_treat = 0  and status = 1", org_id, insp.PatientId, insp.ItemId, startData, insp.InspectDate).First(&inspectionBefore).Error
294
+				if inspectionBefore.ID > 0 {
295
+					inspectionBefore.SgnTreat = 1
296
+					inspectionBefore.UpdatedTime = time.Now().Unix()
297
+					err = writeDb.Save(&inspectionBefore).Error
298
+					if err != nil {
299
+						tx.Rollback()
300
+					}
301
+					insp.ProjectId = 8060
302
+					switch insp.ItemId {
303
+					case 37: //尿素
304
+						insp.ItemId = 8061
305
+						break
306
+					case 38: //尿酸
307
+						insp.ItemId = 10834
308
+						break
309
+					case 42: //β2-微球蛋白
310
+						insp.ItemId = 10835
311
+						break
312
+					case 115: //肌酐
313
+						insp.ItemId = 8060
314
+						break
315
+					}
316
+					insp.UpdatedTime = time.Now().Unix()
317
+					insp.SgnTreat = 1
318
+					err = writeDb.Save(&insp).Error
319
+					if err != nil {
320
+						tx.Rollback()
321
+					}
322
+				} else {
323
+					// 前面两天没有查到数据,则可能当前数据是透前数据,后面两天查询到的数据是透后数据
324
+					endData := inspectionInfo.InspectDate + 60*60*48
325
+					var inspectionEnd models.Inspection
326
+					err = readDb.Model(&models.Inspection{}).Where("org_id = ? and patient_id = ? and project_id = 15 and item_id = ? and inspect_date > ? and inspect_date <= ? and sgn_treat = 0  and status = 1", org_id, insp.PatientId, insp.ItemId, insp.InspectDate, endData).First(&inspectionEnd).Error
327
+					if inspectionEnd.ID > 0 {
328
+						insp.SgnTreat = 1
329
+						insp.UpdatedTime = time.Now().Unix()
330
+						err = writeDb.Save(&insp).Error
331
+						if err != nil {
332
+							tx.Rollback()
333
+						}
334
+						inspectionEnd.ProjectId = 8060
335
+						switch inspectionEnd.ItemId {
336
+						case 37: //尿素
337
+							inspectionEnd.ItemId = 8061
338
+							break
339
+						case 38: //尿酸
340
+							inspectionEnd.ItemId = 10834
341
+							break
342
+						case 42: //β2-微球蛋白
343
+							inspectionEnd.ItemId = 10835
344
+							break
345
+						case 115: //肌酐
346
+							inspectionEnd.ItemId = 8060
347
+							break
348
+						}
349
+						inspectionEnd.UpdatedTime = time.Now().Unix()
350
+						inspectionEnd.SgnTreat = 1
351
+						err = writeDb.Save(&inspectionEnd).Error
352
+						if err != nil {
353
+							tx.Rollback()
354
+						}
355
+					} else {
356
+						// 如果前面两天和后面两天都没有数据,则直接改变状体
357
+						insp.SgnTreat = 1
358
+						insp.UpdatedTime = time.Now().Unix()
359
+						err = writeDb.Save(&insp).Error
360
+						if err != nil {
361
+							tx.Rollback()
362
+						}
363
+					}
364
+				}
365
+			} else {
366
+				continue
367
+			}
368
+		}
369
+	}
370
+	tx.Commit()
371
+	return err
372
+}
373
+
374
+// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
375
+func GetGzkyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
376
+	var inspection_reference models.MiddleInspectionReference
377
+	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
378
+	if inspection_reference.ID > 0 {
379
+		return inspection_reference.ItemId, err
380
+	} else {
381
+		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
382
+		utils.InfoLog("inspection_reference: %v", inspection_reference)
383
+		if inspection_reference.ItemId > 0 {
384
+			return inspection_reference.ItemId + 1, err
385
+		} else {
386
+			return project_id*100 + 1, err
387
+		}
388
+	}
389
+}
390
+
391
+// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
392
+func GetGzkyProjectID(org_id int64, project_name string) (project_id int64, err error) {
393
+	var inspection_reference models.MiddleInspectionReference
394
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
395
+	if inspection_reference.ID > 0 {
396
+		return inspection_reference.ProjectId, err
397
+	} else {
398
+		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
399
+		if inspection_reference.ProjectId > 0 {
400
+			return inspection_reference.ProjectId + 1, err
401
+		} else {
402
+			return 1056701, err
403
+		}
404
+	}
405
+}
406
+
407
+func GzkyReportInfoHandle(CheckInfo AdkItemGzky, org_id int64, patientId int64) {
408
+	tx := writeMiddleDb.Begin()
409
+	var total int
410
+	var RangeMin string
411
+	var RangeMax string
412
+
413
+	timstr := strings.Split(CheckInfo.Reportdate, ".")
414
+	recordDateStr := timstr[0]
415
+
416
+	if len(recordDateStr) == 0 {
417
+		recordDateStr = time.Now().Format("2006-01-02 15:04")
418
+	}
419
+
420
+	record_date_str, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
421
+	record_date := record_date_str.Unix()
422
+	inspect_date := time.Unix(record_date, 0).Format("2006-01-02 15:04")
423
+
424
+	// // 判断检查类型
425
+	ItemType := 1
426
+	Range := strings.Split(CheckInfo.Resultreference, "-")
427
+	if len(Range) > 1 {
428
+		RangeMin = Range[0]
429
+		RangeMax = Range[1]
430
+		ItemType = 1
431
+	} else {
432
+		ItemType = 2
433
+	}
434
+
435
+	var inspection models.MiddleInspection
436
+	var inspection_reference models.MiddleInspectionReference
437
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and project = ? and item_code = ? and status = 1", org_id, CheckInfo.Zhmc, CheckInfo.Itemcode).Find(&inspection_reference).Count(&total).Error
438
+	if inspection_reference.ID > 0 {
439
+		ItemType = inspection_reference.RangeType
440
+	}
441
+	if total <= 0 {
442
+		//  如果配置表里没有相关配置,则创建project_id,item_id和相关配置信息
443
+		project_id, _ := GetChydProjectID(org_id, CheckInfo.Zhmc)
444
+		item_id, _ := GetChydItemID(org_id, CheckInfo.Zhmc, CheckInfo.ItemnameCn, project_id)
445
+
446
+		inspection_reference.OrgId = org_id
447
+		inspection_reference.ProjectName = CheckInfo.Zhmc
448
+		inspection_reference.Project = CheckInfo.Zhmc
449
+		inspection_reference.ProjectId = project_id
450
+		inspection_reference.ItemName = CheckInfo.ItemnameCn
451
+		inspection_reference.ItemNameAddition = CheckInfo.ItemnameEn
452
+		inspection_reference.ItemId = item_id
453
+		inspection_reference.ItemCode = CheckInfo.Itemcode
454
+		inspection_reference.RangeType = ItemType
455
+		inspection_reference.RangeMin = RangeMin
456
+		inspection_reference.RangeMax = RangeMax
457
+		// inspection_reference.RangeValue = RangeValue
458
+		//inspection_reference.RangeOptions = RangeOptions
459
+		inspection_reference.Unit = CheckInfo.Resultunit
460
+		inspection_reference.Status = 1
461
+		inspection_reference.CreatedTime = time.Now().Unix()
462
+		inspection_reference.UpdatedTime = time.Now().Unix()
463
+		inspection_reference.InspectDate = inspect_date
464
+		inspection_reference.UTime = inspect_date
465
+		inspection_reference.Adiconbarcode = CheckInfo.Adiconbarcode
466
+		err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
467
+		if err != nil {
468
+			tx.Rollback()
469
+		}
470
+	}
471
+
472
+	var itotal int
473
+	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, patientId).Find(&inspection).Count(&itotal).Error
474
+	if itotal <= 0 {
475
+		inspection.PatientId = patientId
476
+		inspection.OrgId = org_id
477
+		inspection.ProjectId = inspection_reference.ProjectId
478
+		inspection.ItemName = inspection_reference.ItemName
479
+		inspection.ProjectName = inspection_reference.ProjectName
480
+		inspection.InspectType = ItemType
481
+		inspection.ItemId = inspection_reference.ItemId
482
+		inspection.InspectValue = CheckInfo.Result
483
+		inspection.InspectDate = inspect_date
484
+		inspection.RecordDate = record_date
485
+		//inspection.InspectTips = result.AntiCode
486
+		inspection.Status = 1
487
+		inspection.CreatedTime = time.Now().Unix()
488
+		inspection.UpdatedTime = time.Now().Unix()
489
+		inspection.SysProjectId = inspection_reference.XtProjectId
490
+		inspection.SysItemId = inspection_reference.XtItemId
491
+		inspection.UTime = inspect_date
492
+		inspection.HisUserId = strconv.FormatInt(patientId, 10)
493
+		inspection.Adiconbarcode = CheckInfo.Adiconbarcode
494
+		if inspection_reference.ItemId == 103180107 || inspection_reference.ItemId == 103180301 {
495
+			if strings.Index(CheckInfo.Result, "阳性") != -1 {
496
+				inspection.InspectValue = "阳性"
497
+			} else {
498
+				inspection.InspectValue = "阴性"
499
+			}
500
+		}
501
+
502
+		err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
503
+		if err != nil {
504
+			tx.Rollback()
505
+		}
506
+	}
507
+	tx.Commit()
508
+}
509
+
510
+//
511
+//type gzkylis struct {
512
+//	Finputdate           string `gorm:"column:F_InputDate" json:"F_InputDate"`
513
+//	Fname                string `gorm:"column:F_Name" json:"F_Name"`
514
+//	Fsex                 string `gorm:"column:F_Sex" json:"F_Sex"`
515
+//	Fage                 string `gorm:"column:F_Age" json:"F_Age"`
516
+//	Fhospnaturalitem     string `gorm:"column:F_HospNaturalItem" json:"F_HospNaturalItem"`
517
+//	Fhospnaturalitemname string `gorm:"column:F_HospNaturalItemName" json:"F_HospNaturalItemName"`
518
+//	Fhospitem            string `gorm:"column:F_HospItem" json:"F_HospItem"`
519
+//	Fhospitemname        string `gorm:"column:F_HospItemName" json:"F_HospItemName"`
520
+//	Fresult              string `gorm:"column:F_Result" json:"F_Result"`
521
+//	Funit                string `gorm:"column:F_Unit" json:"F_Unit"`
522
+//	Fhint                string `gorm:"column:F_Hint" json:"F_Hint"`
523
+//	Freference           string `gorm:"column:F_Reference" json:"F_Reference"`
524
+//	Frecordtime          string `gorm:"column:F_RecordTime" json:"F_RecordTime"`
525
+//}
526
+//
527
+//func (gzkylis) TableName() string {
528
+//	return "V_KM_LIS_Result"
529
+//}
530
+//
531
+//func GetGzkyLis(rdb *gorm.DB, synctime string) (record []*gzkylis, err error) {
532
+//	err = rdb.Model(&gzkylis{}).Where("F_RecordTime >= ? ", synctime).Find(&record).Error
533
+//	return
534
+//}
535
+//
536
+//// 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
537
+//func GetGzkyProjectID(org_id int64, project_name string) (project_id int64, err error) {
538
+//	var inspection_reference models.MiddleInspectionReference
539
+//	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?  ", org_id, project_name).First(&inspection_reference).Error
540
+//	if inspection_reference.ID > 0 {
541
+//		return inspection_reference.ProjectId, err
542
+//	} else {
543
+//		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
544
+//		if inspection_reference.ProjectId > 0 {
545
+//			return inspection_reference.ProjectId + 1, err
546
+//		} else {
547
+//			return 1056701, err
548
+//		}
549
+//	}
550
+//}
551
+//
552
+//// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
553
+//func GetGzkyItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
554
+//	var inspection_reference models.MiddleInspectionReference
555
+//	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
556
+//	if inspection_reference.ID > 0 {
557
+//		return inspection_reference.ItemId, err
558
+//	} else {
559
+//		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
560
+//		if inspection_reference.ItemId > 0 {
561
+//			return inspection_reference.ItemId + 1, err
562
+//		} else {
563
+//			return project_id*100 + 1, err
564
+//		}
565
+//	}
566
+//}
567
+//
568
+//// 汕头三优血液透析中心
569
+//func SyncGzkyLis() (err error) {
570
+//	org_id := int64(10567)
571
+//
572
+//	org := &models.DataUploadConfig{
573
+//		OrgId:  org_id,
574
+//		DbHost: "127.0.0.1",
575
+//		DbPort: "1433",
576
+//		DbPass: "1Q2W3e4r!@#$",
577
+//		DbUser: "kyy",
578
+//		DbName: "kmdb",
579
+//	}
580
+//
581
+//	orgDb, err := CreateSqlServiceDB(org.DbHost, org.DbPort, org.DbUser, org.DbPass, org.DbName)
582
+//	if err != nil {
583
+//		utils.ErrorLog("创建数据库连接失败:%v", err)
584
+//		return
585
+//	}
586
+//
587
+//	// var sync_time int64
588
+//	// sync_time = 1627747200
589
+//
590
+//	// scpaLis, _ := GetScpaLis(orgDb, sync_time,"512926196302182682")
591
+//	// utils.InfoLog("IdCardNo:%v",scpaLis)
592
+//
593
+//	// 第一步:获取上一次同步的时间点
594
+//	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
595
+//	var sync_time int64
596
+//	if syncLastInfo.ID > 0 {
597
+//		sync_time = syncLastInfo.SyncTime
598
+//	} else {
599
+//		sync_time = 1685548800
600
+//	}
601
+//
602
+//	SyncTime := time.Unix(sync_time, 0)
603
+//	syncTimeStr := SyncTime.Format("2006-01-02 15:04:05")
604
+//
605
+//	fmt.Println(SyncTime)
606
+//	// 第二步:获取时间内所有检验结果
607
+//	gzkyLis, _ := GetGzkyLis(orgDb, syncTimeStr)
608
+//
609
+//	if len(gzkyLis) > 0 {
610
+//		for _, LisInfo := range gzkyLis {
611
+//			utils.InfoLog("LisInfo:%v", LisInfo)
612
+//			utils.InfoLog("患者姓名:%v", LisInfo.Fname)
613
+//			brxm := LisInfo.Fname
614
+//			// 根据姓名获取患者ID
615
+//			patient, _ := GetUserInfoByName(org_id, brxm)
616
+//			if patient.ID > 0 {
617
+//				project_id, _ := GetGzkyProjectID(org_id, LisInfo.Fhospnaturalitemname)
618
+//				item_id, _ := GetGzkyItemID(org_id, LisInfo.Fhospnaturalitemname, LisInfo.Fhospitemname, project_id)
619
+//				tx := writeMiddleDb.Begin()
620
+//				var inspection models.MiddleInspection
621
+//				var inspection_reference models.MiddleInspectionReference
622
+//
623
+//				tempTime := strings.Split(LisInfo.Frecordtime, "T")
624
+//				utils.InfoLog("tempTime1:%v", tempTime[0])
625
+//				utils.InfoLog("tempTime2:%v", tempTime[1])
626
+//				tempTime1 := strings.Split(tempTime[1], "Z")
627
+//				tempRecord := tempTime[0] + " " + tempTime1[0]
628
+//
629
+//				utils.InfoLog("tempTime3:%v", tempRecord)
630
+//
631
+//				recordTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", tempRecord)
632
+//				utils.InfoLog("tempTime4:%v", recordTime)
633
+//				inspect_date := recordTime.Format("2006-01-02 15:04")
634
+//				recordTimeStr, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", inspect_date)
635
+//				recordTimeInt := recordTimeStr.Unix()
636
+//				utils.InfoLog("tempTime5:%v", recordTimeInt)
637
+//				utils.InfoLog("tempTime6:%v", recordTimeStr)
638
+//
639
+//				var total int
640
+//				var RangeOptions string
641
+//				var RangeMin string
642
+//				var RangeMax string
643
+//				var ItemType int
644
+//				typeFlag := strings.Contains(LisInfo.Freference, "阴性")
645
+//				if typeFlag {
646
+//					ItemType = 2
647
+//					RangeMin = LisInfo.Freference
648
+//					RangeOptions = LisInfo.Fhint
649
+//				} else {
650
+//					Range := strings.Split(LisInfo.Freference, "-")
651
+//					if len(Range) > 1 {
652
+//						RangeMin = Range[0]
653
+//						RangeMax = Range[1]
654
+//						ItemType = 1
655
+//					} else {
656
+//						ItemType = 2
657
+//						RangeMin = LisInfo.Freference
658
+//					}
659
+//					RangeOptions = LisInfo.Fhint
660
+//				}
661
+//
662
+//				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
663
+//				if total <= 0 {
664
+//					inspection_reference.OrgId = org_id
665
+//					inspection_reference.ProjectName = LisInfo.Fhospnaturalitemname
666
+//					inspection_reference.Project = LisInfo.Fhospnaturalitem
667
+//					inspection_reference.ProjectId = project_id
668
+//					inspection_reference.ItemName = LisInfo.Fhospitemname
669
+//					inspection_reference.ItemNameAddition = LisInfo.Fhospitem
670
+//					inspection_reference.ItemId = item_id
671
+//					inspection_reference.RangeType = ItemType
672
+//					inspection_reference.RangeMin = RangeMin
673
+//					inspection_reference.RangeMax = RangeMax
674
+//					inspection_reference.RangeValue = LisInfo.Freference
675
+//					inspection_reference.RangeOptions = RangeOptions
676
+//					inspection_reference.Unit = LisInfo.Funit
677
+//					inspection_reference.Status = 1
678
+//					inspection_reference.CreatedTime = time.Now().Unix()
679
+//					inspection_reference.UpdatedTime = time.Now().Unix()
680
+//					inspection_reference.InspectDate = tempRecord
681
+//					inspection_reference.UTime = tempRecord
682
+//					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
683
+//					if err != nil {
684
+//						tx.Rollback()
685
+//					}
686
+//				}
687
+//				var itotal int
688
+//				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
689
+//				if itotal <= 0 {
690
+//					// inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
691
+//					// inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)
692
+//					inspection.PatientId = patient.ID
693
+//					inspection.OrgId = org_id
694
+//					inspection.ProjectId = project_id
695
+//					inspection.ItemName = inspection_reference.ItemName
696
+//					inspection.ProjectName = inspection_reference.ProjectName
697
+//					inspection.InspectType = ItemType
698
+//					inspection.ItemId = item_id
699
+//					inspection.InspectValue = LisInfo.Fresult
700
+//					inspection.InspectDate = inspect_date
701
+//					inspection.RecordDate = recordTimeInt
702
+//					inspection.InspectTips = LisInfo.Fhint
703
+//					inspection.Status = 1
704
+//					inspection.CreatedTime = time.Now().Unix()
705
+//					inspection.UpdatedTime = time.Now().Unix()
706
+//					// inspection.UTime = record_date.Format(timeLayout)
707
+//					// inspection.HisUserId = strconv.FormatInt(patient_id, 10)
708
+//					inspection.SysProjectId = inspection_reference.XtProjectId
709
+//					inspection.SysItemId = inspection_reference.XtItemId
710
+//					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
711
+//					if err != nil {
712
+//						tx.Rollback()
713
+//					}
714
+//				}
715
+//				tx.Commit()
716
+//			} else {
717
+//				continue
718
+//			}
719
+//		}
720
+//	}
721
+//	var syncInfo models.MiddleSyncInfo
722
+//	syncInfo.OrgId = org_id
723
+//	syncInfo.SyncTime = time.Now().Unix()
724
+//	syncInfo.SyncResultType = 1
725
+//	syncInfo.SyncRsultRemark = "同步成功"
726
+//	syncInfo.SyncTotalNum = 0
727
+//	syncInfo.SyncSuccessNum = 0
728
+//	syncInfo.SyncInfo = ""
729
+//	syncInfo.CreateTime = time.Now().Unix()
730
+//	syncInfo.UpdateTime = time.Now().Unix()
731
+//
732
+//	cwderr := CreateSyncInfo(&syncInfo)
733
+//	if cwderr != nil {
734
+//		utils.ErrorLog("创建同步信息失败:%v", cwderr)
735
+//		return
736
+//	}
737
+//	SyncToGzkytx()
738
+//	return
739
+//}
740
+//
741
+//// func deleteMid(tx *gorm.DB) (err error) {
742
+//// 	err = tx.Exec("UPDATE sgj_xt.xt_drug_cancel_stock as t," +
743
+//// 		"(SELECT t1.user_org_id as orgid,t1.drug_storehouse_out as id from sgj_xt.xt_storehouse_config as t1," +
744
+//// 		"(SELECT distinct org_id as orgid FROM sgj_xt.xt_drug_cancel_stock  WHERE storehouse_id is NULL or storehouse_id = 0 )t2 " +
745
+//// 		"WHERE t1.user_org_id = t2.orgid)tmp " +
746
+//// 		"SET t.storehouse_id = tmp.id,t.mtime = UNIX_TIMESTAMP()" +
747
+//// 		"WHERE (t.storehouse_id = 0 or t.storehouse_id is null) and t.org_id = tmp.orgid").Error
748
+//// 	return
749
+//// }
750
+//
751
+//func SyncToGzkytx() {
752
+//
753
+//	utils.TraceLog("检验检查同步任务开始执行")
754
+//	org_id := int64(10567)
755
+//
756
+//	// 第一步:跟进org_id 去中间库查出需要同步的数据
757
+//	//inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
758
+//	inspections, _ := GetSyncInspectionByOrgId(org_id)
759
+//
760
+//	// 第二步:将数据同步到业务库
761
+//	//if len(inspection_references) > 0 {
762
+//	//	for _, inspection_reference := range inspection_references {
763
+//	//		SyncInspectionReference(&inspection_reference)
764
+//	//	}
765
+//	//}
766
+//
767
+//	if len(inspections) > 0 {
768
+//		for _, inspection := range inspections {
769
+//			if inspection.SysProjectId > 0 && inspection.SysItemId > 0 {
770
+//				SyncGzkyInspection(&inspection)
771
+//			}
772
+//		}
773
+//	}
774
+//	utils.SuccessLog("检验检查同步任务完成")
775
+//}
776
+//
777
+//// 从机构将数据同步到中间库
778
+//func SyncGzkyInspection(data *models.MiddleInspection) error {
779
+//	tx := writeDb.Begin()
780
+//	var inspection models.Inspection
781
+//	var total int
782
+//	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
783
+//	if total <= 0 {
784
+//
785
+//		inspection.OrgId = data.OrgId
786
+//		inspection.PatientId = data.PatientId
787
+//		inspection.ProjectName = data.ProjectName
788
+//		// inspection.Project = data.ProjectName
789
+//		inspection.ProjectId = data.SysProjectId
790
+//		inspection.ItemName = data.ItemName
791
+//		inspection.ItemId = data.SysItemId
792
+//		inspection.InspectType = int64(data.InspectType)
793
+//		inspection.InspectValue = data.InspectValue
794
+//		inspection.InspectTips = data.InspectTips
795
+//		inspection.InspectDate = data.RecordDate
796
+//		inspection.Status = 1
797
+//		inspection.CreatedTime = time.Now().Unix()
798
+//		inspection.UpdatedTime = time.Now().Unix()
799
+//
800
+//		err := tx.Model(&models.Inspection{}).Create(&inspection).Error
801
+//		if err != nil {
802
+//			tx.Rollback()
803
+//		}
804
+//
805
+//		data.IsSync = 1
806
+//		data.SyncId = inspection.ID
807
+//		data.UpdatedTime = time.Now().Unix()
808
+//		ierr := writeMiddleDb.Save(&data).Error
809
+//		if ierr != nil {
810
+//			tx.Rollback()
811
+//		}
812
+//	}
813
+//	tx.Commit()
814
+//	return err
815
+//}

+ 22 - 15
service/lgty_service.go View File

@@ -40,7 +40,7 @@ func SyncLisLgty() (err error) {
40 40
 				if inspectionLastInfo.ID > 0 {
41 41
 					sync_time = inspectionLastInfo.CreatedTime
42 42
 				} else {
43
-					sync_time = 1672502400
43
+					sync_time = 1704038400
44 44
 				}
45 45
 			}
46 46
 
@@ -170,7 +170,7 @@ func ReportInfoHandle(org_id int64) {
170 170
 					//return
171 171
 				}
172 172
 				report_handle.ReportInfoItemNum = int64(report_info_item_num)
173
-				project_id, _ := GetProjectID(org_id, report_handle.Item)
173
+				//project_id, _ := GetProjectID(org_id, report_handle.Item)
174 174
 				patient, perr := GetUserInfoByAdmission(report_handle.PatientId, org_id)
175 175
 				if perr != nil {
176 176
 					utils.ErrorLog("查询病人信息失败:%v", perr)
@@ -183,8 +183,8 @@ func ReportInfoHandle(org_id int64) {
183 183
 							continue
184 184
 						}
185 185
 						// 获取该小项的检验检查item_id,如果没有,则创建一个
186
-						item_id, _ := GetItemID(org_id, report_handle.Item, reportInfo.ItemName, project_id)
187
-						_, _, syerr := LgthSync(&report_handle, reportInfo, project_id, item_id, org_id, patient.ID, patient.AdmissionNumber)
186
+						//item_id, _ := GetItemID(org_id, report_handle.Item, reportInfo.ItemName, project_id)
187
+						_, _, syerr := LgthSync(&report_handle, reportInfo, org_id, patient.ID, patient.AdmissionNumber)
188 188
 						if syerr != nil {
189 189
 							utils.ErrorLog("创建同步信息失败:%v", syerr)
190 190
 							return
@@ -194,7 +194,7 @@ func ReportInfoHandle(org_id int64) {
194 194
 			}
195 195
 		}
196 196
 	}
197
-	SyncToLgey()
197
+	//SyncToLgey()
198 198
 }
199 199
 
200 200
 func SyncToLgey() {
@@ -221,10 +221,12 @@ func SyncToLgey() {
221 221
 }
222 222
 
223 223
 // 从机构将数据同步到中间库
224
-func LgthSync(Head *models.MiddleReportHandle, report ReportInfo, project_id int64, item_id int64, org_id int64, patient_id int64, his_user_id string) (*models.MiddleInspectionReference, *models.MiddleInspection, error) {
224
+func LgthSync(Head *models.MiddleReportHandle, report ReportInfo, org_id int64, patient_id int64, his_user_id string) (*models.MiddleInspectionReference, *models.MiddleInspection, error) {
225 225
 	tx := writeMiddleDb.Begin()
226 226
 	var inspection models.MiddleInspection
227 227
 	var inspection_reference models.MiddleInspectionReference
228
+	//var project_id int64
229
+	//var item_id int64
228 230
 	recordDateStr := Head.CheckTime
229 231
 	utils.InfoLog("打印测试: %v", recordDateStr)
230 232
 
@@ -259,21 +261,26 @@ func LgthSync(Head *models.MiddleReportHandle, report ReportInfo, project_id int
259 261
 		RangeOptions = report.Reference
260 262
 	}
261 263
 
262
-	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
264
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and item_name = ? and range_value = ? and status = 1", org_id, report.ItemName, report.Reference).Find(&inspection_reference).Count(&total).Error
263 265
 	if inspection_reference.ID > 0 {
264 266
 		ItemType = inspection_reference.RangeType
267
+		//project_id = inspection_reference.ProjectId
268
+		//item_id = inspection_reference.ItemId
265 269
 	}
266 270
 	if total <= 0 && len(Head.Item) > 0 {
271
+		projectId, _ := GetProjectID(org_id, Head.Item)
272
+		itemId, _ := GetItemID(org_id, Head.Item, report.ItemName, projectId)
273
+
267 274
 		inspection_reference.OrgId = org_id
268 275
 		inspection_reference.ProjectName = Head.Item
269 276
 		inspection_reference.Project = Head.Item
270
-		inspection_reference.ProjectId = project_id
277
+		inspection_reference.ProjectId = projectId
271 278
 		inspection_reference.ItemName = report.ItemName
272
-		inspection_reference.ItemId = item_id
279
+		inspection_reference.ItemId = itemId
273 280
 		inspection_reference.RangeType = ItemType
274 281
 		inspection_reference.RangeMin = RangeMin
275 282
 		inspection_reference.RangeMax = RangeMax
276
-		// inspection_reference.RangeValue = RangeValue
283
+		inspection_reference.RangeValue = report.Reference
277 284
 		inspection_reference.RangeOptions = RangeOptions
278 285
 		inspection_reference.Unit = report.Unit
279 286
 		inspection_reference.Status = 1
@@ -287,15 +294,15 @@ func LgthSync(Head *models.MiddleReportHandle, report ReportInfo, project_id int
287 294
 		}
288 295
 	}
289 296
 
290
-	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
297
+	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
291 298
 	if itotal <= 0 {
292 299
 		inspection.PatientId = patient_id
293 300
 		inspection.OrgId = org_id
294
-		inspection.ProjectId = project_id
301
+		inspection.ProjectId = inspection_reference.ProjectId
295 302
 		inspection.ItemName = report.ItemName
296 303
 		inspection.ProjectName = Head.Item
297 304
 		inspection.InspectType = ItemType
298
-		inspection.ItemId = item_id
305
+		inspection.ItemId = inspection_reference.ItemId
299 306
 		inspection.InspectValue = report.Result
300 307
 		inspection.InspectDate = inspect_date
301 308
 		inspection.RecordDate = record_date
@@ -335,7 +342,7 @@ func LgthSync(Head *models.MiddleReportHandle, report ReportInfo, project_id int
335 342
 // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
336 343
 func GetItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
337 344
 	var inspection_reference models.MiddleInspectionReference
338
-	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
345
+	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
339 346
 	if inspection_reference.ID > 0 {
340 347
 		return inspection_reference.ItemId, err
341 348
 	} else {
@@ -352,7 +359,7 @@ func GetItemID(org_id int64, project_name string, item_name string, project_id i
352 359
 // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
353 360
 func GetProjectID(org_id int64, project_name string) (project_id int64, err error) {
354 361
 	var inspection_reference models.MiddleInspectionReference
355
-	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
362
+	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project = ? ", org_id, project_name).First(&inspection_reference).Error
356 363
 	if inspection_reference.ID > 0 {
357 364
 		return inspection_reference.ProjectId, err
358 365
 	} else {

+ 4 - 4
service/pljx_service.go View File

@@ -35,7 +35,7 @@ func GetPljxLisReport(rdb *gorm.DB, synctime string) (record []*pljxLisReportRes
35 35
 func SyncLisPljx(org_id int64) (err error) {
36 36
 	org := &models.DataUploadConfig{
37 37
 		OrgId:  org_id,
38
-		DbHost: "localhost",
38
+		DbHost: "(local)",
39 39
 		DbPort: "1433",
40 40
 		DbPass: "1Q2W3e4r!@#$",
41 41
 		DbUser: "kyy",
@@ -55,9 +55,9 @@ func SyncLisPljx(org_id int64) (err error) {
55 55
 	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)
56 56
 	var sync_time int64
57 57
 	if syncLastInfo.ID > 0 {
58
-		sync_time = syncLastInfo.SyncTime
58
+		sync_time = syncLastInfo.SyncTime - 60*60*24*7
59 59
 	} else {
60
-		sync_time = 1698768000 // 2023-01-01
60
+		sync_time = 1704038400 // 2024-01-01
61 61
 	}
62 62
 
63 63
 	SyncTime := time.Unix(sync_time, 0)
@@ -141,7 +141,7 @@ func SyncLisPljx(org_id int64) (err error) {
141 141
 					}
142 142
 				}
143 143
 				var itotal int
144
-				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
144
+				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
145 145
 				if itotal <= 0 {
146 146
 					// inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
147 147
 					// inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)

+ 1 - 1
service/sclsyyyy_service.go View File

@@ -176,7 +176,7 @@ func SyncScyyyyLis() (err error) {
176 176
 				}
177 177
 			}
178 178
 			var itotal int
179
-			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, patientInfo.ID).Find(&inspection).Count(&itotal).Error
179
+			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, patientInfo.ID).Find(&inspection).Count(&itotal).Error
180 180
 			if itotal <= 0 {
181 181
 				// inspection.InspectValue = strings.Replace(LisInfo.Testresult, "&gt;", ">", -1)
182 182
 				// inspection.InspectValue = strings.Replace(LiLisInfo.Testresult, "&lt;", "<", -1)

+ 1 - 1
service/sssy_service.go View File

@@ -675,7 +675,7 @@ func SyncSYData2() {
675 675
 	}
676 676
 	loc, _ := time.LoadLocation("Local")
677 677
 	theTime, _ := time.ParseInLocation("2006-01-02", start_time, loc)
678
-	newtheTime := theTime.Unix() - 60*60*24
678
+	newtheTime := theTime.Unix() - 60*60*24*9
679 679
 
680 680
 	SyncTime := time.Unix(newtheTime, 0)
681 681
 	syncTimeStr := SyncTime.Format("2006-01-02")

+ 0 - 79
service/sy_service.go View File

@@ -87,57 +87,6 @@ func GetStsyItemID(org_id int64, project_name string, item_name string, project_
87 87
 	}
88 88
 }
89 89
 
90
-func SyncShuHeLis() (err error) {
91
-
92
-	org_id := int64(10644)
93
-	org := &models.DataUploadConfig{
94
-		OrgId:  org_id,
95
-		DbHost: "192.168.2.4",
96
-		DbPort: "1433",
97
-		DbPass: "a123456..",
98
-		DbUser: "sa",
99
-		DbName: "BI",
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
-	fmt.Println(orgDb)
108
-
109
-	infoList, _ := GetHisLabelPrintStatusInfo(org_id)
110
-	if len(infoList) > 0 {
111
-		for _, item := range infoList {
112
-			p_ids_arr := strings.Split(item.Ids, ",")
113
-			list, _ := GetHisLabelPrintInfo(org_id, p_ids_arr)
114
-			fmt.Println("list==============", list)
115
-			patients, _ := GetPatientByIDOne(org_id, item.PatientId)
116
-			fmt.Println("patinets", patients.Name)
117
-			fmt.Println("patinets", patients.IdCardNo)
118
-			if len(list) > 0 {
119
-				for _, it := range list {
120
-					printCode := models.DataPrintCode{
121
-						HisUserId:   patients.IdCardNo,
122
-						Name:        patients.Name,
123
-						RecordDate:  it.RecordDate,
124
-						ProjectName: it.ProjectName,
125
-						Ctime:       time.Now().Unix(),
126
-						Mtime:       time.Now().Unix(),
127
-						Status:      1,
128
-						PrintId:     item.ID,
129
-						PatientId:   it.PatientId,
130
-					}
131
-					err = CratePrintCode(orgDb, printCode)
132
-					fmt.Println("errr-000000000000000", err)
133
-				}
134
-			}
135
-
136
-		}
137
-	}
138
-	return
139
-}
140
-
141 90
 // 汕头三优血液透析中心
142 91
 func SyncStsyLis() (err error) {
143 92
 	org_id := int64(10223)
@@ -333,31 +282,3 @@ func SyncToStsytx() {
333 282
 	// 第四步:关闭数据库连接
334 283
 	utils.SuccessLog("检验检查同步任务完成")
335 284
 }
336
-
337
-//舒和
338
-
339
-func CratePrintCode(rdb *gorm.DB, code models.DataPrintCode) error {
340
-
341
-	err := rdb.Create(&code).Error
342
-	return err
343
-}
344
-
345
-func GetHisLabelPrintStatusInfo(user_org_id int64) (info []*models.XtHisLabelPrintStatusInfo, err error) {
346
-
347
-	err = XTReadDB().Where("user_org_id = ? and status=1 and record_date ='2024-09-04'", user_org_id).Find(&info).Error
348
-
349
-	return info, err
350
-}
351
-
352
-func GetHisLabelPrintInfo(user_org_id int64, p_ids_arr []string) (list []*models.HisLabelPrintInfo, err error) {
353
-
354
-	err = XTReadDB().Where("user_org_id = ? and status=1 and id in(?)", user_org_id, p_ids_arr).Find(&list).Error
355
-
356
-	return list, err
357
-}
358
-func GetPatientByIDOne(orgID int64, patientID int64) (models.Patients, error) {
359
-	var patient models.Patients
360
-	err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
361
-
362
-	return patient, err
363
-}

+ 6 - 7
service/szwz_service.go View File

@@ -3,7 +3,6 @@ package service
3 3
 import (
4 4
 	"IC/models"
5 5
 	"IC/utils"
6
-	oracle "github.com/dzwvip/gorm-oracle"
7 6
 	"gorm.io/gorm"
8 7
 	"strings"
9 8
 	"time"
@@ -49,15 +48,15 @@ func GetSzwzyLisReportResule(rdb *gorm.DB, repno string) (record []*wzLisReportR
49 48
 }
50 49
 
51 50
 // 深圳五洲中医院Lis同步
52
-func SyncLisSzwz() (err error) {
51
+func SyncLisSzwz(orgDb *gorm.DB) (err error) {
53 52
 
54 53
 	org_id := int64(10580)
55 54
 
56
-	orgDb, err := gorm.Open(oracle.Open("oracle://BSLIS52:zhsoft@172.9.200.3:1521/JYK"), &gorm.Config{})
57
-
58
-	if err != nil {
59
-		utils.InfoLog("syncTimeStr:%v", err)
60
-	}
55
+	//orgDb, err := gorm.Open(oracle.Open("oracle://BSLIS52:zhsoft@172.9.200.3:1521/JYK"), &gorm.Config{})
56
+	//
57
+	//if err != nil {
58
+	//	utils.InfoLog("syncTimeStr:%v", err)
59
+	//}
61 60
 
62 61
 	// 第一步:获取上一次同步的时间点
63 62
 	syncLastInfo, _ := GetSyncTimeByOrgIDForYs(org_id)