bl_service.go 55KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. package service
  2. import (
  3. "IC/models"
  4. "IC/utils"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. type HisOrder struct {
  12. ID int64 `gorm:"column:id" json:"id" form:"id"`
  13. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  14. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  15. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  16. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  17. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  18. Status int64 `gorm:"column:status" json:"status" form:"status"`
  19. Number string `gorm:"column:number" json:"number" form:"number"`
  20. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  21. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  22. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  23. XtHisPatient XtHisPatient `gorm:"ForeignKey:MdtrtId;AssociationForeignKey:Number" json:"his_patient"`
  24. }
  25. func (HisOrder) TableName() string {
  26. return "his_order"
  27. }
  28. type XtHisPatient struct {
  29. ID int64 `gorm:"column:id" json:"id" form:"id"`
  30. BalanceAccountsType int64 `gorm:"column:balance_accounts_type" json:"balance_accounts_type" form:"balance_accounts_type"`
  31. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  32. Name string `gorm:"column:name" json:"name" form:"name"`
  33. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  34. IdType int64 `gorm:"column:id_type" json:"id_type" form:"id_type"`
  35. MedicalTreatmentType int64 `gorm:"column:medical_treatment_type" json:"medical_treatment_type" form:"medical_treatment_type"`
  36. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  37. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  38. Age int64 `gorm:"column:age" json:"age" form:"age"`
  39. PhoneNumber string `gorm:"column:phone_number" json:"phone_number" form:"phone_number"`
  40. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  41. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  42. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  43. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  44. IsNeedCostOfProduction int64 `gorm:"column:is_need_cost_of_production" json:"is_need_cost_of_production" form:"is_need_cost_of_production"`
  45. RegisterCost float64 `gorm:"column:register_cost" json:"register_cost" form:"register_cost"`
  46. TreatmentCost float64 `gorm:"column:treatment_cost" json:"treatment_cost" form:"treatment_cost"`
  47. CostOfProduction float64 `gorm:"column:cost_of_production" json:"cost_of_production" form:"cost_of_production"`
  48. Total float64 `gorm:"column:total" json:"total" form:"total"`
  49. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  50. Status int64 `gorm:"column:status" json:"status" form:"status"`
  51. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  52. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  53. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  54. Number string `gorm:"column:number" json:"number" form:"number"`
  55. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  56. IsReturn int64 `gorm:"column:is_return" json:"is_return" form:"is_return"`
  57. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  58. SocialType int64 `gorm:"column:social_type" json:"social_type" form:"social_type"`
  59. IdCardType int64 `gorm:"column:id_card_type" json:"id_card_type" form:"id_card_type"`
  60. PType string `gorm:"column:p_type" json:"p_type" form:"p_type"`
  61. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  62. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  63. }
  64. func (XtHisPatient) TableName() string {
  65. return "his_patient"
  66. }
  67. type HisPrescription struct {
  68. ID int64 `gorm:"column:id" json:"id" form:"id"`
  69. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  70. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  71. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  72. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  73. Status int64 `gorm:"column:status" json:"status" form:"status"`
  74. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  75. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  76. Number string `gorm:"column:number" json:"number" form:"number"`
  77. Type int64 `gorm:"column:type" json:"type" form:"type"`
  78. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  79. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  80. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  81. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  82. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  83. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  84. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  85. HisOrder HisOrder `gorm:"ForeignKey:Number;AssociationForeignKey:BatchNumber" json:"order"`
  86. Total string `gorm:"-" json:"total" form:"total"`
  87. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  88. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  89. }
  90. func (HisPrescription) TableName() string {
  91. return "his_prescription"
  92. }
  93. type CmSample struct {
  94. HospitalBarcode string `gorm:"column:hospital_barcode" json:"hospital_barcode" form:"hospital_barcode"`
  95. Hospsamplenumber string `gorm:"column:hospsamplenumber" json:"hospsamplenumber" form:"hospsamplenumber"`
  96. Pno string `gorm:"column:pno" json:"pno" form:"pno"`
  97. Ptype string `gorm:"column:ptype" json:"ptype" form:"ptype"`
  98. Bedno string `gorm:"column:bedno" json:"bedno" form:"bedno"`
  99. Pname string `gorm:"column:pname" json:"pname" form:"pname"`
  100. Psex string `gorm:"column:psex" json:"psex" form:"psex"`
  101. Page string `gorm:"column:page" json:"page" form:"page"`
  102. Pageunit string `gorm:"column:pageunit" json:"pageunit" form:"pageunit"`
  103. Ptel string `gorm:"column:ptel" json:"ptel" form:"ptel"`
  104. Stature string `gorm:"column:stature" json:"stature" form:"stature"`
  105. Avoirdupois string `gorm:"column:avoirdupois" json:"avoirdupois" form:"avoirdupois"`
  106. Gravweek string `gorm:"column:gravweek" json:"gravweek" form:"gravweek"`
  107. Collectiongravday string `gorm:"column:collectiongravday" json:"collectiongravday" form:"collectiongravday"`
  108. Birthday time.Time `gorm:"column:birthday" json:"birthday" form:"birthday"`
  109. Departname string `gorm:"column:departname" json:"departname" form:"departname"`
  110. Docname string `gorm:"column:docname" json:"docname" form:"docname"`
  111. Doctortel string `gorm:"column:doctortel" json:"doctortel" form:"doctortel"`
  112. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  113. Stype string `gorm:"column:stype" json:"stype" form:"stype"`
  114. Samstate string `gorm:"column:samstate" json:"samstate" form:"samstate"`
  115. Desccode string `gorm:"column:desccode" json:"desccode" form:"desccode"`
  116. Descr string `gorm:"column:descr" json:"descr" form:"descr"`
  117. Sampletime time.Time `gorm:"column:sampletime" json:"sampletime" form:"sampletime"`
  118. Senddate time.Time `gorm:"column:senddate" json:"senddate" form:"senddate"`
  119. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  120. Idcard string `gorm:"column:idcard" json:"idcard" form:"idcard"`
  121. CardClass string `gorm:"column:cardclass" json:"cardclass" form:"cardclass"`
  122. }
  123. func (CmSample) TableName() string {
  124. return "cm_sample"
  125. }
  126. type CmLisitems struct {
  127. ItemCode string `gorm:"column:item_code" json:"item_code" form:"item_code"`
  128. ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
  129. Testmethod string `gorm:"column:testmethod" json:"testmethod" form:"testmethod"`
  130. Iscompound string `gorm:"column:iscmpound" json:"iscmpound" form:"iscmpound"`
  131. DepartmentName string `gorm:"column:department_name" json:"department_name" form:"department_name"`
  132. }
  133. func (CmLisitems) TableName() string {
  134. return "v_cm_listtems"
  135. }
  136. type HisLabelPrintInfo struct {
  137. ID int64 `gorm:"column:id" json:"id" form:"id"`
  138. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  139. Number string `gorm:"column:number" json:"number" form:"number"`
  140. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  141. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  142. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  143. Status int64 `gorm:"column:status" json:"status" form:"status"`
  144. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  145. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  146. IsPrint int64 `gorm:"column:is_print" json:"is_print" form:"is_print"`
  147. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  148. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  149. PProjectId int64 `gorm:"column:p_project_id" json:"p_project_id" form:"p_project_id"`
  150. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  151. DoctorName string `gorm:"column:doctor_name" json:"doctor_name" form:"doctor_name"`
  152. PatientName string `gorm:"column:patient_name" json:"patient_name" form:"patient_name"`
  153. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  154. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  155. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  156. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:PProjectId" json:"project"`
  157. Patient models.Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
  158. VMHisProjectTeam VMHisProjectTeam `gorm:"ForeignKey:ID;AssociationForeignKey:ItemId" json:"team"`
  159. }
  160. func (HisLabelPrintInfo) TableName() string {
  161. return "his_label_print_info"
  162. }
  163. type LisSyncProcessStatusInfo struct {
  164. ID int64 `gorm:"column:id" json:"id" form:"id"`
  165. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  166. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  167. Status int64 `gorm:"column:status" json:"status" form:"status"`
  168. LastId int64 `gorm:"column:last_id" json:"last_id" form:"last_id"`
  169. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  170. IsInsert int64 `gorm:"column:is_insert" json:"is_insert" form:"is_insert"`
  171. IsResult int64 `gorm:"column:is_result" json:"is_result" form:"is_result"`
  172. ResultDate int64 `gorm:"column:result_date" json:"result_date" form:"result_date"`
  173. }
  174. func (LisSyncProcessStatusInfo) TableName() string {
  175. return "lis_sync_process_status_info"
  176. }
  177. type CmResult struct {
  178. Barcode string `gorm:"column:barcode" json:"barcode" form:"barcode"`
  179. Itemcode string `gorm:"column:itemcode" json:"itemcode" form:"itemcode"`
  180. Itemname string `gorm:"column:itemname" json:"itemname" form:"itemname"`
  181. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  182. Result string `gorm:"column:result" json:"result" form:"result"`
  183. Refrange string `gorm:"column:refrange" json:"refrange" form:"refrange"`
  184. Ts string `gorm:"column:ts" json:"ts" form:"ts"`
  185. Jyys string `gorm:"column:jyys" json:"jyys" form:"jyys"`
  186. Shys string `gorm:"column:shys" json:"shys" form:"shys"`
  187. Hycode string `gorm:"column:hycode" json:"hycode" form:"hycode"`
  188. Reptype string `gorm:"column:reptype" json:"reptype" form:"reptype"`
  189. TJH string `gorm:"column:tjh" json:"tjh" form:"tjh"`
  190. Repdate time.Time `gorm:"column:repdate" json:"repdate" form:"repdate"`
  191. Groupname string `gorm:"column:groupname" json:"groupname" form:"groupname"`
  192. Groupcode string `gorm:"column:groupcode" json:"groupcode" form:"groupcode"`
  193. Brkb string `gorm:"column:brkb" json:"brkb" form:"brkb"`
  194. Mic string `gorm:"column:mic" json:"mic" form:"mic"`
  195. Yjjy string `gorm:"column:yjjy" json:"yjjy" form:"yjjy"`
  196. Name string `gorm:"column:name" json:"name" form:"name"`
  197. }
  198. func (CmResult) TableName() string {
  199. return "v_cm_result"
  200. }
  201. type LisSyncResultStatusInfo struct {
  202. ID int64 `gorm:"column:id" json:"id" form:"id"`
  203. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  204. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  205. Status int64 `gorm:"column:status" json:"status" form:"status"`
  206. LastId int64 `gorm:"column:last_id" json:"last_id" form:"last_id"`
  207. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  208. IsResult int64 `gorm:"column:is_result" json:"is_result" form:"is_result"`
  209. ResultDate int64 `gorm:"column:result_date" json:"result_date" form:"result_date"`
  210. GpSyncEndDate string `gorm:"column:gp_sync_end_date" json:"gp_sync_end_date" form:"gp_sync_end_date"`
  211. }
  212. func (LisSyncResultStatusInfo) TableName() string {
  213. return "lis_sync_result_status_info"
  214. }
  215. func GetLastSyncRecord(org_id int64) (record LisSyncProcessStatusInfo, err error) {
  216. err = readMiddleDb.Model(&LisSyncProcessStatusInfo{}).Where("org_id = ? AND status = 1", org_id).Last(&record).Error
  217. return
  218. }
  219. func GetLastSyncResultRecord(org_id int64) (record LisSyncResultStatusInfo, err error) {
  220. err = readMiddleDb.Model(&LisSyncResultStatusInfo{}).Where("org_id = ? AND status = 1", org_id).Last(&record).Error
  221. return
  222. }
  223. func GetResultRecord() (record []CmResult, err error) {
  224. err = dataBase.Model(&CmResult{}).Where("repdate >= 2021-08-12 00:00:00").Order("barcode asc").Find(&record).Error
  225. return
  226. }
  227. func GetResultRecordByID(id int64) (record []CmResult, err error) {
  228. err = readDb.Model(&CmResult{}).Where("barcode > ? AND repdate >= 2021-08-12 00:00:00", id).Order("barcode asc").Find(&record).Error
  229. return
  230. }
  231. func GetSaveResultRecord(record LisSyncResultStatusInfo) (err error) {
  232. err = dataBase.Save(record).Error
  233. return
  234. }
  235. func GetLisDataById(org_id int64, last_id int64) (list []*HisLabelPrintInfo, err error) {
  236. //err = readDb.Model(&HisLabelPrintInfo{}).Where("id > ? AND user_org_id = ? AND status = 1", last_id, org_id).Find(&list).Error
  237. err = readDb.Model(&HisLabelPrintInfo{}).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  238. return db.Preload("HisPrescription", func(db *gorm.DB) *gorm.DB {
  239. return db.Preload("HisOrder", func(db *gorm.DB) *gorm.DB {
  240. return db.Preload("XtHisPatient", func(db *gorm.DB) *gorm.DB {
  241. return db.Where("status = 1")
  242. }).Where("status = 1")
  243. }).Where("status = 1")
  244. }).Where("status = 1")
  245. }).Where("id > ? AND user_org_id = ? AND status = 1", last_id, org_id).Find(&list).Error
  246. return
  247. }
  248. func GetAllLisData(org_id int64) (list []*HisLabelPrintInfo, err error) {
  249. err = readDb.Model(&HisLabelPrintInfo{}).Preload("Patient", "status = 1").Preload("VMHisProjectTeam", "status = 1").Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  250. return db.Preload("HisPrescription", func(db *gorm.DB) *gorm.DB {
  251. return db.Preload("HisOrder", func(db *gorm.DB) *gorm.DB {
  252. return db.Preload("XtHisPatient", func(db *gorm.DB) *gorm.DB {
  253. return db.Where("status = 1")
  254. }).Where("status = 1")
  255. }).Where("status = 1")
  256. }).Where("status = 1")
  257. }).Where("user_org_id = ? AND status = 1", org_id).Limit(5).Find(&list).Error
  258. return
  259. }
  260. func GetAllLisResultData(org_id int64) (list []*CmResult, err error) {
  261. err = readDb.Model(&CmResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  262. return
  263. }
  264. func GetLisResultDataByRecord(org_id int64) (list []*CmResult, err error) {
  265. err = readDb.Model(&CmResult{}).Where("user_org_id = ? AND status = 1", org_id).Find(&list).Error
  266. return
  267. }
  268. // 插入中间件逻辑
  269. func GetDataInsertDB(org_id int64) {
  270. record, _ := GetLastSyncRecord(org_id)
  271. if record.ID == 0 {
  272. var cms_arr []CmSample
  273. list, _ := GetAllLisData(org_id)
  274. //插入中间库中
  275. for _, item := range list {
  276. fmt.Println(item.HisPrescriptionProject)
  277. if item.ItemId > 0 {
  278. var cms CmSample
  279. cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
  280. cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
  281. cms.Ptype = "门诊"
  282. cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
  283. if item.Patient.Gender == 1 {
  284. cms.Psex = "男"
  285. } else if item.Patient.Gender == 2 {
  286. cms.Psex = "女"
  287. } else {
  288. cms.Psex = "不详"
  289. }
  290. cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
  291. cms.Pageunit = "岁"
  292. cms.Departname = "肾病学专业"
  293. role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
  294. cms.Docname = role.UserName
  295. diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
  296. //var config []*models.HisXtDiagnoseConfig
  297. var name string
  298. for _, item := range diagnosis_ids {
  299. id, _ := strconv.ParseInt(item, 10, 64)
  300. diagnosisConfig, _ := FindDiagnoseById(id)
  301. if len(name) == 0 {
  302. name = diagnosisConfig.ClassName
  303. } else {
  304. name = name + "," + diagnosisConfig.ClassName
  305. }
  306. }
  307. cms.Diagnosis = name
  308. cms.Stype = ""
  309. cms.Samstate = ""
  310. cms.Desccode = strconv.FormatInt(item.ItemId, 10)
  311. cms.Descr = item.ProjectName
  312. data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
  313. datatime := time.Unix(data/1000, 0)
  314. cms.Sampletime = datatime
  315. cms.Senddate = time.Now()
  316. cms_arr = append(cms_arr, cms)
  317. } else {
  318. var cms CmSample
  319. cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
  320. cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
  321. cms.Ptype = "门诊"
  322. cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
  323. if item.Patient.Gender == 1 {
  324. cms.Psex = "男"
  325. } else if item.Patient.Gender == 2 {
  326. cms.Psex = "女"
  327. } else {
  328. cms.Psex = "不详"
  329. }
  330. cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
  331. cms.Pageunit = "岁"
  332. cms.Departname = "肾病学专业"
  333. role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
  334. cms.Docname = role.UserName
  335. diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
  336. //var config []*models.HisXtDiagnoseConfig
  337. var name string
  338. for _, item := range diagnosis_ids {
  339. id, _ := strconv.ParseInt(item, 10, 64)
  340. diagnosisConfig, _ := FindDiagnoseById(id)
  341. if len(name) == 0 {
  342. name = diagnosisConfig.ClassName
  343. } else {
  344. name = name + "," + diagnosisConfig.ClassName
  345. }
  346. }
  347. cms.Diagnosis = name
  348. cms.Stype = ""
  349. cms.Samstate = ""
  350. cms.Desccode = strconv.FormatInt(item.ProjectId, 10)
  351. cms.Descr = item.ProjectName
  352. tm := time.Unix(item.Ctime, 0)
  353. //data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
  354. //datatime := time.Unix(data/1000, 0)
  355. cms.Sampletime = tm
  356. cms.Senddate = time.Now()
  357. cms_arr = append(cms_arr, cms)
  358. }
  359. }
  360. //插入到中间库
  361. for _, item := range cms_arr {
  362. if len(item.Pno) > 0 {
  363. blDb.Save(item)
  364. }
  365. }
  366. //插入一条插入中间库记录数据
  367. var info LisSyncProcessStatusInfo
  368. info.Ctime = time.Now().Unix()
  369. info.Status = 1
  370. info.Mtime = time.Now().Unix()
  371. info.OrgId = org_id
  372. info.IsInsert = 1
  373. info.IsResult = 0
  374. info.LastId = list[len(list)-1].ID
  375. info.ResultDate = 0
  376. writeMiddleDb.Save(&info)
  377. } else {
  378. var cms_arr []CmSample
  379. if record.LastId != 0 {
  380. list, _ := GetLisDataById(org_id, record.LastId)
  381. //插入中间库中
  382. for _, item := range list {
  383. if item.ItemId > 0 {
  384. fmt.Println()
  385. //teams, _ := GetProjectTeamList(org_id, item.ItemId, item.PrescriptionId)
  386. //for _, subItem := range teams {
  387. var cms CmSample
  388. cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
  389. //cms.Hospsamplenumber = strconv.FormatInt(item.ID, 10)
  390. cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
  391. cms.Ptype = "门诊"
  392. cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
  393. if item.Patient.Gender == 1 {
  394. cms.Psex = "男"
  395. } else if item.Patient.Gender == 2 {
  396. cms.Psex = "女"
  397. } else {
  398. cms.Psex = "不详"
  399. }
  400. cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
  401. cms.Pageunit = "岁"
  402. cms.Departname = "肾病学专业"
  403. role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
  404. cms.Docname = role.UserName
  405. diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
  406. //var config []*models.HisXtDiagnoseConfig
  407. var name string
  408. for _, item := range diagnosis_ids {
  409. id, _ := strconv.ParseInt(item, 10, 64)
  410. diagnosisConfig, _ := FindDiagnoseById(id)
  411. if len(name) == 0 {
  412. name = diagnosisConfig.ClassName
  413. } else {
  414. name = name + "," + diagnosisConfig.ClassName
  415. }
  416. }
  417. cms.Diagnosis = name
  418. cms.Stype = ""
  419. cms.Samstate = ""
  420. cms.Desccode = strconv.FormatInt(item.ItemId, 10)
  421. cms.Descr = item.ProjectName
  422. //data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
  423. //datatime := time.Unix(data/1000, 0)
  424. //cms.Sampletime = datatime
  425. tm := time.Unix(item.Ctime, 0)
  426. cms.Sampletime = tm
  427. cms.Senddate = time.Now()
  428. cms_arr = append(cms_arr, cms)
  429. } else {
  430. var cms CmSample
  431. cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
  432. //cms.Hospsamplenumber = strconv.FormatInt(item.ID, 10)
  433. cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
  434. cms.Ptype = "门诊"
  435. cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
  436. if item.Patient.Gender == 1 {
  437. cms.Psex = "男"
  438. } else if item.Patient.Gender == 2 {
  439. cms.Psex = "女"
  440. } else {
  441. cms.Psex = "不详"
  442. }
  443. cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
  444. cms.Pageunit = "岁"
  445. cms.Departname = "肾病学专业"
  446. role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
  447. cms.Docname = role.UserName
  448. diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
  449. var name string
  450. for _, item := range diagnosis_ids {
  451. id, _ := strconv.ParseInt(item, 10, 64)
  452. diagnosisConfig, _ := FindDiagnoseById(id)
  453. if len(name) == 0 {
  454. name = diagnosisConfig.ClassName
  455. } else {
  456. name = name + "," + diagnosisConfig.ClassName
  457. }
  458. }
  459. cms.Diagnosis = name
  460. cms.Stype = ""
  461. cms.Samstate = ""
  462. cms.Desccode = strconv.FormatInt(item.ProjectId, 10)
  463. cms.Descr = item.ProjectName
  464. tm := time.Unix(item.Ctime, 0)
  465. cms.Sampletime = tm
  466. cms.Senddate = time.Now()
  467. cms_arr = append(cms_arr, cms)
  468. }
  469. }
  470. //插入一条插入中间库记录数据
  471. for _, item := range cms_arr {
  472. if len(item.Pno) > 0 {
  473. blDb.Save(item)
  474. }
  475. }
  476. //插入一条插入中间库记录数据
  477. var info LisSyncProcessStatusInfo
  478. info.Ctime = time.Now().Unix()
  479. info.Status = 1
  480. info.Mtime = time.Now().Unix()
  481. info.OrgId = org_id
  482. info.IsInsert = 1
  483. info.IsResult = 0
  484. info.LastId = list[len(list)-1].ID
  485. info.ResultDate = 0
  486. writeMiddleDb.Save(&info)
  487. }
  488. }
  489. }
  490. // 获取lis返回检验检查结果数据
  491. func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
  492. record, _ := GetLastSyncResultRecord(org_id)
  493. if record.ID == 0 {
  494. list, err := GetResultRecord()
  495. if err == nil {
  496. fmt.Println(list)
  497. //插入到系统检验检查数据
  498. for _, item := range list {
  499. project_id := int64(0)
  500. xt_project_id := int64(0)
  501. if len(item.Barcode) > 0 {
  502. project_id, xt_project_id, _ = GetBljhProjectID(org_id, item.Groupname)
  503. } else {
  504. continue
  505. }
  506. printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
  507. if printInfo.ID == 0 {
  508. fmt.Println(item)
  509. fmt.Println(printInfo)
  510. fmt.Println("数据查询不到")
  511. continue
  512. }
  513. item_id, sys_item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
  514. tx := writeMiddleDb.Begin()
  515. var inspection models.MiddleInspection
  516. var inspection_reference models.MiddleInspectionReference
  517. recordDateStr := ""
  518. inspect_date := item.Repdate.Format("2006-01-02 15:04")
  519. if item.Repdate.Unix() == 0 {
  520. recordDateStr = time.Now().Format("2006-01-02 15:04")
  521. } else {
  522. recordDateStr = inspect_date
  523. }
  524. date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
  525. record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
  526. var total int
  527. var RangeOptions string
  528. var RangeMin string
  529. var RangeMax string
  530. // 判断检查类型
  531. var ItemType int
  532. if strings.Contains(item.Refrange, "-") {
  533. ItemType = 1
  534. } else {
  535. ItemType = 2
  536. }
  537. if ItemType == 1 {
  538. Range := strings.Split(item.Refrange, "-")
  539. RangeMin = Range[0]
  540. RangeMax = Range[1]
  541. } else {
  542. RangeOptions = item.Refrange
  543. }
  544. if xt_project_id > 0 && sys_item_id > 0 {
  545. 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
  546. if inspection_reference.ID > 0 {
  547. ItemType = inspection_reference.RangeType
  548. }
  549. if total <= 0 {
  550. inspection_reference.OrgId = org_id
  551. inspection_reference.ProjectName = item.Groupname
  552. inspection_reference.Project = item.Groupname
  553. inspection_reference.ProjectId = project_id
  554. inspection_reference.ItemName = item.Itemname
  555. inspection_reference.ItemNameAddition = item.Barcode
  556. inspection_reference.ItemId = item_id
  557. inspection_reference.RangeType = ItemType
  558. inspection_reference.RangeMin = RangeMin
  559. inspection_reference.RangeMax = RangeMax
  560. inspection_reference.RangeOptions = RangeOptions
  561. inspection_reference.Unit = item.Unit
  562. inspection_reference.Status = 1
  563. inspection_reference.CreatedTime = time.Now().Unix()
  564. inspection_reference.UpdatedTime = time.Now().Unix()
  565. inspection_reference.InspectDate = inspect_date
  566. inspection_reference.UTime = inspect_date
  567. err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  568. if err != nil {
  569. tx.Rollback()
  570. }
  571. }
  572. } else {
  573. 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
  574. if inspection_reference.ID > 0 {
  575. ItemType = inspection_reference.RangeType
  576. }
  577. if total <= 0 {
  578. inspection_reference.OrgId = org_id
  579. inspection_reference.ProjectName = item.Groupname
  580. inspection_reference.Project = item.Groupname
  581. inspection_reference.ProjectId = project_id
  582. inspection_reference.ItemName = item.Itemname
  583. inspection_reference.ItemNameAddition = item.Barcode
  584. inspection_reference.ItemId = item_id
  585. inspection_reference.RangeType = ItemType
  586. inspection_reference.RangeMin = RangeMin
  587. inspection_reference.RangeMax = RangeMax
  588. inspection_reference.RangeOptions = RangeOptions
  589. inspection_reference.Unit = item.Unit
  590. inspection_reference.Status = 1
  591. inspection_reference.CreatedTime = time.Now().Unix()
  592. inspection_reference.UpdatedTime = time.Now().Unix()
  593. inspection_reference.InspectDate = inspect_date
  594. inspection_reference.UTime = inspect_date
  595. err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  596. if err != nil {
  597. tx.Rollback()
  598. }
  599. }
  600. }
  601. if xt_project_id > 0 && sys_item_id > 0 {
  602. var itotal int
  603. 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
  604. if itotal <= 0 {
  605. //item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
  606. //item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
  607. inspection.PatientId = printInfo.PatientId
  608. inspection.OrgId = org_id
  609. inspection.ProjectId = project_id
  610. inspection.ItemName = inspection_reference.ItemName
  611. inspection.ProjectName = inspection_reference.ProjectName
  612. inspection.InspectType = ItemType
  613. inspection.ItemId = item_id
  614. inspection.InspectValue = item.Result
  615. inspection.InspectDate = inspect_date
  616. inspection.RecordDate = record_date.Unix()
  617. inspection.Status = 1
  618. inspection.CreatedTime = time.Now().Unix()
  619. inspection.UpdatedTime = time.Now().Unix()
  620. inspection.UTime = inspect_date
  621. inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
  622. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  623. if err != nil {
  624. tx.Rollback()
  625. }
  626. }
  627. } else {
  628. var itotal int
  629. 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
  630. if itotal <= 0 {
  631. //item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
  632. //item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
  633. inspection.PatientId = printInfo.PatientId
  634. inspection.OrgId = org_id
  635. inspection.ProjectId = project_id
  636. inspection.ItemName = inspection_reference.ItemName
  637. inspection.ProjectName = inspection_reference.ProjectName
  638. inspection.InspectType = ItemType
  639. inspection.ItemId = item_id
  640. inspection.InspectValue = item.Result
  641. inspection.InspectDate = inspect_date
  642. inspection.RecordDate = record_date.Unix()
  643. inspection.Status = 1
  644. inspection.CreatedTime = time.Now().Unix()
  645. inspection.UpdatedTime = time.Now().Unix()
  646. inspection.UTime = inspect_date
  647. inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
  648. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  649. if err != nil {
  650. tx.Rollback()
  651. }
  652. }
  653. }
  654. tx.Commit()
  655. }
  656. //插入一条查询检验检查结果记录状态数据
  657. var info LisSyncResultStatusInfo
  658. info.Ctime = time.Now().Unix()
  659. info.Status = 1
  660. info.Mtime = time.Now().Unix()
  661. info.OrgId = org_id
  662. info.IsResult = 1
  663. code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
  664. info.LastId = code
  665. info.ResultDate = time.Now().Unix()
  666. writeMiddleDb.Save(&info)
  667. //
  668. }
  669. } else {
  670. if record.LastId != 0 {
  671. list, err := GetResultRecordByID(record.LastId)
  672. fmt.Println(list)
  673. //插入中间库中
  674. //插入一条插入中间库记录数据
  675. if err == nil {
  676. //插入到系统检验检查数据
  677. for _, item := range list {
  678. project_id := int64(0)
  679. sys_project_id := int64(0)
  680. if len(item.Barcode) > 0 {
  681. project_id, sys_project_id, _ = GetBljhProjectID(org_id, item.Groupname)
  682. } else {
  683. continue
  684. }
  685. printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
  686. item_id, sys_item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
  687. tx := writeMiddleDb.Begin()
  688. var inspection models.MiddleInspection
  689. var inspection_reference models.MiddleInspectionReference
  690. recordDateStr := ""
  691. inspect_date := item.Repdate.Format("2006-01-02 15:04")
  692. if item.Repdate.Unix() == 0 {
  693. recordDateStr = time.Now().Format("2006-01-02 15:04")
  694. } else {
  695. recordDateStr = inspect_date
  696. }
  697. date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
  698. record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
  699. var total int
  700. var RangeOptions string
  701. var RangeMin string
  702. var RangeMax string
  703. // 判断检查类型
  704. var ItemType int
  705. if strings.Contains(item.Refrange, "-") {
  706. ItemType = 1
  707. } else {
  708. ItemType = 2
  709. }
  710. if ItemType == 1 {
  711. Range := strings.Split(item.Refrange, "-")
  712. RangeMin = Range[0]
  713. RangeMax = Range[1]
  714. } else {
  715. RangeOptions = item.Refrange
  716. }
  717. 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
  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. var itotal int
  745. 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
  746. if itotal <= 0 {
  747. inspection.PatientId = printInfo.PatientId
  748. inspection.OrgId = org_id
  749. inspection.ProjectId = project_id
  750. inspection.ItemName = inspection_reference.ItemName
  751. inspection.ProjectName = inspection_reference.ProjectName
  752. inspection.InspectType = ItemType
  753. inspection.ItemId = item_id
  754. inspection.InspectValue = item.Result
  755. inspection.InspectDate = inspect_date
  756. inspection.RecordDate = record_date.Unix()
  757. inspection.Status = 1
  758. inspection.CreatedTime = time.Now().Unix()
  759. inspection.UpdatedTime = time.Now().Unix()
  760. inspection.UTime = inspect_date
  761. inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
  762. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  763. if err != nil {
  764. tx.Rollback()
  765. }
  766. }
  767. if sys_project_id > 0 && sys_item_id > 0 {
  768. var itotal int
  769. 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
  770. if itotal <= 0 {
  771. //item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
  772. //item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
  773. inspection.PatientId = printInfo.PatientId
  774. inspection.OrgId = org_id
  775. inspection.ProjectId = project_id
  776. inspection.ItemName = inspection_reference.ItemName
  777. inspection.ProjectName = inspection_reference.ProjectName
  778. inspection.InspectType = ItemType
  779. inspection.ItemId = item_id
  780. inspection.InspectValue = item.Result
  781. inspection.InspectDate = inspect_date
  782. inspection.RecordDate = record_date.Unix()
  783. inspection.Status = 1
  784. inspection.CreatedTime = time.Now().Unix()
  785. inspection.UpdatedTime = time.Now().Unix()
  786. inspection.UTime = inspect_date
  787. inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
  788. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  789. if err != nil {
  790. tx.Rollback()
  791. }
  792. }
  793. } else {
  794. var itotal int
  795. 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
  796. if itotal <= 0 {
  797. //item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
  798. //item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
  799. inspection.PatientId = printInfo.PatientId
  800. inspection.OrgId = org_id
  801. inspection.ProjectId = project_id
  802. inspection.ItemName = inspection_reference.ItemName
  803. inspection.ProjectName = inspection_reference.ProjectName
  804. inspection.InspectType = ItemType
  805. inspection.ItemId = item_id
  806. inspection.InspectValue = item.Result
  807. inspection.InspectDate = inspect_date
  808. inspection.RecordDate = record_date.Unix()
  809. inspection.Status = 1
  810. inspection.CreatedTime = time.Now().Unix()
  811. inspection.UpdatedTime = time.Now().Unix()
  812. inspection.UTime = inspect_date
  813. inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
  814. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  815. if err != nil {
  816. tx.Rollback()
  817. }
  818. }
  819. }
  820. tx.Commit()
  821. }
  822. //插入一条查询检验检查结果记录状态数据
  823. var info LisSyncResultStatusInfo
  824. info.Ctime = time.Now().Unix()
  825. info.Status = 1
  826. info.Mtime = time.Now().Unix()
  827. info.OrgId = org_id
  828. info.IsResult = 1
  829. code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
  830. info.LastId = code
  831. info.ResultDate = time.Now().Unix()
  832. writeMiddleDb.Save(&info)
  833. }
  834. }
  835. }
  836. // 第一步:跟进org_id 去中间库查出需要同步的数据
  837. inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
  838. inspections, _ := GetSyncInspectionByOrgId(org_id)
  839. // 第二步:将数据同步到业务库
  840. if len(inspection_references) > 0 {
  841. for _, inspection_reference := range inspection_references {
  842. SyncInspectionReferenceTwo(&inspection_reference)
  843. }
  844. }
  845. if len(inspections) > 0 {
  846. for _, inspection := range inspections {
  847. SyncInspection(&inspection)
  848. }
  849. }
  850. return
  851. }
  852. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role UserAdminRole, err error) {
  853. err = readUserDb.Model(&UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  854. return
  855. }
  856. type UserAdminRole struct {
  857. ID int64 `gorm:"column:id" json:"id" form:"id"`
  858. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  859. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  860. AppId int64 `gorm:"column:app_id" json:"app_id" form:"app_id"`
  861. RoleId int64 `gorm:"column:role_id" json:"role_id" form:"role_id"`
  862. UserName string `gorm:"column:user_name" json:"user_name" form:"user_name"`
  863. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  864. UserType int64 `gorm:"column:user_type" json:"user_type" form:"user_type"`
  865. UserTitle int64 `gorm:"column:user_title" json:"user_title" form:"user_title"`
  866. Intro string `gorm:"column:intro" json:"intro" form:"intro"`
  867. Status int64 `gorm:"column:status" json:"status" form:"status"`
  868. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  869. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  870. UserTitleName string `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
  871. RoleIds string `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
  872. Message string `gorm:"column:message" json:"message" form:"message"`
  873. Sex int64 `gorm:"column:sex" json:"sex" form:"sex"`
  874. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  875. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  876. IsSort int64 `gorm:"column:is_sort" json:"is_sort" form:"is_sort"`
  877. Department string `gorm:"column:department" json:"department" form:"department"`
  878. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  879. Age int64 `gorm:"column:age" json:"age" form:"age"`
  880. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  881. CardType int64 `gorm:"column:card_type" json:"card_type" form:"card_type"`
  882. IdCard string `gorm:"column:id_card" json:"id_card" form:"id_card"`
  883. Education int64 `gorm:"column:education" json:"education" form:"education"`
  884. StudyMajorName string `gorm:"column:study_major_name" json:"study_major_name" form:"study_major_name"`
  885. WorkMajorName string `gorm:"column:work_major_name" json:"work_major_name" form:"work_major_name"`
  886. RoleType int64 `gorm:"column:role_type" json:"role_type" form:"role_type"`
  887. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  888. DoctorCode string `gorm:"column:doctor_code" json:"doctor_code" form:"doctor_code"`
  889. Licensing int64 `gorm:"column:licensing" json:"licensing" form:"licensing"`
  890. JobNumber string `gorm:"column:job_number" json:"job_number" form:"job_number"`
  891. PrescriptionQualificationIdentification int64 `gorm:"column:prescription_qualification_identification" json:"prescription_qualification_identification" form:"prescription_qualification_identification"`
  892. IdentificationOutpatients int64 `gorm:"column:identification_outpatients" json:"identification_outpatients" form:"identification_outpatients"`
  893. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  894. MedicalRangeCode int64 `gorm:"column:medical_range_code" json:"medical_range_code" form:"medical_range_code"`
  895. MedicalLevel int64 `gorm:"column:medical_level" json:"medical_level" form:"medical_level"`
  896. MedicalTypeJob int64 `gorm:"column:medical_type_job" json:"medical_type_job" form:"medical_type_job"`
  897. PharmacistRegistrationNumber string `gorm:"column:pharmacist_registration_number" json:"pharmacist_registration_number" form:"pharmacist_registration_number"`
  898. DoctorRangeCode int64 `gorm:"column:doctor_range_code" json:"doctor_range_code" form:"doctor_range_code"`
  899. DoctorLevel int64 `gorm:"column:doctor_level" json:"doctor_level" form:"doctor_level"`
  900. DoctorTypeJob int64 `gorm:"column:doctor_type_job" json:"doctor_type_job" form:"doctor_type_job"`
  901. DoctorNumber string `gorm:"column:doctor_number" json:"doctor_number" form:"doctor_number"`
  902. OutpatientIllnessCategory string `gorm:"column:outpatient_illness_category" json:"outpatient_illness_category" form:"outpatient_illness_category"`
  903. IsActive int64 `gorm:"column:is_active" json:"is_active" form:"is_active"`
  904. ActiveStatus int64 `gorm:"column:active_status" json:"active_status" form:"active_status"`
  905. }
  906. func (UserAdminRole) TableName() string {
  907. return "sgj_user_admin_role"
  908. }
  909. func FindDiagnoseById(id int64) (*HisXtDiagnoseConfig, error) {
  910. dealer := &HisXtDiagnoseConfig{}
  911. err := readDb.Model(&HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  912. return dealer, err
  913. }
  914. type HisXtDiagnoseConfig struct {
  915. ID int64 `gorm:"column:id" json:"id" form:"id"`
  916. ClassName string `gorm:"column:class_name" json:"class_name" form:"class_name"`
  917. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  918. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  919. ContentCode string `gorm:"column:content_code" json:"content_code" form:"content_code"`
  920. CountryCode string `gorm:"column:country_code" json:"country_code" form:"country_code"`
  921. CountryContentName string `gorm:"column:country_content_name" json:"country_content_name" form:"country_content_name"`
  922. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  923. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  924. Status int64 `gorm:"column:status" json:"status" form:"status"`
  925. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  926. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  927. }
  928. func (HisXtDiagnoseConfig) TableName() string {
  929. return "his_xt_diagnose_config"
  930. }
  931. type VMHisProjectTeam struct {
  932. ID int64 `gorm:"column:id" json:"id" form:"id"`
  933. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  934. Price float64 `gorm:"column:price" json:"price" form:"price"`
  935. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  936. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  937. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  938. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  939. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  940. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  941. Status int64 `gorm:"column:status" json:"status" form:"status"`
  942. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  943. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  944. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  945. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  946. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  947. }
  948. func (VMHisProjectTeam) TableName() string {
  949. return "xt_his_project_team"
  950. }
  951. type VMItemProjectList struct {
  952. ID int64 `gorm:"column:id" json:"id" form:"id"`
  953. Number int64 `gorm:"column:number" json:"number" form:"number"`
  954. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  955. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  956. Status int64 `gorm:"column:status" json:"status" form:"status"`
  957. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  958. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  959. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  960. Type int64 `gorm:"column:type" json:"type" form:"type"`
  961. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  962. }
  963. func (VMItemProjectList) TableName() string {
  964. return "xt_his_project_list"
  965. }
  966. type VMHisProject struct {
  967. ID int64 `gorm:"column:id" json:"id" form:"id"`
  968. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  969. Price float64 `gorm:"column:price" json:"price" form:"price"`
  970. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  971. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  972. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  973. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  974. Status int64 `gorm:"column:status" json:"status" form:"status"`
  975. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  976. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  977. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  978. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  979. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  980. }
  981. func (VMHisProject) TableName() string {
  982. return "xt_his_project"
  983. }
  984. type HisPrescriptionProject struct {
  985. ID int64 `gorm:"column:id" json:"id" form:"id"`
  986. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  987. Price float64 `gorm:"column:price" json:"price" form:"price"`
  988. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  989. Status int64 `gorm:"column:status" json:"status" form:"status"`
  990. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  991. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  992. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  993. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  994. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  995. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  996. Count int64 `gorm:"column:count" json:"count" form:"count"`
  997. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  998. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  999. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1000. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1001. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1002. Day string `gorm:"column:day" json:"day" form:"day"`
  1003. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1004. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1005. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1006. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1007. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1008. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1009. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1010. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1011. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1012. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1013. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1014. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1015. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1016. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1017. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1018. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1019. HisPrescription HisPrescription `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"his_prescription"`
  1020. }
  1021. func (HisPrescriptionProject) TableName() string {
  1022. return "his_prescription_project"
  1023. }
  1024. func GetProjectTeamList(orgid int64, id int64, p_id int64) (project []*HisPrescriptionProject, err error) {
  1025. err = readDb.Model(&HisPrescriptionProject{}).Where("user_org_id = ? AND status = 1 AND team_id = ? AND prescription_id = ?", orgid, id, p_id).Find(&project).Error
  1026. return
  1027. }
  1028. func GetHisLabelPrintInfoById(id string) (info HisLabelPrintInfo, err error) {
  1029. err = readDb.Model(&HisLabelPrintInfo{}).Where("id = ?", id).First(&info).Error
  1030. return
  1031. }
  1032. func GetPatientsInfoByIDCardNo(id_card_no string, org_id int64) (info models.Patients, err error) {
  1033. err = readDb.Model(&models.Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, org_id).First(&info).Error
  1034. return
  1035. }
  1036. func GetAllLisDataFor10191(org_id int64) (list []models.HisLabelPrintStatusInfo, err error) {
  1037. err = readDb.Model(&models.HisLabelPrintStatusInfo{}).Preload("Patient", "status = 1").Where("user_org_id = ? AND status = 1 and apply_code = ''", org_id).Find(&list).Error
  1038. return
  1039. }
  1040. func GetAllLisDataFor10191LastId(org_id int64, last_id int64) (list []*models.HisLabelPrintStatusInfo, err error) {
  1041. 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
  1042. return
  1043. }