|
@@ -1,6 +1,8 @@
|
1
|
1
|
package service
|
2
|
2
|
|
3
|
3
|
import (
|
|
4
|
+ "IC/models"
|
|
5
|
+ "IC/utils"
|
4
|
6
|
"fmt"
|
5
|
7
|
"github.com/jinzhu/gorm"
|
6
|
8
|
"strconv"
|
|
@@ -543,113 +545,111 @@ func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
|
543
|
545
|
writeMiddleDb.Save(&info)
|
544
|
546
|
//插入到系统检验检查数据
|
545
|
547
|
//for _, item := range list{}
|
546
|
|
- //for _, item := range list {
|
547
|
|
- //
|
548
|
|
- // project_id := int64(0)
|
549
|
|
- // if len(item.Barcode) > 0 {
|
550
|
|
- // project_id, _ = GetGzjhProjectID(org_id, item.Groupname)
|
551
|
|
- // } else {
|
552
|
|
- // continue
|
553
|
|
- // }
|
554
|
|
- // printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
|
555
|
|
- //
|
556
|
|
- // item_id, _ := GetItemID(org_id, item.Groupname, item.Itemname, project_id)
|
557
|
|
- //
|
558
|
|
- // tx := writeMiddleDb.Begin()
|
559
|
|
- // var inspection models.MiddleInspection
|
560
|
|
- // var inspection_reference models.MiddleInspectionReference
|
561
|
|
- //
|
562
|
|
- // recordDateStr := ""
|
563
|
|
- //
|
564
|
|
- // if len(item.Repdate) == 0 {
|
565
|
|
- // recordDateStr = time.Now().Format("2006-01-02 15:04")
|
566
|
|
- // }
|
567
|
|
- //
|
568
|
|
- // inspect_date := item.Repdate
|
569
|
|
- // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
|
570
|
|
- // record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
|
571
|
|
- // var total int
|
572
|
|
- // var RangeOptions string
|
573
|
|
- // var RangeMin string
|
574
|
|
- // var RangeMax string
|
575
|
|
- // // 判断检查类型
|
576
|
|
- // var ItemType int
|
577
|
|
- // if strings.Contains(item.Refrange, "[") && strings.Contains(item.Refrange, "]") {
|
578
|
|
- // ItemType = 1
|
579
|
|
- //
|
580
|
|
- // } else {
|
581
|
|
- // ItemType = 2
|
582
|
|
- //
|
583
|
|
- // }
|
584
|
|
- //
|
585
|
|
- // if ItemType == 1 {
|
586
|
|
- // item.Refrange = strings.Trim(item.Refrange, "[")
|
587
|
|
- // item.Refrange = strings.Trim(item.Refrange, "]")
|
588
|
|
- // Range := strings.Split(item.Refrange, "-")
|
589
|
|
- // RangeMin = Range[0]
|
590
|
|
- // RangeMax = Range[1]
|
591
|
|
- // } else {
|
592
|
|
- // RangeOptions = item.Refrange
|
593
|
|
- // }
|
594
|
|
- //
|
595
|
|
- // 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
|
596
|
|
- // if inspection_reference.ID > 0 {
|
597
|
|
- // ItemType = inspection_reference.RangeType
|
598
|
|
- // }
|
599
|
|
- // if total <= 0 {
|
600
|
|
- // inspection_reference.OrgId = org_id
|
601
|
|
- // inspection_reference.ProjectName = item.Groupname
|
602
|
|
- // inspection_reference.Project = item.Groupname
|
603
|
|
- // inspection_reference.ProjectId = project_id
|
604
|
|
- // inspection_reference.ItemName = item.Itemname
|
605
|
|
- // inspection_reference.ItemNameAddition = item.Barcode
|
606
|
|
- // inspection_reference.ItemId = item_id
|
607
|
|
- // inspection_reference.RangeType = ItemType
|
608
|
|
- // inspection_reference.RangeMin = RangeMin
|
609
|
|
- // inspection_reference.RangeMax = RangeMax
|
610
|
|
- // inspection_reference.RangeOptions = RangeOptions
|
611
|
|
- // inspection_reference.Unit = item.Unit
|
612
|
|
- // inspection_reference.Status = 1
|
613
|
|
- // inspection_reference.CreatedTime = time.Now().Unix()
|
614
|
|
- // inspection_reference.UpdatedTime = time.Now().Unix()
|
615
|
|
- // inspection_reference.InspectDate = inspect_date
|
616
|
|
- // inspection_reference.UTime = inspect_date
|
617
|
|
- // err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
|
618
|
|
- // if err != nil {
|
619
|
|
- // tx.Rollback()
|
620
|
|
- // }
|
621
|
|
- // }
|
622
|
|
- //
|
623
|
|
- // var itotal int
|
624
|
|
- // 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
|
625
|
|
- // if itotal <= 0 {
|
626
|
|
- // //item.Result = strings.Replace(item.Result, ">", ">", -1)
|
627
|
|
- // //item.Result = strings.Replace(item.Result, "<", "<", -1)
|
628
|
|
- // inspection.PatientId = printInfo.PatientId
|
629
|
|
- // inspection.OrgId = org_id
|
630
|
|
- // inspection.ProjectId = project_id
|
631
|
|
- // inspection.ItemName = inspection_reference.ItemName
|
632
|
|
- // inspection.ProjectName = inspection_reference.ProjectName
|
633
|
|
- // inspection.InspectType = ItemType
|
634
|
|
- // inspection.ItemId = item_id
|
635
|
|
- // inspection.InspectValue = item.Result
|
636
|
|
- // inspection.InspectDate = inspect_date
|
637
|
|
- // inspection.RecordDate = record_date.Unix()
|
638
|
|
- // inspection.Status = 1
|
639
|
|
- // inspection.CreatedTime = time.Now().Unix()
|
640
|
|
- // inspection.UpdatedTime = time.Now().Unix()
|
641
|
|
- // inspection.UTime = inspect_date
|
642
|
|
- // inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
|
643
|
|
- // err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
|
644
|
|
- // if err != nil {
|
645
|
|
- // tx.Rollback()
|
646
|
|
- // }
|
647
|
|
- // }
|
648
|
|
- //
|
649
|
|
- // tx.Commit()
|
650
|
|
- //
|
651
|
|
- //}
|
|
548
|
+ for _, item := range list {
|
|
549
|
+
|
|
550
|
+ project_id := int64(0)
|
|
551
|
+ if len(item.Barcode) > 0 {
|
|
552
|
+ project_id, _ = GetGzjhProjectID(org_id, item.Groupname)
|
|
553
|
+ } else {
|
|
554
|
+ continue
|
|
555
|
+ }
|
|
556
|
+ printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
|
|
557
|
+
|
|
558
|
+ item_id, _ := GetItemID(org_id, item.Groupname, item.Itemname, project_id)
|
|
559
|
+
|
|
560
|
+ tx := writeMiddleDb.Begin()
|
|
561
|
+ var inspection models.MiddleInspection
|
|
562
|
+ var inspection_reference models.MiddleInspectionReference
|
|
563
|
+
|
|
564
|
+ recordDateStr := ""
|
652
|
565
|
|
|
566
|
+ if item.Repdate.Unix() == 0 {
|
|
567
|
+ recordDateStr = time.Now().Format("2006-01-02 15:04")
|
|
568
|
+ }
|
|
569
|
+
|
|
570
|
+ inspect_date := item.Repdate.Format("2006-01-02 15:04")
|
|
571
|
+ date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
|
|
572
|
+ record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
|
|
573
|
+ var total int
|
|
574
|
+ var RangeOptions string
|
|
575
|
+ var RangeMin string
|
|
576
|
+ var RangeMax string
|
|
577
|
+ // 判断检查类型
|
|
578
|
+ var ItemType int
|
|
579
|
+ if strings.Contains(item.Refrange, "-") {
|
|
580
|
+ ItemType = 1
|
|
581
|
+
|
|
582
|
+ } else {
|
|
583
|
+ ItemType = 2
|
|
584
|
+
|
|
585
|
+ }
|
|
586
|
+
|
|
587
|
+ if ItemType == 1 {
|
|
588
|
+ Range := strings.Split(item.Refrange, "-")
|
|
589
|
+ RangeMin = Range[0]
|
|
590
|
+ RangeMax = Range[1]
|
|
591
|
+ } else {
|
|
592
|
+ RangeOptions = item.Refrange
|
|
593
|
+ }
|
|
594
|
+
|
|
595
|
+ 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
|
|
596
|
+ if inspection_reference.ID > 0 {
|
|
597
|
+ ItemType = inspection_reference.RangeType
|
|
598
|
+ }
|
|
599
|
+ if total <= 0 {
|
|
600
|
+ inspection_reference.OrgId = org_id
|
|
601
|
+ inspection_reference.ProjectName = item.Groupname
|
|
602
|
+ inspection_reference.Project = item.Groupname
|
|
603
|
+ inspection_reference.ProjectId = project_id
|
|
604
|
+ inspection_reference.ItemName = item.Itemname
|
|
605
|
+ inspection_reference.ItemNameAddition = item.Barcode
|
|
606
|
+ inspection_reference.ItemId = item_id
|
|
607
|
+ inspection_reference.RangeType = ItemType
|
|
608
|
+ inspection_reference.RangeMin = RangeMin
|
|
609
|
+ inspection_reference.RangeMax = RangeMax
|
|
610
|
+ inspection_reference.RangeOptions = RangeOptions
|
|
611
|
+ inspection_reference.Unit = item.Unit
|
|
612
|
+ inspection_reference.Status = 1
|
|
613
|
+ inspection_reference.CreatedTime = time.Now().Unix()
|
|
614
|
+ inspection_reference.UpdatedTime = time.Now().Unix()
|
|
615
|
+ inspection_reference.InspectDate = inspect_date
|
|
616
|
+ inspection_reference.UTime = inspect_date
|
|
617
|
+ err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
|
|
618
|
+ if err != nil {
|
|
619
|
+ tx.Rollback()
|
|
620
|
+ }
|
|
621
|
+ }
|
|
622
|
+
|
|
623
|
+ var itotal int
|
|
624
|
+ 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
|
|
625
|
+ if itotal <= 0 {
|
|
626
|
+ //item.Result = strings.Replace(item.Result, ">", ">", -1)
|
|
627
|
+ //item.Result = strings.Replace(item.Result, "<", "<", -1)
|
|
628
|
+ inspection.PatientId = printInfo.PatientId
|
|
629
|
+ inspection.OrgId = org_id
|
|
630
|
+ inspection.ProjectId = project_id
|
|
631
|
+ inspection.ItemName = inspection_reference.ItemName
|
|
632
|
+ inspection.ProjectName = inspection_reference.ProjectName
|
|
633
|
+ inspection.InspectType = ItemType
|
|
634
|
+ inspection.ItemId = item_id
|
|
635
|
+ inspection.InspectValue = item.Result
|
|
636
|
+ inspection.InspectDate = inspect_date
|
|
637
|
+ inspection.RecordDate = record_date.Unix()
|
|
638
|
+ inspection.Status = 1
|
|
639
|
+ inspection.CreatedTime = time.Now().Unix()
|
|
640
|
+ inspection.UpdatedTime = time.Now().Unix()
|
|
641
|
+ inspection.UTime = inspect_date
|
|
642
|
+ inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
|
|
643
|
+ err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
|
|
644
|
+ if err != nil {
|
|
645
|
+ tx.Rollback()
|
|
646
|
+ }
|
|
647
|
+ }
|
|
648
|
+
|
|
649
|
+ tx.Commit()
|
|
650
|
+
|
|
651
|
+ }
|
|
652
|
+ //
|
653
|
653
|
}
|
654
|
654
|
|
655
|
655
|
} else {
|