bl_service.go 49KB

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