bl_service.go 49KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  155. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:PProjectId" json:"project"`
  156. }
  157. func (HisLabelPrintInfo) TableName() string {
  158. return "his_label_print_info"
  159. }
  160. type LisSyncProcessStatusInfo struct {
  161. ID int64 `gorm:"column:id" json:"id" form:"id"`
  162. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  163. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  164. Status int64 `gorm:"column:status" json:"status" form:"status"`
  165. LastId int64 `gorm:"column:last_id" json:"last_id" form:"last_id"`
  166. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  167. IsInsert int64 `gorm:"column:is_insert" json:"is_insert" form:"is_insert"`
  168. IsResult int64 `gorm:"column:is_result" json:"is_result" form:"is_result"`
  169. ResultDate int64 `gorm:"column:result_date" json:"result_date" form:"result_date"`
  170. }
  171. func (LisSyncProcessStatusInfo) TableName() string {
  172. return "lis_sync_process_status_info"
  173. }
  174. type CmResult struct {
  175. Barcode string `gorm:"column:barcode" json:"barcode" form:"barcode"`
  176. Itemcode string `gorm:"column:itemcode" json:"itemcode" form:"itemcode"`
  177. Itemname string `gorm:"column:itemname" json:"itemname" form:"itemname"`
  178. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  179. Result string `gorm:"column:result" json:"result" form:"result"`
  180. Refrange string `gorm:"column:refrange" json:"refrange" form:"refrange"`
  181. Ts string `gorm:"column:ts" json:"ts" form:"ts"`
  182. Jyys string `gorm:"column:jyys" json:"jyys" form:"jyys"`
  183. Shys string `gorm:"column:shys" json:"shys" form:"shys"`
  184. Hycode string `gorm:"column:hycode" json:"hycode" form:"hycode"`
  185. Reptype string `gorm:"column:reptype" json:"reptype" form:"reptype"`
  186. TJH string `gorm:"column:tjh" json:"tjh" form:"tjh"`
  187. Repdate time.Time `gorm:"column:repdate" json:"repdate" form:"repdate"`
  188. Groupname string `gorm:"column:groupname" json:"groupname" form:"groupname"`
  189. Groupcode string `gorm:"column:groupcode" json:"groupcode" form:"groupcode"`
  190. Brkb string `gorm:"column:brkb" json:"brkb" form:"brkb"`
  191. Mic string `gorm:"column:mic" json:"mic" form:"mic"`
  192. Yjjy string `gorm:"column:yjjy" json:"yjjy" form:"yjjy"`
  193. Name string `gorm:"column:name" json:"name" form:"name"`
  194. }
  195. func (CmResult) TableName() string {
  196. return "v_cm_result"
  197. }
  198. type LisSyncResultStatusInfo struct {
  199. ID int64 `gorm:"column:id" json:"id" form:"id"`
  200. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  201. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  202. Status int64 `gorm:"column:status" json:"status" form:"status"`
  203. LastId int64 `gorm:"column:last_id" json:"last_id" form:"last_id"`
  204. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  205. IsResult int64 `gorm:"column:is_result" json:"is_result" form:"is_result"`
  206. ResultDate int64 `gorm:"column:result_date" json:"result_date" form:"result_date"`
  207. }
  208. func (LisSyncResultStatusInfo) TableName() string {
  209. return "lis_sync_result_status_info"
  210. }
  211. func GetLastSyncRecord(org_id int64) (record LisSyncProcessStatusInfo, err error) {
  212. err = readMiddleDb.Model(&LisSyncProcessStatusInfo{}).Where("org_id = ? AND status = 1", org_id).Last(&record).Error
  213. return
  214. }
  215. func GetLastSyncResultRecord(org_id int64) (record LisSyncResultStatusInfo, err error) {
  216. err = readMiddleDb.Model(&LisSyncResultStatusInfo{}).Where("org_id = ? AND status = 1", org_id).Last(&record).Error
  217. return
  218. }
  219. func GetResultRecord() (record []CmResult, err error) {
  220. err = dataBase.Model(&CmResult{}).Where("repdate >= 2021-08-12 00:00:00").Order("barcode asc").Find(&record).Error
  221. return
  222. }
  223. func GetResultRecordByID(id int64) (record []CmResult, err error) {
  224. err = readDb.Model(&CmResult{}).Where("barcode > ? AND repdate >= 2021-08-12 00:00:00", id).Order("barcode asc").Find(&record).Error
  225. return
  226. }
  227. func GetSaveResultRecord(record LisSyncResultStatusInfo) (err error) {
  228. err = dataBase.Save(record).Error
  229. return
  230. }
  231. func GetLisDataById(org_id int64, last_id int64) (list []*HisLabelPrintInfo, err error) {
  232. //err = readDb.Model(&HisLabelPrintInfo{}).Where("id > ? AND user_org_id = ? AND status = 1", last_id, org_id).Find(&list).Error
  233. err = readDb.Model(&HisLabelPrintInfo{}).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  234. return db.Preload("HisPrescription", func(db *gorm.DB) *gorm.DB {
  235. return db.Preload("HisOrder", func(db *gorm.DB) *gorm.DB {
  236. return db.Preload("XtHisPatient", func(db *gorm.DB) *gorm.DB {
  237. return db.Where("status = 1")
  238. }).Where("status = 1")
  239. }).Where("status = 1")
  240. }).Where("status = 1")
  241. }).Where("id > ? AND user_org_id = ? AND status = 1", last_id, org_id).Find(&list).Error
  242. return
  243. }
  244. func GetAllLisData(org_id int64) (list []*HisLabelPrintInfo, err error) {
  245. err = readDb.Model(&HisLabelPrintInfo{}).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  246. return db.Preload("HisPrescription", func(db *gorm.DB) *gorm.DB {
  247. return db.Preload("HisOrder", func(db *gorm.DB) *gorm.DB {
  248. return db.Preload("XtHisPatient", func(db *gorm.DB) *gorm.DB {
  249. return db.Where("status = 1")
  250. }).Where("status = 1")
  251. }).Where("status = 1")
  252. }).Where("status = 1")
  253. }).Where("user_org_id = ? AND status = 1", org_id).Find(&list).Error
  254. return
  255. }
  256. func GetAllLisResultData(org_id int64) (list []*CmResult, err error) {
  257. err = readDb.Model(&CmResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  258. return
  259. }
  260. func GetLisResultDataByRecord(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. //插入中间件逻辑
  265. func GetDataInsertDB(org_id int64) {
  266. record, _ := GetLastSyncRecord(org_id)
  267. if record.ID == 0 {
  268. var cms_arr []CmSample
  269. list, _ := GetAllLisData(org_id)
  270. //插入中间库中
  271. for _, item := range list {
  272. fmt.Println(item.HisPrescriptionProject)
  273. if item.ItemId > 0 {
  274. var cms CmSample
  275. cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
  276. cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
  277. cms.Ptype = "门诊"
  278. cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
  279. if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 1 {
  280. cms.Psex = "男"
  281. } else if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 2 {
  282. cms.Psex = "女"
  283. }
  284. cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
  285. cms.Pageunit = "岁"
  286. cms.Departname = "肾病学专业"
  287. role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
  288. cms.Docname = role.UserName
  289. diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
  290. //var config []*models.HisXtDiagnoseConfig
  291. var name string
  292. for _, item := range diagnosis_ids {
  293. id, _ := strconv.ParseInt(item, 10, 64)
  294. diagnosisConfig, _ := FindDiagnoseById(id)
  295. if len(name) == 0 {
  296. name = diagnosisConfig.ClassName
  297. } else {
  298. name = name + "," + diagnosisConfig.ClassName
  299. }
  300. }
  301. cms.Diagnosis = name
  302. cms.Stype = ""
  303. cms.Samstate = ""
  304. cms.Desccode = strconv.FormatInt(item.ID, 10)
  305. cms.Descr = item.ProjectName
  306. data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
  307. datatime := time.Unix(data/1000, 0)
  308. cms.Sampletime = datatime
  309. cms.Senddate = time.Now()
  310. cms_arr = append(cms_arr, cms)
  311. } else {
  312. var cms CmSample
  313. cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
  314. cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
  315. cms.Ptype = "门诊"
  316. cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
  317. if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 1 {
  318. cms.Psex = "男"
  319. } else if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 2 {
  320. cms.Psex = "女"
  321. }
  322. cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
  323. cms.Pageunit = "岁"
  324. cms.Departname = "肾病学专业"
  325. role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
  326. cms.Docname = role.UserName
  327. diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
  328. //var config []*models.HisXtDiagnoseConfig
  329. var name string
  330. for _, item := range diagnosis_ids {
  331. id, _ := strconv.ParseInt(item, 10, 64)
  332. diagnosisConfig, _ := FindDiagnoseById(id)
  333. if len(name) == 0 {
  334. name = diagnosisConfig.ClassName
  335. } else {
  336. name = name + "," + diagnosisConfig.ClassName
  337. }
  338. }
  339. cms.Diagnosis = name
  340. cms.Stype = ""
  341. cms.Samstate = ""
  342. cms.Desccode = strconv.FormatInt(item.ID, 10)
  343. cms.Descr = item.ProjectName
  344. tm := time.Unix(item.Ctime, 0)
  345. //data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
  346. //datatime := time.Unix(data/1000, 0)
  347. cms.Sampletime = tm
  348. cms.Senddate = time.Now()
  349. cms_arr = append(cms_arr, cms)
  350. }
  351. }
  352. //插入到中间库
  353. for _, item := range cms_arr {
  354. if len(item.Pno) > 0 {
  355. blDb.Save(item)
  356. }
  357. }
  358. //插入一条插入中间库记录数据
  359. var info LisSyncProcessStatusInfo
  360. info.Ctime = time.Now().Unix()
  361. info.Status = 1
  362. info.Mtime = time.Now().Unix()
  363. info.OrgId = org_id
  364. info.IsInsert = 1
  365. info.IsResult = 0
  366. info.LastId = list[len(list)-1].ID
  367. info.ResultDate = 0
  368. writeMiddleDb.Save(&info)
  369. } else {
  370. var cms_arr []CmSample
  371. if record.LastId != 0 {
  372. list, _ := GetLisDataById(org_id, record.LastId)
  373. //插入中间库中
  374. for _, item := range list {
  375. if item.ItemId > 0 {
  376. fmt.Println()
  377. //teams, _ := GetProjectTeamList(org_id, item.ItemId, item.PrescriptionId)
  378. //for _, subItem := range teams {
  379. var cms CmSample
  380. cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
  381. //cms.Hospsamplenumber = strconv.FormatInt(item.ID, 10)
  382. cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
  383. cms.Ptype = "门诊"
  384. cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
  385. if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 1 {
  386. cms.Psex = "男"
  387. } else if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 2 {
  388. cms.Psex = "女"
  389. }
  390. cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
  391. cms.Pageunit = "岁"
  392. cms.Departname = "肾病学专业"
  393. role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
  394. cms.Docname = role.UserName
  395. diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
  396. //var config []*models.HisXtDiagnoseConfig
  397. var name string
  398. for _, item := range diagnosis_ids {
  399. id, _ := strconv.ParseInt(item, 10, 64)
  400. diagnosisConfig, _ := FindDiagnoseById(id)
  401. if len(name) == 0 {
  402. name = diagnosisConfig.ClassName
  403. } else {
  404. name = name + "," + diagnosisConfig.ClassName
  405. }
  406. }
  407. cms.Diagnosis = name
  408. cms.Stype = ""
  409. cms.Samstate = ""
  410. cms.Desccode = strconv.FormatInt(item.ID, 10)
  411. cms.Descr = item.ProjectName
  412. //data, _ := strconv.ParseInt(strconv.FormatInt(item.Ctime, 10), 10, 64)
  413. //datatime := time.Unix(data/1000, 0)
  414. //cms.Sampletime = datatime
  415. tm := time.Unix(item.Ctime, 0)
  416. cms.Sampletime = tm
  417. cms.Senddate = time.Now()
  418. cms_arr = append(cms_arr, cms)
  419. } else {
  420. var cms CmSample
  421. cms.HospitalBarcode = strconv.FormatInt(item.ID, 10)
  422. //cms.Hospsamplenumber = strconv.FormatInt(item.ID, 10)
  423. cms.Pno = item.HisPrescriptionProject.HisPrescription.HisOrder.MdtrtId
  424. cms.Ptype = "门诊"
  425. cms.Pname = item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Name
  426. if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 1 {
  427. cms.Psex = "男"
  428. } else if item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Gender == 2 {
  429. cms.Psex = "女"
  430. }
  431. cms.Page = strconv.FormatInt(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Age, 10)
  432. cms.Pageunit = "岁"
  433. cms.Departname = "肾病学专业"
  434. role, _ := GetAdminUserInfoByID(org_id, item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Doctor)
  435. cms.Docname = role.UserName
  436. diagnosis_ids := strings.Split(item.HisPrescriptionProject.HisPrescription.HisOrder.XtHisPatient.Diagnosis, ",")
  437. var name string
  438. for _, item := range diagnosis_ids {
  439. id, _ := strconv.ParseInt(item, 10, 64)
  440. diagnosisConfig, _ := FindDiagnoseById(id)
  441. if len(name) == 0 {
  442. name = diagnosisConfig.ClassName
  443. } else {
  444. name = name + "," + diagnosisConfig.ClassName
  445. }
  446. }
  447. cms.Diagnosis = name
  448. cms.Stype = ""
  449. cms.Samstate = ""
  450. cms.Desccode = strconv.FormatInt(item.ID, 10)
  451. cms.Descr = item.ProjectName
  452. tm := time.Unix(item.Ctime, 0)
  453. cms.Sampletime = tm
  454. cms.Senddate = time.Now()
  455. cms_arr = append(cms_arr, cms)
  456. }
  457. }
  458. //插入一条插入中间库记录数据
  459. for _, item := range cms_arr {
  460. if len(item.Pno) > 0 {
  461. blDb.Save(item)
  462. }
  463. }
  464. //插入一条插入中间库记录数据
  465. var info LisSyncProcessStatusInfo
  466. info.Ctime = time.Now().Unix()
  467. info.Status = 1
  468. info.Mtime = time.Now().Unix()
  469. info.OrgId = org_id
  470. info.IsInsert = 1
  471. info.IsResult = 0
  472. info.LastId = list[len(list)-1].ID
  473. info.ResultDate = 0
  474. writeMiddleDb.Save(&info)
  475. }
  476. }
  477. }
  478. //获取lis返回检验检查结果数据
  479. func GetResultDataInsertDB(org_id int64) (result []*CmResult) {
  480. record, _ := GetLastSyncResultRecord(org_id)
  481. if record.ID == 0 {
  482. list, err := GetResultRecord()
  483. if err == nil {
  484. fmt.Println(list)
  485. //插入到系统检验检查数据
  486. for _, item := range list {
  487. project_id := int64(0)
  488. if len(item.Barcode) > 0 {
  489. project_id, _ = GetBljhProjectID(org_id, item.Groupname)
  490. } else {
  491. continue
  492. }
  493. printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
  494. if printInfo.ID == 0 {
  495. fmt.Println(item)
  496. fmt.Println(printInfo)
  497. fmt.Println("数据查询不到")
  498. continue
  499. }
  500. item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
  501. tx := writeMiddleDb.Begin()
  502. var inspection models.MiddleInspection
  503. var inspection_reference models.MiddleInspectionReference
  504. recordDateStr := ""
  505. inspect_date := item.Repdate.Format("2006-01-02 15:04")
  506. if item.Repdate.Unix() == 0 {
  507. recordDateStr = time.Now().Format("2006-01-02 15:04")
  508. } else {
  509. recordDateStr = inspect_date
  510. }
  511. date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
  512. record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
  513. var total int
  514. var RangeOptions string
  515. var RangeMin string
  516. var RangeMax string
  517. // 判断检查类型
  518. var ItemType int
  519. if strings.Contains(item.Refrange, "-") {
  520. ItemType = 1
  521. } else {
  522. ItemType = 2
  523. }
  524. if ItemType == 1 {
  525. Range := strings.Split(item.Refrange, "-")
  526. RangeMin = Range[0]
  527. RangeMax = Range[1]
  528. } else {
  529. RangeOptions = item.Refrange
  530. }
  531. 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
  532. if inspection_reference.ID > 0 {
  533. ItemType = inspection_reference.RangeType
  534. }
  535. if total <= 0 {
  536. inspection_reference.OrgId = org_id
  537. inspection_reference.ProjectName = item.Groupname
  538. inspection_reference.Project = item.Groupname
  539. inspection_reference.ProjectId = project_id
  540. inspection_reference.ItemName = item.Itemname
  541. inspection_reference.ItemNameAddition = item.Barcode
  542. inspection_reference.ItemId = item_id
  543. inspection_reference.RangeType = ItemType
  544. inspection_reference.RangeMin = RangeMin
  545. inspection_reference.RangeMax = RangeMax
  546. inspection_reference.RangeOptions = RangeOptions
  547. inspection_reference.Unit = item.Unit
  548. inspection_reference.Status = 1
  549. inspection_reference.CreatedTime = time.Now().Unix()
  550. inspection_reference.UpdatedTime = time.Now().Unix()
  551. inspection_reference.InspectDate = inspect_date
  552. inspection_reference.UTime = inspect_date
  553. err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  554. if err != nil {
  555. tx.Rollback()
  556. }
  557. }
  558. var itotal int
  559. 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
  560. if itotal <= 0 {
  561. //item.Result = strings.Replace(item.Result, "&gt;", ">", -1)
  562. //item.Result = strings.Replace(item.Result, "&lt;", "<", -1)
  563. inspection.PatientId = printInfo.PatientId
  564. inspection.OrgId = org_id
  565. inspection.ProjectId = project_id
  566. inspection.ItemName = inspection_reference.ItemName
  567. inspection.ProjectName = inspection_reference.ProjectName
  568. inspection.InspectType = ItemType
  569. inspection.ItemId = item_id
  570. inspection.InspectValue = item.Result
  571. inspection.InspectDate = inspect_date
  572. inspection.RecordDate = record_date.Unix()
  573. inspection.Status = 1
  574. inspection.CreatedTime = time.Now().Unix()
  575. inspection.UpdatedTime = time.Now().Unix()
  576. inspection.UTime = inspect_date
  577. inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
  578. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  579. if err != nil {
  580. tx.Rollback()
  581. }
  582. }
  583. tx.Commit()
  584. }
  585. //插入一条查询检验检查结果记录状态数据
  586. var info LisSyncResultStatusInfo
  587. info.Ctime = time.Now().Unix()
  588. info.Status = 1
  589. info.Mtime = time.Now().Unix()
  590. info.OrgId = org_id
  591. info.IsResult = 1
  592. code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
  593. info.LastId = code
  594. info.ResultDate = time.Now().Unix()
  595. writeMiddleDb.Save(&info)
  596. //
  597. }
  598. } else {
  599. if record.LastId != 0 {
  600. list, err := GetResultRecordByID(record.LastId)
  601. fmt.Println(list)
  602. //插入中间库中
  603. //插入一条插入中间库记录数据
  604. if err == nil {
  605. //插入到系统检验检查数据
  606. for _, item := range list {
  607. project_id := int64(0)
  608. if len(item.Barcode) > 0 {
  609. project_id, _ = GetBljhProjectID(org_id, item.Groupname)
  610. } else {
  611. continue
  612. }
  613. printInfo, _ := GetHisLabelPrintInfoById(item.Barcode)
  614. item_id, _ := GetBlItemID(org_id, item.Groupname, item.Itemname, project_id)
  615. tx := writeMiddleDb.Begin()
  616. var inspection models.MiddleInspection
  617. var inspection_reference models.MiddleInspectionReference
  618. recordDateStr := ""
  619. inspect_date := item.Repdate.Format("2006-01-02 15:04")
  620. if item.Repdate.Unix() == 0 {
  621. recordDateStr = time.Now().Format("2006-01-02 15:04")
  622. } else {
  623. recordDateStr = inspect_date
  624. }
  625. date, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", recordDateStr)
  626. record_date, _ := utils.ParseTimeStringToTime("2006-01-02", date.Format("2006-01-02"))
  627. var total int
  628. var RangeOptions string
  629. var RangeMin string
  630. var RangeMax string
  631. // 判断检查类型
  632. var ItemType int
  633. if strings.Contains(item.Refrange, "-") {
  634. ItemType = 1
  635. } else {
  636. ItemType = 2
  637. }
  638. if ItemType == 1 {
  639. Range := strings.Split(item.Refrange, "-")
  640. RangeMin = Range[0]
  641. RangeMax = Range[1]
  642. } else {
  643. RangeOptions = item.Refrange
  644. }
  645. 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
  646. if inspection_reference.ID > 0 {
  647. ItemType = inspection_reference.RangeType
  648. }
  649. if total <= 0 {
  650. inspection_reference.OrgId = org_id
  651. inspection_reference.ProjectName = item.Groupname
  652. inspection_reference.Project = item.Groupname
  653. inspection_reference.ProjectId = project_id
  654. inspection_reference.ItemName = item.Itemname
  655. inspection_reference.ItemNameAddition = item.Barcode
  656. inspection_reference.ItemId = item_id
  657. inspection_reference.RangeType = ItemType
  658. inspection_reference.RangeMin = RangeMin
  659. inspection_reference.RangeMax = RangeMax
  660. inspection_reference.RangeOptions = RangeOptions
  661. inspection_reference.Unit = item.Unit
  662. inspection_reference.Status = 1
  663. inspection_reference.CreatedTime = time.Now().Unix()
  664. inspection_reference.UpdatedTime = time.Now().Unix()
  665. inspection_reference.InspectDate = inspect_date
  666. inspection_reference.UTime = inspect_date
  667. err = tx.Model(&models.MiddleInspectionReference{}).Create(&inspection_reference).Error
  668. if err != nil {
  669. tx.Rollback()
  670. }
  671. }
  672. var itotal int
  673. 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
  674. if itotal <= 0 {
  675. inspection.PatientId = printInfo.PatientId
  676. inspection.OrgId = org_id
  677. inspection.ProjectId = project_id
  678. inspection.ItemName = inspection_reference.ItemName
  679. inspection.ProjectName = inspection_reference.ProjectName
  680. inspection.InspectType = ItemType
  681. inspection.ItemId = item_id
  682. inspection.InspectValue = item.Result
  683. inspection.InspectDate = inspect_date
  684. inspection.RecordDate = record_date.Unix()
  685. inspection.Status = 1
  686. inspection.CreatedTime = time.Now().Unix()
  687. inspection.UpdatedTime = time.Now().Unix()
  688. inspection.UTime = inspect_date
  689. inspection.HisUserId = strconv.FormatInt(printInfo.PatientId, 10)
  690. err = tx.Model(&models.MiddleInspection{}).Create(&inspection).Error
  691. if err != nil {
  692. tx.Rollback()
  693. }
  694. }
  695. tx.Commit()
  696. }
  697. //插入一条查询检验检查结果记录状态数据
  698. var info LisSyncResultStatusInfo
  699. info.Ctime = time.Now().Unix()
  700. info.Status = 1
  701. info.Mtime = time.Now().Unix()
  702. info.OrgId = org_id
  703. info.IsResult = 1
  704. code, _ := strconv.ParseInt(list[0].Barcode, 10, 64)
  705. info.LastId = code
  706. info.ResultDate = time.Now().Unix()
  707. writeMiddleDb.Save(&info)
  708. }
  709. }
  710. }
  711. // 第一步:跟进org_id 去中间库查出需要同步的数据
  712. inspection_references, _ := GetSyncInspectionReferenceByOrgId(org_id)
  713. inspections, _ := GetSyncInspectionByOrgId(org_id)
  714. // 第二步:将数据同步到业务库
  715. if len(inspection_references) > 0 {
  716. for _, inspection_reference := range inspection_references {
  717. SyncInspectionReference(&inspection_reference)
  718. }
  719. }
  720. if len(inspections) > 0 {
  721. for _, inspection := range inspections {
  722. SyncInspection(&inspection)
  723. }
  724. }
  725. return
  726. }
  727. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role UserAdminRole, err error) {
  728. err = readUserDb.Model(&UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  729. return
  730. }
  731. type UserAdminRole struct {
  732. ID int64 `gorm:"column:id" json:"id" form:"id"`
  733. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  734. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  735. AppId int64 `gorm:"column:app_id" json:"app_id" form:"app_id"`
  736. RoleId int64 `gorm:"column:role_id" json:"role_id" form:"role_id"`
  737. UserName string `gorm:"column:user_name" json:"user_name" form:"user_name"`
  738. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  739. UserType int64 `gorm:"column:user_type" json:"user_type" form:"user_type"`
  740. UserTitle int64 `gorm:"column:user_title" json:"user_title" form:"user_title"`
  741. Intro string `gorm:"column:intro" json:"intro" form:"intro"`
  742. Status int64 `gorm:"column:status" json:"status" form:"status"`
  743. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  744. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  745. UserTitleName string `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
  746. RoleIds string `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
  747. Message string `gorm:"column:message" json:"message" form:"message"`
  748. Sex int64 `gorm:"column:sex" json:"sex" form:"sex"`
  749. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  750. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  751. IsSort int64 `gorm:"column:is_sort" json:"is_sort" form:"is_sort"`
  752. Department string `gorm:"column:department" json:"department" form:"department"`
  753. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  754. Age int64 `gorm:"column:age" json:"age" form:"age"`
  755. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  756. CardType int64 `gorm:"column:card_type" json:"card_type" form:"card_type"`
  757. IdCard string `gorm:"column:id_card" json:"id_card" form:"id_card"`
  758. Education int64 `gorm:"column:education" json:"education" form:"education"`
  759. StudyMajorName string `gorm:"column:study_major_name" json:"study_major_name" form:"study_major_name"`
  760. WorkMajorName string `gorm:"column:work_major_name" json:"work_major_name" form:"work_major_name"`
  761. RoleType int64 `gorm:"column:role_type" json:"role_type" form:"role_type"`
  762. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  763. DoctorCode string `gorm:"column:doctor_code" json:"doctor_code" form:"doctor_code"`
  764. Licensing int64 `gorm:"column:licensing" json:"licensing" form:"licensing"`
  765. JobNumber string `gorm:"column:job_number" json:"job_number" form:"job_number"`
  766. PrescriptionQualificationIdentification int64 `gorm:"column:prescription_qualification_identification" json:"prescription_qualification_identification" form:"prescription_qualification_identification"`
  767. IdentificationOutpatients int64 `gorm:"column:identification_outpatients" json:"identification_outpatients" form:"identification_outpatients"`
  768. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  769. MedicalRangeCode int64 `gorm:"column:medical_range_code" json:"medical_range_code" form:"medical_range_code"`
  770. MedicalLevel int64 `gorm:"column:medical_level" json:"medical_level" form:"medical_level"`
  771. MedicalTypeJob int64 `gorm:"column:medical_type_job" json:"medical_type_job" form:"medical_type_job"`
  772. PharmacistRegistrationNumber string `gorm:"column:pharmacist_registration_number" json:"pharmacist_registration_number" form:"pharmacist_registration_number"`
  773. DoctorRangeCode int64 `gorm:"column:doctor_range_code" json:"doctor_range_code" form:"doctor_range_code"`
  774. DoctorLevel int64 `gorm:"column:doctor_level" json:"doctor_level" form:"doctor_level"`
  775. DoctorTypeJob int64 `gorm:"column:doctor_type_job" json:"doctor_type_job" form:"doctor_type_job"`
  776. DoctorNumber string `gorm:"column:doctor_number" json:"doctor_number" form:"doctor_number"`
  777. OutpatientIllnessCategory string `gorm:"column:outpatient_illness_category" json:"outpatient_illness_category" form:"outpatient_illness_category"`
  778. IsActive int64 `gorm:"column:is_active" json:"is_active" form:"is_active"`
  779. ActiveStatus int64 `gorm:"column:active_status" json:"active_status" form:"active_status"`
  780. }
  781. func (UserAdminRole) TableName() string {
  782. return "sgj_user_admin_role"
  783. }
  784. func FindDiagnoseById(id int64) (*HisXtDiagnoseConfig, error) {
  785. dealer := &HisXtDiagnoseConfig{}
  786. err := readDb.Model(&HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  787. return dealer, err
  788. }
  789. type HisXtDiagnoseConfig struct {
  790. ID int64 `gorm:"column:id" json:"id" form:"id"`
  791. ClassName string `gorm:"column:class_name" json:"class_name" form:"class_name"`
  792. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  793. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  794. ContentCode string `gorm:"column:content_code" json:"content_code" form:"content_code"`
  795. CountryCode string `gorm:"column:country_code" json:"country_code" form:"country_code"`
  796. CountryContentName string `gorm:"column:country_content_name" json:"country_content_name" form:"country_content_name"`
  797. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  798. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  799. Status int64 `gorm:"column:status" json:"status" form:"status"`
  800. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  801. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  802. }
  803. func (HisXtDiagnoseConfig) TableName() string {
  804. return "his_xt_diagnose_config"
  805. }
  806. type VMHisProjectTeam struct {
  807. ID int64 `gorm:"column:id" json:"id" form:"id"`
  808. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  809. Price float64 `gorm:"column:price" json:"price" form:"price"`
  810. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  811. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  812. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  813. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  814. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  815. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  816. Status int64 `gorm:"column:status" json:"status" form:"status"`
  817. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  818. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  819. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  820. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  821. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  822. }
  823. func (VMHisProjectTeam) TableName() string {
  824. return "xt_his_project_team"
  825. }
  826. type VMItemProjectList struct {
  827. ID int64 `gorm:"column:id" json:"id" form:"id"`
  828. Number int64 `gorm:"column:number" json:"number" form:"number"`
  829. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  830. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  831. Status int64 `gorm:"column:status" json:"status" form:"status"`
  832. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  833. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  834. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  835. Type int64 `gorm:"column:type" json:"type" form:"type"`
  836. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  837. }
  838. func (VMItemProjectList) TableName() string {
  839. return "xt_his_project_list"
  840. }
  841. type VMHisProject struct {
  842. ID int64 `gorm:"column:id" json:"id" form:"id"`
  843. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  844. Price float64 `gorm:"column:price" json:"price" form:"price"`
  845. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  846. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  847. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  848. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  849. Status int64 `gorm:"column:status" json:"status" form:"status"`
  850. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  851. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  852. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  853. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  854. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  855. }
  856. func (VMHisProject) TableName() string {
  857. return "xt_his_project"
  858. }
  859. type HisPrescriptionProject struct {
  860. ID int64 `gorm:"column:id" json:"id" form:"id"`
  861. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  862. Price float64 `gorm:"column:price" json:"price" form:"price"`
  863. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  864. Status int64 `gorm:"column:status" json:"status" form:"status"`
  865. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  866. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  867. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  868. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  869. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  870. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  871. Count int64 `gorm:"column:count" json:"count" form:"count"`
  872. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  873. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  874. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  875. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  876. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  877. Day string `gorm:"column:day" json:"day" form:"day"`
  878. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  879. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  880. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  881. Type int64 `gorm:"column:type" json:"type" form:"type"`
  882. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  883. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  884. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  885. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  886. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  887. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  888. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  889. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  890. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  891. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  892. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  893. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  894. HisPrescription HisPrescription `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"his_prescription"`
  895. }
  896. func (HisPrescriptionProject) TableName() string {
  897. return "his_prescription_project"
  898. }
  899. func GetProjectTeamList(orgid int64, id int64, p_id int64) (project []*HisPrescriptionProject, err error) {
  900. err = readDb.Model(&HisPrescriptionProject{}).Where("user_org_id = ? AND status = 1 AND team_id = ? AND prescription_id = ?", orgid, id, p_id).Find(&project).Error
  901. return
  902. }
  903. func GetHisLabelPrintInfoById(id string) (info HisLabelPrintInfo, err error) {
  904. err = readDb.Model(&HisLabelPrintInfo{}).Where("id = ?", id).First(&info).Error
  905. return
  906. }