sh_service.go 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. package service
  2. import (
  3. "fmt"
  4. "regexp"
  5. "unicode"
  6. )
  7. type KMResult struct {
  8. FRequestCode string `gorm:"column:F_RequestCode" json:"F_RequestCode" form:"F_RequestCode"`
  9. FHospSampleID string `gorm:"column:F_HospSampleID" json:"F_HospSampleID" form:"F_HospSampleID"`
  10. FHospSampleNumber string `gorm:"column:F_HospSampleNumber" json:"F_HospSampleNumber" form:"F_HospSampleNumber"`
  11. FInputDate string `gorm:"column:F_InputDate" json:"F_InputDate" form:"F_InputDate"`
  12. FSamplingDate string `gorm:"column:F_SamplingDate" json:"F_SamplingDate" form:"F_SamplingDate"`
  13. FName string `gorm:"column:F_Name" json:"F_Name" form:"F_Name"`
  14. FSex string `gorm:"column:F_Sex" json:"F_Sex" form:"F_Sex"`
  15. FAge string `gorm:"column:F_Age" json:"F_Age" form:"F_Age"`
  16. FAgeUnit string `gorm:"column:F_AgeUnit" json:"F_AgeUnit" form:"F_AgeUnit"`
  17. FPatientNumber string `gorm:"column:F_PatientNumber" json:"F_PatientNumber" form:"F_PatientNumber"`
  18. FItemType string `gorm:"column:F_ItemType" json:"F_ItemType" form:"F_ItemType"`
  19. FCompoundItem string `gorm:"column:F_CompoundItem" json:"F_CompoundItem" form:"F_CompoundItem"`
  20. FCompoundItemName string `gorm:"column:F_CompoundItemName" json:"F_CompoundItemName" form:"F_CompoundItemName"`
  21. FNaturalItem string `gorm:"column:F_NaturalItem" json:"F_NaturalItem" form:"F_NaturalItem"`
  22. FNaturalItemName string `gorm:"column:F_NaturalItemName" json:"F_NaturalItemName" form:"F_NaturalItemName"`
  23. FSingleItem string `gorm:"column:F_SingleItem" json:"F_SingleItem" form:"F_SingleItem"`
  24. FSingleItemName string `gorm:"column:F_SingleItemName" json:"F_SingleItemName" form:"F_SingleItemName"`
  25. FHospNaturalItem string `gorm:"column:F_HospNaturalItem" json:"F_HospNaturalItem" form:"F_HospNaturalItem"`
  26. FHospNaturalItemName string `gorm:"column:F_HospNaturalItemName" json:"F_HospNaturalItemName" form:"F_HospNaturalItemName"`
  27. FHospItem string `gorm:"column:F_HospItem" json:"F_HospItem" form:"F_HospItem"`
  28. FHospItemName string `gorm:"column:F_HospItemName" json:"F_HospItemName" form:"F_HospItemName"`
  29. FTestNO string `gorm:"column:F_TestNO" json:"F_TestNO" form:"F_TestNO"`
  30. FResult string `gorm:"column:F_Result" json:"F_Result" form:"F_Result"`
  31. FUnit string `gorm:"column:F_Unit" json:"F_Unit" form:"F_Unit"`
  32. FHint string `gorm:"column:F_Hint" json:"F_Hint" form:"F_Hint"`
  33. FSuggestion string `gorm:"column:F_Suggestion" json:"F_Suggestion" form:"F_Suggestion"`
  34. FReference string `gorm:"column:F_Reference" json:"F_Reference" form:"F_Reference"`
  35. FReference2 string `gorm:"column:F_Reference2" json:"F_Reference2" form:"F_Reference2"`
  36. FDepartmentName string `gorm:"column:F_DepartmentName" json:"F_DepartmentName" form:"F_DepartmentName"`
  37. FRecorderName string `gorm:"column: F_RecorderName" json:"F_RecorderName" form:"F_RecorderName"`
  38. FRecordTime string `gorm:"column:F_RecordTime" json:"F_RecordTime" form:"F_RecordTime"`
  39. FCheckerName string `gorm:"column:F_CheckerName" json:"F_CheckerName" form:"F_CheckerName"`
  40. FCheckTime string `gorm:"column:F_CheckTime" json:"F_CheckTime" form:"F_CheckTime"`
  41. FAuthorizeName string `gorm:"column:F_AuthorizeName" json:"F_AuthorizeName" form:"F_AuthorizeName"`
  42. FAuthorizeTime string `gorm:"column:F_AuthorizeTime" json:"F_AuthorizeTime" form:"F_AuthorizeTime"`
  43. FSubResults string `gorm:"column:F_SubResults" json:"F_SubResults" form:"F_SubResults"`
  44. FPathologyGrossingDesc string `gorm:"column:F_PathologyGrossingDesc" json:"F_PathologyGrossingDesc" form:"F_PathologyGrossingDesc"`
  45. FReportBarCode string `gorm:"column:F_ReportBarCode" json:"F_ReportBarCode" form:"F_ReportBarCode"`
  46. FReceiveTime string `gorm:"column:F_ReceiveTime" json:"F_ReceiveTime" form:"F_ReceiveTime"`
  47. FStatus string `gorm:"column:F_Status" json:"F_Status" form:"F_Status"`
  48. FRemark string `gorm:"column:F_Remark" json:"F_Remark" form:"F_Remark"`
  49. FTestMethodName string `gorm:"column:F_TestMethodName" json:"F_TestMethodName" form:"F_TestMethodName"`
  50. FMachineName string `gorm:"column:F_MachineName" json:"F_MachineName" form:"F_MachineName"`
  51. FItemDesc string `gorm:"column:F_ItemDesc" json:"F_ItemDesc" form:"F_ItemDesc"`
  52. FIsDelayed string `gorm:"column:F_IsDelayed" json:"F_IsDelayed" form:"F_IsDelayed"`
  53. FDelayeddesc string `gorm:"column:F_Delayeddesc" json:"F_Delayeddesc" form:"F_Delayeddesc"`
  54. FIsReimbu string `gorm:"column:F_IsReimbu" json:"F_IsReimbu" form:"F_IsReimbu"`
  55. FReimbuDesc string `gorm:"column:F_ReimbuDesc" json:"F_ReimbuDesc" form:"F_ReimbuDesc"`
  56. FDetailItemID string `gorm:"column:F_DetailItemID" json:"F_DetailItemID" form:"F_DetailItemID"`
  57. FIDCardNo string `gorm:"column:F_IDCardNo" json:"F_IDCardNo" form:"F_IDCardNo"`
  58. }
  59. func (KMResult) TableName() string {
  60. return "v_km_lis_result"
  61. }
  62. //获取lis返回检验检查结果数据
  63. func GetSHResultDataInsertDB(org_id int64) (result []*KMResult) {
  64. record, _ := GetLastSyncResultRecord(org_id)
  65. fmt.Println(record)
  66. //if record.ID == 0 {
  67. // list, err := GetSHResultRecord()
  68. // if err == nil {
  69. // fmt.Println(list)
  70. //
  71. // //插入到系统检验检查数据
  72. // for _, item := range list {
  73. // project_id := int64(0)
  74. // if len(item.FIDCardNo) > 0 {
  75. // project_id, _ = GetShjhProjectID(org_id, item.FCompoundItemName)
  76. // } else {
  77. // continue
  78. // }
  79. // printInfo, _ := GetPatientsInfoByIDCardNo(item.FIDCardNo, 10215)
  80. //
  81. // if printInfo.ID == 0 {
  82. // fmt.Println(item)
  83. // fmt.Println(printInfo)
  84. // fmt.Println("暂无该患者")
  85. // continue
  86. // }
  87. //
  88. // item_id, _ := GetShItemID(org_id, item.FCompoundItemName, item.FSingleItemName, project_id)
  89. //
  90. // tx := writeMiddleDb.Begin()
  91. // var inspection models.MiddleInspection
  92. // var inspection_reference models.MiddleInspectionReference
  93. //
  94. // recordDateStr := ""
  95. // //inspect_date := item.FRecordTime.Format("2006-01-02 15:04")
  96. //
  97. // recordDateStr = item.FRecordTime
  98. // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
  99. // record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
  100. // var total int
  101. // var RangeOptions string
  102. // var RangeMin string
  103. // var RangeMax string
  104. // // 判断检查类型
  105. // var ItemType int
  106. // if IsChineseChar(item.FReference) || strings.Contains(item.FReference, "|") || strings.Contains(item.FReference, "≤") {
  107. // ItemType = 2
  108. // } else {
  109. // if strings.Contains(item.FReference, "-") {
  110. // ItemType = 1
  111. // } else {
  112. // ItemType = 2
  113. // }
  114. // }
  115. //
  116. // if ItemType == 1 {
  117. // Range := strings.Split(item.FReference, "-")
  118. // RangeMin = Range[0]
  119. // RangeMax = Range[1]
  120. // } else {
  121. // RangeOptions = item.FReference
  122. // }
  123. //
  124. // 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
  125. // if inspection_reference.ID > 0 {
  126. // ItemType = inspection_reference.RangeType
  127. // }
  128. // if total <= 0 {
  129. // inspection_reference.OrgId = org_id
  130. // inspection_reference.ProjectName = item.FCompoundItemName
  131. // inspection_reference.Project = item.FCompoundItemName
  132. // inspection_reference.ProjectId = project_id
  133. // inspection_reference.ItemName = item.FSingleItemName
  134. // inspection_reference.ItemNameAddition = ""
  135. // inspection_reference.ItemId = item_id
  136. // inspection_reference.RangeType = ItemType
  137. // inspection_reference.RangeMin = RangeMin
  138. // inspection_reference.RangeMax = RangeMax
  139. // inspection_reference.RangeOptions = RangeOptions
  140. // inspection_reference.Unit = item.FUnit
  141. // inspection_reference.Status = 1
  142. // inspection_reference.CreatedTime = time.Now().Unix()
  143. // inspection_reference.UpdatedTime = time.Now().Unix()
  144. // inspection_reference.InspectDate = item.FCheckTime
  145. // inspection_reference.UTime = item.FCheckTime
  146. // err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  147. // if err != nil {
  148. // tx.Rollback()
  149. // }
  150. // }
  151. //
  152. // var itotal int
  153. // 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
  154. // if itotal <= 0 {
  155. // inspection.PatientId = printInfo.ID
  156. // inspection.OrgId = org_id
  157. // inspection.ProjectId = project_id
  158. // inspection.ItemName = inspection_reference.ItemName
  159. // inspection.ProjectName = inspection_reference.ProjectName
  160. // inspection.InspectType = ItemType
  161. // inspection.ItemId = item_id
  162. // inspection.InspectValue = item.FResult
  163. // inspection.InspectDate = item.FCheckTime
  164. // inspection.RecordDate = record_date.Unix()
  165. // inspection.Status = 1
  166. // inspection.CreatedTime = time.Now().Unix()
  167. // inspection.UpdatedTime = time.Now().Unix()
  168. // inspection.UTime = item.FCheckTime
  169. // inspection.HisUserId = strconv.FormatInt(printInfo.ID, 10)
  170. // err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  171. // if err != nil {
  172. // tx.Rollback()
  173. // }
  174. // }
  175. //
  176. // tx.Commit()
  177. //
  178. // }
  179. // //插入一条查询检验检查结果记录状态数据
  180. // var info LisSyncResultStatusInfo
  181. // info.Ctime = time.Now().Unix()
  182. // info.Status = 1
  183. // info.Mtime = time.Now().Unix()
  184. // info.OrgId = org_id
  185. // info.IsResult = 1
  186. // info.LastId = int64(len(list))
  187. // info.ResultDate = time.Now().Unix()
  188. // writeMiddleDb.Save(&info)
  189. // }
  190. //
  191. //} else
  192. //{
  193. // if record.LastId != 0 {
  194. // list, err := GetResultRecordByID(record.LastId)
  195. // fmt.Println(list)
  196. // //插入中间库中
  197. // //插入一条插入中间库记录数据
  198. // if err == nil {
  199. //
  200. // //插入到系统检验检查数据
  201. // for _, item := range list {
  202. // project_id := int64(0)
  203. // if len(item.Barcode) > 0 {
  204. // project_id, _ = GetBljhProjectID(org_id, item.Groupname)
  205. // } else {
  206. // continue
  207. // }
  208. // printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
  209. // item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
  210. //
  211. // tx := writeMiddleDb.Begin()
  212. // var inspection models.MiddleInspection
  213. // var inspection_reference models.MiddleInspectionReference
  214. //
  215. // recordDateStr := ""
  216. // inspect_date := item.Repdate.Format("2006-01-02 15:04")
  217. // if item.Repdate.Unix() == 0 {
  218. // recordDateStr = time.Now().Format("2006-01-02 15:04")
  219. // } else {
  220. //
  221. // recordDateStr = inspect_date
  222. // }
  223. //
  224. // date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
  225. // record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
  226. // var total int
  227. // var RangeOptions string
  228. // var RangeMin string
  229. // var RangeMax string
  230. // // 判断检查类型
  231. // var ItemType int
  232. // if strings.Contains(item.Refrange, "-") {
  233. // ItemType = 1
  234. //
  235. // } else {
  236. // ItemType = 2
  237. //
  238. // }
  239. //
  240. // if ItemType == 1 {
  241. // Range := strings.Split(item.Refrange, "-")
  242. // RangeMin = Range[0]
  243. // RangeMax = Range[1]
  244. // } else {
  245. // RangeOptions = item.Refrange
  246. // }
  247. //
  248. // 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
  249. // if inspection_reference.ID > 0 {
  250. // ItemType = inspection_reference.RangeType
  251. // }
  252. // if total <= 0 {
  253. // inspection_reference.OrgId = org_id
  254. // inspection_reference.ProjectName = item.Groupname
  255. // inspection_reference.Project = item.Groupname
  256. // inspection_reference.ProjectId = project_id
  257. // inspection_reference.ItemName = item.Itemname
  258. // inspection_reference.ItemNameAddition = item.Barcode
  259. // inspection_reference.ItemId = item_id
  260. // inspection_reference.RangeType = ItemType
  261. // inspection_reference.RangeMin = RangeMin
  262. // inspection_reference.RangeMax = RangeMax
  263. // inspection_reference.RangeOptions = RangeOptions
  264. // inspection_reference.Unit = item.Unit
  265. // inspection_reference.Status = 1
  266. // inspection_reference.CreatedTime = time.Now().Unix()
  267. // inspection_reference.UpdatedTime = time.Now().Unix()
  268. // inspection_reference.InspectDate = inspect_date
  269. // inspection_reference.UTime = inspect_date
  270. // err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  271. // if err != nil {
  272. // tx.Rollback()
  273. // }
  274. // }
  275. //
  276. // var itotal int
  277. // 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
  278. // if itotal <= 0 {
  279. // inspection.PatientId = printInfo.PatientId
  280. // inspection.OrgId = org_id
  281. // inspection.ProjectId = project_id
  282. // inspection.ItemName = inspection_reference.ItemName
  283. // inspection.ProjectName = inspection_reference.ProjectName
  284. // inspection.InspectType = ItemType
  285. // inspection.ItemId = item_id
  286. // inspection.InspectValue = item.Result
  287. // inspection.InspectDate = inspect_date
  288. // inspection.RecordDate = record_date.Unix()
  289. // inspection.Status = 1
  290. // inspection.CreatedTime = time.Now().Unix()
  291. // inspection.UpdatedTime = time.Now().Unix()
  292. // inspection.UTime = inspect_date
  293. // inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
  294. // err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  295. // if err != nil {
  296. // tx.Rollback()
  297. // }
  298. // }
  299. //
  300. // tx.Commit()
  301. //
  302. // }
  303. // //插入一条查询检验检查结果记录状态数据
  304. // var info LisSyncResultStatusInfo
  305. // info.Ctime = time.Now().Unix()
  306. // info.Status = 1
  307. // info.Mtime = time.Now().Unix()
  308. // info.OrgId = org_id
  309. // info.IsResult = 1
  310. // code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
  311. // info.LastId = code
  312. // info.ResultDate = time.Now().Unix()
  313. // writeMiddleDb.Save(&info)
  314. //
  315. // }
  316. //
  317. // }
  318. //
  319. //}
  320. //
  321. //// 第一步:跟进org_id 去中间库查出需要同步的数据
  322. //inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
  323. //inspections, _ := GetSyncInspectionByOrgId(org_id)
  324. //
  325. //// 第二步:将数据同步到业务库
  326. //if len(inspection_references) > 0 {
  327. // for _, inspection_reference := range inspection_references {
  328. // SyncInspectionReference(&inspection_reference)
  329. // }
  330. //}
  331. //
  332. //if len(inspections) > 0 {
  333. // for _, inspection := range inspections {
  334. // SyncInspection(&inspection)
  335. // }
  336. //}
  337. return
  338. }
  339. func GetSHResultRecord() (record []*KMResult, err error) {
  340. err = dataBase.Model(&KMResult{}).Order("barcode asc").Find(&record).Error
  341. return
  342. }
  343. //判断是否包含中文
  344. func IsChineseChar(str string) bool {
  345. for _, r := range str {
  346. if unicode.Is(unicode.Scripts["Han"], r) || (regexp.MustCompile("[\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]").MatchString(string(r))) {
  347. return true
  348. }
  349. }
  350. return false
  351. }
  352. func GetResultRecordByTime(id int64) (record []*KMResult, err error) {
  353. err = readDb.Model(&KMResult{}).Where("barcode > ? AND repdate >= 2021-08-12 00:00:00", id).Order("barcode asc").Find(&record).Error
  354. return
  355. }