csx 3 years ago
parent
commit
60f80e370c
1 changed files with 120 additions and 121 deletions
  1. 120 121
      service/bl_service.go

+ 120 - 121
service/bl_service.go View File

@@ -243,8 +243,8 @@ func GetResultRecord() (record []CmResult, err error) {
243 243
 	return
244 244
 }
245 245
 
246
-func GetResultRecordByID(id int64) (record []*CmResult, err error) {
247
-	err = readDb.Model(&CmResult{}).Where("barcode > ?", id).Order("barcode desc").Find(&record).Error
246
+func GetResultRecordByID(id int64) (record []CmResult, err error) {
247
+	err = readDb.Model(&CmResult{}).Where("barcode > ?", id).Order("barcode asc").Find(&record).Error
248 248
 	return
249 249
 }
250 250
 
@@ -532,17 +532,7 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
532 532
 		list, err := GetResultRecord()
533 533
 		if err == nil {
534 534
 			fmt.Println(list)
535
-			//插入一条查询检验检查结果记录状态数据
536
-			var info LisSyncResultStatusInfo
537
-			info.Ctime = time.Now().Unix()
538
-			info.Status = 1
539
-			info.Mtime = time.Now().Unix()
540
-			info.OrgId = org_id
541
-			info.IsResult = 1
542
-			code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
543
-			info.LastId = code
544
-			info.ResultDate = time.Now().Unix()
545
-			writeMiddleDb.Save(&info)
535
+
546 536
 			//插入到系统检验检查数据
547 537
 			for _, item := range list {
548 538
 				fmt.Println(item)
@@ -651,18 +641,134 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
651 641
 				tx.Commit()
652 642
 
653 643
 			}
644
+			//插入一条查询检验检查结果记录状态数据
645
+			var info LisSyncResultStatusInfo
646
+			info.Ctime = time.Now().Unix()
647
+			info.Status = 1
648
+			info.Mtime = time.Now().Unix()
649
+			info.OrgId = org_id
650
+			info.IsResult = 1
651
+			code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
652
+			info.LastId = code
653
+			info.ResultDate = time.Now().Unix()
654
+			writeMiddleDb.Save(&info)
654 655
 			//
655 656
 		}
656 657
 
657 658
 	} else {
658 659
 		if record.LastId != 0 {
659 660
 
660
-			list, err := GetResultRecordByID(record.LastId)
661
+			list, err := GetResultRecord()
661 662
 			fmt.Println(list)
662 663
 			//插入中间库中
663 664
 			//插入一条插入中间库记录数据
664 665
 			if err == nil {
665 666
 
667
+				//插入到系统检验检查数据
668
+				for _, item := range list {
669
+
670
+					project_id := int64(0)
671
+					if len("180") > 0 {
672
+						project_id, _ = GetBljhProjectID(org_id, item.Groupname)
673
+					} else {
674
+						continue
675
+					}
676
+					printInfo, _ := GetHisLabelPrintInfoById("180")
677
+
678
+					item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
679
+
680
+					tx := writeMiddleDb.Begin()
681
+					var inspection models.MiddleInspection
682
+					var inspection_reference models.MiddleInspectionReference
683
+
684
+					recordDateStr := ""
685
+					inspect_date := item.Repdate.Format("2006-01-02 15:04")
686
+					if item.Repdate.Unix() == 0 {
687
+						recordDateStr = time.Now().Format("2006-01-02 15:04")
688
+					} else {
689
+
690
+						recordDateStr = inspect_date
691
+					}
692
+
693
+					date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
694
+					record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
695
+					var total int
696
+					var RangeOptions string
697
+					var RangeMin string
698
+					var RangeMax string
699
+					// 判断检查类型
700
+					var ItemType int
701
+					if strings.Contains(item.Refrange, "-") {
702
+						ItemType = 1
703
+
704
+					} else {
705
+						ItemType = 2
706
+
707
+					}
708
+
709
+					if ItemType == 1 {
710
+						Range := strings.Split(item.Refrange, "-")
711
+						RangeMin = Range[0]
712
+						RangeMax = Range[1]
713
+					} else {
714
+						RangeOptions = item.Refrange
715
+					}
716
+
717
+					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
718
+					if inspection_reference.ID > 0 {
719
+						ItemType = inspection_reference.RangeType
720
+					}
721
+					if total <= 0 {
722
+						inspection_reference.OrgId = org_id
723
+						inspection_reference.ProjectName = item.Groupname
724
+						inspection_reference.Project = item.Groupname
725
+						inspection_reference.ProjectId = project_id
726
+						inspection_reference.ItemName = item.Itemname
727
+						inspection_reference.ItemNameAddition = item.Barcode
728
+						inspection_reference.ItemId = item_id
729
+						inspection_reference.RangeType = ItemType
730
+						inspection_reference.RangeMin = RangeMin
731
+						inspection_reference.RangeMax = RangeMax
732
+						inspection_reference.RangeOptions = RangeOptions
733
+						inspection_reference.Unit = item.Unit
734
+						inspection_reference.Status = 1
735
+						inspection_reference.CreatedTime = time.Now().Unix()
736
+						inspection_reference.UpdatedTime = time.Now().Unix()
737
+						inspection_reference.InspectDate = inspect_date
738
+						inspection_reference.UTime = inspect_date
739
+						err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
740
+						if err != nil {
741
+							tx.Rollback()
742
+						}
743
+					}
744
+
745
+					var itotal int
746
+					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, printInfo.PatientId).Find(&inspection).Count(&itotal).Error
747
+					if itotal <= 0 {
748
+						inspection.PatientId = printInfo.PatientId
749
+						inspection.OrgId = org_id
750
+						inspection.ProjectId = project_id
751
+						inspection.ItemName = inspection_reference.ItemName
752
+						inspection.ProjectName = inspection_reference.ProjectName
753
+						inspection.InspectType = ItemType
754
+						inspection.ItemId = item_id
755
+						inspection.InspectValue = item.Result
756
+						inspection.InspectDate = inspect_date
757
+						inspection.RecordDate = record_date.Unix()
758
+						inspection.Status = 1
759
+						inspection.CreatedTime = time.Now().Unix()
760
+						inspection.UpdatedTime = time.Now().Unix()
761
+						inspection.UTime = inspect_date
762
+						inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
763
+						err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
764
+						if err != nil {
765
+							tx.Rollback()
766
+						}
767
+					}
768
+
769
+					tx.Commit()
770
+
771
+				}
666 772
 				//插入一条查询检验检查结果记录状态数据
667 773
 				var info LisSyncResultStatusInfo
668 774
 				info.Ctime = time.Now().Unix()
@@ -674,113 +780,6 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
674 780
 				info.LastId = code
675 781
 				info.ResultDate = time.Now().Unix()
676 782
 				writeMiddleDb.Save(&info)
677
-				//插入到系统检验检查数据
678
-				//for _, item := range list {
679
-				//
680
-				//	project_id := int64(0)
681
-				//	if len(item.Barcode) > 0 {
682
-				//		project_id, _ = GetGzjhProjectID(org_id, item.Groupname)
683
-				//	} else {
684
-				//		continue
685
-				//	}
686
-				//	printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
687
-				//
688
-				//	item_id, _ := GetItemID(org_id, item.Groupname, item.Itemname, project_id)
689
-				//
690
-				//	tx := writeMiddleDb.Begin()
691
-				//	var inspection models.MiddleInspection
692
-				//	var inspection_reference models.MiddleInspectionReference
693
-				//
694
-				//	recordDateStr := ""
695
-				//
696
-				//	if len(item.Repdate) == 0 {
697
-				//		recordDateStr = time.Now().Format("2006-01-02 15:04")
698
-				//	}
699
-				//
700
-				//	inspect_date := item.Repdate
701
-				//	date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
702
-				//	record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
703
-				//	var total int
704
-				//	var RangeOptions string
705
-				//	var RangeMin string
706
-				//	var RangeMax string
707
-				//	// 判断检查类型
708
-				//	var ItemType int
709
-				//	if strings.Contains(item.Refrange, "[") && strings.Contains(item.Refrange, "]") {
710
-				//		ItemType = 1
711
-				//
712
-				//	} else {
713
-				//		ItemType = 2
714
-				//
715
-				//	}
716
-				//
717
-				//	if ItemType == 1 {
718
-				//		item.Refrange = strings.Trim(item.Refrange, "[")
719
-				//		item.Refrange = strings.Trim(item.Refrange, "]")
720
-				//		Range := strings.Split(item.Refrange, "-")
721
-				//		RangeMin = Range[0]
722
-				//		RangeMax = Range[1]
723
-				//	} else {
724
-				//		RangeOptions = item.Refrange
725
-				//	}
726
-				//
727
-				//	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
728
-				//	if inspection_reference.ID > 0 {
729
-				//		ItemType = inspection_reference.RangeType
730
-				//	}
731
-				//	if total <= 0 {
732
-				//		inspection_reference.OrgId = org_id
733
-				//		inspection_reference.ProjectName = item.Groupname
734
-				//		inspection_reference.Project = item.Groupname
735
-				//		inspection_reference.ProjectId = project_id
736
-				//		inspection_reference.ItemName = item.Itemname
737
-				//		inspection_reference.ItemNameAddition = item.Barcode
738
-				//		inspection_reference.ItemId = item_id
739
-				//		inspection_reference.RangeType = ItemType
740
-				//		inspection_reference.RangeMin = RangeMin
741
-				//		inspection_reference.RangeMax = RangeMax
742
-				//		inspection_reference.RangeOptions = RangeOptions
743
-				//		inspection_reference.Unit = item.Unit
744
-				//		inspection_reference.Status = 1
745
-				//		inspection_reference.CreatedTime = time.Now().Unix()
746
-				//		inspection_reference.UpdatedTime = time.Now().Unix()
747
-				//		inspection_reference.InspectDate = inspect_date
748
-				//		inspection_reference.UTime = inspect_date
749
-				//		err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
750
-				//		if err != nil {
751
-				//			tx.Rollback()
752
-				//		}
753
-				//	}
754
-				//
755
-				//	var itotal int
756
-				//	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, printInfo.PatientId).Find(&inspection).Count(&itotal).Error
757
-				//	if itotal <= 0 {
758
-				//		//item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
759
-				//		//item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
760
-				//		inspection.PatientId = printInfo.PatientId
761
-				//		inspection.OrgId = org_id
762
-				//		inspection.ProjectId = project_id
763
-				//		inspection.ItemName = inspection_reference.ItemName
764
-				//		inspection.ProjectName = inspection_reference.ProjectName
765
-				//		inspection.InspectType = ItemType
766
-				//		inspection.ItemId = item_id
767
-				//		inspection.InspectValue = item.Result
768
-				//		inspection.InspectDate = inspect_date
769
-				//		inspection.RecordDate = record_date.Unix()
770
-				//		inspection.Status = 1
771
-				//		inspection.CreatedTime = time.Now().Unix()
772
-				//		inspection.UpdatedTime = time.Now().Unix()
773
-				//		inspection.UTime = inspect_date
774
-				//		inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
775
-				//		err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
776
-				//		if err != nil {
777
-				//			tx.Rollback()
778
-				//		}
779
-				//	}
780
-				//
781
-				//	tx.Commit()
782
-				//
783
-				//}
784 783
 
785 784
 			}
786 785