patientmanage_service.go 120KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269
  1. package service
  2. import (
  3. "XT_New/models"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/jinzhu/gorm"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. func GetIllnessListTwo() (ills []*models.Illness, err error) {
  12. err = readUserDb.Where("status=1").Find(&ills).Error
  13. return
  14. }
  15. func GetBloodDialysisPatient(orgid int64, page int64, limit int64) (patients []*models.Patients, total int64, err error) {
  16. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  17. if orgid > 0 {
  18. db = db.Where("x.user_org_id = ?", orgid)
  19. }
  20. offset := (page - 1) * limit
  21. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  22. Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
  23. fmt.Println("err是什么", err)
  24. return
  25. }
  26. func GetAllBloodDialysisPatient(orgid int64, page int64, limit int64, lapseto int64, source int64) (patients []*models.XtPatientsNew, total int64, err error) {
  27. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  28. if orgid > 0 {
  29. db = db.Where("x.user_org_id = ? and x.blood_patients = 1", orgid)
  30. }
  31. if lapseto > 0 {
  32. db = db.Where("x.lapseto = ?", lapseto)
  33. }
  34. if source > 0 {
  35. db = db.Where("x.source = ?", source)
  36. }
  37. offset := (page - 1) * limit
  38. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  39. Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
  40. fmt.Println("err是什么", err)
  41. return
  42. }
  43. func GetAllSlowPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
  44. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  45. if orgid > 0 {
  46. db = db.Where("x.user_org_id = ? and x.slow_patients = 1", orgid)
  47. }
  48. offset := (page - 1) * limit
  49. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  50. Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
  51. fmt.Println("err是什么", err)
  52. return
  53. }
  54. func GetAllMemberPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
  55. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  56. if orgid > 0 {
  57. db = db.Where("x.user_org_id = ? and x.member_patients = 1", orgid)
  58. }
  59. offset := (page - 1) * limit
  60. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  61. Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id").Find(&patients).Error
  62. fmt.Println("err是什么", err)
  63. return
  64. }
  65. func GetAllPatient(orgid int64) (patients []*models.PatientsNew, err error) {
  66. db := XTReadDB().Table("xt_patients_new as x")
  67. err = db.Raw("select id,name from xt_patients_new where user_org_id = ? and status =1", orgid).Scan(&patients).Error
  68. return
  69. }
  70. func ChechLastDialysisNoTwo(orgID int64) (dialysisNo int64) {
  71. var patient models.Patients
  72. err := readDb.Model(&models.Patients{}).Where("user_org_id=? and status = 1", orgID).Order("dialysis_no desc").First(&patient).Error
  73. if err != nil {
  74. return
  75. }
  76. if patient.ID == 0 {
  77. return
  78. }
  79. dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
  80. return
  81. }
  82. func GetBloodPatientInfo(orgid int64, phone string) (*models.Patients, error) {
  83. patients := models.Patients{}
  84. var err error
  85. err = XTReadDB().Model(&patients).Where("user_org_id = ? and phone = ? and status = 1", orgid, phone).Find(&patients).Error
  86. if err == gorm.ErrRecordNotFound {
  87. return nil, err
  88. }
  89. if err != nil {
  90. return nil, err
  91. }
  92. return &patients, nil
  93. }
  94. func GetSlowPatientInfo(orgid int64, phone string) (*models.CdmPatients, error) {
  95. patients := models.CdmPatients{}
  96. var err error
  97. err = PatientReadDB().Model(&patients).Where("user_org_id = ? and phone = ? and status = 1", orgid, phone).Find(&patients).Error
  98. if err == gorm.ErrRecordNotFound {
  99. return nil, err
  100. }
  101. if err != nil {
  102. return nil, err
  103. }
  104. return &patients, nil
  105. }
  106. func GetMemberPatientInfo(orgid int64, phone string) (*models.SgjUserCustomer, error) {
  107. customer := models.SgjUserCustomer{}
  108. err := UserReadDB().Model(&customer).Where("user_org_id = ? and mobile = ? and status =1", orgid, phone).Find(&customer).Error
  109. if err == gorm.ErrRecordNotFound {
  110. return nil, err
  111. }
  112. if err != nil {
  113. return nil, err
  114. }
  115. return &customer, nil
  116. }
  117. func CreateOldPatient(patients *models.Patients) error {
  118. err := XTWriteDB().Create(&patients).Error
  119. return err
  120. }
  121. func GetLastOldPatient(orgid int64) (models.Patients, error) {
  122. patients := models.Patients{}
  123. err := XTReadDB().Model(&patients).Where("user_org_id = ? and status =1", orgid).Last(&patients).Error
  124. return patients, err
  125. }
  126. func AddContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64) (err error) {
  127. utx := writeDb.Begin()
  128. if len(contagions) > 0 {
  129. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  130. insertParams := make([]string, 0)
  131. insertData := make([]interface{}, 0)
  132. for _, contagion := range contagions {
  133. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  134. insertData = append(insertData, patienid)
  135. insertData = append(insertData, contagion)
  136. insertData = append(insertData, 1)
  137. insertData = append(insertData, createdtime)
  138. insertData = append(insertData, updatedtime)
  139. }
  140. thisSQL += strings.Join(insertParams, ",")
  141. err = utx.Exec(thisSQL, insertData...).Error
  142. fmt.Println("这个错误err", err)
  143. }
  144. utx.Commit()
  145. return
  146. }
  147. func AddSlowContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64, orgid int64) (err error) {
  148. utx := PatientWriteDB().Begin()
  149. if len(contagions) > 0 {
  150. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time,user_org_id) VALUES "
  151. insertParams := make([]string, 0)
  152. insertData := make([]interface{}, 0)
  153. for _, contagion := range contagions {
  154. insertParams = append(insertParams, "(?, ?, ?, ?, ?,?)")
  155. insertData = append(insertData, patienid)
  156. insertData = append(insertData, contagion)
  157. insertData = append(insertData, 1)
  158. insertData = append(insertData, createdtime)
  159. insertData = append(insertData, updatedtime)
  160. insertData = append(insertData, orgid)
  161. }
  162. thisSQL += strings.Join(insertParams, ", ")
  163. err = utx.Exec(thisSQL, insertData...).Error
  164. if err != nil {
  165. utx.Rollback()
  166. utx.Rollback()
  167. return
  168. }
  169. }
  170. utx.Commit()
  171. return
  172. }
  173. func AddSlowDiseases(patienid int64, createdtime int64, updatedtime int64, diseases []int64, orgid int64) (err error) {
  174. utx := PatientWriteDB().Begin()
  175. if len(diseases) > 0 {
  176. thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time,user_org_id) VALUES "
  177. insertParams := make([]string, 0)
  178. insertData := make([]interface{}, 0)
  179. for _, disease := range diseases {
  180. insertParams = append(insertParams, "(?, ?, ?, ?, ?,?)")
  181. insertData = append(insertData, patienid)
  182. insertData = append(insertData, disease)
  183. insertData = append(insertData, 1)
  184. insertData = append(insertData, createdtime)
  185. insertData = append(insertData, updatedtime)
  186. insertData = append(insertData, orgid)
  187. }
  188. thisSQL += strings.Join(insertParams, ", ")
  189. err = utx.Exec(thisSQL, insertData...).Error
  190. if err != nil {
  191. utx.Rollback()
  192. return
  193. }
  194. }
  195. utx.Commit()
  196. return
  197. }
  198. func CreateNewPatient(patientsNew *models.XtPatientsNew) error {
  199. err := XTWriteDB().Create(&patientsNew).Error
  200. return err
  201. }
  202. func CreateCdmPatient(cdmpatient *models.CdmPatients) error {
  203. err := PatientWriteDB().Create(&cdmpatient).Error
  204. return err
  205. }
  206. func CreateMemberPatient(customer *models.SgjUserCustomer) error {
  207. err := UserWriteDB().Create(&customer).Error
  208. return err
  209. }
  210. func GetOldCdmPatient(orgid int64) (models.CdmPatients, error) {
  211. patients := models.CdmPatients{}
  212. err := PatientReadDB().Model(&patients).Where("user_org_id = ? and status =1", orgid).Last(&patients).Error
  213. return patients, err
  214. }
  215. func GetPatientDetailTwo(id int64) (models.XtPatientsNew, error) {
  216. patients := models.XtPatientsNew{}
  217. err := XTReadDB().Where("id=? and status = 1", id).Find(&patients).Error
  218. return patients, err
  219. }
  220. func GetPatientNewId(id int64) (models.XtPatientsNew, error) {
  221. patientsNew := models.XtPatientsNew{}
  222. err := XTReadDB().Where("blood_id = ? and status = 1", id).Find(&patientsNew).Error
  223. return patientsNew, err
  224. }
  225. func GetPatientDiseasesTwo(id int64) []int64 {
  226. var dis []models.XtPatientsInfectiousDiseases
  227. ids := make([]int64, 0)
  228. err := XTReadDB().Model(&models.XtPatientsInfectiousDiseases{}).Where("patient_id = ? and status = 1", id).Find(&dis).Error
  229. if err != nil || len(dis) == 0 {
  230. return ids
  231. }
  232. for _, item := range dis {
  233. ids = append(ids, item.DiseaseId)
  234. }
  235. return ids
  236. }
  237. func GetSlowPatientDiseases(id int64) (infeciousdisease []*models.CdmPatientsInfectiousDiseases, err error) {
  238. //var dis []models.CdmPatientsInfectiousDiseases
  239. //diseases := models.CdmPatientsChronicDiseases{}
  240. //ids := make([]int64, 0)
  241. //err := PatientReadDB().Model(&diseases).Where("patient_id = ? and status =1", id).Find(&ids).Error
  242. //if err != nil || len(dis) == 0 {
  243. // return ids
  244. //}
  245. //for _, item := range dis {
  246. // ids = append(ids, item.DiseaseId)
  247. //}
  248. //return ids
  249. err = PatientReadDB().Model(&infeciousdisease).Where("patient_id = ? and status =1", id).Find(&infeciousdisease).Error
  250. return infeciousdisease, err
  251. }
  252. func GetCronicDiseases(id int64) (chronic []*models.CdmPatientsChronicDiseases, err error) {
  253. //var dis []models.CdmPatientsChronicDiseases
  254. //ids := make([]int64, 0)
  255. //err := PatientReadDB().Model(&models.CdmPatientsChronicDiseases{}).Where("patient_id = ? and status =1", id).Find(&ids).Error
  256. //if err != nil || len(dis) == 0 {
  257. // return ids
  258. //}
  259. //for _, item := range dis {
  260. // ids = append(ids, item.DiseaseId)
  261. //}
  262. //return ids
  263. err = PatientReadDB().Model(&chronic).Where("patient_id = ? and status =1", id).Find(&chronic).Error
  264. return chronic, err
  265. }
  266. func CreatePatientTwo(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
  267. user, _ := GetSgjUserByMobild(patient.Phone)
  268. customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
  269. utx := writeDb.Begin()
  270. btx := writeUserDb.Begin()
  271. if user.ID == 0 {
  272. user.Mobile = patient.Phone
  273. user.Avatar = patient.Avatar
  274. user.AvatarThumb = patient.Avatar
  275. user.Birthday = patient.Birthday
  276. user.Username = patient.Name
  277. user.Gender = patient.Gender
  278. user.Sources = 11
  279. user.Introduce = patient.Remark
  280. user.Status = 1
  281. user.UpdatedTime = patient.UpdatedTime
  282. user.CreatedTime = patient.CreatedTime
  283. err = btx.Create(&user).Error
  284. if err != nil {
  285. utx.Rollback()
  286. btx.Rollback()
  287. return
  288. }
  289. }
  290. patient.UserId = user.ID
  291. if customer == nil {
  292. err = btx.Create(&models.SgjCustomer{
  293. UserOrgId: patient.UserOrgId,
  294. UserId: user.ID,
  295. Mobile: patient.Phone,
  296. Name: patient.Name,
  297. Gender: patient.Gender,
  298. Birthday: patient.Birthday,
  299. Sources: 11,
  300. Status: 1,
  301. CreatedTime: patient.CreatedTime,
  302. UpdatedTime: patient.UpdatedTime,
  303. Avatar: patient.Avatar,
  304. Remark: patient.Remark,
  305. }).Error
  306. if err != nil {
  307. utx.Rollback()
  308. btx.Rollback()
  309. return
  310. }
  311. }
  312. err = utx.Create(patient).Error
  313. if err != nil {
  314. utx.Rollback()
  315. btx.Rollback()
  316. return
  317. }
  318. var lapseto models.PatientLapseto
  319. lapseto.PatientId = patient.ID
  320. lapseto.LapsetoType = patient.Lapseto
  321. lapseto.CreatedTime = patient.CreatedTime
  322. lapseto.UpdatedTime = patient.CreatedTime
  323. lapseto.Status = 1
  324. lapseto.LapsetoTime = patient.CreatedTime
  325. err = utx.Create(&lapseto).Error
  326. if err != nil {
  327. utx.Rollback()
  328. btx.Rollback()
  329. return
  330. }
  331. if len(contagions) > 0 {
  332. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  333. insertParams := make([]string, 0)
  334. insertData := make([]interface{}, 0)
  335. for _, contagion := range contagions {
  336. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  337. insertData = append(insertData, patient.ID)
  338. insertData = append(insertData, contagion)
  339. insertData = append(insertData, 1)
  340. insertData = append(insertData, patient.CreatedTime)
  341. insertData = append(insertData, patient.UpdatedTime)
  342. }
  343. thisSQL += strings.Join(insertParams, ", ")
  344. err = utx.Exec(thisSQL, insertData...).Error
  345. if err != nil {
  346. utx.Rollback()
  347. btx.Rollback()
  348. return
  349. }
  350. }
  351. if len(diseases) > 0 {
  352. thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  353. insertParams := make([]string, 0)
  354. insertData := make([]interface{}, 0)
  355. for _, disease := range diseases {
  356. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  357. insertData = append(insertData, patient.ID)
  358. insertData = append(insertData, disease)
  359. insertData = append(insertData, 1)
  360. insertData = append(insertData, patient.CreatedTime)
  361. insertData = append(insertData, patient.UpdatedTime)
  362. }
  363. thisSQL += strings.Join(insertParams, ", ")
  364. err = utx.Exec(thisSQL, insertData...).Error
  365. if err != nil {
  366. utx.Rollback()
  367. btx.Rollback()
  368. return
  369. }
  370. }
  371. utx.Commit()
  372. btx.Commit()
  373. return
  374. }
  375. func FindPatientByMobileFive(mobile string, orgID int64) (patient models.XtPatientsNew, err error) {
  376. err = readDb.Model(&models.Patients{}).Where("phone=? and user_org_id=? and status=1", mobile, orgID).First(&patient).Error
  377. return
  378. }
  379. func FindPatientByDialysisNoFive(orgID int64, dialysisNo string) (patient models.Patients, err error) {
  380. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=?", orgID, dialysisNo).First(&patient).Error
  381. return
  382. }
  383. func FindPatientByIdCardNoFive(orgID int64, idCardNo string) (patient models.XtPatientsNew, err error) {
  384. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=?", orgID, idCardNo).First(&patient).Error
  385. return
  386. }
  387. func FindPatientByIdCardNoOne(orgID int64, idCardNo string, id int64) (patient models.XtPatientsNew, err error) {
  388. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=? and id<>?", orgID, idCardNo, id).First(&patient).Error
  389. return
  390. }
  391. func FindPatientByDialysisNoOne(orgID int64, dialysisNo string, id int64) (patient models.Patients, err error) {
  392. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=? and id<>?", orgID, dialysisNo, id).First(&patient).Error
  393. return
  394. }
  395. func FindPatientByMobileOne(mobile string, orgID int64, id int64) (patient models.XtPatientsNew, err error) {
  396. err = readDb.Model(&models.XtPatientsNew{}).Where(" status=1 and user_org_id=? and phone=? and id<>?", orgID, mobile, id).First(&patient).Error
  397. return
  398. //db := readDb.Table("xt_patients_new as x")
  399. //err = db.Not("phone = ?", mobile).Where("user_org_id = ? and id = ? and status =1", orgID, id).Find(&patient).Error
  400. //return
  401. }
  402. func GetPatientData(phone string, orgid int64) (*models.XtPatientsNew, error) {
  403. var patientnew models.XtPatientsNew
  404. var err error
  405. err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status =? and blood_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
  406. if err == gorm.ErrRecordNotFound {
  407. return nil, err
  408. }
  409. if err != nil {
  410. return nil, err
  411. }
  412. return &patientnew, nil
  413. }
  414. func GetSlowPatientData(phone string, orgid int64) (*models.CdmPatients, error) {
  415. var patientnew models.CdmPatients
  416. err = PatientReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ?", orgid, phone, 1).Find(&patientnew).Error
  417. if err == gorm.ErrRecordNotFound {
  418. return nil, err
  419. }
  420. if err != nil {
  421. return nil, err
  422. }
  423. return &patientnew, nil
  424. }
  425. func GetMemberNewPatient(phone string, orgid int64) (*models.XtPatientsNew, error) {
  426. var patientnew models.XtPatientsNew
  427. err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ? and member_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
  428. if err == gorm.ErrRecordNotFound {
  429. return nil, err
  430. }
  431. if err != nil {
  432. return nil, err
  433. }
  434. return &patientnew, nil
  435. }
  436. func GetLastMemberPatient(orgid int64) (models.SgjUserCustomer, error) {
  437. customer := models.SgjUserCustomer{}
  438. err := UserReadDB().Model(&customer).Where("user_org_id = ? and status = 1", orgid).Last(&customer).Error
  439. return customer, err
  440. }
  441. func GetLastNewSlowPatient(phone string, orgid int64) (*models.XtPatientsNew, error) {
  442. var patientnew models.XtPatientsNew
  443. err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ? and slow_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
  444. if err == gorm.ErrRecordNotFound {
  445. return nil, err
  446. }
  447. if err != nil {
  448. return nil, err
  449. }
  450. return &patientnew, nil
  451. }
  452. func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvices, total int64, err error) {
  453. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  454. table := UserReadDB().Table("sgj_user_admin_role as r")
  455. tabletwo := readDb.Table("xt_dialysis_prescription as s").Where("s.status = 1")
  456. fmt.Print("table", table, tabletwo)
  457. if orgID > 0 {
  458. db = db.Where("x.user_org_id=?", orgID)
  459. }
  460. if patientID > 0 {
  461. db = db.Where("x.patient_id = ?", patientID)
  462. }
  463. if advice_type == 1 {
  464. db = db.Where("x.advice_type = ?", advice_type)
  465. }
  466. if advice_type == 3 {
  467. db = db.Where("x.advice_type = 2 or x.advice_type = 3")
  468. }
  469. if advice_type == 4 {
  470. db = db.Where("x.advice_type = ?", advice_type)
  471. }
  472. if start > 0 {
  473. db = db.Where("x.start_time>=?", start)
  474. }
  475. if end > 0 {
  476. db = db.Where("x.start_time<=?", end)
  477. }
  478. //offset := (page - 1) * limit
  479. err = db.Group("x.id").Count(&total).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name,s.dialyzer_perfusion_apparatus,s.anticoagulant,s.anticoagulant_shouji,s.anticoagulant_weichi,s.anticoagulant_zongliang,s.dialysis_dialyszers,s.dialysis_irrigation, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Joins("left join xt_dialysis_prescription as s on s.patient_id = x.patient_id and s.record_date = x.advice_date and s.user_org_id = ?", orgID).Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&doctoradvice).Error
  480. fmt.Print("err", err)
  481. return
  482. }
  483. func GetNewDoctorAdviceOne(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, total int64, err error) {
  484. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  485. table := UserReadDB().Table("sgj_user_admin_role as r")
  486. fmt.Println("table", table)
  487. tabletwo := readDb.Table("xt_dialysis_prescription as s").Where("s.status = 1")
  488. fmt.Print("table", table, tabletwo)
  489. if orgID > 0 {
  490. db = db.Where("x.user_org_id=?", orgID)
  491. }
  492. if patientID > 0 {
  493. db = db.Where("x.patient_id = ?", patientID)
  494. }
  495. if advice_type == 1 {
  496. db = db.Where("x.advice_type = ?", advice_type)
  497. }
  498. if advice_type == 3 {
  499. db = db.Where("x.advice_type = 2 or x.advice_type = 3")
  500. }
  501. if advice_type == 4 {
  502. db = db.Where("x.advice_type = ?", advice_type)
  503. }
  504. if start > 0 {
  505. db = db.Where("x.start_time>=?", start)
  506. }
  507. if end > 0 {
  508. db = db.Where("x.start_time<=?", end)
  509. }
  510. offset := (page - 1) * limit
  511. err = db.Order("x.start_time desc").Group("x.start_time").Count(&total).Offset(offset).Limit(limit).Select("x.id, x.user_org_id, x.patient_id, x.advice_type, x.advice_date, x.record_date, x.start_time, x.advice_name,x.advice_desc, x.reminder_date, x.drug_spec, x.drug_spec_unit, x.single_dose, x.single_dose_unit, x.prescribing_number, x.prescribing_number_unit, x.delivery_way, x.execution_frequency, x.advice_doctor, x.status, x.created_time,x.updated_time, x.advice_affirm, x.remark, x.stop_time, x.stop_reason, x.stop_doctor, x.stop_state, x.parent_id, x.execution_time, x.execution_staff, x.execution_state, x.checker, x.check_state, x.check_time, x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.parent_id,r.user_name,s.dialyzer_perfusion_apparatus,s.anticoagulant,s.anticoagulant_shouji,s.anticoagulant_weichi,s.anticoagulant_zongliang,s.dialysis_dialyszers,s.dialysis_irrigation, IF(x.parent_id > 0, x.parent_id, x.id) as advice_order").Joins("Left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.advice_doctor").Joins("left join xt_dialysis_prescription as s on s.patient_id = x.patient_id and s.record_date = x.advice_date and s.user_org_id = ?", orgID).Scan(&doctoradvice).Error
  512. fmt.Print("错误是什么", err)
  513. return
  514. }
  515. func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
  516. db := XTReadDB().Table("xt_patient_dryweight as x").Where("x.status = 1")
  517. if orgId > 0 {
  518. db = db.Where("x.user_org_id = ?", orgId)
  519. }
  520. if patientid > 0 {
  521. db = db.Where("x.patient_id = ?", patientid)
  522. }
  523. if startime > 0 {
  524. db = db.Where("x.ctime >= ?", startime)
  525. }
  526. if endtime > 0 {
  527. db = db.Where("x.ctime <=?", endtime)
  528. }
  529. offset := (page - 1) * limit
  530. err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
  531. Select("x.id,x.dry_weight,x.creator,x.remakes,x.patient_id,x.ctime,x.adjusted_value,x.user_id,x.user_org_id,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.creator").Scan(&dryWeight).Error
  532. return dryWeight, total, err
  533. }
  534. func ToSearch(orgId int64, name string) (patient []*models.XtPatientsNew, err error) {
  535. likeKey := "%" + name + "%"
  536. err = XTReadDB().Where("name like ? and user_org_id = ?", likeKey, orgId).Find(&patient).Error
  537. return patient, err
  538. }
  539. func GetCourseManagement(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (patientCourse []*models.PatientCourseOfDiseases, total int64, err error) {
  540. db := XTReadDB().Table("xt_patient_course_of_disease as x").Where("x.status = 1")
  541. if patientid > 0 {
  542. db = db.Where("x.patient_id = ?", patientid)
  543. }
  544. if orgid > 0 {
  545. db = db.Where("x.org_id = ?", orgid)
  546. }
  547. if startime > 0 {
  548. db = db.Where("x.record_time >=?", startime)
  549. }
  550. if endtime > 0 {
  551. db = db.Where("x.record_time <= ?", endtime)
  552. }
  553. offset := (page - 1) * limit
  554. err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
  555. Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.title,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Scan(&patientCourse).Error
  556. return patientCourse, total, err
  557. }
  558. func DeleteCouseManagement(patientid int64) error {
  559. err := XTWriteDB().Model(models.PatientCourseOfDisease{}).Where("id = ?", patientid).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  560. return err
  561. }
  562. func GetCouseManagentDetail(id int64) (models.PatientCourseOfDiseasess, error) {
  563. disease := models.PatientCourseOfDiseasess{}
  564. db := XTReadDB().Table("xt_patient_course_of_disease as x")
  565. err := db.Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.title,s.name,r.user_name").Joins("left join xt_patients as s on s.id = x.patient_id ").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Where("x.id = ?", id).Scan(&disease).Error
  566. return disease, err
  567. }
  568. func DeleteDryWeight(id int64) error {
  569. err := XTWriteDB().Model(models.SgjPatientDryweight{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  570. return err
  571. }
  572. func GetDryWeightDetail(id int64) (models.SgjPatientDryweights, error) {
  573. dryweight := models.SgjPatientDryweights{}
  574. db := XTReadDB().Table("xt_patient_dryweight as x")
  575. err := db.Select("x.id,x.dry_weight,x.creator,x.remakes,x.patient_id,x.adjusted_value,x.user_org_id,x.user_id,x.ctime,s.name,r.user_name").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.user_id").Where("x.id = ?", id).Scan(&dryweight).Error
  576. return dryweight, err
  577. }
  578. func GetlongDialysisrecord(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (prescription []*models.XtDialysisSolution, total int64, err error) {
  579. db := XTReadDB().Table("xt_dialysis_solution as x").Where("x.status = 1 and x.solution_status=1")
  580. if patientid > 0 {
  581. db = db.Where("x.patient_id = ?", patientid)
  582. }
  583. if orgid > 0 {
  584. db = db.Where("x.user_org_id = ?", orgid)
  585. }
  586. if startime > 0 {
  587. db = db.Where("x.created_time >=?", startime)
  588. }
  589. if endtime > 0 {
  590. db = db.Where("x.created_time <= ?", endtime)
  591. }
  592. offset := (page - 1) * limit
  593. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).Group("x.id").
  594. Select("x.id,x.name,x.sub_name,x.user_org_id,x.patient_id,x.parent_id,x.type,x.period,x.times,x.anticoagulant,x.anticoagulant_shouji,x.anticoagulant_weichi,x.anticoagulant_zongliang,x.anticoagulant_gaimingcheng,x.anticoagulant_gaijiliang,x.mode_name,x.mode_id,x.dialysis_duration,x.replacement_way,x.hemodialysis_machine,x.blood_filter,x.perfusion_apparatus,x.blood_flow_volume,x.dewater,x.displace_liqui,x.glucose,x.dry_weight,x.dialysate_flow,x.kalium,x.sodium,x.calcium,x.bicarbonate,x.doctor,x.first_dialysis,x.remark,x.initiate_mode,x.affirm_state,x.use_state,x.status,x.registrars_id,x.created_time,x.updated_time,x.solution_type,x.dialysate_temperature,x.conductivity,x.dialysis_duration_hour,x.dialysis_duration_minute,x.target_ultrafiltration,x.dialysate_formulation,x.dialyzer,x.replacement_total,x.dialyzer_perfusion_apparatus,x.body_fluid,x.special_medicine,x.special_medicine_other,x.displace_liqui_part,x.displace_liqui_value,x.blood_access,x.ultrafiltration,x.body_fluid_other,x.target_ktv,x.dialysis_dialyszers,x.dialysis_irrigation").Find(&prescription).Error
  595. return
  596. }
  597. func GetRescuerecord(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (rescuerecord []*models.XtPatientRescueRecords, total int64, err error) {
  598. db := XTReadDB().Table("xt_patient_rescue_record as x").Where("x.status = 1")
  599. if patientid > 0 {
  600. db = db.Where("x.patient_id = ?", patientid)
  601. }
  602. if orgid > 0 {
  603. db = db.Where("x.org_id = ?", orgid)
  604. }
  605. if startime > 0 {
  606. db = db.Where("x.record_time >=?", startime)
  607. }
  608. if endtime > 0 {
  609. db = db.Where("x.record_time <= ?", endtime)
  610. }
  611. offset := (page - 1) * limit
  612. err = db.Count(&total).Order("x.record_time desc").Offset(offset).Limit(limit).Group("x.id").
  613. Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.status,r.user_name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Scan(&rescuerecord).Error
  614. return
  615. }
  616. func GetScheduling(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64, modeType int64) (schedules []*models.XtSchedules, total int64, err error) {
  617. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  618. if patientid > 0 {
  619. db = db.Where("x.patient_id = ?", patientid)
  620. }
  621. if orgid > 0 {
  622. db = db.Where("x.user_org_id = ?", orgid)
  623. }
  624. if startime > 0 {
  625. db = db.Where("x.schedule_date >=?", startime)
  626. }
  627. if endtime > 0 {
  628. db = db.Where("x.schedule_date <= ?", endtime)
  629. }
  630. if modeType > 0 {
  631. db = db.Where("x.mode_id = ?", modeType)
  632. }
  633. offset := (page - 1) * limit
  634. err = db.Count(&total).Order("x.schedule_date desc").Offset(offset).Limit(limit).Group("x.id").
  635. Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.status,x.created_time,x.updated_time,s.number,z.name").Joins("left join xt_device_number as s on s.id = x.bed_id").Joins("left join xt_device_zone as z on z.id = x.partition_id").Scan(&schedules).Error
  636. return
  637. }
  638. func GetEducation(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (treatment []*models.XtTreatmentSummary, total int64, err error) {
  639. db := XTReadDB().Table("xt_treatment_summary as x").Where("x.status = 1")
  640. if patientid > 0 {
  641. db = db.Where("x.patient_id = ?", patientid)
  642. }
  643. if orgid > 0 {
  644. db = db.Where("x.user_org_id = ?", orgid)
  645. }
  646. if startime > 0 {
  647. db = db.Where("x.assessment_date >=?", startime)
  648. }
  649. if endtime > 0 {
  650. db = db.Where("x.assessment_date <= ?", endtime)
  651. }
  652. offset := (page - 1) * limit
  653. err = db.Count(&total).Order("x.assessment_date desc").Offset(offset).Limit(limit).Group("x.id").
  654. Select("x.id,x.user_org_id,x.patient_id,x.assessment_date,x.dialysis_order_id,x.mission,x.dialysis_summary,x.change,x.sj_nurse,x.zl_nurse,x.hd_nurse,x.xj_nurse,x.zl_doctor,x.channel_image,x.puncture,x.puncture_needle,x.puncture_direction,x.status,x.created_time,x.updated_time,x.creater,x.modifier").Scan(&treatment).Error
  655. return
  656. }
  657. func GetSchedulingDetail(id int64) (models.XtScheduless, error) {
  658. schedules := models.XtScheduless{}
  659. db := XTReadDB().Table("xt_schedule as x")
  660. err := db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,n.number,z.name").Joins("left join xt_device_number as n on n.id = x.bed_id").Joins("left join xt_device_zone as z on z.id = x.partition_id").Where("x.id =?", id).Scan(&schedules).Error
  661. return schedules, err
  662. }
  663. func GetSchedulingTwo(id int64) (models.XtScheduless, error) {
  664. schedules := models.XtScheduless{}
  665. db := XTReadDB().Table("xt_schedule as x")
  666. err := db.Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,z.name").Joins("left join xt_patients as z on z.id = x.patient_id").Where("x.id =?", id).Scan(&schedules).Error
  667. return schedules, err
  668. }
  669. func DeleteScheduling(id int64) error {
  670. err := XTWriteDB().Model(models.XtSchedules{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  671. return err
  672. }
  673. func GetEducationDetailOne(id int64) (models.XtTreatmentSummarys, error) {
  674. summarys := models.XtTreatmentSummarys{}
  675. db := XTReadDB().Table("xt_treatment_summary as x")
  676. err := db.Select("x.id,x.user_org_id,x.patient_id,x.assessment_date,x.dialysis_order_id,x.mission,x.dialysis_summary,x.change,x.sj_nurse,x.zl_nurse,x.hd_nurse,x.xj_nurse,x.zl_doctor,x.channel_image,x.puncture,x.puncture_needle,x.puncture_direction,x.status,x.created_time,x.creater,x.modifier,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.id = ?", id).Scan(&summarys).Error
  677. return summarys, err
  678. }
  679. func DeleteEducation(id int64) error {
  680. err := XTWriteDB().Model(models.XtTreatmentSummary{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  681. return err
  682. }
  683. func GetRescueRecordDetail(id int64) (models.XtPatientRescueRecords, error) {
  684. records := models.XtPatientRescueRecords{}
  685. db := XTReadDB().Table("xt_patient_rescue_record as x")
  686. err := db.Select("x.id,x.org_id,x.patient_id,x.recorder,x.record_time,x.content,x.status,r.user_name,s.name").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = x.recorder").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.id=?", id).Scan(&records).Error
  687. return records, err
  688. }
  689. func DeleteRescueRecord(id int64) error {
  690. err := XTWriteDB().Model(models.XtPatientRescueRecord{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  691. return err
  692. }
  693. func ToSearchePatient(keyword string, orgId int64) (paitents []*models.XtPatientsNew, err error) {
  694. likeKey := "%" + keyword + "%"
  695. err = XTReadDB().Where("user_org_id = ? and name like ? or dialysis_no like ?", orgId, likeKey, likeKey).Find(&paitents).Error
  696. return paitents, err
  697. }
  698. func SearchallPatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
  699. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  700. if len(keyword) > 0 {
  701. likeKey := "%" + keyword + "%"
  702. db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ? OR x.first_letter=?", likeKey, likeKey, likeKey)
  703. }
  704. if orgid > 0 {
  705. db = db.Where("x.user_org_id = ?", orgid)
  706. }
  707. err = db.Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.infectious_next_record_time,x.is_infectious,x.remind_cycle,x.response_result,x.is_open_remind,x.first_treatment_date,x.dialysis_age,x.expense_kind,x.tell_phone,x.contact_name,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id,x.member_fistdate,x.member_patienttype,x.member_treatement,x.equitment_id").Find(&patients).Error
  708. return patients, err
  709. }
  710. func GetSearchallBlood(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
  711. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.blood_patients = 1")
  712. if len(keyword) > 0 {
  713. likeKey := "%" + keyword + "%"
  714. db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
  715. }
  716. if orgid > 0 {
  717. db = db.Where("x.user_org_id = ?", orgid)
  718. }
  719. err = db.Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.infectious_next_record_time,x.is_infectious,x.remind_cycle,x.response_result,x.is_open_remind,x.first_treatment_date,x.dialysis_age,x.expense_kind,x.tell_phone,x.contact_name,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id,x.member_fistdate,x.member_patienttype,x.member_treatement,x.equitment_id").Find(&patients).Error
  720. return patients, err
  721. }
  722. func GetSlowSearchePatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
  723. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.slow_patients = 1")
  724. if len(keyword) > 0 {
  725. likeKey := "%" + keyword + "%"
  726. db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
  727. }
  728. if orgid > 0 {
  729. db = db.Where("x.user_org_id = ?", orgid)
  730. }
  731. err = db.Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.infectious_next_record_time,x.is_infectious,x.remind_cycle,x.response_result,x.is_open_remind,x.first_treatment_date,x.dialysis_age,x.expense_kind,x.tell_phone,x.contact_name,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id,x.member_fistdate,x.member_patienttype,x.member_treatement,x.equitment_id").Find(&patients).Error
  732. return patients, err
  733. }
  734. func GetMemberSearchPatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
  735. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.member_patients = 1")
  736. if len(keyword) > 0 {
  737. likeKey := "%" + keyword + "%"
  738. db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
  739. }
  740. if orgid > 0 {
  741. db = db.Where("x.user_org_id = ?", orgid)
  742. }
  743. err = db.Select("x.id,x.user_org_id,x.user_id,x.avatar,x.patient_type,x.dialysis_no,x.admission_number,x.source,x.lapseto,x.partition_id,x.bed_id,x.name,x.alias,x.gender,x.marital_status,x.id_card_no,x.birthday,x.reimbursement_way_id,x.health_care_type,x.health_care_no,x.health_care_due_date,x.height,x.blood_type,x.rh,x.health_care_due_alert_date,x.education_level,x.profession,x.phone,x.home_telephone,x.relative_phone,x.relative_relations,x.home_address,x.work_unit,x.unit_address,x.children,x.receiving_date,x.is_hospital_first_dialysis,x.first_dialysis_date,x.first_dialysis_hospital,x.predialysis_condition,x.pre_hospital_dialysis_frequency,x.pre_hospital_dialysis_times,x.hospital_first_dialysis_date,x.induction_period,x.initial_dialysis,x.total_dialysis,x.attending_doctor_id,x.head_nurse_id,x.evaluate,x.diagnose,x.remark,x.registrars_id,x.registrars,x.qr_code,x.binding_state,x.patient_complains,x.present_history,x.past_history,x.temperature,x.pulse,x.respiratory,x.sbp,x.dbp,x.status,x.created_time,x.updated_time,x.nation,x.native_place,x.age,x.infectious_next_record_time,x.is_infectious,x.remind_cycle,x.response_result,x.is_open_remind,x.first_treatment_date,x.dialysis_age,x.expense_kind,x.tell_phone,x.contact_name,x.blood_patients,x.slow_patients,x.member_patients,x.ecommer_patients,x.blood_id,x.slow_id,x.member_id,x.member_fistdate,x.member_patienttype,x.member_treatement,x.equitment_id").Find(&patients).Error
  744. return patients, err
  745. }
  746. func GetLongDialysisDetail(id int64) (models.XtDialysisSolution, error) {
  747. solution := models.XtDialysisSolution{}
  748. err := XTReadDB().Model(&solution).Where("id=? and status =1", id).Find(&solution).Error
  749. return solution, err
  750. }
  751. func GetPatientName(id int64) (models.Patients, error) {
  752. patientsNew := models.Patients{}
  753. err := XTReadDB().Model(&patientsNew).Where("id = ? and status = 1", id).Find(&patientsNew).Error
  754. return patientsNew, err
  755. }
  756. func DeleteLongDialysis(id int64) error {
  757. err := XTWriteDB().Model(models.XtDialysisSolution{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  758. return err
  759. }
  760. func GetDialysisrecord(patientID int64, start int64, end int64, limit int64, page int64, orgID int64, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
  761. offset := (page - 1) * limit
  762. var total int64
  763. var err error
  764. var orders []*models.PatientDialysisRecord
  765. db := readDb.Table("xt_dialysis_order as do").
  766. Preload("MonitoringRecord", "patient_id = ? and user_org_id = ? and status = 1", patientID, orgID).
  767. Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  768. Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  769. Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
  770. return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
  771. return readUserDb.Where("status = 1")
  772. })
  773. }).
  774. Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  775. Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  776. Preload("Device", "org_id=? and status=1", orgID).
  777. Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
  778. return readUserDb.Where("org_id=? and status = 1", orgID)
  779. }).
  780. Joins("JOIN xt_schedule as s ON s.patient_id=? and FROM_UNIXTIME(s.schedule_date, '%Y-%m-%d')=FROM_UNIXTIME(do.dialysis_date, '%Y-%m-%d')", patientID).
  781. Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id and s.status = 1", orgID).
  782. Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Group("s.schedule_date")
  783. if start > 0 {
  784. db = db.Where("do.dialysis_date>=?", start)
  785. }
  786. if end > 0 {
  787. db = db.Where("do.dialysis_date<=?", end)
  788. }
  789. if mode_id > 0 {
  790. db = db.Joins("JOIN xt_dialysis_prescription as dp ON dp.record_id=do.id")
  791. db = db.Where("dp.mode_id=?", mode_id)
  792. }
  793. err = db.Count(&total).Offset(offset).Limit(limit).Order("do.dialysis_date desc").Select("do.bed_id, do.id, do.dialysis_date, do.user_org_id, do.patient_id, do.prescription_id, do.stage, do.remark, do.status, do.created_time, do.updated_time,do.start_nurse,do.finish_nurse ,s.schedule_type, s.partition_id, dz.name as partition_name").Find(&orders).Error
  794. if len(orders) > 0 {
  795. ids := make([]int64, 0)
  796. for _, order := range orders {
  797. dialyzer := order.DialysisPrescription.Dialyzer
  798. ids = append(ids, dialyzer)
  799. }
  800. if len(ids) > 0 {
  801. var dialyzers []*models.DeviceNumber
  802. err = readDb.Model(&models.DeviceNumber{}).Where("id IN (?) and org_id=? and status=1", ids, orgID).Find(&dialyzers).Error
  803. if err != nil {
  804. return nil, 0, err
  805. }
  806. dialyzerMap := make(map[int64]models.DeviceNumber, 0)
  807. for _, item := range dialyzers {
  808. dialyzerMap[item.ID] = *item
  809. }
  810. for orderIndex, order := range orders {
  811. if _, exist := dialyzerMap[order.DialysisPrescription.Dialyzer]; exist {
  812. orders[orderIndex].DeviceNumber = dialyzerMap[order.DialysisPrescription.Dialyzer].Number
  813. }
  814. }
  815. }
  816. }
  817. return orders, total, err
  818. }
  819. func GetAllDoctorTwo(orgid int64, appid int64) (appRole []*models.SgjUserAdminRole, err error) {
  820. err = UserReadDB().Where("org_id = ? and app_id = ?", orgid, appid).Find(&appRole).Error
  821. return appRole, err
  822. }
  823. func GetDoctorAdviceDetail(state int64, id int64, orgid int64) (advices []*models.DoctorAdvices, err error) {
  824. db := XTReadDB().Table("xt_doctor_advice as x")
  825. err = db.Order("x.id desc").Select("x.id,x.user_org_id,x.patient_id,x.advice_type,x.advice_date,x.start_time,x.advice_name,x.advice_desc,x.reminder_date,x.single_dose,x.single_dose_unit,x.prescribing_number,x.prescribing_number_unit,x.delivery_way,x.execution_frequency,x.advice_doctor,x.status,x.created_time,x.updated_time,x.advice_affirm,x.remark,x.stop_time,x.stop_reason,x.stop_doctor,x.stop_state,x.parent_id,x.execution_time,x.execution_staff,x.execution_state,x.checker,x.record_date,x.dialysis_order_id,x.check_time,x.check_state,x.drug_spec,x.drug_spec_unit,x.groupno,x.remind_type,x.frequency_type,x.day_count,x.week_day,x.template_id,x.modifier,s.name").Joins("left join xt_patients as s on s.id=x.patient_id").Where("x.start_time = ? and x.patient_id = ? and x.user_org_id = ? and x.status = 1", state, id, orgid).Scan(&advices).Error
  826. return advices, err
  827. }
  828. func DeleteManagement(groupid int64, orgid int64, patientid int64) error {
  829. err := XTWriteDB().Model(models.DoctorAdvice{}).Where("start_time =? and user_org_id = ? and patient_id =?", groupid, orgid, patientid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  830. return err
  831. }
  832. func DeleteChild(id int64) error {
  833. err := XTWriteDB().Model(models.DoctorAdvice{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  834. return err
  835. }
  836. func DeletePatient(id int64) error {
  837. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id=? or parent_id = ?", id, id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  838. return err
  839. }
  840. func GetNewPatient(id int64) (models.XtPatientsNew, error) {
  841. patientsNew := models.XtPatientsNew{}
  842. err := XTReadDB().Model(&patientsNew).Where("id=?", id).Find(&patientsNew).Error
  843. return patientsNew, err
  844. }
  845. func UpdatedPatient(patients models.Patients, id int64) error {
  846. err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "admission_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "out_reason": patients.OutReason, "death_time": patients.DeathTime, "relative_phone": patients.RelativePhone, "remark": patients.Remark, "sch_remark": patients.SchRemark, "treatment_plan": patients.TreatmentPlan}).Error
  847. return err
  848. }
  849. func UpdateXtPatientNew(patients models.XtPatientsNew, id int64) error {
  850. err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "admission_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "out_reason": patients.OutReason, "death_time": patients.DeathTime, "relative_phone": patients.RelativePhone, "remark": patients.Remark, "sch_remark": patients.SchRemark, "treatment_plan": patients.TreatmentPlan}).Error
  851. return err
  852. }
  853. func UpdateXtPatientNewOne(patients models.XtPatientsNew, id int64) error {
  854. err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "adminssion_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "member_patienttype": patients.MemberPatienttype, "member_treatement": patients.MemberTreatement, "treatment_plan": patients.TreatmentPlan}).Error
  855. return err
  856. }
  857. func UpdateContagions(patientid int64) (models.XtPatientsInfectiousDiseases, error) {
  858. diseases := models.XtPatientsInfectiousDiseases{}
  859. err := XTWriteDB().Model(&diseases).Where("patient_id = ?", patientid).Update(map[string]interface{}{"status": 2, "updated_time": time.Now().Unix()}).Error
  860. return diseases, err
  861. }
  862. func UpdateCustomer(cdmpatient models.CdmPatients, id int64) error {
  863. err := PatientWriteDB().Model(&cdmpatient).Where("id=?", id).Update(map[string]interface{}{"name": cdmpatient.Name, "phone": cdmpatient.Phone, "gender": cdmpatient.Gender, "birthday": cdmpatient.Birthday, "diagnose": cdmpatient.Diagnose, "source": cdmpatient.Source, "avatar": cdmpatient.Avatar, "id_card_no": cdmpatient.IdCardNo, "updated_time": cdmpatient.UpdatedTime}).Error
  864. return err
  865. }
  866. func UpdatedCustomer(customer models.SgjUserCustomer, id int64) error {
  867. err := UserWriteDB().Model(&customer).Where("id = ?", id).Update(map[string]interface{}{"name": customer.Name, "mobile": customer.Mobile, "gender": customer.Gender, "birthday": customer.Birthday, "ill_date": customer.IllDate, "avatar": customer.Avatar, "illness_id": customer.IllnessId, "treat_type": customer.TreatType}).Error
  868. return err
  869. }
  870. func GetInspectionByOrgId(orgid int64) (*models.XtInspectionReference, error) {
  871. diseases := models.XtInspectionReference{}
  872. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  873. if err == gorm.ErrRecordNotFound {
  874. return nil, err
  875. }
  876. if err != nil {
  877. return nil, err
  878. }
  879. return &diseases, nil
  880. }
  881. func GetAllProjectName(date int64, orgid int64, patientid int64) (inspection []*models.XtInspection, err error) {
  882. err = XTReadDB().Model(&inspection).Where("inspect_date = ? and org_id = ? and patient_id = ? and status = 1", date, orgid, patientid).Order("inspect_date desc").Group("project_name").Find(&inspection).Error
  883. return inspection, err
  884. }
  885. func GetAllInspection(orgid int64) (inspection []*models.XtInspectionReference, err error) {
  886. err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&inspection).Error
  887. return inspection, err
  888. }
  889. func GetInspection(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64, projectid int64) (inspection []*models.Inspection, total int64, err error) {
  890. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  891. if patientid > 0 {
  892. db = db.Where("x.patient_id = ?", patientid)
  893. }
  894. if startime > 0 {
  895. db = db.Where("x.inspect_date >= ?", startime)
  896. }
  897. if endtime > 0 {
  898. db = db.Where("x.inspect_date<=?", endtime)
  899. }
  900. if orgid > 0 {
  901. db = db.Where("x.org_id = ?", orgid)
  902. }
  903. if projectid > 0 {
  904. db = db.Where("x.project_id = ?", projectid)
  905. }
  906. err = db.Count(&total).Order("x.inspect_date desc").Group("x.id").
  907. Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.created_time").Find(&inspection).Error
  908. return inspection, total, err
  909. }
  910. func GetInspectionDetail(patientid int64, date int64, orgid int64, projectid int64) (inspection []*models.Inspections, err error) {
  911. db := XTReadDB().Table("xt_inspection as x").Where("x.status =1")
  912. table := XTReadDB().Table("xt_inspection_reference as r")
  913. fmt.Print("table", table)
  914. if patientid > 0 {
  915. db = db.Where("x.patient_id = ?", patientid)
  916. }
  917. if date > 0 {
  918. db = db.Where("x.inspect_date = ?", date)
  919. }
  920. if orgid > 0 {
  921. db = db.Where("x.org_id = ?", orgid)
  922. }
  923. if projectid > 0 {
  924. db = db.Where("x.project_id = ?", projectid)
  925. }
  926. err = db.Group("x.id").Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,x.status,x.created_time,x.updated_time,r.range_type,r.range_min,r.range_max,r.range_value,r.range_options,r.unit").Joins("left join xt_inspection_reference as r on (r.item_id = x.item_id AND r.org_id = x.org_id) OR ( x.item_id = r.id AND r.org_id = 0) ").Scan(&inspection).Error
  927. return inspection, err
  928. }
  929. func CreateFeedBack(feedback *models.XtPatientFeedback) error {
  930. err := XTWriteDB().Model(&feedback).Create(&feedback).Error
  931. return err
  932. }
  933. func DeleteInspection(date int64, orgid int64) error {
  934. err := XTWriteDB().Model(models.Inspection{}).Where("inspect_date = ? and org_id = ?", date, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  935. return err
  936. }
  937. func DeleteChildInspection(name string, date int64, orgid int64) error {
  938. err := XTWriteDB().Model(models.Inspection{}).Where("project_name = ? and inspect_date = ? and org_id = ?", name, date, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  939. return err
  940. }
  941. func SaveMessage(id int64, orgid int64, role *models.SgjUserAdminRole) error {
  942. err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("admin_user_id = ? and org_id = ?", id, orgid).Update(map[string]interface{}{"message": role.Message, "mtime": time.Now().Unix()}).Error
  943. return err
  944. }
  945. func SaveSex(id int64, role *models.SgjUserAdminRole) error {
  946. err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("admin_user_id = ?", id).Update(map[string]interface{}{"sex": role.Sex, "mtime": time.Now().Unix()}).Error
  947. return err
  948. }
  949. func SaveBirthday(id int64, role *models.SgjUserAdminRole) error {
  950. err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("admin_user_id = ?", id).Update(map[string]interface{}{"birthday": role.Birthday, "mtime": time.Now().Unix()}).Error
  951. return err
  952. }
  953. func GetPartitionByName(name string, orgid int64) (*models.DeviceZone, error) {
  954. zone := models.DeviceZone{}
  955. err := XTReadDB().Model(&zone).Where("name = ? and org_id = ? and status = 1", name, orgid).Find(&zone).Error
  956. if err == gorm.ErrRecordNotFound {
  957. return nil, err
  958. }
  959. if err != nil {
  960. return nil, err
  961. }
  962. return &zone, nil
  963. }
  964. func GetPartitionByNameOne(name string, orgid int64) (zone models.DeviceZone, err error) {
  965. err = XTReadDB().Model(&zone).Where("name = ? and org_id = ? and status = 1", name, orgid).First(&zone).Error
  966. return zone, err
  967. }
  968. func CreatedZone(zone *models.DeviceZone) error {
  969. err := XTWriteDB().Model(&zone).Create(&zone).Error
  970. return err
  971. }
  972. func GetAllZone(orgid int64, page int64, limit int64) (zone []*models.DeviceZones, total int64, err error) {
  973. db := XTReadDB().Table("xt_device_zone as x").Where("x.status =1")
  974. table := XTReadDB().Table("xt_device_number as n")
  975. fmt.Println("table", table)
  976. if orgid > 0 {
  977. db = db.Where("x.org_id = ?", orgid)
  978. }
  979. offset := (page - 1) * limit
  980. err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.type,n.number").Joins("left join xt_device_number as n on n.zone_id = x.id AND n.status = 1").Scan(&zone).Error
  981. return zone, total, err
  982. }
  983. func DeleteZoneById(id int64) error {
  984. err := XTWriteDB().Model(models.DeviceZone{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  985. return err
  986. }
  987. func GetGroupByName(name string, orgid int64) (*models.DeviceGroup, error) {
  988. group := models.DeviceGroup{}
  989. err := XTReadDB().Model(&group).Where("name = ? and org_id = ? and status = 1", name, orgid).Find(&group).Error
  990. if err == gorm.ErrRecordNotFound {
  991. return nil, err
  992. }
  993. if err != nil {
  994. return nil, err
  995. }
  996. return &group, nil
  997. }
  998. func GetGroupByNameOne(name string, orgid int64) (group models.DeviceGroup, err error) {
  999. err = XTReadDB().Model(&group).Where("name = ? and org_id = ? and status =1", name, orgid).First(&group).Error
  1000. return group, err
  1001. }
  1002. func SaveGroup(group *models.DeviceGroup) error {
  1003. err := XTWriteDB().Model(&group).Create(&group).Error
  1004. return err
  1005. }
  1006. func GetAllGroup(orgid int64, page int64, limit int64) (group []*models.DeviceGroups, total int64, err error) {
  1007. db := XTReadDB().Table("xt_device_group as x").Where("x.status = 1")
  1008. table := XTReadDB().Table("xt_device_number as n")
  1009. fmt.Println("table", table)
  1010. if orgid > 0 {
  1011. db = db.Where("x.org_id = ?", orgid)
  1012. }
  1013. offset := (page - 1) * limit
  1014. err = db.Group("x.id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Select("x.id,x.org_id,x.name,x.status,x.ctime,x.mtime,n.number").Joins("left join xt_device_number as n on n.group_id = x.id And n.status = 1").Scan(&group).Error
  1015. return group, total, err
  1016. }
  1017. func DeleteGroup(id int64) error {
  1018. err := XTWriteDB().Model(models.DeviceGroup{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  1019. return err
  1020. }
  1021. func GetAllZoneOne(orgid int64) (zone []*models.DeviceZone, err error) {
  1022. err = XTReadDB().Model(&zone).Where("org_id = ? and status =1", orgid).Find(&zone).Error
  1023. return zone, err
  1024. }
  1025. func GetAllBedNumberList(orgid int64) (number []*models.DeviceNumber, err error) {
  1026. err = XTReadDB().Where("org_id =? and status =1", orgid).Find(&number).Error
  1027. return number, err
  1028. }
  1029. func GetAllGroupOne(orgid int64) (group []*models.DeviceGroup, err error) {
  1030. err = XTReadDB().Model(&group).Where("org_id =?", orgid).Find(&group).Error
  1031. return group, err
  1032. }
  1033. func GetBedByName(name string, orgid int64) (*models.DeviceNumber, error) {
  1034. number := models.DeviceNumber{}
  1035. err := XTReadDB().Model(&number).Where("number=? and org_id = ? and status =1", name, orgid).Find(&number).Error
  1036. if err == gorm.ErrRecordNotFound {
  1037. return nil, err
  1038. }
  1039. if err != nil {
  1040. return nil, err
  1041. }
  1042. return &number, nil
  1043. }
  1044. func GetBedByNameOne(name string, orgid int64) (number models.DeviceNumber, err error) {
  1045. err = XTReadDB().Model(&number).Where("number=? and org_id = ? and status = 1", name, orgid).First(&number).Error
  1046. return number, err
  1047. }
  1048. func CreateNumber(number *models.DeviceNumber) error {
  1049. err := XTWriteDB().Model(&number).Create(&number).Error
  1050. return err
  1051. }
  1052. func GetAllNumber(page int64, limit int64, orgid int64) (number []*models.DeviceNumber, total int64, err error) {
  1053. db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
  1054. if orgid > 0 {
  1055. db = db.Where("x.org_id = ?", orgid)
  1056. }
  1057. offset := (page - 1) * limit
  1058. err = db.Count(&total).Offset(offset).Limit(limit).Order("x.ctime asc").Select("x.id,x.org_id,x.number,x.group_id,x.zone_id,x.status").Find(&number).Error
  1059. return number, total, err
  1060. }
  1061. func GetSchedu(bedid int64, thetime int64, orgid int64) (*models.XtSchedule, error) {
  1062. schedule := models.XtSchedule{}
  1063. err := XTReadDB().Model(&schedule).Where("bed_id = ? and schedule_date = ? and user_org_id = ? and status = 1", bedid, thetime, orgid).Find(&schedule).Error
  1064. if err == gorm.ErrRecordNotFound {
  1065. return nil, err
  1066. }
  1067. if err != nil {
  1068. return nil, err
  1069. }
  1070. return &schedule, nil
  1071. }
  1072. func DeleteBed(id int64) error {
  1073. err := XTWriteDB().Model(models.DeviceNumber{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "ctime": time.Now().Unix()}).Error
  1074. return err
  1075. }
  1076. func GetMemberPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
  1077. err = XTReadDB().Model(&patients).Where("user_org_id = ? AND member_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
  1078. return patients, err
  1079. }
  1080. func GetSlowPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
  1081. err = XTReadDB().Model(&patients).Where("user_org_id = ? AND slow_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
  1082. return patients, err
  1083. }
  1084. func GetBloodPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
  1085. err = XTReadDB().Model(&patients).Where("user_org_id = ? AND blood_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
  1086. return patients, err
  1087. }
  1088. func SaveName(id int64, admin *models.SgjUserAdmin) error {
  1089. err = UserWriteDB().Model(models.SgjUserAdmin{}).Where("id=?", id).Update(map[string]interface{}{"name": admin.Name, "mtime": time.Now().Unix()}).Error
  1090. return err
  1091. }
  1092. func GetAdminUserId(id int64) (models.SgjUserAdminRole, error) {
  1093. role := models.SgjUserAdminRole{}
  1094. err := UserReadDB().Where("id=? and status =1", id).Find(&role).Error
  1095. return role, err
  1096. }
  1097. func GetMyOrganaziton(id int64) (org []*models.SgjUserOrg, err error) {
  1098. db := UserReadDB().Table("sgj_user_org as x").Where("x.status = 1")
  1099. table := UserReadDB().Table("sgj_user_admin as a")
  1100. fmt.Println("table", table)
  1101. err = db.Select("x.id,x.creator,x.org_name,x.org_short_name,x.org_logo,x.org_introduction,x.illness,x.province,x.city,x.district,x.address,x.longitude,x.latitude,x.org_type,x.comments,x.evaluate,x.gallery,x.business_week,x.business_time,x.contact_name,x.telephone,x.claim,x.operating_state,x.source,x.ttype,x.ttid,x.tuid,x.reason,x.level,x.website,x.import,x.sortno,a.is_super_admin").Joins("left join sgj_user_admin as a on a.id = x.creator").Where("x.creator = ?", id).Scan(&org).Error
  1102. return org, err
  1103. }
  1104. func GetOrgInformation(id int64) (models.SgjUserOrg, error) {
  1105. org := models.SgjUserOrg{}
  1106. err := UserReadDB().Where("id=? and status = 1", id).Find(&org).Error
  1107. return org, err
  1108. }
  1109. func GetShortName(orgtype int64) (models.SgjUserOrgType, error) {
  1110. orgType := models.SgjUserOrgType{}
  1111. err := UserReadDB().Model(&orgType).Where("id=? and status = 1", orgtype).Find(&orgType).Error
  1112. return orgType, err
  1113. }
  1114. func GetTypeName(id int64) (models.SgjUserOrgType, error) {
  1115. orgType := models.SgjUserOrgType{}
  1116. err := UserReadDB().Model(&orgType).Where("id=? and status = 1", id).Find(&orgType).Error
  1117. return orgType, err
  1118. }
  1119. func GetOrgProvince(id int64) (models.SgjUserDistrict, error) {
  1120. district := models.SgjUserDistrict{}
  1121. err := UserReadDB().Model(&district).Where("id=?", id).Find(&district).Error
  1122. return district, err
  1123. }
  1124. func GetAllOrgType() (orgType []*models.SgjUserOrgType, err error) {
  1125. err = UserReadDB().Model(&models.SgjUserOrgType{}).Where("status= ? AND id = ? OR id = ? OR id = ? OR id = ? OR id = ? OR id = ?", 1, 1, 7, 12, 16, 21, 26).Find(&orgType).Error
  1126. return
  1127. }
  1128. func UpdateOrg(id int64, org models.SgjUserOrg) error {
  1129. err := UserWriteDB().Model(&org).Where("id = ?", id).Update(map[string]interface{}{"org_name": org.OrgName, "org_short_name": org.OrgShortName, "province": org.Province, "city": org.City, "district": org.District, "address": org.Address, "org_type": org.OrgType, "telephone": org.Telephone, "contact_name": org.ContactName, "mtime": time.Now().Unix()}).Error
  1130. return err
  1131. }
  1132. func GetMyInfoName(id int64) (models.SgjUserAdminRole, error) {
  1133. role := models.SgjUserAdminRole{}
  1134. err := UserReadDB().Model(&role).Where("id=? and status = 1", id).Find(&role).Error
  1135. return role, err
  1136. }
  1137. func GetAdminName(id int64, orgid int64) (models.AdminUsers, error) {
  1138. user := models.AdminUsers{}
  1139. //err := UserReadDB().Model(&user).Where("id=? and status =1", id).Find(&user).Error
  1140. //return user, err
  1141. db := UserReadDB().Table("sgj_user_admin as x").Where("x.status = 1")
  1142. table := UserReadDB().Table("sgj_user_admin_role as r")
  1143. fmt.Println("table", table)
  1144. err := db.Group("x.id").Select("x.id,x.mobile,x.password,x.is_super_admin,x.source,x.name,r.admin_user_id,r.org_id,r.app_id,r.role_id,r.user_name,r.avatar,r.message,r.sex,r.birthday").Where("x.id = ?", id).Joins("left join sgj_user_admin_role as r on r.admin_user_id = x.id and r.org_id = ?", orgid).Scan(&user).Error
  1145. return user, err
  1146. }
  1147. func GetCreatByOrgId(orgid int64) (models.SgjUserOrg, error) {
  1148. org := models.SgjUserOrg{}
  1149. err := UserReadDB().Model(&org).Where("id=? and status = 1", orgid).Find(&org).Error
  1150. return org, err
  1151. }
  1152. func GetMyOrgInformationFour(creator int64, orgid int64) (models.SgjUserAdminRole, error) {
  1153. role := models.SgjUserAdminRole{}
  1154. err := UserReadDB().Model(&role).Where("admin_user_id = ? and org_id = ? and status = 1", creator, orgid).Find(&role).Error
  1155. return role, err
  1156. }
  1157. func GetPartionDetail(id int64) (models.DeviceZone, error) {
  1158. zone := models.DeviceZone{}
  1159. err := XTReadDB().Model(&zone).Where("id=? and status = 1", id).Find(&zone).Error
  1160. return zone, err
  1161. }
  1162. func UpdatePartition(id int64, zone *models.DeviceZone) error {
  1163. err := XTWriteDB().Model(&zone).Where("id=?", id).Update(map[string]interface{}{"name": zone.Name, "type": zone.Type, "mtime": time.Now().Unix()}).Error
  1164. return err
  1165. }
  1166. func GetGroupDetail(id int64) (models.DeviceGroup, error) {
  1167. group := models.DeviceGroup{}
  1168. err := XTReadDB().Model(&group).Where("id=? and status = 1", id).Find(&group).Error
  1169. return group, err
  1170. }
  1171. func UpdateGroup(id int64, group *models.DeviceGroup) error {
  1172. err := XTWriteDB().Model(&group).Where("id=?", id).Update(map[string]interface{}{"name": group.Name, "mtime": time.Now().Unix()}).Error
  1173. return err
  1174. }
  1175. func GetBedDetail(id int64) (models.DeviceNumber, error) {
  1176. number := models.DeviceNumber{}
  1177. err := XTReadDB().Model(&number).Where("id=? and status =1", id).Find(&number).Error
  1178. return number, err
  1179. }
  1180. func UpdatedBed(id int64, number *models.DeviceNumber) error {
  1181. err = XTWriteDB().Model(&number).Where("id=?", id).Update(map[string]interface{}{"number": number.Number, "zone_id": number.ZoneID, "group_id": number.GroupID, "mtime": time.Now().Unix()}).Error
  1182. return err
  1183. }
  1184. func CreateLoginLod(log *models.SgjUserAdminLoginLog) error {
  1185. err := UserWriteDB().Model(&log).Create(&log).Error
  1186. return err
  1187. }
  1188. func GetAppId(orgid int64) (models.OrgApp, error) {
  1189. app := models.OrgApp{}
  1190. err := UserReadDB().Model(&app).Where("org_id = ? and status = 1 and app_type = 3", orgid).Find(&app).Error
  1191. return app, err
  1192. }
  1193. func GetRoleName(adminid int64, orgid int64, appid int64) (models.Roles, error) {
  1194. role := models.Roles{}
  1195. err := UserReadDB().Model(&role).Where("creator = ? and org_id = ? and app_id = ? and status =1", adminid, orgid, appid).Find(&role).Error
  1196. return role, err
  1197. }
  1198. func GetRole(id int64) (models.Role, error) {
  1199. role := models.Role{}
  1200. err := UserReadDB().Model(&role).Where("id = ? and status =1", id).Find(&role).Error
  1201. return role, err
  1202. }
  1203. func GetPositionName(adminid int64, orgid int64, appid int64) (models.App_Role, error) {
  1204. role := models.App_Role{}
  1205. err := UserReadDB().Model(&role).Where("admin_user_id = ? and org_id = ? and app_id = ?", adminid, orgid, appid).Find(&role).Error
  1206. return role, err
  1207. }
  1208. func GetAdmin(id int64) (models.SgjUserAdmin, error) {
  1209. admin := models.SgjUserAdmin{}
  1210. err := UserReadDB().Model(&admin).Where("id=? and status =1", id).Find(&admin).Error
  1211. return admin, err
  1212. }
  1213. func GetPosition(id int64) (models.SgjUserAdminRole, error) {
  1214. roles := models.SgjUserAdminRole{}
  1215. err = UserReadDB().Model(&roles).Where("id=? and status = 1", id).Find(&roles).Error
  1216. return roles, err
  1217. }
  1218. func GetPositionOne(id int64) (models.SgjUserAdmin, error) {
  1219. admin := models.SgjUserAdmin{}
  1220. err = UserReadDB().Model(&admin).Where("id=? and status = 1", id).Find(&admin).Error
  1221. return admin, err
  1222. }
  1223. func GetMyOrgInformation(id int64, appid int64) (models.SgjUserAdminRole, error) {
  1224. admin := models.SgjUserAdminRole{}
  1225. err := UserReadDB().Model(&admin).Where("admin_user_id=? and app_id = ? and status = 1", id, appid).First(&admin).Error
  1226. return admin, err
  1227. }
  1228. func SaveNameTwo(id int64, orgid int64, role *models.SgjUserAdminRole) error {
  1229. err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("admin_user_id =? and org_id = ?", id, orgid).Update(map[string]interface{}{"user_name": role.UserName, "mtime": time.Now().Unix()}).Error
  1230. return err
  1231. }
  1232. func AddPatientLapseto(lapseto *models.PatientLapseto) error {
  1233. err := XTWriteDB().Create(&lapseto).Error
  1234. return err
  1235. }
  1236. func GetDialysAfterRecord(patientid int64, startime int64, endtime int64, orgid int64) (dislysis []*models.XtAssessmentAfterDislysis, err error) {
  1237. db := XTReadDB().Model(&dislysis)
  1238. if startime > 0 {
  1239. db = db.Where("assessment_date >= ?", startime)
  1240. }
  1241. if endtime > 0 {
  1242. db = db.Where("assessment_date <= ?", endtime)
  1243. }
  1244. if patientid > 0 {
  1245. db = db.Where("patient_id = ?", patientid)
  1246. }
  1247. if orgid > 0 {
  1248. db = db.Where("user_org_id = ?", orgid)
  1249. }
  1250. err = db.Find(dislysis).Error
  1251. return dislysis, err
  1252. }
  1253. func GetDialysisDateByDate(starTime int64, patientId int64, orgId int64) (*models.XtPatientVascularAccess, error) {
  1254. access := models.XtPatientVascularAccess{}
  1255. err := XTReadDB().Model(&access).Where("start_time = ? and patient_id = ? and user_org_id = ? and status = 1", starTime, patientId, orgId).Find(&access).Error
  1256. if err == gorm.ErrRecordNotFound {
  1257. return nil, err
  1258. }
  1259. if err != nil {
  1260. return nil, err
  1261. }
  1262. return &access, nil
  1263. }
  1264. func GetDialysisDateByDateOne(starTime int64, patientId int64, orgId int64, id int64) (*models.XtPatientVascularAccess, error) {
  1265. access := models.XtPatientVascularAccess{}
  1266. err := XTReadDB().Model(&access).Where("start_time = ? and patient_id = ? and user_org_id = ? and status = 1 and id <> ?", starTime, patientId, orgId, id).Find(&access).Error
  1267. if err == gorm.ErrRecordNotFound {
  1268. return nil, err
  1269. }
  1270. if err != nil {
  1271. return nil, err
  1272. }
  1273. return &access, nil
  1274. }
  1275. func SaveVascularAccess(access *models.XtPatientVascularAccess) error {
  1276. err := XTWriteDB().Create(&access).Error
  1277. return err
  1278. }
  1279. func GetAllVacualAccessList(orgid int64, limit int64, page int64, patientId int64) (vascular []*models.XtPatientVascularAccess, total int64, err error) {
  1280. offset := (page - 1) * limit
  1281. err = XTReadDB().Model(&vascular).Where("user_org_id = ? and status = 1 and patient_id = ?", orgid, patientId).Count(&total).Offset(offset).Limit(limit).Order("start_time desc").Find(&vascular).Error
  1282. return vascular, total, err
  1283. }
  1284. func GetVasularAccessByDetail(id int64) (models.XtPatientVascularAccess, error) {
  1285. access := models.XtPatientVascularAccess{}
  1286. err := XTReadDB().Where("id = ? and status =1", id).Find(&access).Error
  1287. return access, err
  1288. }
  1289. func UpdateVascularAccess(access *models.XtPatientVascularAccess, id int64) error {
  1290. err := XTWriteDB().Model(&access).Where("id= ?", id).Updates(map[string]interface{}{"access_project": access.AccessProject, "blood_access_part_id": access.BloodAccessPartId, "inflow_pass": access.InflowPass, "start_time": access.StartTime, "first_start_time": access.FirstStartTime, "blood_access_part_opera_id": access.BloodAccessPartOperaId, "stop_reason": access.StopReason, "remark": access.Remark, "user_status": access.UserStatus, "modify": access.Modify, "stop_time": access.StopTime, "other_vascular": access.OtherVascular, "ci_type": access.CiType, "blood_cultupe": access.BloodCultupe, "sequelae_type": access.SequelaeType}).Error
  1291. return err
  1292. }
  1293. func DeleteVasularAccess(id int64) error {
  1294. access := models.XtPatientVascularAccess{}
  1295. err := XTWriteDB().Model(&access).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  1296. return err
  1297. }
  1298. func CreatePatientWayAssessment(assessment *models.XtPatientPasswayAssessment) error {
  1299. err := XTWriteDB().Create(&assessment).Error
  1300. return err
  1301. }
  1302. func GetAllPassWayAssessment(parent_id int64, patient_id int64, page int64, limit int64, orgid int64) (assessment []*models.XtPatientPasswayAssessment, total int64, err error) {
  1303. offset := (page - 1) * limit
  1304. err = XTReadDB().Model(&assessment).Where("parent_id = ? and patient_id = ? and user_org_id = ? and status =1", parent_id, patient_id, orgid).Count(&total).Offset(offset).Limit(limit).Order("start_time desc").Find(&assessment).Error
  1305. return assessment, total, err
  1306. }
  1307. func GetPasswayAssesmentById(id int64) (models.XtPatientPasswayAssessment, error) {
  1308. assessment := models.XtPatientPasswayAssessment{}
  1309. err := XTReadDB().Model(&assessment).Where("id=? and status =1", id).Find(&assessment).Error
  1310. return assessment, err
  1311. }
  1312. func UpdatePassWayAssesment(assessment *models.XtPatientPasswayAssessment, id int64) error {
  1313. err := XTWriteDB().Model(&assessment).Where("id = ?", id).Updates(map[string]interface{}{"start_time": assessment.StartTime, "creator": assessment.Creator, "blood_project": assessment.BloodProject, "blood_result": assessment.BloodResult, "blood_dealwith": assessment.BloodDealwith, "modify": assessment.Modify, "updated_time": time.Now().Unix()}).Error
  1314. return err
  1315. }
  1316. func DeleteWayAssessment(id int64) error {
  1317. assessment := models.XtPatientPasswayAssessment{}
  1318. err := XTWriteDB().Model(&assessment).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  1319. return err
  1320. }
  1321. func GetLastPassWayAssessment(orgid int64, patientId int64) (models.XtPatientVascularAccess, error) {
  1322. assessment := models.XtPatientVascularAccess{}
  1323. redis := RedisClient()
  1324. defer redis.Close()
  1325. // cur_date := time.Now().Format("2006-01-02")
  1326. key := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patientId, 10) + ":pass_way_assessment_last"
  1327. pass_way_assessment_last_str, _ := redis.Get(key).Result()
  1328. if len(pass_way_assessment_last_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  1329. err := XTReadDB().Model(&assessment).Where("user_org_id = ? and patient_id = ? and status =1 and user_status = 1", orgid, patientId).Order("start_time desc").Last(&assessment).Error
  1330. if err != nil {
  1331. if err == gorm.ErrRecordNotFound {
  1332. if assessment.ID <= 0 {
  1333. redis.Set(key, "pass_way_null", time.Second*60*60*18)
  1334. }
  1335. return assessment, nil
  1336. } else {
  1337. return assessment, err
  1338. }
  1339. } else {
  1340. if assessment.ID > 0 {
  1341. //缓存数据
  1342. pass_way_assessment_last_str, err := json.Marshal(assessment)
  1343. if err == nil {
  1344. redis.Set(key, pass_way_assessment_last_str, time.Second*60*60*18)
  1345. return assessment, nil
  1346. }
  1347. } else {
  1348. redis.Set(key, "pass_way_null", time.Second*60*60*18)
  1349. return assessment, nil
  1350. }
  1351. return assessment, nil
  1352. }
  1353. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  1354. if pass_way_assessment_last_str == "pass_way_null" {
  1355. return assessment, nil
  1356. } else {
  1357. json.Unmarshal([]byte(pass_way_assessment_last_str), &assessment)
  1358. return assessment, nil
  1359. }
  1360. }
  1361. }
  1362. func GetAccessList(orgid int64) (*models.Dataconfig, error) {
  1363. dataconfig := models.Dataconfig{}
  1364. err := XTReadDB().Model(&dataconfig).Where("org_id = 0 and name = '血管通路' and status = ?", 1).Find(&dataconfig).Error
  1365. return &dataconfig, err
  1366. }
  1367. func GetParentAccessList(orgid int64, parentid int64) (dataconfig []*models.Dataconfig, err error) {
  1368. err = XTReadDB().Model(&dataconfig).Where("org_id in(0,?) and parent_id = ? and status =1", orgid, parentid).Find(&dataconfig).Error
  1369. return dataconfig, err
  1370. }
  1371. func GetBloodAccess(orgid int64) (*models.Dataconfig, error) {
  1372. dataconfig := models.Dataconfig{}
  1373. err := XTReadDB().Model(&dataconfig).Where("org_id = 0 and name = '血管通路部位' and status = 1 ").Find(&dataconfig).Error
  1374. return &dataconfig, err
  1375. }
  1376. func GetPatientScheduleCount(orgid int64, startTime int64, endTime int64, ids []string) (schedule []*models.VmXtSchedule, err error) {
  1377. db := XTReadDB().Table("xt_schedule as x").Where("x.status =1")
  1378. if orgid > 0 {
  1379. db = db.Where("x.user_org_id = ?", orgid)
  1380. }
  1381. if startTime > 0 {
  1382. db = db.Where("x.schedule_date >=?", startTime)
  1383. }
  1384. if endTime > 0 {
  1385. db = db.Where("x.schedule_date<=?", endTime)
  1386. }
  1387. if len(ids) > 0 {
  1388. db = db.Where("x.partition_id in (?)", ids)
  1389. }
  1390. err = db.Select("count(x.id) as count,x.schedule_type,x.schedule_week").Group("x.schedule_week,x.schedule_type").Scan(&schedule).Error
  1391. return schedule, err
  1392. }
  1393. func GetTotalBedNumber(orgid int64, ids []string) (list []*models.XtDeviceNumber, total int64, err error) {
  1394. //err = XTReadDB().Model(&list).Where("org_id = ? and status = 1 ",orgid).Count(&total).Find(&list).Error
  1395. //return list,total,err
  1396. db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
  1397. if orgid > 0 {
  1398. db = db.Where("x.org_id = ?", orgid)
  1399. }
  1400. if len(ids) > 0 {
  1401. db = db.Where("x.zone_id in (?)", ids)
  1402. }
  1403. err = db.Count(&total).Find(&list).Error
  1404. return list, total, err
  1405. }
  1406. func GetInspectionMajorItem(startime int64, lasttime int64, orgid int64, patientid int64) (inspection []*models.XtInspection, err error) {
  1407. db := XTReadDB().Table("xt_inspection")
  1408. //err = db.Raw("select * from xt_inspection where id in(select max(id) from xt_inspection where org_id = ? and status = 1 and patient_id = ? and inspect_date>=? and inspect_date<=? group by project_id)", orgid, patientid, lasttime, startime).Scan(&inspection).Error
  1409. err = db.Raw("select * from xt_inspection where org_id = ? and status = 1 and patient_id = ? and inspect_date>=? and inspect_date<=? group by project_id", orgid, patientid, lasttime, startime).Scan(&inspection).Error
  1410. return inspection, err
  1411. }
  1412. func GetInspectionDetailByProject(project_id int64, patientid int64, inspect_date int64, orgid int64) (inspection []*models.VmInspection, err error) {
  1413. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  1414. table := XTReadDB().Table("xt_inspection_reference as t").Where("t.status = 1")
  1415. fmt.Println(table)
  1416. if inspect_date > 0 {
  1417. db = db.Where("x.inspect_date=?", inspect_date)
  1418. }
  1419. if orgid > 0 {
  1420. db = db.Where("x.org_id = ?", orgid)
  1421. }
  1422. if patientid > 0 {
  1423. db = db.Where("x.patient_id = ?", patientid)
  1424. }
  1425. if project_id > 0 {
  1426. db = db.Where("x.project_id = ?", project_id)
  1427. }
  1428. err = db.Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,t.range_max,t.range_min,t.range_value,t.unit").Joins("left join xt_inspection_reference as t on t.id = x.item_id").Scan(&inspection).Error
  1429. return inspection, err
  1430. }
  1431. func GetInspectionItemlist(patientid int64, inspect_date []string, projectid []string) (inspection []*models.VmInspection, err error) {
  1432. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  1433. table := XTReadDB().Table("xt_inspection_reference as s").Where("s.status = 1")
  1434. fmt.Println(table)
  1435. if patientid > 0 {
  1436. db = db.Where("x.patient_id = ? and x.inspect_value <> ''", patientid)
  1437. }
  1438. if len(inspect_date) > 0 {
  1439. db = db.Where("x.inspect_date in(?)", inspect_date)
  1440. }
  1441. if len(projectid) > 0 {
  1442. db = db.Where("x.project_id in(?)", projectid)
  1443. }
  1444. err = db.Select("x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,t.range_max,t.range_min,t.range_value,t.unit").Joins("left join xt_inspection_reference as t on t.id = x.item_id").Scan(&inspection).Error
  1445. return inspection, err
  1446. }
  1447. func GetDialysisBeforInitDateList(patient_id int64, startime int64, endtime int64) (models.PredialysisEvaluation, error) {
  1448. befor := models.PredialysisEvaluation{}
  1449. db := XTReadDB().Model(&befor).Where("status = 1")
  1450. if patient_id > 0 {
  1451. db = db.Where("patient_id = ? and assessment_date>=? and assessment_date<=? ", patient_id, startime, endtime)
  1452. }
  1453. err = db.Last(&befor).Error
  1454. return befor, err
  1455. }
  1456. func GetDialysisPrescriptionDataList(patient_id int64, startime int64, endtime int64) (models.DialysisPrescription, error) {
  1457. prescription := models.DialysisPrescription{}
  1458. db := XTReadDB().Model(&prescription).Where("status = 1")
  1459. if patient_id > 0 {
  1460. db = db.Where("patient_id = ? and record_date>=? and record_date<=?", patient_id, startime, endtime)
  1461. }
  1462. err = db.Last(&prescription).Error
  1463. return prescription, err
  1464. }
  1465. func GetDialysisAssementAfter(patient_id int64, startime int64, endtime int64) (models.AssessmentAfterDislysis, error) {
  1466. after := models.AssessmentAfterDislysis{}
  1467. db := XTReadDB().Model(&after).Where("status = 1")
  1468. if patient_id > 0 {
  1469. db = db.Where("patient_id = ? and assessment_date>=? and assessment_date<=?", patient_id, startime, endtime)
  1470. }
  1471. err = db.Last(&after).Error
  1472. return after, err
  1473. }
  1474. func GetDialysisDialysisMode(patient_id int64, startime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
  1475. db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
  1476. table := readDb.Table("xt_schedule as s").Where("s.status = 1")
  1477. fmt.Println(table)
  1478. p := readDb.Table("xt_patients as p").Where("p.status = 1")
  1479. fmt.Println(p)
  1480. if startime > 0 {
  1481. db = db.Where("o.dialysis_date >=?", startime)
  1482. }
  1483. if endtime > 0 {
  1484. db = db.Where("o.dialysis_date<=?", endtime)
  1485. }
  1486. if orgid > 0 {
  1487. db = db.Where("o.user_org_id = ? and o.stage = 2", orgid)
  1488. }
  1489. if patient_id > 0 {
  1490. db = db.Where("o.patient_id = ?", patient_id)
  1491. }
  1492. err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id and s.schedule_date = o.dialysis_date and s.status= 1").Joins("left join xt_patients as p on o.patient_id = p.id").Group("s.mode_id").Scan(&counts).Error
  1493. return counts, err
  1494. }
  1495. func CreateSummary(summary *models.XtTemplateSummary) error {
  1496. err = XTWriteDB().Create(&summary).Error
  1497. return err
  1498. }
  1499. func UpdateTempalteSummary(summary *models.XtTemplateSummary) error {
  1500. err = XTWriteDB().Save(&summary).Error
  1501. return err
  1502. }
  1503. func GetTemplateSummaryList(patientid int64, orgid int64, startime int64, endtime int64) (summary []*models.XtTemplateSummary, err error) {
  1504. db := XTReadDB().Model(&summary).Where("status = 1")
  1505. if startime > 0 {
  1506. db = db.Where("record_time >=?", startime)
  1507. }
  1508. if endtime > 0 {
  1509. db = db.Where("record_time<=?", endtime)
  1510. }
  1511. if patientid > 0 {
  1512. db = db.Where("patient_id = ?", patientid)
  1513. }
  1514. if orgid > 0 {
  1515. db = db.Where("user_org_id = ?", orgid)
  1516. }
  1517. err = db.Order("record_time desc").Find(&summary).Error
  1518. return summary, err
  1519. }
  1520. func GetTemplateSummaryDetail(id int64) (models.XtTemplateSummary, error) {
  1521. summary := models.XtTemplateSummary{}
  1522. err := XTReadDB().Model(&summary).Where("id=?", id).Find(&summary).Error
  1523. return summary, err
  1524. }
  1525. func GetTemplateSummaryPrintDetail(id int64) (models.XtTemplateSummary, error) {
  1526. summary := models.XtTemplateSummary{}
  1527. err := XTReadDB().Model(&summary).Where("id=? and status = 1", id).Preload("Patients", "status = 1").Find(&summary).Error
  1528. return summary, err
  1529. }
  1530. func GetTreateSummary(startime int64, endtime int64, limit int64, page int64, creater int64, patient_id int64) (list []*models.XtTemplateSummary, total int64, err error) {
  1531. db := XTReadDB().Model(&list).Where("status = 1")
  1532. offset := (page - 1) * limit
  1533. if startime > 0 {
  1534. db = db.Where("record_time >=?", startime)
  1535. }
  1536. if endtime > 0 {
  1537. db = db.Where("record_time<=?", endtime)
  1538. }
  1539. if creater > 0 {
  1540. db = db.Where("admin_user_id = ?", creater)
  1541. }
  1542. if patient_id > 0 {
  1543. db = db.Where("patient_id = ?", patient_id)
  1544. }
  1545. err = db.Count(&total).Offset(offset).Limit(limit).Order("record_time desc").Find(&list).Error
  1546. return list, total, err
  1547. }
  1548. func DeleteSummary(ids []string) error {
  1549. summary := models.XtTemplateSummary{}
  1550. err := XTWriteDB().Model(&summary).Where("id in(?)", ids).Updates(map[string]interface{}{"status": 0}).Error
  1551. return err
  1552. }
  1553. func CreateHisSummary(summary *models.XtHospitalSummary) error {
  1554. err := XTWriteDB().Create(&summary).Error
  1555. return err
  1556. }
  1557. func GetHospitalSummaryList(orgid int64, patient_id int64, startime int64, endtime int64) (list []*models.XtHospitalSummary, err error) {
  1558. db := XTReadDB().Model(&list).Where("status = 1")
  1559. if orgid > 0 {
  1560. db = db.Where("user_org_id = ?", orgid)
  1561. }
  1562. if startime > 0 {
  1563. db = db.Where("record_date >=?", startime)
  1564. }
  1565. if endtime > 0 {
  1566. db = db.Where("record_date <=?", endtime)
  1567. }
  1568. if patient_id > 0 {
  1569. db = db.Where("patient_id = ?", patient_id)
  1570. }
  1571. err = db.Find(&list).Order("ctime desc").Error
  1572. return list, err
  1573. }
  1574. func GetHospitalSummaryDetail(id int64) (models.XtHospitalSummary, error) {
  1575. summary := models.XtHospitalSummary{}
  1576. err := XTReadDB().Where("id = ? and status = 1", id).Find(&summary).Error
  1577. return summary, err
  1578. }
  1579. func UpdateHospital(id int64, summary models.XtHospitalSummary) error {
  1580. err := XTWriteDB().Model(&summary).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"title": summary.Title, "admission_time": summary.AdmissionTime, "discharge_time": summary.DischargeTime, "sick_personnel": summary.SickPersonnel, "xray": summary.Xray, "connecticut": summary.Connecticut, "nuclear_magnetic_resonance": summary.NuclearMagneticResonance, "ultrasound": summary.Ultrasound, "pathology": summary.Pathology, "admitting_diagnosis_id": summary.AdmittingDiagnosisId, "admitting_diagnosis": summary.AdmittingDiagnosis, "discharge_diagnosis_id": summary.DischargeDiagnosisId, "discharge_diagnosis": summary.DischargeDiagnosis, "diagnosis_admission_id": summary.DiagnosisAdmissionId, "diagnosis_admission": summary.DiagnosisAdmission, "treatment_id": summary.TreatmentId, "treatment": summary.Treatment, "illness_discharge_id": summary.IllnessDischargeId, "illness_discharge": summary.IllnessDischarge, "discharge_advice_id": summary.DischargeAdviceId, "discharge_advice": summary.DischargeAdvice, "mtime": summary.Mtime, "record_time": summary.RecordTime, "dean_id": summary.DeanId, "doctor": summary.Doctor, "record_date": summary.RecordDate}).Error
  1581. return err
  1582. }
  1583. func DeleteHospitalSummary(id []string) error {
  1584. err := XTWriteDB().Model(models.XtHospitalSummary{}).Where("id in (?) and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  1585. return err
  1586. }
  1587. func GetAllPatientScheduleList(org_id int64) (patient []*models.PatientsThirty, err error) {
  1588. err = XTReadDB().Where("user_org_id = ? and status = 1", org_id).Find(&patient).Error
  1589. return patient, err
  1590. }
  1591. func GetAllDialysiOrderList(patient_id int64, org_id int64) (order []*models.DialysisOrder, err error) {
  1592. err = XTReadDB().Where("patient_id = ? and user_org_id = ? and status= 1 and dialysis_date<=1672416000", patient_id, org_id).Find(&order).Error
  1593. return order, err
  1594. }
  1595. func GetDialysisTotalCountThree(org_id int64, patient_id int64, dialysis_date int64) (models.BloodDialysisOrderCount, error) {
  1596. order := models.BloodDialysisOrderCount{}
  1597. db := XTReadDB().Table("xt_dialysis_order as o")
  1598. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule as x on x.patient_id = o.patient_id where o.status =1 and o.user_org_id = ? and o.patient_id = ? and o.dialysis_date<=? and x.schedule_date = o.dialysis_date and x.status = 1 ", org_id, patient_id, dialysis_date).Scan(&order).Error
  1599. return order, err
  1600. }
  1601. func UpdateDialysisOrderSix(patient_id int64, dialysis_date int64, user_org_id int64, dialysis_total int64) (models.DialysisOrder, error) {
  1602. order := models.DialysisOrder{}
  1603. err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"dialysis_total": dialysis_total}).Error
  1604. return order, err
  1605. }
  1606. func CreatePatientFirstDisease(firstdisease models.XtPatientFirstDisease) error {
  1607. err := XTWriteDB().Create(&firstdisease).Error
  1608. return err
  1609. }
  1610. func GetPatientDiseaseList(org_id int64, patient_id int64, start_time int64, end_time int64) (disease []*models.XtPatientFirstDisease, err error) {
  1611. db := XTReadDB().Model(&disease).Where("status=1")
  1612. if org_id > 0 {
  1613. db = db.Where("user_org_id =?", org_id)
  1614. }
  1615. if patient_id > 0 {
  1616. db = db.Where("patient_id = ?", patient_id)
  1617. }
  1618. if start_time > 0 {
  1619. db = db.Where("record_date >=?", start_time)
  1620. }
  1621. if end_time > 0 {
  1622. db = db.Where("record_date<=?", end_time)
  1623. }
  1624. err = db.Find(&disease).Error
  1625. return disease, err
  1626. }
  1627. func GetFirstDetailById(id int64) (models.XtPatientFirstDisease, error) {
  1628. disease := models.XtPatientFirstDisease{}
  1629. err = XTReadDB().Where("id = ? and status= 1", id).Find(&disease).Error
  1630. return disease, err
  1631. }
  1632. func UpdatePatientFirstDisease(disease models.XtPatientFirstDisease, id int64) error {
  1633. err := XTWriteDB().Model(&models.XtPatientFirstDisease{}).Where("id =? and status = 1", id).Update(map[string]interface{}{"title": disease.Title, "doctor": disease.Doctor, "record_date": disease.RecordDate, "main_content": disease.MainContent, "patient_case": disease.PatientCase, "tentative_diagnosis": disease.TentativeDiagnosis, "diagnostic_basis": disease.DiagnosticBasis, "differential_diagnosis": disease.DifferentialDiagnosis, "treatment_plan": disease.TreatmentPlan, "project_id": disease.ProjectId, "inspect_date": disease.InspectDate}).Error
  1634. return err
  1635. }
  1636. func DeleteFirstDisease(id []string) error {
  1637. err := XTWriteDB().Model(models.XtPatientFirstDisease{}).Where("id in (?) and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  1638. return err
  1639. }
  1640. type InspectionCount struct {
  1641. Count int64
  1642. }
  1643. func GetNormalInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64) (total int64, err error) {
  1644. var count []*InspectionCount
  1645. err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1 WHERE (x.status = 1) AND (x.org_id = ? and x.reference_project_id = ? and x.reference_item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ? and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.`inspect_value` <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, max_value, min_value).Scan(&count).Error
  1646. for _, items := range count {
  1647. total = total + items.Count
  1648. }
  1649. return total, err2
  1650. }
  1651. func GetUnusualInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64) (total int64, err error) {
  1652. var count []*InspectionCount
  1653. err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1 WHERE (x.status = 1) AND (x.org_id = ? and x.reference_project_id = ? and x.reference_item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value > ?) OR (xti.status = 1 AND xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, max_value, orgid, projectid, item_id, startime, endtime, min_value).Scan(&count).Error
  1654. for _, items := range count {
  1655. total = total + items.Count
  1656. }
  1657. return total, err2
  1658. }
  1659. func GetPatientNotInspectionTotal(startime int64, endtime int64, orgid int64, projectid int64, item_id int64) (total int64, err error) {
  1660. err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.reference_project_id = ? and pd.reference_item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
  1661. return total, err
  1662. }
  1663. func GetPatientInspectionByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, patient_id int64) (inspections []*models.Inspection, err error) {
  1664. db := XTReadDB().Table("xt_inspection as x").Select("patient_id,inspect_date,inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
  1665. if startime > 0 {
  1666. db = db.Where("x.inspect_date >= ?", startime)
  1667. }
  1668. if endtime > 0 {
  1669. db = db.Where("x.inspect_date<=?", endtime)
  1670. }
  1671. if orgid > 0 {
  1672. db = db.Where("x.org_id = ?", orgid)
  1673. }
  1674. if projectid > 0 {
  1675. db = db.Where("x.reference_project_id = ?", projectid)
  1676. }
  1677. if item_id > 0 {
  1678. db = db.Where("x.reference_item_id = ?", item_id)
  1679. }
  1680. if patient_id > 0 {
  1681. db = db.Where("x.patient_id = ?", patient_id)
  1682. }
  1683. err = db.Find(&inspections).Error
  1684. return inspections, err
  1685. }
  1686. func GetPatientKTVORURRInspectionByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, patient_id int64) (inspections []*models.Inspection, err error) {
  1687. db := XTReadDB().Table("xt_inspection as x").Select("patient_id,inspect_date,inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
  1688. if startime > 0 {
  1689. db = db.Where("x.inspect_date >= ?", startime)
  1690. }
  1691. if endtime > 0 {
  1692. db = db.Where("x.inspect_date<=?", endtime)
  1693. }
  1694. if orgid > 0 {
  1695. db = db.Where("x.org_id = ?", orgid)
  1696. }
  1697. if projectid > 0 {
  1698. db = db.Where("x.project_id = ?", projectid)
  1699. }
  1700. if item_id > 0 {
  1701. db = db.Where("x.item_id = ?", item_id)
  1702. }
  1703. if patient_id > 0 {
  1704. db = db.Where("x.patient_id = ?", patient_id)
  1705. }
  1706. err = db.Find(&inspections).Error
  1707. return inspections, err
  1708. }
  1709. func GetPatientKTVByID(startime int64, endtime int64, orgid int64, patient_id int64) (inspections []*models.Inspection, err error) {
  1710. db := XTReadDB().Table("xt_assessment_after_dislysis as x").Select("patient_id as patient_id,assessment_date as inspect_date,ktv as inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
  1711. if startime > 0 {
  1712. db = db.Where("x.assessment_date >= ?", startime)
  1713. }
  1714. if endtime > 0 {
  1715. db = db.Where("x.assessment_date<=?", endtime)
  1716. }
  1717. if orgid > 0 {
  1718. db = db.Where("x.user_org_id = ?", orgid)
  1719. }
  1720. if patient_id > 0 {
  1721. db = db.Where("x.patient_id = ?", patient_id)
  1722. }
  1723. err = db.Find(&inspections).Error
  1724. return inspections, err
  1725. }
  1726. func GetPatientURRByID(startime int64, endtime int64, orgid int64, patient_id int64) (inspections []*models.Inspection, err error) {
  1727. db := XTReadDB().Table("xt_assessment_after_dislysis as x").Select("patient_id as patient_id,assessment_date as inspect_date,urr as inspect_value").Joins("join xt_patients p On p.id = x.patient_id and p.status = 1 and p.lapseto = 1").Where("x.status = 1")
  1728. if startime > 0 {
  1729. db = db.Where("x.assessment_date >= ?", startime)
  1730. }
  1731. if endtime > 0 {
  1732. db = db.Where("x.assessment_date<=?", endtime)
  1733. }
  1734. if orgid > 0 {
  1735. db = db.Where("x.user_org_id = ?", orgid)
  1736. }
  1737. if patient_id > 0 {
  1738. db = db.Where("x.patient_id = ?", patient_id)
  1739. }
  1740. err = db.Find(&inspections).Error
  1741. return inspections, err
  1742. }
  1743. func GetNormalInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
  1744. db := XTReadDB().Table("xt_inspection as xti ")
  1745. if len(keyword) > 0 {
  1746. keyword = "%" + keyword + "%"
  1747. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
  1748. } else {
  1749. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
  1750. }
  1751. err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x WHERE (x.status = 1) AND (x.org_id = ? and x.reference_project_id = ? and x.reference_item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ? and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.`inspect_value` <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, max_value, min_value).Scan(&xti).Error
  1752. return xti, err2
  1753. }
  1754. func GetUnusualInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
  1755. db := XTReadDB().Table("xt_inspection as xti ")
  1756. if len(keyword) > 0 {
  1757. keyword = "%" + keyword + "%"
  1758. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
  1759. } else {
  1760. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
  1761. }
  1762. err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x WHERE (x.status = 1) AND (x.org_id = ? and x.reference_project_id = ? and x.reference_item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value > ?) OR (xti.status = 1 AND xti.org_id = ? and xti.reference_project_id = ? and xti.reference_item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, max_value, orgid, projectid, item_id, startime, endtime, min_value).Scan(&xti).Error
  1763. return xti, err2
  1764. }
  1765. func GetPatientNotInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, keyword string) (patient []*models.XtPatientsTen, err error) {
  1766. err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.reference_project_id = ? and pd.reference_item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
  1767. return patient, err
  1768. }
  1769. func GetUnusualKTVPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
  1770. db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
  1771. if len(keyword) > 0 {
  1772. keyword = "%" + keyword + "%"
  1773. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
  1774. } else {
  1775. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
  1776. }
  1777. err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv +'0' < ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
  1778. return xti, err2
  1779. }
  1780. func GetUnusualKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
  1781. db := XTReadDB().Table("xt_inspection as xti ")
  1782. if len(keyword) > 0 {
  1783. keyword = "%" + keyword + "%"
  1784. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
  1785. } else {
  1786. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
  1787. }
  1788. err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.org_id = ? and xti.project_id = ? and xti.item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&xti).Error
  1789. return xti, err2
  1790. }
  1791. func GetNormalKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, max_value float64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
  1792. db := XTReadDB().Table("xt_inspection as xti ")
  1793. if len(keyword) > 0 {
  1794. keyword = "%" + keyword + "%"
  1795. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
  1796. } else {
  1797. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.inspect_date,'%Y-%m-%d') as date,xti.inspect_value as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
  1798. }
  1799. err2 := db.Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.org_id = ? and xti.project_id = ? and xti.item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&xti).Error
  1800. return xti, err2
  1801. }
  1802. func GetPatientNotKTVORURRInspectionPatientList(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, keyword string) (patient []*models.XtPatientsTen, err error) {
  1803. err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.project_id = ? and pd.item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
  1804. return patient, err
  1805. }
  1806. func GetNormalKTVPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
  1807. db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
  1808. if len(keyword) > 0 {
  1809. keyword = "%" + keyword + "%"
  1810. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
  1811. } else {
  1812. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,xti.ktv as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
  1813. }
  1814. err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date<= ? and xti.ktv + '0' >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
  1815. return xti, err2
  1816. }
  1817. func GetPatientNotKTVPatientList(startime int64, endtime int64, orgid int64) (patient []*models.XtPatientsTen, err error) {
  1818. err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.ktv <> '' and pd.assessment_date >= ? and pd.assessment_date<=? ", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
  1819. return patient, err
  1820. }
  1821. func GetNormalURRPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
  1822. db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
  1823. if len(keyword) > 0 {
  1824. keyword = "%" + keyword + "%"
  1825. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
  1826. } else {
  1827. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1")
  1828. }
  1829. err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date<= ? and REPLACE(xti.urr, '%', '') + 0 >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
  1830. return xti, err2
  1831. }
  1832. func GetUnusualURRPatientList(startime int64, endtime int64, orgid int64, min_value float64, keyword string) (xti []*models.Inspection, err error) {
  1833. db := XTReadDB().Table("xt_assessment_after_dislysis as xti ")
  1834. if len(keyword) > 0 {
  1835. keyword = "%" + keyword + "%"
  1836. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 and name like ?", keyword)
  1837. } else {
  1838. db = db.Select("xti.patient_id as patient_id,FROM_UNIXTIME(xti.assessment_date,'%Y-%m-%d') as date,REPLACE(xti.urr, '%', '') + 0 as inspect_value,pp.name as name, pp.dialysis_no as dialysis_no").Joins("join xt_patients pp On pp.id = xti.patient_id and pp.status = 1 and pp.lapseto = 1 ")
  1839. }
  1840. err2 := db.Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ?) group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '') + 0 < ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&xti).Error
  1841. return xti, err2
  1842. }
  1843. func GetPatientNotURRPatientList(startime int64, endtime int64, orgid int64) (patient []*models.XtPatientsTen, err error) {
  1844. err = XTReadDB().Model(models.XtPatientsTen{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and xti.urr <> '' and pd.assessment_date >= ? and pd.assessment_date<=? ", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Find(&patient).Error
  1845. return patient, err
  1846. }
  1847. func GetNormalKTVTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
  1848. var count []*InspectionCount
  1849. err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1 WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv + '0' >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
  1850. for _, items := range count {
  1851. total = total + items.Count
  1852. }
  1853. return total, err2
  1854. }
  1855. func GetUnusualKTVTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
  1856. var count []*InspectionCount
  1857. err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti ").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1 WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.ktv <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and xti.ktv + '0'< ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
  1858. for _, items := range count {
  1859. total = total + items.Count
  1860. }
  1861. return total, err2
  1862. }
  1863. func GetPatientNotKTVTotal(startime int64, endtime int64, orgid int64) (total int64, err error) {
  1864. err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.user_org_id = ? and pd.assessment_date >= ? and pd.assessment_date<=? and pd.ktv <> ''", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
  1865. return total, err
  1866. }
  1867. func GetNormalURRTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
  1868. var count []*InspectionCount
  1869. err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1 WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '') + 0 >= ? ) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
  1870. for _, items := range count {
  1871. total = total + items.Count
  1872. }
  1873. return total, err2
  1874. }
  1875. func GetUnusualURRTotalByID(startime int64, endtime int64, orgid int64, min_value float64) (total int64, err error) {
  1876. var count []*InspectionCount
  1877. err2 := XTReadDB().Table("xt_assessment_after_dislysis as xti ").Select("count(*) as count").Joins("join (SELECT max(assessment_date) as ind, patient_id as pid FROM xt_assessment_after_dislysis as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1 WHERE (x.status = 1) AND (x.user_org_id = ? and x.assessment_date >= ? and x.assessment_date <= ? and x.urr <> '') group by patient_id) as ta on ta.ind = xti.`assessment_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.user_org_id = ? and xti.assessment_date >= ? and xti.assessment_date <= ? and REPLACE(xti.urr, '%', '')+ 0 < ?) Group by xti.patient_id", orgid, startime, endtime, orgid, startime, endtime, min_value).Scan(&count).Error
  1878. for _, items := range count {
  1879. total = total + items.Count
  1880. }
  1881. return total, err2
  1882. }
  1883. func GetPatientNotURRTotal(startime int64, endtime int64, orgid int64) (total int64, err error) {
  1884. err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_assessment_after_dislysis pd ON xt_patients.id = pd.patient_id and pd.user_org_id = ? and pd.assessment_date >= ? and pd.assessment_date<=? and pd.urr <> ''", orgid, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
  1885. return total, err
  1886. }
  1887. func GetNormalKTVORURRInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, min_value float64) (total int64, err error) {
  1888. var count []*InspectionCount
  1889. err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x Join xt_patients pp on pp.id = x.patient_id and pp.lapseto = 1 WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1) AND (xti.org_id = ? and xti.project_id = ? and xti.item_id = ? and xti.inspect_date >= ? and xti.inspect_date<= ? and xti.inspect_value >= ? ) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&count).Error
  1890. for _, items := range count {
  1891. total = total + items.Count
  1892. }
  1893. return total, err2
  1894. }
  1895. func GetUnusualKTVORURRInspectionTotalByID(startime int64, endtime int64, orgid int64, projectid int64, item_id int64, min_value float64) (total int64, err error) {
  1896. var count []*InspectionCount
  1897. err2 := XTReadDB().Table("xt_inspection as xti ").Select("count(*) as count").Joins("join (SELECT max(inspect_date) as ind, patient_id as pid FROM xt_inspection as x JOIN xt_patients pp on pp.id = x.patient_id and pp.status = 1 and pp.lapseto = 1 WHERE (x.status = 1) AND (x.org_id = ? and x.project_id = ? and x.item_id = ? and x.inspect_date >= ? and x.inspect_date <= ?) group by patient_id) as ta on ta.ind = xti.`inspect_date` and xti.patient_id = ta.pid WHERE (xti.status = 1 AND xti.org_id = ? and xti.project_id = ? and xti.item_id = ? and xti.inspect_date >= ? and xti.inspect_date <= ? and xti.inspect_value < ?) Group by xti.patient_id", orgid, projectid, item_id, startime, endtime, orgid, projectid, item_id, startime, endtime, min_value).Scan(&count).Error
  1898. for _, items := range count {
  1899. total = total + items.Count
  1900. }
  1901. return total, err2
  1902. }
  1903. func GetPatientNotKTVORURRInspectionTotal(startime int64, endtime int64, orgid int64, projectid int64, item_id int64) (total int64, err error) {
  1904. err = XTReadDB().Model(models.XtPatients{}).Joins("LEFT JOIN xt_inspection pd ON xt_patients.id = pd.patient_id and pd.org_id = ? and pd.project_id = ? and pd.item_id = ? and pd.inspect_date >= ? and pd.inspect_date<=? ", orgid, projectid, item_id, startime, endtime).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and pd.patient_id IS NULL and xt_patients.lapseto = 1", orgid).Count(&total).Error
  1905. return total, err
  1906. }
  1907. func GetFiveInspectionPatientList(orgid int64, keyword string) (xti []*models.XtPatientsTenOne, err error) {
  1908. keyword = "%" + keyword + "%"
  1909. err = XTReadDB().Model(models.XtPatientsTenOne{}).Where("xt_patients.user_org_id = ? and xt_patients.status = 1 and xt_patients.lapseto = 1 and xt.patients.name like ?", orgid, keyword).Find(&xti).Error
  1910. return
  1911. }
  1912. func GetPatientFiveInspectionByID(startime int64, endtime int64, orgid int64, keyword string) (inspections []models.InspectionTen, err error) {
  1913. keyword = "%" + keyword + "%"
  1914. db := XTReadDB().Table("xt_patients as p").Select("p.id as patient_id, p.name as name, IFNULL(a.inspect_value, '') AS 'ipth',IFNULL(b.inspect_value, '') AS 'xuejia',IFNULL(c.inspect_value, '') AS 'xuelin',IFNULL(d.inspect_value, '') AS 'bdb',IFNULL(e.inspect_value, '') AS 'xhdb'").Joins("LEFT JOIN `xt_inspection` a ON p.id = a.patient_id AND a.org_id = ? and a.`reference_item_id` = 171 and a.`reference_project_id` = 20 and a.`inspect_date` >= ? and a.`inspect_date` <= ? LEFT JOIN xt_inspection b ON p.id = b.patient_id AND b.org_id = ? and b.`reference_item_id` = 48 and b.`reference_project_id` = 4 and b.`inspect_date` >= ? and b.`inspect_date` <= ? LEFT JOIN xt_inspection c ON p.id = c.patient_id AND c.org_id = ? and c.`reference_item_id` = 169 and c.`reference_project_id` = 4 and c.`inspect_date` >= ? and c.`inspect_date` <= ? LEFT JOIN xt_inspection d ON p.id = d.patient_id AND d.org_id = ? and d.`reference_item_id` = 35 and d.`reference_project_id` = 2 and d.`inspect_date` >= ? and d.`inspect_date` <= ? LEFT JOIN xt_inspection e ON p.id = e.patient_id AND e.org_id = ? and e.`reference_item_id` = 17 and e.`reference_project_id` = 1 and e.`inspect_date` >= ? and e.`inspect_date` <= ?", orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime, orgid, startime, endtime).Where("p.name like ? and p.user_org_id = ? and p.status = 1 and p.lapseto = 1 ", keyword, orgid).Group("p.id")
  1915. err = db.Find(&inspections).Error
  1916. return inspections, err
  1917. }