张保健 1 vuosi sitten
vanhempi
commit
637cd84f34

+ 1 - 1
controllers/lis.go Näytä tiedosto

@@ -39,7 +39,7 @@ func (c *LisController) SyncTest() {
39 39
 	// 获取备份库里所有的医嘱信息
40 40
 	// service.EmrBloodDiaylOrder()
41 41
 	// service.EmrBloodDiaylDetail()
42
-	service.SyncScpaLis()
42
+	//service.SyncScpaLis()
43 43
 	c.ServeSuccessJSON(map[string]interface{}{
44 44
 		"resultList": "12345",
45 45
 	})

+ 4 - 1
main.go Näytä tiedosto

@@ -15,11 +15,14 @@ func init() {
15 15
 }
16 16
 
17 17
 func main() {
18
-	service.BeginAutoSyncLis()
18
+	//service.BeginAutoSyncLis()
19 19
 	//service.GetDataInsertDB(10138)
20 20
 	//service.GetResultDataInsertDB(10138)
21 21
 	// service.GetSHResultDataInsertDB(10215)
22 22
 	// service.Synctfyz()
23 23
 	// service.GetSHResultDataInsertDB(10215)
24
+
25
+	service.SyncSYData2(10191)
26
+	//service.UploadSYData(10191)
24 27
 	beego.Run()
25 28
 }

+ 1 - 0
models/exists_report.go Näytä tiedosto

@@ -0,0 +1 @@
1
+package models

+ 77 - 0
models/jy_apply.go Näytä tiedosto

@@ -0,0 +1,77 @@
1
+package models
2
+
3
+import "encoding/xml"
4
+
5
+type JYApplyEnvelope struct {
6
+	XMLName xml.Name    `xml:"soap:Envelope"`
7
+	Soap    string      `xml:"xmlns:soap,attr"`
8
+	Xsi     string      `xml:"xmlns:xsi,attr"`
9
+	Xsd     string      `xml:"xmlns:xsd,attr"`
10
+	Body    JYApplyBody `xml:"soap:Body"`
11
+}
12
+
13
+type JYApplyBody struct {
14
+	XMLName         xml.Name        `xml:"soap:Body"`
15
+	InspectApplyReq InspectApplyReq `xml:"InspectApplyByInstituteItemCode"`
16
+}
17
+
18
+type InspectApplyReq struct {
19
+	XMLName         xml.Name `xml:"http://tempuri.org/ InspectApplyByInstituteItemCode"`
20
+	ApiKey          string   `xml:"apiKey"`
21
+	Apply           JYApply  `xml:"apply"`
22
+	ApplyDetailList struct {
23
+		CustomerApplyDetail []CustomerApplyDetail `xml:"CustomerApplyDetail"`
24
+	} `xml:"applyDetailList"`
25
+	//ApplyDetailList []JYApplyDetail    `xml:"applyDetailList>JYApplyDetail"`
26
+	ApplyAdditional *JYApplyAdditional `xml:"applyAdditional,omitempty"`
27
+}
28
+
29
+type EnvelopeFour struct {
30
+	XMLName xml.Name         `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
31
+	Body    EnvelopeBodyFour `xml:"Body"`
32
+}
33
+
34
+type EnvelopeBodyFour struct {
35
+	InspectApplyByInstituteItemCodeResponse InspectApplyByInstituteItemCodeResponse `xml:"InspectApplyByInstituteItemCodeResponse"`
36
+}
37
+
38
+type InspectApplyByInstituteItemCodeResponse struct {
39
+	XMLName      xml.Name `xml:"http://tempuri.org/ InspectApplyByInstituteItemCodeResponse"`
40
+	InspectApply string   `xml:"InspectApplyByInstituteItemCodeResult"`
41
+}
42
+
43
+type InspectApplyData struct {
44
+	Res           int           `json:"Res"`
45
+	Error         string        `json:"Error"`
46
+	JYApplyResult JYApplyResult `json:"Data"`
47
+}
48
+
49
+type JYApply struct {
50
+	XMLName      xml.Name `xml:"apply"`
51
+	PatientName  string   `xml:"PatientName"`
52
+	Sex          string   `xml:"Sex"`
53
+	Age          string   `xml:"Age"`
54
+	AgeUnit      string   `xml:"AgeUnit"`
55
+	RegisterCode string   `xml:"RegisterCode"`
56
+	Diagnosis    string   `xml:"Diagnosis"`
57
+	Ward         string   `xml:"Ward"`
58
+	BedCode      string   `xml:"BedCode"`
59
+	SendDoctor   string   `xml:"SendDoctor"`
60
+	PatientType  int      `xml:"PatientType"`
61
+	PatientPhone string   `xml:"PatientPhone"`
62
+}
63
+
64
+type CustomerApplyDetail struct {
65
+	RowIndex               int64  `xml:"RowIndex"`
66
+	CustomerChargeItemCode string `xml:"CustomerChargeItemCode"`
67
+	TakeSampleTime         string `xml:"TakeSampleTime"`
68
+	Barcode                string `xml:"Barcode"`
69
+	CustomerBarcode        string `xml:"CustomerBarcode"`
70
+	Comment                string `xml:"Comment"`
71
+}
72
+type JYApplyResult struct {
73
+	ApplyCode   string  `xml:"ApplyCode"`
74
+	TotalAmount float64 `xml:"TotalAmount"`
75
+}
76
+type JYApplyAdditional struct {
77
+}

+ 70 - 0
models/report_list.go Näytä tiedosto

@@ -0,0 +1,70 @@
1
+package models
2
+
3
+import "encoding/xml"
4
+
5
+type ReportListEnvelope struct {
6
+	XMLName xml.Name       `xml:"soap:Envelope"`
7
+	Soap    string         `xml:"xmlns:soap,attr"`
8
+	Xsi     string         `xml:"xmlns:xsi,attr"`
9
+	Xsd     string         `xml:"xmlns:xsd,attr"`
10
+	Body    ReportListBody `xml:"soap:Body"`
11
+}
12
+
13
+type ReportListBody struct {
14
+	XMLName      xml.Name     `xml:"soap:Body"`
15
+	GetReportReq GetReportReq `xml:"GetAllSampleList"`
16
+}
17
+
18
+type GetReportReq struct {
19
+	XMLName       xml.Name `xml:"http://tempuri.org/ GetAllSampleList"`
20
+	Key           string   `xml:"key"`
21
+	BeginDateTime string   `xml:"BeginDateTime"`
22
+	EndDateTime   string   `xml:"EndDateTime"`
23
+	DateType      int      `xml:"DateType"`
24
+	PrintState    int      `xml:"PrintState"`
25
+}
26
+
27
+type EnvelopeTwo struct {
28
+	XMLName xml.Name     `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
29
+	Body    EnvelopeBody `xml:"Body"`
30
+}
31
+
32
+type EnvelopeBody struct {
33
+	GetAllSampleListResponse GetAllSampleListResponse `xml:"GetAllSampleListResponse"`
34
+}
35
+
36
+type GetAllSampleListResponse struct {
37
+	XMLName                xml.Name `xml:"http://tempuri.org/ GetAllSampleListResponse"`
38
+	GetAllSampleListResult string   `xml:"GetAllSampleListResult"`
39
+}
40
+
41
+type ReportData struct {
42
+	Res                    int                      `json:"Res"`
43
+	Error                  string                   `json:"Error"`
44
+	GPReportListResultData []GPReportListResultData `json:"Data"`
45
+}
46
+
47
+type GPReportListResultData struct {
48
+	RecordID           string `json:"RecordID"`
49
+	PatientName        string `json:"PatientName"`
50
+	Sex                string `json:"Sex"`
51
+	Age                int    `json:"Age"`
52
+	AgeUnit            string `json:"AgeUnit"`
53
+	OfficeName         string `json:"OfficeName"`
54
+	BedCode            string `json:"BedCode"`
55
+	Barcode            string `json:"Barcode"`
56
+	CustomerBarcode    string `json:"CustomerBarcode"`
57
+	SampleCode         string `json:"SampleCode"`
58
+	SampleCategory     string `json:"SampleCategory"`
59
+	SampleDescription  string `json:"SampleDescription"`
60
+	Diagnostics        string `json:"Diagnostics"`
61
+	TakeSampleDateTime string `json:"TakeSampleDateTime"`
62
+	ReceiveDateTime    string `json:"ReceiveDateTime"`
63
+	AuditDateTime      string `json:"AuditDateTime"`
64
+	InspectDate        string `json:"InspectDate"`
65
+	SendDoctor         string `json:"SendDoctor"`
66
+	InspectDoctorName  string `json:"InspectDoctorName"`
67
+	AuditorName        string `json:"AuditorName"`
68
+	Instrument         string `json:"Instrument"`
69
+	Comment            string `json:"Comment"`
70
+}

+ 55 - 0
models/report_result.go Näytä tiedosto

@@ -0,0 +1,55 @@
1
+package models
2
+
3
+import "encoding/xml"
4
+
5
+type ReportResultEnvelope struct {
6
+	XMLName xml.Name         `xml:"soap:Envelope"`
7
+	Soap    string           `xml:"xmlns:soap,attr"`
8
+	Xsi     string           `xml:"xmlns:xsi,attr"`
9
+	Xsd     string           `xml:"xmlns:xsd,attr"`
10
+	Body    ReportResultBody `xml:"soap:Body"`
11
+}
12
+
13
+type ReportResultBody struct {
14
+	XMLName            xml.Name           `xml:"soap:Body"`
15
+	GetReportResultReq GetReportResultReq `xml:"GetJSONReportItemListByCustomerBarocde"`
16
+}
17
+
18
+type GetReportResultReq struct {
19
+	XMLName         xml.Name `xml:"http://tempuri.org/ GetJSONReportItemListByCustomerBarocde"`
20
+	Key             string   `xml:"key"`
21
+	CustomerBarCode string   `xml:"CustomerBarCode"`
22
+}
23
+
24
+type EnvelopeThree struct {
25
+	XMLName xml.Name          `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
26
+	Body    EnvelopeBodyThree `xml:"Body"`
27
+}
28
+
29
+type EnvelopeBodyThree struct {
30
+	GetJSONReportItemListByCustomerBarocdeResponse GetJSONReportItemListByCustomerBarocdeResponse `xml:"GetJSONReportItemListByCustomerBarocdeResponse"`
31
+}
32
+
33
+type GetJSONReportItemListByCustomerBarocdeResponse struct {
34
+	XMLName                                      xml.Name `xml:"http://tempuri.org/ GetJSONReportItemListByCustomerBarocdeResponse"`
35
+	GetJSONReportItemListByCustomerBarocdeResult string   `xml:"GetJSONReportItemListByCustomerBarocdeResult"`
36
+}
37
+
38
+type ReportResultData struct {
39
+	Res           int             `json:"Res"`
40
+	Error         string          `json:"Error"`
41
+	InspectResult []InspectResult `json:"Data"`
42
+}
43
+
44
+type InspectResult struct {
45
+	ChargeItemName string `json:"ChargeItemName"`
46
+	InspectionName string `json:"InspectionName"`
47
+	InspectionCode string `json:"InspectionCode"`
48
+	Result         string `json:"Result"`
49
+	Reference      string `json:"Reference"`
50
+	Barcode        string `json:"Barcode"`
51
+	Unit           string `json:"Unit"`
52
+	Flag           string `json:"Flag"`
53
+	intFlag        int    `json:"intFlag"`
54
+	ListResult     GPReportListResultData
55
+}

+ 55 - 0
models/report_result_two.go Näytä tiedosto

@@ -0,0 +1,55 @@
1
+package models
2
+
3
+import "encoding/xml"
4
+
5
+type GPReportResultEnvelope struct {
6
+	XMLName xml.Name           `xml:"soap:Envelope"`
7
+	Soap    string             `xml:"xmlns:soap,attr"`
8
+	Xsi     string             `xml:"xmlns:xsi,attr"`
9
+	Xsd     string             `xml:"xmlns:xsd,attr"`
10
+	Body    GPReportResultBody `xml:"soap:Body"`
11
+}
12
+
13
+type GPReportResultBody struct {
14
+	XMLName            xml.Name             `xml:"soap:Body"`
15
+	GetReportResultReq GetGPReportResultReq `xml:"GetJSONReportItemListByGPBarocde"`
16
+}
17
+
18
+type GetGPReportResultReq struct {
19
+	XMLName   xml.Name `xml:"http://tempuri.org/ GetJSONReportItemListByGPBarocde"`
20
+	Key       string   `xml:"key"`
21
+	GPBarCode string   `xml:"GPBarCode"`
22
+}
23
+
24
+type EnvelopeFive struct {
25
+	XMLName xml.Name         `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
26
+	Body    EnvelopeBodyFive `xml:"Body"`
27
+}
28
+
29
+type EnvelopeBodyFive struct {
30
+	GetJSONReportItemListByGPBarocdeResponse GetJSONReportItemListByGPBarocdeResponse `xml:"GetJSONReportItemListByGPBarocdeResponse"`
31
+}
32
+
33
+type GetJSONReportItemListByGPBarocdeResponse struct {
34
+	XMLName                                xml.Name `xml:"http://tempuri.org/ GetJSONReportItemListByGPBarocdeResponse"`
35
+	GetJSONReportItemListByGPBarocdeResult string   `xml:"GetJSONReportItemListByGPBarocdeResult"`
36
+}
37
+
38
+type ReportResultDataFive struct {
39
+	Res           int                 `json:"Res"`
40
+	Error         string              `json:"Error"`
41
+	InspectResult []InspectResultFive `json:"Data"`
42
+}
43
+
44
+type InspectResultFive struct {
45
+	ChargeItemName string `json:"ChargeItemName"`
46
+	InspectionName string `json:"InspectionName"`
47
+	InspectionCode string `json:"InspectionCode"`
48
+	Result         string `json:"Result"`
49
+	Reference      string `json:"Reference"`
50
+	Barcode        string `json:"Barcode"`
51
+	Unit           string `json:"Unit"`
52
+	Flag           string `json:"Flag"`
53
+	IntFlag        int    `json:"intFlag"`
54
+	ListResult     GPReportListResultData
55
+}

+ 219 - 83
service/bl_service.go Näytä tiedosto

@@ -146,23 +146,25 @@ func (CmLisitems) TableName() string {
146 146
 }
147 147
 
148 148
 type HisLabelPrintInfo struct {
149
-	ID                     int64                  `gorm:"column:id" json:"id" form:"id"`
150
-	PatientId              int64                  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
151
-	Number                 string                 `gorm:"column:number" json:"number" form:"number"`
152
-	Ctime                  int64                  `gorm:"column:ctime" json:"ctime" form:"ctime"`
153
-	Mtime                  int64                  `gorm:"column:mtime" json:"mtime" form:"mtime"`
154
-	DoctorId               int64                  `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
155
-	Status                 int64                  `gorm:"column:status" json:"status" form:"status"`
156
-	ProjectName            string                 `gorm:"column:project_name" json:"project_name" form:"project_name"`
157
-	ProjectId              int64                  `gorm:"column:project_id" json:"project_id" form:"project_id"`
158
-	IsPrint                int64                  `gorm:"column:is_print" json:"is_print" form:"is_print"`
159
-	RecordDate             int64                  `gorm:"column:record_date" json:"record_date" form:"record_date"`
160
-	ItemId                 int64                  `gorm:"column:item_id" json:"item_id" form:"item_id"`
161
-	PProjectId             int64                  `gorm:"column:p_project_id" json:"p_project_id" form:"p_project_id"`
162
-	UserOrgId              int64                  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
163
-	DoctorName             string                 `gorm:"column:doctor_name" json:"doctor_name" form:"doctor_name"`
164
-	PatientName            string                 `gorm:"column:patient_name" json:"patient_name" form:"patient_name"`
165
-	FeedetlSn              string                 `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
149
+	ID          int64  `gorm:"column:id" json:"id" form:"id"`
150
+	PatientId   int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
151
+	Number      string `gorm:"column:number" json:"number" form:"number"`
152
+	Ctime       int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
153
+	Mtime       int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
154
+	DoctorId    int64  `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
155
+	Status      int64  `gorm:"column:status" json:"status" form:"status"`
156
+	ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
157
+	ProjectId   int64  `gorm:"column:project_id" json:"project_id" form:"project_id"`
158
+	IsPrint     int64  `gorm:"column:is_print" json:"is_print" form:"is_print"`
159
+	RecordDate  int64  `gorm:"column:record_date" json:"record_date" form:"record_date"`
160
+	ItemId      int64  `gorm:"column:item_id" json:"item_id" form:"item_id"`
161
+	PProjectId  int64  `gorm:"column:p_project_id" json:"p_project_id" form:"p_project_id"`
162
+	UserOrgId   int64  `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
163
+	DoctorName  string `gorm:"column:doctor_name" json:"doctor_name" form:"doctor_name"`
164
+	PatientName string `gorm:"column:patient_name" json:"patient_name" form:"patient_name"`
165
+	FeedetlSn   string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
166
+	Phone       string `gorm:"column:phone" json:"phone" form:"phone"`
167
+
166 168
 	PrescriptionId         int64                  `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
167 169
 	HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:PProjectId" json:"project"`
168 170
 	Patient                models.Patients        `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
@@ -216,14 +218,15 @@ func (CmResult) TableName() string {
216 218
 }
217 219
 
218 220
 type LisSyncResultStatusInfo struct {
219
-	ID         int64 `gorm:"column:id" json:"id" form:"id"`
220
-	Ctime      int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
221
-	Mtime      int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
222
-	Status     int64 `gorm:"column:status" json:"status" form:"status"`
223
-	LastId     int64 `gorm:"column:last_id" json:"last_id" form:"last_id"`
224
-	OrgId      int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
225
-	IsResult   int64 `gorm:"column:is_result" json:"is_result" form:"is_result"`
226
-	ResultDate int64 `gorm:"column:result_date" json:"result_date" form:"result_date"`
221
+	ID            int64  `gorm:"column:id" json:"id" form:"id"`
222
+	Ctime         int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
223
+	Mtime         int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
224
+	Status        int64  `gorm:"column:status" json:"status" form:"status"`
225
+	LastId        int64  `gorm:"column:last_id" json:"last_id" form:"last_id"`
226
+	OrgId         int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
227
+	IsResult      int64  `gorm:"column:is_result" json:"is_result" form:"is_result"`
228
+	ResultDate    int64  `gorm:"column:result_date" json:"result_date" form:"result_date"`
229
+	GpSyncEndDate string `gorm:"column:gp_sync_end_date" json:"gp_sync_end_date" form:"gp_sync_end_date"`
227 230
 }
228 231
 
229 232
 func (LisSyncResultStatusInfo) TableName() string {
@@ -293,7 +296,7 @@ func GetLisResultDataByRecord(org_id int64) (list []*CmResult, err error) {
293 296
 	return
294 297
 }
295 298
 
296
-//插入中间件逻辑
299
+// 插入中间件逻辑
297 300
 func GetDataInsertDB(org_id int64) {
298 301
 	record, _ := GetLastSyncRecord(org_id)
299 302
 	if record.ID == 0 {
@@ -540,7 +543,7 @@ func GetDataInsertDB(org_id int64) {
540 543
 	}
541 544
 }
542 545
 
543
-//获取lis返回检验检查结果数据
546
+// 获取lis返回检验检查结果数据
544 547
 func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
545 548
 	record, _ := GetLastSyncResultRecord(org_id)
546 549
 	if record.ID == 0 {
@@ -551,8 +554,9 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
551 554
 			//插入到系统检验检查数据
552 555
 			for _, item := range list {
553 556
 				project_id := int64(0)
557
+				xt_project_id := int64(0)
554 558
 				if len(item.Barcode) > 0 {
555
-					project_id, _ = GetBljhProjectID(org_id, item.Groupname)
559
+					project_id, xt_project_id, _ = GetBljhProjectID(org_id, item.Groupname)
556 560
 				} else {
557 561
 					continue
558 562
 				}
@@ -565,7 +569,7 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
565 569
 					continue
566 570
 				}
567 571
 
568
-				item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
572
+				item_id, sys_item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
569 573
 
570 574
 				tx := writeMiddleDb.Begin()
571 575
 				var inspection models.MiddleInspection
@@ -590,7 +594,6 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
590 594
 				var ItemType int
591 595
 				if strings.Contains(item.Refrange, "-") {
592 596
 					ItemType = 1
593
-
594 597
 				} else {
595 598
 					ItemType = 2
596 599
 
@@ -604,60 +607,123 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
604 607
 					RangeOptions = item.Refrange
605 608
 				}
606 609
 
607
-				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
608
-				if inspection_reference.ID > 0 {
609
-					ItemType = inspection_reference.RangeType
610
-				}
611
-				if total <= 0 {
612
-					inspection_reference.OrgId = org_id
613
-					inspection_reference.ProjectName = item.Groupname
614
-					inspection_reference.Project = item.Groupname
615
-					inspection_reference.ProjectId = project_id
616
-					inspection_reference.ItemName = item.Itemname
617
-					inspection_reference.ItemNameAddition = item.Barcode
618
-					inspection_reference.ItemId = item_id
619
-					inspection_reference.RangeType = ItemType
620
-					inspection_reference.RangeMin = RangeMin
621
-					inspection_reference.RangeMax = RangeMax
622
-					inspection_reference.RangeOptions = RangeOptions
623
-					inspection_reference.Unit = item.Unit
624
-					inspection_reference.Status = 1
625
-					inspection_reference.CreatedTime = time.Now().Unix()
626
-					inspection_reference.UpdatedTime = time.Now().Unix()
627
-					inspection_reference.InspectDate = inspect_date
628
-					inspection_reference.UTime = inspect_date
629
-					err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
630
-					if err != nil {
631
-						tx.Rollback()
610
+				if xt_project_id > 0 && sys_item_id > 0 {
611
+					err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and xt_project_id = ? and xt_item_id = ? and status = 1", org_id, xt_project_id, sys_item_id).Find(&inspection_reference).Count(&total).Error
612
+					if inspection_reference.ID > 0 {
613
+						ItemType = inspection_reference.RangeType
614
+					}
615
+					if total <= 0 {
616
+						inspection_reference.OrgId = org_id
617
+						inspection_reference.ProjectName = item.Groupname
618
+						inspection_reference.Project = item.Groupname
619
+						inspection_reference.ProjectId = project_id
620
+						inspection_reference.ItemName = item.Itemname
621
+						inspection_reference.ItemNameAddition = item.Barcode
622
+						inspection_reference.ItemId = item_id
623
+						inspection_reference.RangeType = ItemType
624
+						inspection_reference.RangeMin = RangeMin
625
+						inspection_reference.RangeMax = RangeMax
626
+						inspection_reference.RangeOptions = RangeOptions
627
+						inspection_reference.Unit = item.Unit
628
+						inspection_reference.Status = 1
629
+						inspection_reference.CreatedTime = time.Now().Unix()
630
+						inspection_reference.UpdatedTime = time.Now().Unix()
631
+						inspection_reference.InspectDate = inspect_date
632
+						inspection_reference.UTime = inspect_date
633
+						err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
634
+						if err != nil {
635
+							tx.Rollback()
636
+						}
632 637
 					}
633
-				}
634 638
 
635
-				var itotal int
636
-				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.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
637
-				if itotal <= 0 {
638
-					//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
639
-					//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
640
-					inspection.PatientId = printInfo.PatientId
641
-					inspection.OrgId = org_id
642
-					inspection.ProjectId = project_id
643
-					inspection.ItemName = inspection_reference.ItemName
644
-					inspection.ProjectName = inspection_reference.ProjectName
645
-					inspection.InspectType = ItemType
646
-					inspection.ItemId = item_id
647
-					inspection.InspectValue = item.Result
648
-					inspection.InspectDate = inspect_date
649
-					inspection.RecordDate = record_date.Unix()
650
-					inspection.Status = 1
651
-					inspection.CreatedTime = time.Now().Unix()
652
-					inspection.UpdatedTime = time.Now().Unix()
653
-					inspection.UTime = inspect_date
654
-					inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
655
-					err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
656
-					if err != nil {
657
-						tx.Rollback()
639
+				} else {
640
+					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
641
+					if inspection_reference.ID > 0 {
642
+						ItemType = inspection_reference.RangeType
658 643
 					}
644
+					if total <= 0 {
645
+						inspection_reference.OrgId = org_id
646
+						inspection_reference.ProjectName = item.Groupname
647
+						inspection_reference.Project = item.Groupname
648
+						inspection_reference.ProjectId = project_id
649
+						inspection_reference.ItemName = item.Itemname
650
+						inspection_reference.ItemNameAddition = item.Barcode
651
+						inspection_reference.ItemId = item_id
652
+						inspection_reference.RangeType = ItemType
653
+						inspection_reference.RangeMin = RangeMin
654
+						inspection_reference.RangeMax = RangeMax
655
+						inspection_reference.RangeOptions = RangeOptions
656
+						inspection_reference.Unit = item.Unit
657
+						inspection_reference.Status = 1
658
+						inspection_reference.CreatedTime = time.Now().Unix()
659
+						inspection_reference.UpdatedTime = time.Now().Unix()
660
+						inspection_reference.InspectDate = inspect_date
661
+						inspection_reference.UTime = inspect_date
662
+						err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
663
+						if err != nil {
664
+							tx.Rollback()
665
+						}
666
+					}
667
+
659 668
 				}
660 669
 
670
+				if xt_project_id > 0 && sys_item_id > 0 {
671
+					var itotal int
672
+					err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and xt_project_id = ? and xt_item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, xt_project_id, sys_item_id, record_date.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
673
+					if itotal <= 0 {
674
+						//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
675
+						//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
676
+						inspection.PatientId = printInfo.PatientId
677
+						inspection.OrgId = org_id
678
+						inspection.ProjectId = project_id
679
+						inspection.ItemName = inspection_reference.ItemName
680
+						inspection.ProjectName = inspection_reference.ProjectName
681
+						inspection.InspectType = ItemType
682
+						inspection.ItemId = item_id
683
+
684
+						inspection.InspectValue = item.Result
685
+						inspection.InspectDate = inspect_date
686
+						inspection.RecordDate = record_date.Unix()
687
+						inspection.Status = 1
688
+						inspection.CreatedTime = time.Now().Unix()
689
+						inspection.UpdatedTime = time.Now().Unix()
690
+						inspection.UTime = inspect_date
691
+						inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
692
+						err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
693
+						if err != nil {
694
+							tx.Rollback()
695
+						}
696
+					}
697
+
698
+				} else {
699
+					var itotal int
700
+					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.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
701
+					if itotal <= 0 {
702
+						//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
703
+						//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
704
+						inspection.PatientId = printInfo.PatientId
705
+						inspection.OrgId = org_id
706
+						inspection.ProjectId = project_id
707
+						inspection.ItemName = inspection_reference.ItemName
708
+						inspection.ProjectName = inspection_reference.ProjectName
709
+						inspection.InspectType = ItemType
710
+						inspection.ItemId = item_id
711
+
712
+						inspection.InspectValue = item.Result
713
+						inspection.InspectDate = inspect_date
714
+						inspection.RecordDate = record_date.Unix()
715
+						inspection.Status = 1
716
+						inspection.CreatedTime = time.Now().Unix()
717
+						inspection.UpdatedTime = time.Now().Unix()
718
+						inspection.UTime = inspect_date
719
+						inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
720
+						err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
721
+						if err != nil {
722
+							tx.Rollback()
723
+						}
724
+					}
725
+
726
+				}
661 727
 				tx.Commit()
662 728
 
663 729
 			}
@@ -686,13 +752,15 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
686 752
 				//插入到系统检验检查数据
687 753
 				for _, item := range list {
688 754
 					project_id := int64(0)
755
+					sys_project_id := int64(0)
756
+
689 757
 					if len(item.Barcode) > 0 {
690
-						project_id, _ = GetBljhProjectID(org_id, item.Groupname)
758
+						project_id, sys_project_id, _ = GetBljhProjectID(org_id, item.Groupname)
691 759
 					} else {
692 760
 						continue
693 761
 					}
694 762
 					printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
695
-					item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
763
+					item_id, sys_item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
696 764
 
697 765
 					tx := writeMiddleDb.Begin()
698 766
 					var inspection models.MiddleInspection
@@ -731,7 +799,7 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
731 799
 						RangeOptions = item.Refrange
732 800
 					}
733 801
 
734
-					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
802
+					err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and xt_project_id = ? and xt_item_id = ? and status = 1", org_id, project_id, item_id).Find(&inspection_reference).Count(&total).Error
735 803
 					if inspection_reference.ID > 0 {
736 804
 						ItemType = inspection_reference.RangeType
737 805
 					}
@@ -783,6 +851,64 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
783 851
 						}
784 852
 					}
785 853
 
854
+					if sys_project_id > 0 && sys_item_id > 0 {
855
+						var itotal int
856
+						err = readMiddleDb.Model(&models.MiddleInspection{}).Where("org_id = ? and xt_project_id = ? and xt_item_id = ? and record_date = ? and patient_id = ?  and status = 1", org_id, sys_item_id, record_date.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
857
+						if itotal <= 0 {
858
+							//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
859
+							//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
860
+							inspection.PatientId = printInfo.PatientId
861
+							inspection.OrgId = org_id
862
+							inspection.ProjectId = project_id
863
+							inspection.ItemName = inspection_reference.ItemName
864
+							inspection.ProjectName = inspection_reference.ProjectName
865
+							inspection.InspectType = ItemType
866
+							inspection.ItemId = item_id
867
+
868
+							inspection.InspectValue = item.Result
869
+							inspection.InspectDate = inspect_date
870
+							inspection.RecordDate = record_date.Unix()
871
+							inspection.Status = 1
872
+							inspection.CreatedTime = time.Now().Unix()
873
+							inspection.UpdatedTime = time.Now().Unix()
874
+							inspection.UTime = inspect_date
875
+							inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
876
+							err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
877
+							if err != nil {
878
+								tx.Rollback()
879
+							}
880
+						}
881
+
882
+					} else {
883
+						var itotal int
884
+						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.Unix(), printInfo.PatientId).Find(&inspection).Count(&itotal).Error
885
+						if itotal <= 0 {
886
+							//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
887
+							//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
888
+							inspection.PatientId = printInfo.PatientId
889
+							inspection.OrgId = org_id
890
+							inspection.ProjectId = project_id
891
+							inspection.ItemName = inspection_reference.ItemName
892
+							inspection.ProjectName = inspection_reference.ProjectName
893
+							inspection.InspectType = ItemType
894
+							inspection.ItemId = item_id
895
+
896
+							inspection.InspectValue = item.Result
897
+							inspection.InspectDate = inspect_date
898
+							inspection.RecordDate = record_date.Unix()
899
+							inspection.Status = 1
900
+							inspection.CreatedTime = time.Now().Unix()
901
+							inspection.UpdatedTime = time.Now().Unix()
902
+							inspection.UTime = inspect_date
903
+							inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
904
+							err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
905
+							if err != nil {
906
+								tx.Rollback()
907
+							}
908
+						}
909
+
910
+					}
911
+
786 912
 					tx.Commit()
787 913
 
788 914
 				}
@@ -811,7 +937,7 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
811 937
 	// 第二步:将数据同步到业务库
812 938
 	if len(inspection_references) > 0 {
813 939
 		for _, inspection_reference := range inspection_references {
814
-			SyncInspectionReference(&inspection_reference)
940
+			SyncInspectionReferenceTwo(&inspection_reference)
815 941
 		}
816 942
 	}
817 943
 
@@ -1024,3 +1150,13 @@ func GetPatientsInfoByIDCardNo(id_card_no string, org_id int64) (info models.Pat
1024 1150
 	err = readDb.Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, org_id).First(&info).Error
1025 1151
 	return
1026 1152
 }
1153
+
1154
+func GetAllLisDataFor10191(org_id int64) (list []models.HisLabelPrintStatusInfo, err error) {
1155
+	err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Preload("Patient", "status = 1").Where("user_org_id = ? AND status = 1  and apply_code = ''", org_id).Find(&list).Error
1156
+	return
1157
+}
1158
+
1159
+func GetAllLisDataFor10191LastId(org_id int64, last_id int64) (list []*models.HisLabelPrintStatusInfo, err error) {
1160
+	err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Preload("Patient", "status = 1").Where("user_org_id = ? AND status = 1 and is_print = 1 and id > ?", org_id, last_id).Find(&list).Error
1161
+	return
1162
+}

+ 412 - 0
service/xml_service.go Näytä tiedosto

@@ -0,0 +1,412 @@
1
+package service
2
+
3
+import (
4
+	"IC/models"
5
+	"bytes"
6
+	"encoding/json"
7
+	"encoding/xml"
8
+	"fmt"
9
+	"io/ioutil"
10
+	"net/http"
11
+)
12
+
13
+// 获取可下载标本列表
14
+func GetGPReportListData(start_date string, end_date string, key string) (result []models.GPReportListResultData) {
15
+	// 构建SOAP请求数据
16
+	requestData := &models.ReportListEnvelope{
17
+		Soap: "http://schemas.xmlsoap.org/soap/envelope/",
18
+		Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
19
+		Xsd:  "http://www.w3.org/2001/XMLSchema",
20
+		Body: models.ReportListBody{
21
+			GetReportReq: models.GetReportReq{
22
+				XMLName:       xml.Name{Local: "GetAllSampleList", Space: "http://tempuri.org/"},
23
+				Key:           key,
24
+				BeginDateTime: start_date,
25
+				EndDateTime:   end_date,
26
+				DateType:      1,
27
+				PrintState:    0,
28
+			},
29
+		},
30
+	}
31
+
32
+	// 将SOAP请求数据转换为XML格式
33
+	requestBody, err := xml.Marshal(requestData)
34
+	if err != nil {
35
+		fmt.Println("XML Marshal error:", err)
36
+		return result
37
+	}
38
+
39
+	// 创建POST请求
40
+	url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
41
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
42
+	if err != nil {
43
+		fmt.Println("Request creation error:", err)
44
+		return result
45
+	}
46
+
47
+	// 设置请求头
48
+	req.Header.Set("Content-Type", "text/xml; charset=utf-8")
49
+	req.Header.Set("Content-Length", "length")
50
+	req.Header.Set("SOAPAction", "http://tempuri.org/GetAllSampleList")
51
+
52
+	// 发送请求
53
+	client := &http.Client{}
54
+	resp, err := client.Do(req)
55
+	if err != nil {
56
+		fmt.Println("Request error:", err)
57
+		return result
58
+	}
59
+	defer resp.Body.Close()
60
+
61
+	// 读取响应数据
62
+	responseBody, err := ioutil.ReadAll(resp.Body)
63
+	//fmt.Println(string(responseBody))
64
+	if err != nil {
65
+		fmt.Println("Response read error:", err)
66
+		return result
67
+	}
68
+
69
+	// 解析XML数据
70
+	var envelope_two models.EnvelopeTwo
71
+	err2 := xml.Unmarshal(responseBody, &envelope_two)
72
+	if err2 != nil {
73
+		fmt.Println("XML Unmarshal error:", err2)
74
+		return result
75
+	}
76
+
77
+	// 获取GetReportListResult的JSON字符串
78
+	jsonStr := envelope_two.Body.GetAllSampleListResponse.GetAllSampleListResult
79
+	//fmt.Println(jsonStr)
80
+	// 解析JSON字符串到结构体
81
+	var reportData models.ReportData
82
+	err = json.Unmarshal([]byte(jsonStr), &reportData)
83
+	if err != nil {
84
+		fmt.Println("JSON Unmarshal error:", err)
85
+		return result
86
+	}
87
+	if reportData.Res == 0 {
88
+		//fmt.Println( . ."Data:", reportData.GPReportListResultData)
89
+		return reportData.GPReportListResultData
90
+	}
91
+	return result
92
+}
93
+
94
+// 根据院所自身条码获取标本检测结果或诊断结果,遍历结果
95
+//func GetGPResultData(result []models.GPReportListResultData, key string) (results []models.InspectResult) {
96
+//	for _, item := range result {
97
+//
98
+//		// 构建SOAP请求数据
99
+//		requestData := &models.ReportResultEnvelope{
100
+//			Soap: "http://schemas.xmlsoap.org/soap/envelope/",
101
+//			Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
102
+//			Xsd:  "http://www.w3.org/2001/XMLSchema",
103
+//			Body: models.ReportResultBody{
104
+//				GetReportResultReq: models.GetReportResultReq{
105
+//					XMLName:         xml.Name{Local: "GetJSONReportItemListByCustomerBarocde", Space: "http://tempuri.org/"},
106
+//					Key:             key,
107
+//					CustomerBarCode: item.CustomerBarcode,
108
+//				},
109
+//			},
110
+//		}
111
+//
112
+//		// 将SOAP请求数据转换为XML格式
113
+//		requestBody, err := xml.Marshal(requestData)
114
+//		if err != nil {
115
+//			fmt.Println("XML Marshal error:", err)
116
+//
117
+//		}
118
+//
119
+//		// 创建POST请求
120
+//		url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
121
+//		req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
122
+//		if err != nil {
123
+//			fmt.Println("Request creation error:", err)
124
+//		}
125
+//		// 设置请求头
126
+//		req.Header.Set("Content-Type", "text/xml; charset=utf-8")
127
+//		req.Header.Set("Content-Length", "length")
128
+//		req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByCustomerBarocde")
129
+//		// 发送请求
130
+//		client := &http.Client{}
131
+//		resp, err := client.Do(req)
132
+//		if err != nil {
133
+//			fmt.Println("Request error:", err)
134
+//
135
+//		}
136
+//		defer resp.Body.Close()
137
+//		// 读取响应数据
138
+//		responseBody, err := ioutil.ReadAll(resp.Body)
139
+//		if err != nil {
140
+//			fmt.Println("Response read error:", err)
141
+//		}
142
+//
143
+//		// 解析XML数据
144
+//		var envelope_three models.EnvelopeThree
145
+//		err2 := xml.Unmarshal(responseBody, &envelope_three)
146
+//		if err2 != nil {
147
+//			fmt.Println("XML Unmarshal error:", err2)
148
+//		}
149
+//		// 获取GetReportListResult的JSON字符串
150
+//		jsonStr := envelope_three.Body.GetJSONReportItemListByCustomerBarocdeResponse.GetJSONReportItemListByCustomerBarocdeResult
151
+//		// 解析JSON字符串到结构体
152
+//		fmt.Println(jsonStr)
153
+//		var reportData models.ReportResultData
154
+//		err = json.Unmarshal([]byte(jsonStr), &reportData)
155
+//		if err != nil {
156
+//			fmt.Println("JSON Unmarshal error:", err)
157
+//		}
158
+//		if reportData.Res == 0 {
159
+//			fmt.Println("Data:", reportData.InspectResult)
160
+//			reportData.InspectResult.ListResult = item
161
+//			results = append(results, reportData.InspectResult)
162
+//		}
163
+//	}
164
+//	return results
165
+//}
166
+
167
+// 根据高品条码获取标本检测结果或诊断结果,遍历结果
168
+func GetGPResultDataTwo(result []models.GPReportListResultData, key string) (results []models.InspectResultFive) {
169
+	for _, item := range result {
170
+		if len(item.CustomerBarcode) > 0 {
171
+			fmt.Println("~~~~~~-------")
172
+			// 构建SOAP请求数据
173
+			requestData := &models.ReportResultEnvelope{
174
+				Soap: "http://schemas.xmlsoap.org/soap/envelope/",
175
+				Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
176
+				Xsd:  "http://www.w3.org/2001/XMLSchema",
177
+				Body: models.ReportResultBody{
178
+					GetReportResultReq: models.GetReportResultReq{
179
+						XMLName:         xml.Name{Local: "GetJSONReportItemListByCustomerBarocde", Space: "http://tempuri.org/"},
180
+						Key:             key,
181
+						CustomerBarCode: item.CustomerBarcode,
182
+					},
183
+				},
184
+			}
185
+
186
+			// 将SOAP请求数据转换为XML格式
187
+			requestBody, err := xml.Marshal(requestData)
188
+			if err != nil {
189
+				fmt.Println("XML Marshal error:", err)
190
+
191
+			}
192
+
193
+			// 创建POST请求
194
+			url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
195
+			req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
196
+			if err != nil {
197
+				fmt.Println("Request creation error:", err)
198
+			}
199
+			// 设置请求头
200
+			req.Header.Set("Content-Type", "text/xml; charset=utf-8")
201
+			req.Header.Set("Content-Length", "length")
202
+			req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByCustomerBarocde")
203
+			// 发送请求
204
+			client := &http.Client{}
205
+			resp, err := client.Do(req)
206
+			if err != nil {
207
+				fmt.Println("Request error:", err)
208
+
209
+			}
210
+			defer resp.Body.Close()
211
+			// 读取响应数据
212
+			responseBody, err := ioutil.ReadAll(resp.Body)
213
+			if err != nil {
214
+				fmt.Println("Response read error:", err)
215
+			}
216
+
217
+			// 解析XML数据
218
+			var envelope_three models.EnvelopeThree
219
+			err2 := xml.Unmarshal(responseBody, &envelope_three)
220
+			if err2 != nil {
221
+				fmt.Println("XML Unmarshal error:", err2)
222
+			}
223
+			// 获取GetReportListResult的JSON字符串
224
+			jsonStr := envelope_three.Body.GetJSONReportItemListByCustomerBarocdeResponse.GetJSONReportItemListByCustomerBarocdeResult
225
+			// 解析JSON字符串到结构体
226
+			//fmt.Println(jsonStr)
227
+			var reportData models.ReportResultData
228
+			err = json.Unmarshal([]byte(jsonStr), &reportData)
229
+			if err != nil {
230
+				fmt.Println("JSON Unmarshal error:", err)
231
+			}
232
+			if reportData.Res == 0 {
233
+				//reportData.ListResult = item
234
+				for _, subItem := range reportData.InspectResult {
235
+					subItem.ListResult = item
236
+					var resultTwo models.InspectResultFive
237
+					resultTwo.ListResult = subItem.ListResult
238
+					resultTwo.Result = subItem.Result
239
+					resultTwo.Barcode = subItem.Barcode
240
+					resultTwo.Flag = subItem.Flag
241
+					resultTwo.Unit = subItem.Unit
242
+					resultTwo.ChargeItemName = subItem.ChargeItemName
243
+					resultTwo.InspectionName = subItem.InspectionName
244
+					resultTwo.InspectionCode = subItem.InspectionCode
245
+					resultTwo.Reference = subItem.Reference
246
+					results = append(results, resultTwo)
247
+				}
248
+			}
249
+		} else {
250
+
251
+			if len(item.Barcode) > 0 {
252
+				//fmt.Println("11122222")
253
+				// 构建SOAP请求数据
254
+				requestData := &models.GPReportResultEnvelope{
255
+					Soap: "http://schemas.xmlsoap.org/soap/envelope/",
256
+					Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
257
+					Xsd:  "http://www.w3.org/2001/XMLSchema",
258
+					Body: models.GPReportResultBody{
259
+						GetReportResultReq: models.GetGPReportResultReq{
260
+							XMLName:   xml.Name{Local: "GetJSONReportItemListByGPBarocde", Space: "http://tempuri.org/"},
261
+							Key:       key,
262
+							GPBarCode: item.Barcode,
263
+						},
264
+					},
265
+				}
266
+
267
+				// 将SOAP请求数据转换为XML格式
268
+				requestBody, err := xml.Marshal(requestData)
269
+				if err != nil {
270
+					fmt.Println("XML Marshal error:", err)
271
+
272
+				}
273
+
274
+				// 创建POST请求
275
+				url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
276
+				req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
277
+				if err != nil {
278
+					fmt.Println("Request creation error:", err)
279
+				}
280
+				// 设置请求头
281
+				req.Header.Set("Content-Type", "text/xml; charset=utf-8")
282
+				req.Header.Set("Content-Length", "length")
283
+				req.Header.Set("SOAPAction", "http://tempuri.org/GetJSONReportItemListByGPBarocde")
284
+				// 发送请求
285
+				client := &http.Client{}
286
+				resp, err := client.Do(req)
287
+				if err != nil {
288
+					fmt.Println("Request error:", err)
289
+
290
+				}
291
+				defer resp.Body.Close()
292
+				// 读取响应数据
293
+				responseBody, err := ioutil.ReadAll(resp.Body)
294
+				if err != nil {
295
+					fmt.Println("Response read error:", err)
296
+				}
297
+
298
+				// 解析XML数据
299
+				var envelope_five models.EnvelopeFive
300
+				err2 := xml.Unmarshal(responseBody, &envelope_five)
301
+				if err2 != nil {
302
+					fmt.Println("XML Unmarshal error:", err2)
303
+				}
304
+
305
+				// 获取GetReportListResult的JSON字符串
306
+				jsonStr := envelope_five.Body.GetJSONReportItemListByGPBarocdeResponse.GetJSONReportItemListByGPBarocdeResult
307
+				// 解析JSON字符串到结构体
308
+				var reportData models.ReportResultDataFive
309
+				err = json.Unmarshal([]byte(jsonStr), &reportData)
310
+				if err != nil {
311
+					fmt.Println("JSON Unmarshal error:", err)
312
+				}
313
+				//fmt.Println(reportData)
314
+
315
+				if reportData.Res == 0 {
316
+					//reportData.ListResult = item
317
+					for _, subItem := range reportData.InspectResult {
318
+						subItem.ListResult = item
319
+						results = append(results, subItem)
320
+
321
+					}
322
+				}
323
+
324
+			}
325
+		}
326
+
327
+	}
328
+	return results
329
+
330
+}
331
+
332
+// 送检单
333
+func PostInspectApply(key string, apply models.JYApply, list []models.CustomerApplyDetail) models.InspectApplyData {
334
+	// 构建SOAP请求数据
335
+	requestData := &models.JYApplyEnvelope{
336
+		Soap: "http://schemas.xmlsoap.org/soap/envelope/",
337
+		Xsi:  "http://www.w3.org/2001/XMLSchema-instance",
338
+		Xsd:  "http://www.w3.org/2001/XMLSchema",
339
+		Body: models.JYApplyBody{
340
+			InspectApplyReq: models.InspectApplyReq{
341
+				XMLName: xml.Name{Local: "InspectApplyByInstituteItemCode", Space: "http://tempuri.org/"},
342
+				ApiKey:  key,
343
+				Apply:   apply,
344
+				ApplyDetailList: struct {
345
+					CustomerApplyDetail []models.CustomerApplyDetail `xml:"CustomerApplyDetail"`
346
+				}{
347
+					CustomerApplyDetail: list,
348
+				},
349
+				ApplyAdditional: nil,
350
+			},
351
+		},
352
+	}
353
+
354
+	// 将SOAP请求数据转换为XML格式
355
+	requestBody, err := xml.Marshal(requestData)
356
+	if err != nil {
357
+		fmt.Println("XML Marshal error:", err)
358
+	}
359
+	fmt.Println(string(requestBody))
360
+
361
+	// 创建POST请求
362
+	url := "http://gpis.cnhiqc.com:9799/InstituteLISService.asmx"
363
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
364
+	if err != nil {
365
+		fmt.Println("Request creation error:", err)
366
+	}
367
+
368
+	// 设置请求头
369
+	req.Header.Set("Content-Type", "text/xml; charset=utf-8")
370
+	req.Header.Set("Content-Length", "length")
371
+	req.Header.Set("SOAPAction", "http://tempuri.org/InspectApplyByInstituteItemCode")
372
+
373
+	// 发送请求
374
+	client := &http.Client{}
375
+	resp, err := client.Do(req)
376
+	if err != nil {
377
+		fmt.Println("Request error:", err)
378
+	}
379
+	defer resp.Body.Close()
380
+
381
+	// 读取响应数据
382
+	responseBody, err := ioutil.ReadAll(resp.Body)
383
+	if err != nil {
384
+		fmt.Println("Response read error:", err)
385
+
386
+	}
387
+	fmt.Println(string(responseBody))
388
+
389
+	// 解析XML数据
390
+	var envelope_four models.EnvelopeFour
391
+	err2 := xml.Unmarshal(responseBody, &envelope_four)
392
+	if err2 != nil {
393
+		fmt.Println("XML Unmarshal error:", err2)
394
+
395
+	}
396
+
397
+	// 获取GetReportListResult的JSON字符串
398
+	jsonStr := envelope_four.Body.InspectApplyByInstituteItemCodeResponse.InspectApply
399
+
400
+	// 解析JSON字符串到结构体
401
+	var reportData models.InspectApplyData
402
+	err = json.Unmarshal([]byte(jsonStr), &reportData)
403
+
404
+	if err != nil {
405
+		fmt.Println("JSON Unmarshal error:", err)
406
+	}
407
+	if reportData.Res != 0 {
408
+		fmt.Println("Data:", reportData)
409
+		//return reportData.JYApplyResult
410
+	}
411
+	return reportData
412
+}

+ 27 - 10
service/ystx_service.go Näytä tiedosto

@@ -1497,34 +1497,51 @@ func SyncToHbdytx() {
1497 1497
 }
1498 1498
 
1499 1499
 // 根据机构ID和检验检查名称获取该检查的project_id,如没有,则创建一个
1500
-func GetBljhProjectID(org_id int64, project_name string) (project_id int64, err error) {
1500
+func GetBljhProjectID(org_id int64, project_name string) (project_id int64, sys_project_id int64, err error) {
1501 1501
 	var inspection_reference models.MiddleInspectionReference
1502 1502
 	err = readMiddleDb.Model(&models.MiddleInspectionReference{}).Where("org_id = ? and status = 1 and project_name = ?", org_id, project_name).First(&inspection_reference).Error
1503 1503
 	if inspection_reference.ID > 0 {
1504
-		return inspection_reference.ProjectId, err
1504
+		return inspection_reference.ProjectId, inspection_reference.XtProjectId, err
1505 1505
 	} else {
1506 1506
 		err = readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id=? ", org_id).Select("max(project_id) as project_id").Scan(&inspection_reference).Error
1507 1507
 		if inspection_reference.ProjectId > 0 {
1508
-			return inspection_reference.ProjectId + 1, err
1508
+			return inspection_reference.ProjectId + 1, 0, err
1509 1509
 		} else {
1510
-			return 5210138, err
1510
+			return 5210138, 0, err
1511 1511
 		}
1512 1512
 	}
1513 1513
 }
1514 1514
 
1515
+//// 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
1516
+//func GetBlItemIDTwo(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, sys_project_id int64, err error) {
1517
+//	var inspection_reference models.MiddleInspectionReference
1518
+//	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
1519
+//	if inspection_reference.ID > 0 {
1520
+//		return inspection_reference.ItemId, err
1521
+//	} else {
1522
+//		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
1523
+//		utils.InfoLog("inspection_reference: %v", inspection_reference)
1524
+//		if inspection_reference.ItemId > 0 {
1525
+//			return inspection_reference.ItemId + 1, err
1526
+//		} else {
1527
+//			return project_id*10 + 1, err
1528
+//		}
1529
+//	}
1530
+//}
1531
+
1515 1532
 // 根据机构ID和检验检查小项名称获取该检查的item_id,如没有,则创建一个
1516
-func GetBlItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, err error) {
1533
+func GetBlItemID(org_id int64, project_name string, item_name string, project_id int64) (item_id int64, sys_item_id int64, err error) {
1517 1534
 	var inspection_reference models.MiddleInspectionReference
1518 1535
 	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
1519 1536
 	if inspection_reference.ID > 0 {
1520
-		return inspection_reference.ItemId, err
1537
+		return inspection_reference.ItemId, inspection_reference.XtItemId, err
1521 1538
 	} else {
1522
-		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
1539
+		err := readMiddleDb.Table("xt_middle_inspection_reference").Where("org_id = ? and xt_project_id = ? ", org_id, project_id).Select("max(item_id) as item_id").First(&inspection_reference).Error
1523 1540
 		utils.InfoLog("inspection_reference: %v", inspection_reference)
1524 1541
 		if inspection_reference.ItemId > 0 {
1525
-			return inspection_reference.ItemId + 1, err
1542
+			return inspection_reference.ItemId + 1, 0, err
1526 1543
 		} else {
1527
-			return project_id*10 + 1, err
1544
+			return project_id*10 + 1, 0, err
1528 1545
 		}
1529 1546
 	}
1530 1547
 }
@@ -1696,7 +1713,7 @@ func Synctfyz() (err error) {
1696 1713
 				}
1697 1714
 				utils.InfoLog("advice:%v", advice)
1698 1715
 				// 根据同步来的 advice_id 来查询库里是否已经存在
1699
-				advice_info, _ := GetAdviceBySyncAdviceIdTwo(org_id, strconv.FormatInt(yz.AdviceId,10))
1716
+				advice_info, _ := GetAdviceBySyncAdviceIdTwo(org_id, strconv.FormatInt(yz.AdviceId, 10))
1700 1717
 				utils.InfoLog("advice_info:%v", advice_info)
1701 1718
 				if advice_info.ID > 0 {
1702 1719
 					key := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(temp_patient_id, 10) + ":" + strconv.FormatInt(schedulesTime, 10) + ":doctor_advices"