patientmanage_service.go 59KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. func GetIllnessListTwo() (ills []*models.Illness, err error) {
  11. err = readUserDb.Where("status=1").Find(&ills).Error
  12. return
  13. }
  14. func GetBloodDialysisPatient(orgid int64, page int64, limit int64) (patients []*models.Patients, total int64, err error) {
  15. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  16. if orgid > 0 {
  17. db = db.Where("x.user_org_id = ?", orgid)
  18. }
  19. offset := (page - 1) * limit
  20. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  21. 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
  22. fmt.Println("err是什么", err)
  23. return
  24. }
  25. func GetAllBloodDialysisPatient(orgid int64, page int64, limit int64, lapseto int64, source int64) (patients []*models.XtPatientsNew, total int64, err error) {
  26. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  27. if orgid > 0 {
  28. db = db.Where("x.user_org_id = ? and x.blood_patients = 1", orgid)
  29. }
  30. if lapseto > 0 {
  31. db = db.Where("x.lapseto = ?", lapseto)
  32. }
  33. if source > 0 {
  34. db = db.Where("x.source = ?", source)
  35. }
  36. offset := (page - 1) * limit
  37. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  38. 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
  39. fmt.Println("err是什么", err)
  40. return
  41. }
  42. func GetAllSlowPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
  43. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  44. if orgid > 0 {
  45. db = db.Where("x.user_org_id = ? and x.slow_patients = 1", orgid)
  46. }
  47. offset := (page - 1) * limit
  48. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  49. 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
  50. fmt.Println("err是什么", err)
  51. return
  52. }
  53. func GetAllMemberPatient(orgid int64, page int64, limit int64) (patients []*models.XtPatientsNew, total int64, err error) {
  54. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  55. if orgid > 0 {
  56. db = db.Where("x.user_org_id = ? and x.member_patients = 1", orgid)
  57. }
  58. offset := (page - 1) * limit
  59. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).
  60. 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
  61. fmt.Println("err是什么", err)
  62. return
  63. }
  64. func GetAllPatient(orgid int64) (patients []*models.PatientsNew, err error) {
  65. db := XTReadDB().Table("xt_patients_new as x")
  66. err = db.Raw("select id,name from xt_patients_new where user_org_id = ? and status =1", orgid).Scan(&patients).Error
  67. return
  68. }
  69. func ChechLastDialysisNoTwo(orgID int64) (dialysisNo int64) {
  70. var patient models.Patients
  71. err := readDb.Model(&models.Patients{}).Where("user_org_id=? and status = 1", orgID).Order("dialysis_no desc").First(&patient).Error
  72. if err != nil {
  73. return
  74. }
  75. if patient.ID == 0 {
  76. return
  77. }
  78. dialysisNo, _ = strconv.ParseInt(patient.DialysisNo, 10, 64)
  79. return
  80. }
  81. func GetBloodPatientInfo(orgid int64, phone string) (*models.Patients, error) {
  82. patients := models.Patients{}
  83. var err error
  84. err = XTReadDB().Model(&patients).Where("user_org_id = ? and phone = ? and status = 1", orgid, phone).Find(&patients).Error
  85. if err == gorm.ErrRecordNotFound {
  86. return nil, err
  87. }
  88. if err != nil {
  89. return nil, err
  90. }
  91. return &patients, nil
  92. }
  93. func GetSlowPatientInfo(orgid int64, phone string) (*models.CdmPatients, error) {
  94. patients := models.CdmPatients{}
  95. var err error
  96. err = PatientReadDB().Model(&patients).Where("user_org_id = ? and phone = ? and status = 1", orgid, phone).Find(&patients).Error
  97. if err == gorm.ErrRecordNotFound {
  98. return nil, err
  99. }
  100. if err != nil {
  101. return nil, err
  102. }
  103. return &patients, nil
  104. }
  105. func GetMemberPatientInfo(orgid int64, phone string) (*models.SgjUserCustomer, error) {
  106. customer := models.SgjUserCustomer{}
  107. err := UserReadDB().Model(&customer).Where("user_org_id = ? and mobile = ? and status =1", orgid, phone).Find(&customer).Error
  108. if err == gorm.ErrRecordNotFound {
  109. return nil, err
  110. }
  111. if err != nil {
  112. return nil, err
  113. }
  114. return &customer, nil
  115. }
  116. func CreateOldPatient(patients *models.Patients) error {
  117. err := XTWriteDB().Create(&patients).Error
  118. return err
  119. }
  120. func GetLastOldPatient(orgid int64) (models.Patients, error) {
  121. patients := models.Patients{}
  122. err := XTReadDB().Model(&patients).Where("user_org_id = ? and status =1", orgid).Last(&patients).Error
  123. return patients, err
  124. }
  125. func AddContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64) (err error) {
  126. utx := writeDb.Begin()
  127. if len(contagions) > 0 {
  128. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  129. insertParams := make([]string, 0)
  130. insertData := make([]interface{}, 0)
  131. for _, contagion := range contagions {
  132. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  133. insertData = append(insertData, patienid)
  134. insertData = append(insertData, contagion)
  135. insertData = append(insertData, 1)
  136. insertData = append(insertData, createdtime)
  137. insertData = append(insertData, updatedtime)
  138. }
  139. thisSQL += strings.Join(insertParams, ",")
  140. err = utx.Exec(thisSQL, insertData...).Error
  141. fmt.Println("这个错误err", err)
  142. }
  143. utx.Commit()
  144. return
  145. }
  146. func AddSlowContagions(patienid int64, createdtime int64, updatedtime int64, contagions []int64, orgid int64) (err error) {
  147. utx := PatientWriteDB().Begin()
  148. if len(contagions) > 0 {
  149. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time,user_org_id) VALUES "
  150. insertParams := make([]string, 0)
  151. insertData := make([]interface{}, 0)
  152. for _, contagion := range contagions {
  153. insertParams = append(insertParams, "(?, ?, ?, ?, ?,?)")
  154. insertData = append(insertData, patienid)
  155. insertData = append(insertData, contagion)
  156. insertData = append(insertData, 1)
  157. insertData = append(insertData, createdtime)
  158. insertData = append(insertData, updatedtime)
  159. insertData = append(insertData, orgid)
  160. }
  161. thisSQL += strings.Join(insertParams, ", ")
  162. err = utx.Exec(thisSQL, insertData...).Error
  163. if err != nil {
  164. utx.Rollback()
  165. utx.Rollback()
  166. return
  167. }
  168. }
  169. utx.Commit()
  170. return
  171. }
  172. func AddSlowDiseases(patienid int64, createdtime int64, updatedtime int64, diseases []int64, orgid int64) (err error) {
  173. utx := PatientWriteDB().Begin()
  174. if len(diseases) > 0 {
  175. thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time,user_org_id) VALUES "
  176. insertParams := make([]string, 0)
  177. insertData := make([]interface{}, 0)
  178. for _, disease := range diseases {
  179. insertParams = append(insertParams, "(?, ?, ?, ?, ?,?)")
  180. insertData = append(insertData, patienid)
  181. insertData = append(insertData, disease)
  182. insertData = append(insertData, 1)
  183. insertData = append(insertData, createdtime)
  184. insertData = append(insertData, updatedtime)
  185. insertData = append(insertData, orgid)
  186. }
  187. thisSQL += strings.Join(insertParams, ", ")
  188. err = utx.Exec(thisSQL, insertData...).Error
  189. if err != nil {
  190. utx.Rollback()
  191. return
  192. }
  193. }
  194. utx.Commit()
  195. return
  196. }
  197. func CreateNewPatient(patientsNew *models.XtPatientsNew) error {
  198. err := XTWriteDB().Create(&patientsNew).Error
  199. return err
  200. }
  201. func CreateCdmPatient(cdmpatient *models.CdmPatients) error {
  202. err := PatientWriteDB().Create(&cdmpatient).Error
  203. return err
  204. }
  205. func CreateMemberPatient(customer *models.SgjUserCustomer) error {
  206. err := UserWriteDB().Create(&customer).Error
  207. return err
  208. }
  209. func GetOldCdmPatient(orgid int64) (models.CdmPatients, error) {
  210. patients := models.CdmPatients{}
  211. err := PatientReadDB().Model(&patients).Where("user_org_id = ? and status =1", orgid).Last(&patients).Error
  212. return patients, err
  213. }
  214. func GetPatientDetailTwo(id int64) (models.XtPatientsNew, error) {
  215. patients := models.XtPatientsNew{}
  216. err := XTReadDB().Where("id=? and status = 1", id).Find(&patients).Error
  217. return patients, err
  218. }
  219. func GetPatientDiseasesTwo(id int64) []int64 {
  220. var dis []models.XtPatientsInfectiousDiseases
  221. ids := make([]int64, 0)
  222. err := XTReadDB().Model(&models.XtPatientsInfectiousDiseases{}).Where("patient_id = ? and status = 1", id).Find(&dis).Error
  223. if err != nil || len(dis) == 0 {
  224. return ids
  225. }
  226. for _, item := range dis {
  227. ids = append(ids, item.DiseaseId)
  228. }
  229. return ids
  230. }
  231. func GetSlowPatientDiseases(id int64) (infeciousdisease []*models.CdmPatientsInfectiousDiseases, err error) {
  232. //var dis []models.CdmPatientsInfectiousDiseases
  233. //diseases := models.CdmPatientsChronicDiseases{}
  234. //ids := make([]int64, 0)
  235. //err := PatientReadDB().Model(&diseases).Where("patient_id = ? and status =1", id).Find(&ids).Error
  236. //if err != nil || len(dis) == 0 {
  237. // return ids
  238. //}
  239. //for _, item := range dis {
  240. // ids = append(ids, item.DiseaseId)
  241. //}
  242. //return ids
  243. err = PatientReadDB().Model(&infeciousdisease).Where("patient_id = ? and status =1", id).Find(&infeciousdisease).Error
  244. return infeciousdisease, err
  245. }
  246. func GetCronicDiseases(id int64) (chronic []*models.CdmPatientsChronicDiseases, err error) {
  247. //var dis []models.CdmPatientsChronicDiseases
  248. //ids := make([]int64, 0)
  249. //err := PatientReadDB().Model(&models.CdmPatientsChronicDiseases{}).Where("patient_id = ? and status =1", id).Find(&ids).Error
  250. //if err != nil || len(dis) == 0 {
  251. // return ids
  252. //}
  253. //for _, item := range dis {
  254. // ids = append(ids, item.DiseaseId)
  255. //}
  256. //return ids
  257. err = PatientReadDB().Model(&chronic).Where("patient_id = ? and status =1", id).Find(&chronic).Error
  258. return chronic, err
  259. }
  260. func CreatePatientTwo(patient *models.Patients, contagions []int64, diseases []int64) (err error) {
  261. user, _ := GetSgjUserByMobild(patient.Phone)
  262. customer, _ := GetSgjCoustomerByMobile(patient.UserOrgId, patient.Phone)
  263. utx := writeDb.Begin()
  264. btx := writeUserDb.Begin()
  265. if user.ID == 0 {
  266. user.Mobile = patient.Phone
  267. user.Avatar = patient.Avatar
  268. user.AvatarThumb = patient.Avatar
  269. user.Birthday = patient.Birthday
  270. user.Username = patient.Name
  271. user.Gender = patient.Gender
  272. user.Sources = 11
  273. user.Introduce = patient.Remark
  274. user.Status = 1
  275. user.UpdatedTime = patient.UpdatedTime
  276. user.CreatedTime = patient.CreatedTime
  277. err = btx.Create(&user).Error
  278. if err != nil {
  279. utx.Rollback()
  280. btx.Rollback()
  281. return
  282. }
  283. }
  284. patient.UserId = user.ID
  285. if customer == nil {
  286. err = btx.Create(&models.SgjCustomer{
  287. UserOrgId: patient.UserOrgId,
  288. UserId: user.ID,
  289. Mobile: patient.Phone,
  290. Name: patient.Name,
  291. Gender: patient.Gender,
  292. Birthday: patient.Birthday,
  293. Sources: 11,
  294. Status: 1,
  295. CreatedTime: patient.CreatedTime,
  296. UpdatedTime: patient.UpdatedTime,
  297. Avatar: patient.Avatar,
  298. Remark: patient.Remark,
  299. }).Error
  300. if err != nil {
  301. utx.Rollback()
  302. btx.Rollback()
  303. return
  304. }
  305. }
  306. err = utx.Create(patient).Error
  307. if err != nil {
  308. utx.Rollback()
  309. btx.Rollback()
  310. return
  311. }
  312. var lapseto models.PatientLapseto
  313. lapseto.PatientId = patient.ID
  314. lapseto.LapsetoType = patient.Lapseto
  315. lapseto.CreatedTime = patient.CreatedTime
  316. lapseto.UpdatedTime = patient.CreatedTime
  317. lapseto.Status = 1
  318. lapseto.LapsetoTime = patient.CreatedTime
  319. err = utx.Create(&lapseto).Error
  320. if err != nil {
  321. utx.Rollback()
  322. btx.Rollback()
  323. return
  324. }
  325. if len(contagions) > 0 {
  326. thisSQL := "INSERT INTO xt_patients_infectious_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  327. insertParams := make([]string, 0)
  328. insertData := make([]interface{}, 0)
  329. for _, contagion := range contagions {
  330. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  331. insertData = append(insertData, patient.ID)
  332. insertData = append(insertData, contagion)
  333. insertData = append(insertData, 1)
  334. insertData = append(insertData, patient.CreatedTime)
  335. insertData = append(insertData, patient.UpdatedTime)
  336. }
  337. thisSQL += strings.Join(insertParams, ", ")
  338. err = utx.Exec(thisSQL, insertData...).Error
  339. if err != nil {
  340. utx.Rollback()
  341. btx.Rollback()
  342. return
  343. }
  344. }
  345. if len(diseases) > 0 {
  346. thisSQL := "INSERT INTO xt_patients_chronic_diseases (patient_id, disease_id, status, created_time, updated_time) VALUES "
  347. insertParams := make([]string, 0)
  348. insertData := make([]interface{}, 0)
  349. for _, disease := range diseases {
  350. insertParams = append(insertParams, "(?, ?, ?, ?, ?)")
  351. insertData = append(insertData, patient.ID)
  352. insertData = append(insertData, disease)
  353. insertData = append(insertData, 1)
  354. insertData = append(insertData, patient.CreatedTime)
  355. insertData = append(insertData, patient.UpdatedTime)
  356. }
  357. thisSQL += strings.Join(insertParams, ", ")
  358. err = utx.Exec(thisSQL, insertData...).Error
  359. if err != nil {
  360. utx.Rollback()
  361. btx.Rollback()
  362. return
  363. }
  364. }
  365. utx.Commit()
  366. btx.Commit()
  367. return
  368. }
  369. func FindPatientByIdCardNoOne(orgID int64, idCardNo string) (patient models.Patients, err error) {
  370. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and id_card_no=?", orgID, idCardNo).First(&patient).Error
  371. return
  372. }
  373. func FindPatientByDialysisNoOne(orgID int64, dialysisNo string) (patient models.Patients, err error) {
  374. err = readDb.Model(&models.Patients{}).Where("status=1 and user_org_id=? and dialysis_no=?", orgID, dialysisNo).First(&patient).Error
  375. return
  376. }
  377. func FindPatientByMobileOne(mobile string, orgID int64) (patient models.Patients, err error) {
  378. err = readDb.Model(&models.Patients{}).Where("phone=? and user_org_id=? and status=1", mobile, orgID).First(&patient).Error
  379. return
  380. }
  381. func GetPatientData(phone string, orgid int64) (*models.XtPatientsNew, error) {
  382. var patientnew models.XtPatientsNew
  383. var err error
  384. err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status =? and blood_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
  385. if err == gorm.ErrRecordNotFound {
  386. return nil, err
  387. }
  388. if err != nil {
  389. return nil, err
  390. }
  391. return &patientnew, nil
  392. }
  393. func GetSlowPatientData(phone string, orgid int64) (*models.CdmPatients, error) {
  394. var patientnew models.CdmPatients
  395. err = PatientReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ?", orgid, phone, 1).Find(&patientnew).Error
  396. if err == gorm.ErrRecordNotFound {
  397. return nil, err
  398. }
  399. if err != nil {
  400. return nil, err
  401. }
  402. return &patientnew, nil
  403. }
  404. func GetMemberNewPatient(phone string, orgid int64) (*models.XtPatientsNew, error) {
  405. var patientnew models.XtPatientsNew
  406. err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ? and member_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
  407. if err == gorm.ErrRecordNotFound {
  408. return nil, err
  409. }
  410. if err != nil {
  411. return nil, err
  412. }
  413. return &patientnew, nil
  414. }
  415. func GetLastMemberPatient(orgid int64) (models.SgjUserCustomer, error) {
  416. customer := models.SgjUserCustomer{}
  417. err := UserReadDB().Model(&customer).Where("user_org_id = ? and status = 1", orgid).Last(&customer).Error
  418. return customer, err
  419. }
  420. func GetLastNewSlowPatient(phone string, orgid int64) (*models.XtPatientsNew, error) {
  421. var patientnew models.XtPatientsNew
  422. err = XTReadDB().Model(&patientnew).Where("user_org_id = ? and phone = ? and status = ? and slow_patients = ?", orgid, phone, 1, 1).Find(&patientnew).Error
  423. if err == gorm.ErrRecordNotFound {
  424. return nil, err
  425. }
  426. if err != nil {
  427. return nil, err
  428. }
  429. return &patientnew, nil
  430. }
  431. func GetNewDoctorAdvice(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvices, total int64, err error) {
  432. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  433. table := UserReadDB().Table("sgj_user_admin_role as r")
  434. fmt.Print("table", table)
  435. if orgID > 0 {
  436. db = db.Where("x.user_org_id=?", orgID)
  437. }
  438. if patientID > 0 {
  439. db = db.Where("x.patient_id = ?", patientID)
  440. }
  441. if advice_type > 0 {
  442. db = db.Where("x.advice_type = ?", advice_type)
  443. } else if advice_type == 0 {
  444. db = db.Where("x.advice_type in (?)", []int{1, 3})
  445. }
  446. if start > 0 {
  447. db = db.Where("x.start_time>=?", start)
  448. }
  449. if end > 0 {
  450. db = db.Where("start_time<=?", end)
  451. }
  452. //offset := (page - 1) * limit
  453. 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, 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").Order("start_time desc, groupno desc, advice_order desc, id asc").Scan(&doctoradvice).Error
  454. fmt.Print("err", err)
  455. return
  456. }
  457. func GetNewDoctorAdviceOne(patientID int64, advice_type int64, start int64, end int64, limit int64, page int64, orgID int64) (doctoradvice []*models.DoctorAdvice, total int64, err error) {
  458. db := readDb.Table("xt_doctor_advice as x").Where("x.status = 1")
  459. table := UserReadDB().Table("sgj_user_admin_role as r")
  460. fmt.Println("table", table)
  461. if orgID > 0 {
  462. db = db.Where("x.user_org_id=?", orgID)
  463. }
  464. if patientID > 0 {
  465. db = db.Where("x.patient_id = ?", patientID)
  466. }
  467. if advice_type > 0 {
  468. db = db.Where("x.advice_type = ?", advice_type)
  469. } else if advice_type == 0 {
  470. db = db.Where("x.advice_type in (?)", []int{1, 3})
  471. }
  472. if start > 0 {
  473. db = db.Where("x.start_time>=?", start)
  474. }
  475. if end > 0 {
  476. db = db.Where("start_time<=?", end)
  477. }
  478. offset := (page - 1) * limit
  479. err = db.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, 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").Order("start_time desc").Scan(&doctoradvice).Error
  480. fmt.Print("错误是什么东西", err)
  481. return
  482. }
  483. func GetDryWeight(patientid int64, startime int64, endtime int64, limit int64, page int64, orgId int64) (dryWeight []*models.XtPatientDryweight, total int64, err error) {
  484. db := XTReadDB().Table("xt_patient_dryweight as x").Where("x.status = 1")
  485. if orgId > 0 {
  486. db = db.Where("x.user_org_id = ?", orgId)
  487. }
  488. if patientid > 0 {
  489. db = db.Where("x.patient_id = ?", patientid)
  490. }
  491. if startime > 0 {
  492. db = db.Where("x.ctime >= ?", startime)
  493. }
  494. if endtime > 0 {
  495. db = db.Where("x.ctime <=?", endtime)
  496. }
  497. offset := (page - 1) * limit
  498. err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
  499. 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
  500. return dryWeight, total, err
  501. }
  502. func ToSearch(orgId int64, name string) (patient []*models.XtPatientsNew, err error) {
  503. likeKey := "%" + name + "%"
  504. err = XTReadDB().Where("name like ? and user_org_id = ?", likeKey, orgId).Find(&patient).Error
  505. return patient, err
  506. }
  507. func GetCourseManagement(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (patientCourse []*models.PatientCourseOfDiseases, total int64, err error) {
  508. db := XTReadDB().Table("xt_patient_course_of_disease as x").Where("x.status = 1")
  509. if patientid > 0 {
  510. db = db.Where("x.patient_id = ?", patientid)
  511. }
  512. if orgid > 0 {
  513. db = db.Where("x.org_id = ?", orgid)
  514. }
  515. if startime > 0 {
  516. db = db.Where("x.record_time >=?", startime)
  517. }
  518. if endtime > 0 {
  519. db = db.Where("x.record_time <= ?", endtime)
  520. }
  521. offset := (page - 1) * limit
  522. err = db.Count(&total).Order("x.ctime desc").Offset(offset).Limit(limit).Group("x.id").
  523. 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
  524. return patientCourse, total, err
  525. }
  526. func DeleteCouseManagement(patientid int64) error {
  527. err := XTWriteDB().Model(models.PatientCourseOfDisease{}).Where("id = ?", patientid).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  528. return err
  529. }
  530. func GetCouseManagentDetail(id int64) (models.PatientCourseOfDiseasess, error) {
  531. disease := models.PatientCourseOfDiseasess{}
  532. db := XTReadDB().Table("xt_patient_course_of_disease as x")
  533. 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
  534. return disease, err
  535. }
  536. func DeleteDryWeight(id int64) error {
  537. err := XTWriteDB().Model(models.SgjPatientDryweight{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  538. return err
  539. }
  540. func GetDryWeightDetail(id int64) (models.SgjPatientDryweights, error) {
  541. dryweight := models.SgjPatientDryweights{}
  542. db := XTReadDB().Table("xt_patient_dryweight as x")
  543. 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
  544. return dryweight, err
  545. }
  546. func GetlongDialysisrecord(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (prescription []*models.XtDialysisSolution, total int64, err error) {
  547. db := XTReadDB().Table("xt_dialysis_solution as x").Where("x.status = 1")
  548. if patientid > 0 {
  549. db = db.Where("x.patient_id = ?", patientid)
  550. }
  551. if orgid > 0 {
  552. db = db.Where("x.user_org_id = ?", orgid)
  553. }
  554. if startime > 0 {
  555. db = db.Where("x.created_time >=?", startime)
  556. }
  557. if endtime > 0 {
  558. db = db.Where("x.created_time <= ?", endtime)
  559. }
  560. offset := (page - 1) * limit
  561. err = db.Count(&total).Order("x.created_time desc").Offset(offset).Limit(limit).Group("x.id").
  562. 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").Find(&prescription).Error
  563. return
  564. }
  565. func GetRescuerecord(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (rescuerecord []*models.XtPatientRescueRecords, total int64, err error) {
  566. db := XTReadDB().Table("xt_patient_rescue_record as x").Where("x.status = 1")
  567. if patientid > 0 {
  568. db = db.Where("x.patient_id = ?", patientid)
  569. }
  570. if orgid > 0 {
  571. db = db.Where("x.org_id = ?", orgid)
  572. }
  573. if startime > 0 {
  574. db = db.Where("x.record_time >=?", startime)
  575. }
  576. if endtime > 0 {
  577. db = db.Where("x.record_time <= ?", endtime)
  578. }
  579. offset := (page - 1) * limit
  580. err = db.Count(&total).Order("x.record_time desc").Offset(offset).Limit(limit).Group("x.id").
  581. 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
  582. return
  583. }
  584. func GetScheduling(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64, modeType int64) (schedules []*models.XtSchedules, total int64, err error) {
  585. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  586. if patientid > 0 {
  587. db = db.Where("x.patient_id = ?", patientid)
  588. }
  589. if orgid > 0 {
  590. db = db.Where("x.user_org_id = ?", orgid)
  591. }
  592. if startime > 0 {
  593. db = db.Where("x.schedule_date >=?", startime)
  594. }
  595. if endtime > 0 {
  596. db = db.Where("x.schedule_date <= ?", endtime)
  597. }
  598. if modeType > 0 {
  599. db = db.Where("x.mode_id = ?", modeType)
  600. }
  601. offset := (page - 1) * limit
  602. err = db.Count(&total).Order("x.schedule_date desc").Offset(offset).Limit(limit).Group("x.id").
  603. 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
  604. return
  605. }
  606. func GetEducation(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64) (treatment []*models.XtTreatmentSummary, total int64, err error) {
  607. db := XTReadDB().Table("xt_treatment_summary as x").Where("x.status = 1")
  608. if patientid > 0 {
  609. db = db.Where("x.patient_id = ?", patientid)
  610. }
  611. if orgid > 0 {
  612. db = db.Where("x.user_org_id = ?", orgid)
  613. }
  614. if startime > 0 {
  615. db = db.Where("x.assessment_date >=?", startime)
  616. }
  617. if endtime > 0 {
  618. db = db.Where("x.assessment_date <= ?", endtime)
  619. }
  620. offset := (page - 1) * limit
  621. err = db.Count(&total).Order("x.assessment_date desc").Offset(offset).Limit(limit).Group("x.id").
  622. 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
  623. return
  624. }
  625. func GetSchedulingDetail(id int64) (models.XtScheduless, error) {
  626. schedules := models.XtScheduless{}
  627. db := XTReadDB().Table("xt_schedule as x")
  628. 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
  629. return schedules, err
  630. }
  631. func GetSchedulingTwo(id int64) (models.XtScheduless, error) {
  632. schedules := models.XtScheduless{}
  633. db := XTReadDB().Table("xt_schedule as x")
  634. 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
  635. return schedules, err
  636. }
  637. func DeleteScheduling(id int64) error {
  638. err := XTWriteDB().Model(models.XtSchedules{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  639. return err
  640. }
  641. func GetEducationDetailOne(id int64) (models.XtTreatmentSummarys, error) {
  642. summarys := models.XtTreatmentSummarys{}
  643. db := XTReadDB().Table("xt_treatment_summary as x")
  644. 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
  645. return summarys, err
  646. }
  647. func DeleteEducation(id int64) error {
  648. err := XTWriteDB().Model(models.XtTreatmentSummary{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  649. return err
  650. }
  651. func GetRescueRecordDetail(id int64) (models.XtPatientRescueRecords, error) {
  652. records := models.XtPatientRescueRecords{}
  653. db := XTReadDB().Table("xt_patient_rescue_record as x")
  654. 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
  655. return records, err
  656. }
  657. func DeleteRescueRecord(id int64) error {
  658. err := XTWriteDB().Model(models.XtPatientRescueRecord{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  659. return err
  660. }
  661. func ToSearchePatient(keyword string, orgId int64) (paitents []*models.XtPatientsNew, err error) {
  662. likeKey := "%" + keyword + "%"
  663. err = XTReadDB().Where("name like ? or dialysis_no like ? and user_org_id = ?", likeKey, likeKey, orgId).Find(&paitents).Error
  664. return paitents, err
  665. }
  666. func SearchallPatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
  667. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1")
  668. if len(keyword) > 0 {
  669. likeKey := "%" + keyword + "%"
  670. db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
  671. }
  672. if orgid > 0 {
  673. db = db.Where("x.user_org_id = ?", orgid)
  674. }
  675. 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
  676. return patients, err
  677. }
  678. func GetSearchallBlood(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
  679. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.blood_patients = 1")
  680. if len(keyword) > 0 {
  681. likeKey := "%" + keyword + "%"
  682. db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
  683. }
  684. if orgid > 0 {
  685. db = db.Where("x.user_org_id = ?", orgid)
  686. }
  687. 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
  688. return patients, err
  689. }
  690. func GetSlowSearchePatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
  691. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.slow_patients = 1")
  692. if len(keyword) > 0 {
  693. likeKey := "%" + keyword + "%"
  694. db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
  695. }
  696. if orgid > 0 {
  697. db = db.Where("x.user_org_id = ?", orgid)
  698. }
  699. 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
  700. return patients, err
  701. }
  702. func GetMemberSearchPatient(keyword string, orgid int64) (patients []*models.XtPatientsNew, err error) {
  703. db := XTReadDB().Table("xt_patients_new as x").Where("x.status = 1 and x.member_patients = 1")
  704. if len(keyword) > 0 {
  705. likeKey := "%" + keyword + "%"
  706. db = db.Where("x.name LIKE ? OR x.dialysis_no LIKE ?", likeKey, likeKey)
  707. }
  708. if orgid > 0 {
  709. db = db.Where("x.user_org_id = ?", orgid)
  710. }
  711. 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
  712. return patients, err
  713. }
  714. func GetLongDialysisDetail(id int64) (models.XtDialysisSolution, error) {
  715. solution := models.XtDialysisSolution{}
  716. err := XTReadDB().Model(&solution).Where("id=? and status =1", id).Find(&solution).Error
  717. return solution, err
  718. }
  719. func GetPatientName(id int64) (models.Patients, error) {
  720. patientsNew := models.Patients{}
  721. err := XTReadDB().Model(&patientsNew).Where("id=? and status = 1", id).Find(&patientsNew).Error
  722. return patientsNew, err
  723. }
  724. func DeleteLongDialysis(id int64) error {
  725. err := XTWriteDB().Model(models.XtDialysisSolution{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  726. return err
  727. }
  728. func GetDialysisrecord(patientID int64, start int64, end int64, limit int64, page int64, orgID int64, mode_id int64) ([]*models.PatientDialysisRecord, int64, error) {
  729. offset := (page - 1) * limit
  730. var total int64
  731. var err error
  732. var orders []*models.PatientDialysisRecord
  733. db := readDb.Table("xt_dialysis_order as do").
  734. Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  735. Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  736. Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
  737. return readDb.Where("patient_id=? and user_org_id=? and status=1", patientID, orgID).Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
  738. return readUserDb.Where("status = 1")
  739. })
  740. }).
  741. Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  742. Preload("TreatmentSummary", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
  743. Preload("Device", "org_id=? and status=1", orgID).
  744. Preload("UserAdminRole", func(db *gorm.DB) *gorm.DB {
  745. return readUserDb.Where("org_id=? and status = 1", orgID)
  746. }).
  747. 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).
  748. Joins("JOIN xt_device_zone as dz ON dz.org_id = ? and dz.id=s.partition_id", orgID).
  749. Where("do.patient_id=? and do.user_org_id=? and do.stage = 2 and do.status=1", patientID, orgID).Group("s.schedule_date")
  750. if start > 0 {
  751. db = db.Where("do.dialysis_date>=?", start)
  752. }
  753. if end > 0 {
  754. db = db.Where("do.dialysis_date<=?", end)
  755. }
  756. if mode_id > 0 {
  757. db = db.Joins("JOIN xt_dialysis_prescription as dp ON dp.record_id=do.id")
  758. db = db.Where("dp.mode_id=?", mode_id)
  759. }
  760. 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
  761. if len(orders) > 0 {
  762. ids := make([]int64, 0)
  763. for _, order := range orders {
  764. dialyzer := order.DialysisPrescription.Dialyzer
  765. ids = append(ids, dialyzer)
  766. }
  767. if len(ids) > 0 {
  768. var dialyzers []*models.DeviceNumber
  769. err = readDb.Model(&models.DeviceNumber{}).Where("id IN (?) and org_id=? and status=1", ids, orgID).Find(&dialyzers).Error
  770. if err != nil {
  771. return nil, 0, err
  772. }
  773. dialyzerMap := make(map[int64]models.DeviceNumber, 0)
  774. for _, item := range dialyzers {
  775. dialyzerMap[item.ID] = *item
  776. }
  777. for orderIndex, order := range orders {
  778. if _, exist := dialyzerMap[order.DialysisPrescription.Dialyzer]; exist {
  779. orders[orderIndex].DeviceNumber = dialyzerMap[order.DialysisPrescription.Dialyzer].Number
  780. }
  781. }
  782. }
  783. }
  784. return orders, total, err
  785. }
  786. func GetAllDoctorTwo(orgid int64, appid int64) (appRole []*models.SgjUserAdminRole, err error) {
  787. err = UserReadDB().Where("org_id = ? and app_id = ? and status = ? ", orgid, appid, 1).Find(&appRole).Error
  788. return appRole, err
  789. }
  790. func GetDoctorAdviceDetail(id int64, orgid int64) (advices []*models.DoctorAdvices, err error) {
  791. db := XTReadDB().Table("xt_doctor_advice as x")
  792. 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.groupno = ? and x.status = 1 and x.user_org_id = ?", id, orgid).Scan(&advices).Error
  793. return advices, err
  794. }
  795. func DeleteManagement(groupid int64, orgid int64) error {
  796. err := XTWriteDB().Model(models.DoctorAdvice{}).Where("groupno=? and user_org_id = ?", groupid, orgid).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  797. return err
  798. }
  799. func DeleteChild(id int64) error {
  800. err := XTWriteDB().Model(models.DoctorAdvice{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  801. return err
  802. }
  803. func DeletePatient(id int64) error {
  804. err = XTWriteDB().Model(models.DoctorAdvice{}).Where("id=? and parent_id = ?", id, id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  805. return err
  806. }
  807. func GetNewPatient(id int64) (models.XtPatientsNew, error) {
  808. patientsNew := models.XtPatientsNew{}
  809. err := XTReadDB().Model(&patientsNew).Where("id=?", id).Find(&patientsNew).Error
  810. return patientsNew, err
  811. }
  812. func UpdatedPatient(patients models.Patients, id int64) error {
  813. 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}).Error
  814. return err
  815. }
  816. func UpdateXtPatientNew(patients models.XtPatientsNew, id int64) error {
  817. 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}).Error
  818. return err
  819. }
  820. func UpdateContagions(patientid int64) (models.XtPatientsInfectiousDiseases, error) {
  821. diseases := models.XtPatientsInfectiousDiseases{}
  822. err := XTWriteDB().Model(&diseases).Where("patient_id = ?", patientid).Update(map[string]interface{}{"status": 2, "updated_time": time.Now().Unix()}).Error
  823. return diseases, err
  824. }
  825. func UpdateCustomer(cdmpatient models.CdmPatients, id int64) error {
  826. 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
  827. return err
  828. }
  829. func UpdatedCustomer(customer models.SgjUserCustomer, id int64) error {
  830. 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
  831. return err
  832. }
  833. func GetInspectionByOrgId(orgid int64) (*models.XtInspectionReference, error) {
  834. diseases := models.XtInspectionReference{}
  835. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  836. if err == gorm.ErrRecordNotFound {
  837. return nil, err
  838. }
  839. if err != nil {
  840. return nil, err
  841. }
  842. return &diseases, nil
  843. }
  844. func GetAllInspection(orgid int64) (inspection []*models.XtInspectionReference, err error) {
  845. err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&inspection).Error
  846. return inspection, err
  847. }
  848. func GetInspection(patientid int64, startime int64, endtime int64, limit int64, page int64, orgid int64, projectid int64) (inspection []*models.Inspection, total int64, err error) {
  849. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  850. if patientid > 0 {
  851. db = db.Where("x.patient_id = ?", patientid)
  852. }
  853. if startime > 0 {
  854. db = db.Where("x.inspect_date >= ?", startime)
  855. }
  856. if endtime > 0 {
  857. db = db.Where("x.inspect_date<=?", endtime)
  858. }
  859. if orgid > 0 {
  860. db = db.Where("x.org_id = ?", orgid)
  861. }
  862. if projectid > 0 {
  863. db = db.Where("x.project_id = ?", projectid)
  864. }
  865. err = db.Count(&total).Order("x.inspect_date desc").Group("x.id").
  866. 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
  867. return inspection, total, err
  868. }
  869. func GetInspectionDetail(patientid int64, date int64, orgid int64, projectid int64) (inspection []*models.Inspections, err error) {
  870. db := XTReadDB().Table("xt_inspection as x").Where("x.status =1")
  871. table := XTReadDB().Table("xt_inspection_reference as r")
  872. fmt.Print("table", table)
  873. if patientid > 0 {
  874. db = db.Where("x.patient_id = ?", patientid)
  875. }
  876. if date > 0 {
  877. db = db.Where("x.inspect_date = ?", date)
  878. }
  879. if orgid > 0 {
  880. db = db.Where("x.org_id = ?", orgid)
  881. }
  882. if projectid > 0 {
  883. db = db.Where("x.project_id = ?", projectid)
  884. }
  885. 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,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.id = x.item_id ").Scan(&inspection).Error
  886. return inspection, err
  887. }
  888. func CreateFeedBack(feedback *models.XtPatientFeedback) error {
  889. err := XTWriteDB().Model(&feedback).Create(&feedback).Error
  890. return err
  891. }
  892. func DeleteInspection(date int64, orgid int64) error {
  893. 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
  894. return err
  895. }
  896. func DeleteChildInspection(name string, date int64, orgid int64) error {
  897. 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
  898. return err
  899. }
  900. func SaveMessage(id int64, role *models.SgjUserAdminRole) error {
  901. err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("id = ?", id).Update(map[string]interface{}{"message": role.Message, "mtime": time.Now().Unix()}).Error
  902. return err
  903. }
  904. func SaveSex(id int64, role *models.SgjUserAdminRole) error {
  905. err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("id = ?", id).Update(map[string]interface{}{"sex": role.Sex, "mtime": time.Now().Unix()}).Error
  906. return err
  907. }
  908. func SaveBirthday(id int64, role *models.SgjUserAdminRole) error {
  909. err := UserWriteDB().Model(models.SgjUserAdminRole{}).Where("id = ?", id).Update(map[string]interface{}{"birthday": role.Birthday, "mtime": time.Now().Unix()}).Error
  910. return err
  911. }
  912. func CreatedZone(zone *models.DeviceZone) error {
  913. err := XTWriteDB().Model(&zone).Create(&zone).Error
  914. return err
  915. }
  916. func GetAllZone(orgid int64, page int64, limit int64) (zone []*models.DeviceZones, total int64, err error) {
  917. db := XTReadDB().Table("xt_device_zone as x").Where("x.status =1")
  918. table := XTReadDB().Table("xt_device_number as n")
  919. fmt.Println("table", table)
  920. if orgid > 0 {
  921. db = db.Where("x.org_id = ?", orgid)
  922. }
  923. offset := (page - 1) * limit
  924. 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
  925. return zone, total, err
  926. }
  927. func DeleteZoneById(id int64) error {
  928. err := XTWriteDB().Model(models.DeviceZone{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  929. return err
  930. }
  931. func SaveGroup(group *models.DeviceGroup) error {
  932. err := XTWriteDB().Model(&group).Create(&group).Error
  933. return err
  934. }
  935. func GetAllGroup(orgid int64, page int64, limit int64) (group []*models.DeviceGroups, total int64, err error) {
  936. db := XTReadDB().Table("xt_device_group as x").Where("x.status = 1")
  937. table := XTReadDB().Table("xt_device_number as n")
  938. fmt.Println("table", table)
  939. if orgid > 0 {
  940. db = db.Where("x.org_id = ?", orgid)
  941. }
  942. offset := (page - 1) * limit
  943. 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
  944. return group, total, err
  945. }
  946. func DeleteGroup(id int64) error {
  947. err := XTWriteDB().Model(models.DeviceGroup{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  948. return err
  949. }
  950. func GetAllZoneOne(orgid int64) (zone []*models.DeviceZone, err error) {
  951. err = XTReadDB().Model(&zone).Where("org_id = ?", orgid).Find(&zone).Error
  952. return zone, err
  953. }
  954. func GetAllGroupOne(orgid int64) (group []*models.DeviceGroup, err error) {
  955. err = XTReadDB().Model(&group).Where("org_id =?", orgid).Find(&group).Error
  956. return group, err
  957. }
  958. func CreateNumber(number *models.DeviceNumber) error {
  959. err := XTWriteDB().Model(&number).Create(&number).Error
  960. return err
  961. }
  962. func GetAllNumber(page int64, limit int64, orgid int64) (number []*models.DeviceNumber, total int64, err error) {
  963. db := XTReadDB().Table("xt_device_number as x").Where("x.status = 1")
  964. if orgid > 0 {
  965. db = db.Where("x.org_id = ?", orgid)
  966. }
  967. offset := (page - 1) * limit
  968. 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
  969. return number, total, err
  970. }
  971. func DeleteBed(id int64) error {
  972. err := XTWriteDB().Model(models.DeviceNumber{}).Where("id=?", id).Update(map[string]interface{}{"status": 0, "ctime": time.Now().Unix()}).Error
  973. return err
  974. }
  975. func GetMemberPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
  976. err = XTReadDB().Model(&patients).Where("user_org_id = ? AND member_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
  977. return patients, err
  978. }
  979. func GetSlowPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
  980. err = XTReadDB().Model(&patients).Where("user_org_id = ? AND slow_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
  981. return patients, err
  982. }
  983. func GetBloodPatient(orgid int64) (patients []*models.XtPatientsNew, err error) {
  984. err = XTReadDB().Model(&patients).Where("user_org_id = ? AND blood_patients = ? AND status = 1", orgid, 1).Find(&patients).Error
  985. return patients, err
  986. }
  987. func SaveName(id int64, role *models.SgjUserAdminRole) error {
  988. err = UserWriteDB().Model(models.SgjUserAdminRole{}).Where("id=?", id).Update(map[string]interface{}{"user_name": role.UserName, "mtime": time.Now().Unix()}).Error
  989. return err
  990. }
  991. func GetAdminUserId(id int64) (models.SgjUserAdminRole, error) {
  992. role := models.SgjUserAdminRole{}
  993. err := UserReadDB().Where("id=? and status =1", id).Find(&role).Error
  994. return role, err
  995. }
  996. func GetMyOrganaziton(id int64) (org []*models.SgjUserOrg, err error) {
  997. db := UserReadDB().Table("sgj_user_org as x").Where("x.status = 1")
  998. table := UserReadDB().Table("sgj_user_admin as a")
  999. fmt.Println("table", table)
  1000. 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
  1001. return org, err
  1002. }
  1003. func GetOrgInformation(id int64) (models.SgjUserOrg, error) {
  1004. org := models.SgjUserOrg{}
  1005. fmt.Println("hhh")
  1006. err := UserReadDB().Where("id=? and status = 1", id).Find(&org).Error
  1007. return org, err
  1008. }
  1009. func GetShortName(orgtype int64) (models.SgjUserOrgType, error) {
  1010. orgType := models.SgjUserOrgType{}
  1011. err := UserReadDB().Model(&orgType).Where("id=? and status = 1", orgtype).Find(&orgType).Error
  1012. return orgType, err
  1013. }
  1014. func GetTypeName(id int64) (models.SgjUserOrgType, error) {
  1015. orgType := models.SgjUserOrgType{}
  1016. err := UserReadDB().Model(&orgType).Where("id=? and status = 1", id).Find(&orgType).Error
  1017. return orgType, err
  1018. }
  1019. func GetOrgProvince(id int64) (models.SgjUserDistrict, error) {
  1020. district := models.SgjUserDistrict{}
  1021. err := UserReadDB().Model(&district).Where("id=?", id).Find(&district).Error
  1022. return district, err
  1023. }
  1024. func GetAllOrgType() (orgType []*models.SgjUserOrgType, err error) {
  1025. 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
  1026. return
  1027. }
  1028. func UpdateOrg(id int64, org models.SgjUserOrg) error {
  1029. 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
  1030. return err
  1031. }
  1032. func GetMyInfoName(id int64) (models.SgjUserAdminRole, error) {
  1033. role := models.SgjUserAdminRole{}
  1034. err := UserReadDB().Model(&role).Where("id=? and status = 1", id).Find(&role).Error
  1035. return role, err
  1036. }
  1037. func GetAdminName(id int64) (models.AdminUser, error) {
  1038. user := models.AdminUser{}
  1039. err := UserReadDB().Model(&user).Where("id=? and status =1", id).Find(&user).Error
  1040. return user, err
  1041. }