123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- package service
-
- import (
- "fmt"
- "regexp"
- "unicode"
- )
-
- type KMResult struct {
- FRequestCode string `gorm:"column:F_RequestCode" json:"F_RequestCode" form:"F_RequestCode"`
- FHospSampleID string `gorm:"column:F_HospSampleID" json:"F_HospSampleID" form:"F_HospSampleID"`
- FHospSampleNumber string `gorm:"column:F_HospSampleNumber" json:"F_HospSampleNumber" form:"F_HospSampleNumber"`
- FInputDate string `gorm:"column:F_InputDate" json:"F_InputDate" form:"F_InputDate"`
- FSamplingDate string `gorm:"column:F_SamplingDate" json:"F_SamplingDate" form:"F_SamplingDate"`
- FName string `gorm:"column:F_Name" json:"F_Name" form:"F_Name"`
- FSex string `gorm:"column:F_Sex" json:"F_Sex" form:"F_Sex"`
- FAge string `gorm:"column:F_Age" json:"F_Age" form:"F_Age"`
- FAgeUnit string `gorm:"column:F_AgeUnit" json:"F_AgeUnit" form:"F_AgeUnit"`
- FPatientNumber string `gorm:"column:F_PatientNumber" json:"F_PatientNumber" form:"F_PatientNumber"`
- FItemType string `gorm:"column:F_ItemType" json:"F_ItemType" form:"F_ItemType"`
- FCompoundItem string `gorm:"column:F_CompoundItem" json:"F_CompoundItem" form:"F_CompoundItem"`
- FCompoundItemName string `gorm:"column:F_CompoundItemName" json:"F_CompoundItemName" form:"F_CompoundItemName"`
- FNaturalItem string `gorm:"column:F_NaturalItem" json:"F_NaturalItem" form:"F_NaturalItem"`
- FNaturalItemName string `gorm:"column:F_NaturalItemName" json:"F_NaturalItemName" form:"F_NaturalItemName"`
- FSingleItem string `gorm:"column:F_SingleItem" json:"F_SingleItem" form:"F_SingleItem"`
- FSingleItemName string `gorm:"column:F_SingleItemName" json:"F_SingleItemName" form:"F_SingleItemName"`
- FHospNaturalItem string `gorm:"column:F_HospNaturalItem" json:"F_HospNaturalItem" form:"F_HospNaturalItem"`
- FHospNaturalItemName string `gorm:"column:F_HospNaturalItemName" json:"F_HospNaturalItemName" form:"F_HospNaturalItemName"`
- FHospItem string `gorm:"column:F_HospItem" json:"F_HospItem" form:"F_HospItem"`
- FHospItemName string `gorm:"column:F_HospItemName" json:"F_HospItemName" form:"F_HospItemName"`
- FTestNO string `gorm:"column:F_TestNO" json:"F_TestNO" form:"F_TestNO"`
- FResult string `gorm:"column:F_Result" json:"F_Result" form:"F_Result"`
- FUnit string `gorm:"column:F_Unit" json:"F_Unit" form:"F_Unit"`
- FHint string `gorm:"column:F_Hint" json:"F_Hint" form:"F_Hint"`
- FSuggestion string `gorm:"column:F_Suggestion" json:"F_Suggestion" form:"F_Suggestion"`
- FReference string `gorm:"column:F_Reference" json:"F_Reference" form:"F_Reference"`
- FReference2 string `gorm:"column:F_Reference2" json:"F_Reference2" form:"F_Reference2"`
- FDepartmentName string `gorm:"column:F_DepartmentName" json:"F_DepartmentName" form:"F_DepartmentName"`
- FRecorderName string `gorm:"column: F_RecorderName" json:"F_RecorderName" form:"F_RecorderName"`
- FRecordTime string `gorm:"column:F_RecordTime" json:"F_RecordTime" form:"F_RecordTime"`
- FCheckerName string `gorm:"column:F_CheckerName" json:"F_CheckerName" form:"F_CheckerName"`
- FCheckTime string `gorm:"column:F_CheckTime" json:"F_CheckTime" form:"F_CheckTime"`
- FAuthorizeName string `gorm:"column:F_AuthorizeName" json:"F_AuthorizeName" form:"F_AuthorizeName"`
- FAuthorizeTime string `gorm:"column:F_AuthorizeTime" json:"F_AuthorizeTime" form:"F_AuthorizeTime"`
- FSubResults string `gorm:"column:F_SubResults" json:"F_SubResults" form:"F_SubResults"`
- FPathologyGrossingDesc string `gorm:"column:F_PathologyGrossingDesc" json:"F_PathologyGrossingDesc" form:"F_PathologyGrossingDesc"`
- FReportBarCode string `gorm:"column:F_ReportBarCode" json:"F_ReportBarCode" form:"F_ReportBarCode"`
- FReceiveTime string `gorm:"column:F_ReceiveTime" json:"F_ReceiveTime" form:"F_ReceiveTime"`
- FStatus string `gorm:"column:F_Status" json:"F_Status" form:"F_Status"`
- FRemark string `gorm:"column:F_Remark" json:"F_Remark" form:"F_Remark"`
- FTestMethodName string `gorm:"column:F_TestMethodName" json:"F_TestMethodName" form:"F_TestMethodName"`
- FMachineName string `gorm:"column:F_MachineName" json:"F_MachineName" form:"F_MachineName"`
- FItemDesc string `gorm:"column:F_ItemDesc" json:"F_ItemDesc" form:"F_ItemDesc"`
- FIsDelayed string `gorm:"column:F_IsDelayed" json:"F_IsDelayed" form:"F_IsDelayed"`
- FDelayeddesc string `gorm:"column:F_Delayeddesc" json:"F_Delayeddesc" form:"F_Delayeddesc"`
- FIsReimbu string `gorm:"column:F_IsReimbu" json:"F_IsReimbu" form:"F_IsReimbu"`
- FReimbuDesc string `gorm:"column:F_ReimbuDesc" json:"F_ReimbuDesc" form:"F_ReimbuDesc"`
- FDetailItemID string `gorm:"column:F_DetailItemID" json:"F_DetailItemID" form:"F_DetailItemID"`
- FIDCardNo string `gorm:"column:F_IDCardNo" json:"F_IDCardNo" form:"F_IDCardNo"`
- }
-
- func (KMResult) TableName() string {
- return "v_km_lis_result"
- }
-
- //获取lis返回检验检查结果数据
- func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
- record, _ := GetLastSyncResultRecord(org_id)
- fmt.Println(record)
- //if record.ID == 0 {
- // list, err := GetSHResultRecord()
- // if err == nil {
- // fmt.Println(list)
- //
- // //插入到系统检验检查数据
- // for _, item := range list {
- // project_id := int64(0)
- // if len(item.FIDCardNo) > 0 {
- // project_id, _ = GetShjhProjectID(org_id, item.FCompoundItemName)
- // } else {
- // continue
- // }
- // printInfo, _ := GetPatientsInfoByIDCardNo(item.FIDCardNo, 10215)
- //
- // if printInfo.ID == 0 {
- // fmt.Println(item)
- // fmt.Println(printInfo)
- // fmt.Println("暂无该患者")
- // continue
- // }
- //
- // item_id, _ := GetShItemID(org_id, item.FCompoundItemName, item.FSingleItemName, project_id)
- //
- // tx := writeMiddleDb.Begin()
- // var inspection models.MiddleInspection
- // var inspection_reference models.MiddleInspectionReference
- //
- // recordDateStr := ""
- // //inspect_date := item.FRecordTime.Format("2006-01-02 15:04")
- //
- // recordDateStr = item.FRecordTime
- // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
- // record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
- // var total int
- // var RangeOptions string
- // var RangeMin string
- // var RangeMax string
- // // 判断检查类型
- // var ItemType int
- // if IsChineseChar(item.FReference) || strings.Contains(item.FReference, "|") || strings.Contains(item.FReference, "≤") {
- // ItemType = 2
- // } else {
- // if strings.Contains(item.FReference, "-") {
- // ItemType = 1
- // } else {
- // ItemType = 2
- // }
- // }
- //
- // if ItemType == 1 {
- // Range := strings.Split(item.FReference, "-")
- // RangeMin = Range[0]
- // RangeMax = Range[1]
- // } else {
- // RangeOptions = item.FReference
- // }
- //
- // 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
- // if inspection_reference.ID > 0 {
- // ItemType = inspection_reference.RangeType
- // }
- // if total <= 0 {
- // inspection_reference.OrgId = org_id
- // inspection_reference.ProjectName = item.FCompoundItemName
- // inspection_reference.Project = item.FCompoundItemName
- // inspection_reference.ProjectId = project_id
- // inspection_reference.ItemName = item.FSingleItemName
- // inspection_reference.ItemNameAddition = ""
- // inspection_reference.ItemId = item_id
- // inspection_reference.RangeType = ItemType
- // inspection_reference.RangeMin = RangeMin
- // inspection_reference.RangeMax = RangeMax
- // inspection_reference.RangeOptions = RangeOptions
- // inspection_reference.Unit = item.FUnit
- // inspection_reference.Status = 1
- // inspection_reference.CreatedTime = time.Now().Unix()
- // inspection_reference.UpdatedTime = time.Now().Unix()
- // inspection_reference.InspectDate = item.FCheckTime
- // inspection_reference.UTime = item.FCheckTime
- // err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
- // if err != nil {
- // tx.Rollback()
- // }
- // }
- //
- // var itotal int
- // 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.ID).Find(&inspection).Count(&itotal).Error
- // if itotal <= 0 {
- // inspection.PatientId = printInfo.ID
- // inspection.OrgId = org_id
- // inspection.ProjectId = project_id
- // inspection.ItemName = inspection_reference.ItemName
- // inspection.ProjectName = inspection_reference.ProjectName
- // inspection.InspectType = ItemType
- // inspection.ItemId = item_id
- // inspection.InspectValue = item.FResult
- // inspection.InspectDate = item.FCheckTime
- // inspection.RecordDate = record_date.Unix()
- // inspection.Status = 1
- // inspection.CreatedTime = time.Now().Unix()
- // inspection.UpdatedTime = time.Now().Unix()
- // inspection.UTime = item.FCheckTime
- // inspection.HisUserId = strconv.FormatInt(printInfo.ID, 10)
- // err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
- // if err != nil {
- // tx.Rollback()
- // }
- // }
- //
- // tx.Commit()
- //
- // }
- // //插入一条查询检验检查结果记录状态数据
- // var info LisSyncResultStatusInfo
- // info.Ctime = time.Now().Unix()
- // info.Status = 1
- // info.Mtime = time.Now().Unix()
- // info.OrgId = org_id
- // info.IsResult = 1
- // info.LastId = int64(len(list))
- // info.ResultDate = time.Now().Unix()
- // writeMiddleDb.Save(&info)
- // }
- //
- //} else
- //{
- // if record.LastId != 0 {
- // list, err := GetResultRecordByID(record.LastId)
- // fmt.Println(list)
- // //插入中间库中
- // //插入一条插入中间库记录数据
- // if err == nil {
- //
- // //插入到系统检验检查数据
- // for _, item := range list {
- // project_id := int64(0)
- // if len(item.Barcode) > 0 {
- // project_id, _ = GetBljhProjectID(org_id, item.Groupname)
- // } else {
- // continue
- // }
- // printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
- // item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
- //
- // tx := writeMiddleDb.Begin()
- // var inspection models.MiddleInspection
- // var inspection_reference models.MiddleInspectionReference
- //
- // recordDateStr := ""
- // inspect_date := item.Repdate.Format("2006-01-02 15:04")
- // if item.Repdate.Unix() == 0 {
- // recordDateStr = time.Now().Format("2006-01-02 15:04")
- // } else {
- //
- // recordDateStr = inspect_date
- // }
- //
- // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
- // record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
- // var total int
- // var RangeOptions string
- // var RangeMin string
- // var RangeMax string
- // // 判断检查类型
- // var ItemType int
- // if strings.Contains(item.Refrange, "-") {
- // ItemType = 1
- //
- // } else {
- // ItemType = 2
- //
- // }
- //
- // if ItemType == 1 {
- // Range := strings.Split(item.Refrange, "-")
- // RangeMin = Range[0]
- // RangeMax = Range[1]
- // } else {
- // RangeOptions = item.Refrange
- // }
- //
- // 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
- // if inspection_reference.ID > 0 {
- // ItemType = inspection_reference.RangeType
- // }
- // if total <= 0 {
- // inspection_reference.OrgId = org_id
- // inspection_reference.ProjectName = item.Groupname
- // inspection_reference.Project = item.Groupname
- // inspection_reference.ProjectId = project_id
- // inspection_reference.ItemName = item.Itemname
- // inspection_reference.ItemNameAddition = item.Barcode
- // inspection_reference.ItemId = item_id
- // inspection_reference.RangeType = ItemType
- // inspection_reference.RangeMin = RangeMin
- // inspection_reference.RangeMax = RangeMax
- // inspection_reference.RangeOptions = RangeOptions
- // inspection_reference.Unit = item.Unit
- // inspection_reference.Status = 1
- // inspection_reference.CreatedTime = time.Now().Unix()
- // inspection_reference.UpdatedTime = time.Now().Unix()
- // inspection_reference.InspectDate = inspect_date
- // inspection_reference.UTime = inspect_date
- // err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
- // if err != nil {
- // tx.Rollback()
- // }
- // }
- //
- // var itotal int
- // 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
- // if itotal <= 0 {
- // inspection.PatientId = printInfo.PatientId
- // inspection.OrgId = org_id
- // inspection.ProjectId = project_id
- // inspection.ItemName = inspection_reference.ItemName
- // inspection.ProjectName = inspection_reference.ProjectName
- // inspection.InspectType = ItemType
- // inspection.ItemId = item_id
- // inspection.InspectValue = item.Result
- // inspection.InspectDate = inspect_date
- // inspection.RecordDate = record_date.Unix()
- // inspection.Status = 1
- // inspection.CreatedTime = time.Now().Unix()
- // inspection.UpdatedTime = time.Now().Unix()
- // inspection.UTime = inspect_date
- // inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
- // err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
- // if err != nil {
- // tx.Rollback()
- // }
- // }
- //
- // tx.Commit()
- //
- // }
- // //插入一条查询检验检查结果记录状态数据
- // var info LisSyncResultStatusInfo
- // info.Ctime = time.Now().Unix()
- // info.Status = 1
- // info.Mtime = time.Now().Unix()
- // info.OrgId = org_id
- // info.IsResult = 1
- // code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
- // info.LastId = code
- // info.ResultDate = time.Now().Unix()
- // writeMiddleDb.Save(&info)
- //
- // }
- //
- // }
- //
- //}
- //
- //// 第一步:跟进org_id 去中间库查出需要同步的数据
- //inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
- //inspections, _ := GetSyncInspectionByOrgId(org_id)
- //
- //// 第二步:将数据同步到业务库
- //if len(inspection_references) > 0 {
- // for _, inspection_reference := range inspection_references {
- // SyncInspectionReference(&inspection_reference)
- // }
- //}
- //
- //if len(inspections) > 0 {
- // for _, inspection := range inspections {
- // SyncInspection(&inspection)
- // }
- //}
- return
-
- }
-
- func GetSHResultRecord() (record []*KMResult, err error) {
- err = dataBase.Model(&KMResult{}).Order("barcode asc").Find(&record).Error
- return
- }
-
- //判断是否包含中文
- func IsChineseChar(str string) bool {
- for _, r := range str {
- if unicode.Is(unicode.Scripts["Han"], r) || (regexp.MustCompile("[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]").MatchString(string(r))) {
- return true
- }
- }
- return false
- }
-
- func GetResultRecordByTime(id int64) (record []*KMResult, err error) {
- err = readDb.Model(&KMResult{}).Where("barcode > ? AND repdate >= 2021-08-12 00:00:00", id).Order("barcode asc").Find(&record).Error
- return
- }
|