his_project_service.go 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. func GetHisProjectIsExist(projectName string, orgid int64) (*models.XtHisProject, error) {
  8. var project models.XtHisProject
  9. var err error
  10. err = XTReadDB().Model(&project).Where("project_name = ? and user_org_id = ? and status = 1", projectName, orgid).Find(&project).Error
  11. if err == gorm.ErrRecordNotFound {
  12. return nil, err
  13. }
  14. if err != nil {
  15. return nil, err
  16. }
  17. return &project, nil
  18. }
  19. func CreateHisProject(project *models.XtHisProject) error {
  20. err := XTWriteDB().Model(&project).Create(&project).Error
  21. return err
  22. }
  23. func GetHisProjectList(orgid int64, limit int64, page int64, charge int64, start int64, keyword string, isMark int64) (hisproject []*models.XtHisProject, total int64, err error) {
  24. offset := (page - 1) * limit
  25. likeKey := "%" + keyword + "%"
  26. db := XTReadDB().Table("xt_his_project as x").Where("x.status = 1")
  27. if orgid > 0 {
  28. db = db.Where("x.user_org_id = ?", orgid)
  29. }
  30. if start > 0 {
  31. db = db.Where("x.medical_status = ?", start)
  32. }
  33. if charge > 0 {
  34. db = db.Where("x.is_estimate = ? ", charge)
  35. }
  36. if len(keyword) > 0 {
  37. db = db.Where("x.project_name like ?", likeKey)
  38. }
  39. if isMark > 0 {
  40. db = db.Where("x.is_mark = ?", isMark)
  41. }
  42. err = db.Select("x.id,x.project_name,x.pinyin,x.wubi,x.price,x.unit,x.cost_classify,x.executive_section,x.medical_coverage,x.statistical_classification,x.disease_directory,x.is_record,x.medical_code,x.tube_color,x.medical_status,x.remark,x.sign,x.default_number,x.is_default,x.is_charge,x.is_estimate,x.is_workload,x.sort,x.doctor_advice,x.user_org_id,x.status,x.created_time,x.is_mark,x.social_security_directory_code").Count(&total).Offset(offset).Limit(limit).Order("created_time desc").Find(&hisproject).Error
  43. return hisproject, total, err
  44. }
  45. func GetProjectDetail(id int64) (models.XtHisProject, error) {
  46. project := models.XtHisProject{}
  47. err := XTReadDB().Model(&project).Where("id=? and status = 1", id).Find(&project).Error
  48. return project, err
  49. }
  50. func UpdatedProject(id int64, pro *models.XtHisProject) error {
  51. err := XTWriteDB().Model(&pro).Where("id=?", id).Updates(map[string]interface{}{"project_name": pro.ProjectName, "pinyin": pro.Pinyin, "wubi": pro.Pinyin, "price": pro.Price, "unit": pro.Unit, "cost_classify": pro.CostClassify, "executive_section": pro.ExecutiveSection, "medical_coverage": pro.MedicalCoverage, "statistical_classification": pro.StatisticalClassification, "disease_directory": pro.DiseaseDirectory, "is_record": pro.IsRecord, "medical_code": pro.MedicalCode, "tube_color": pro.TubeColor, "medical_status": pro.MedicalStatus, "remark": pro.Remark, "sign": pro.Sign, "default_number": pro.DefaultNumber, "is_default": pro.IsDefault, "is_charge": pro.IsCharge, "is_estimate": pro.IsEstimate, "is_workload": pro.IsWorkload, "sort": pro.Sort, "doctor_advice": pro.DoctorAdvice, "single_dose": pro.SingleDose, "execution_frequency": pro.ExecutionFrequency, "delivery_way": pro.DeliveryWay, "number_days": pro.NumberDays, "total": pro.Total, "updated_time": pro.UpdatedTime, "category": pro.Category, "specail_project": pro.SpecailProject, "social_security_directory_code": pro.SocialSecurityDirectoryCode, "record_date": pro.RecordDate, "is_print": pro.IsPrint, "bbx01": pro.Bbx01, "bby01": pro.Bby01, "zuobiao_id": pro.ZuobiaoId}).Error
  52. return err
  53. }
  54. func DeleteHisProject(id int64) error {
  55. project := models.XtHisProject{}
  56. err := XTWriteDB().Model(&project).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
  57. return err
  58. }
  59. func GetHisProjectByNameOne(projectName string, orgid int64) (*models.XtHisProjectTeam, error) {
  60. projectTeam := models.XtHisProjectTeam{}
  61. err := XTReadDB().Model(&projectTeam).Where("project_team = ? and user_org_id = ? and status = 1", projectName, orgid).First(&projectTeam).Error
  62. if err != nil {
  63. if err == gorm.ErrRecordNotFound {
  64. return nil, err
  65. } else {
  66. return nil, err
  67. }
  68. }
  69. return &projectTeam, nil
  70. }
  71. func CreatedProjectTeam(team *models.XtHisProjectTeam) error {
  72. err := XTWriteDB().Model(&team).Create(&team).Error
  73. return err
  74. }
  75. func GetProjectTeamList(limit int64, page int64, orgid int64, keyword string) (projectTeam []*models.XtHisProjectTeam, total int64, err error) {
  76. offset := (page - 1) * limit
  77. likeKey := "%" + keyword + "%"
  78. db := XTReadDB().Model(&projectTeam).Where("status=1")
  79. if len(keyword) > 0 {
  80. db = db.Where("project_team like ?", likeKey)
  81. }
  82. if orgid > 0 {
  83. db = db.Where("user_org_id = ?", orgid)
  84. }
  85. err = db.Count(&total).Offset(offset).Limit(limit).Order("sort asc").Find(&projectTeam).Error
  86. return projectTeam, total, err
  87. }
  88. func GetProjectTeamDetail(id int64) (models.XtHisProjectTeam, error) {
  89. projectTeam := models.XtHisProjectTeam{}
  90. err := XTReadDB().Model(&projectTeam).Where("id= ? and status = 1", id).Find(&projectTeam).Error
  91. return projectTeam, err
  92. }
  93. func UpdatedProjectTeam(id int64, team *models.XtHisProjectTeam) error {
  94. err := XTWriteDB().Model(&team).Where("id=? and status = 1", id).Updates(map[string]interface{}{"project_team": team.ProjectTeam, "price": team.Price, "pinyin": team.Pinyin, "wubi": team.Wubi, "tube_color": team.TubeColor, "team_type": team.TeamType, "remark": team.Remark, "project_id": team.ProjectId, "item_id": team.ItemId, "sort": team.Sort}).Error
  95. return err
  96. }
  97. func DeleteProjectTeam(id int64) error {
  98. team := models.XtHisProjectTeam{}
  99. err := XTWriteDB().Model(&team).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  100. return err
  101. }
  102. func CreateDePartment(department *models.XtHisDepartment) error {
  103. err := XTWriteDB().Model(&department).Create(&department).Error
  104. return err
  105. }
  106. func GetDepartMentList(limit int64, page int64, orgid int64) (departMent []*models.XtHisDepartment, total int64, err error) {
  107. offset := (page - 1) * limit
  108. err = XTReadDB().Model(&departMent).Where("user_org_id = ? and status = 1", orgid).Count(&total).Offset(offset).Limit(limit).Order("created_time desc").Find(&departMent).Error
  109. return departMent, total, err
  110. }
  111. func GetDepartMentDetail(id int64) (models.XtHisDepartment, error) {
  112. department := models.XtHisDepartment{}
  113. err := XTReadDB().Model(&department).Where("id=? and status = 1", id).Find(&department).Error
  114. return department, err
  115. }
  116. func UpdatedDepartment(id int64, department *models.XtHisDepartment) error {
  117. err := XTWriteDB().Model(&department).Where("id=? and status = 1", id).Updates(map[string]interface{}{"name": department.Name, "number": department.Number, "updated_time": time.Now().Unix()}).Error
  118. return err
  119. }
  120. func DeleteDepartment(id int64) error {
  121. department := models.XtHisDepartment{}
  122. err := XTWriteDB().Model(&department).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  123. return err
  124. }
  125. func GetBloodPatientList(orgid int64, startime int64) (schedule []*models.SchedulesVm, err error) {
  126. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  127. if orgid > 0 {
  128. db = db.Where("x.user_org_id = ?", orgid)
  129. }
  130. if startime > 0 {
  131. db = db.Where("x.schedule_date = ?", startime)
  132. }
  133. err = db.Select("x.id,x.user_org_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,p.name,p.id_card_no").Joins("left join xt_patients as p on p.id = x.patient_id").Scan(&schedule).Error
  134. return schedule, err
  135. }
  136. func GetHisPatient(orgid int64, recorddate int64) (paitent []*models.HisPatient, err error) {
  137. err = XTReadDB().Model(&paitent).Where("user_org_id = ? and record_date = ? and status = 1", orgid, recorddate).Find(&paitent).Error
  138. return paitent, err
  139. }
  140. func GetHisPrescriptionOther(orgid int64, recorddate int64) (prescription []*models.HisPrescriptionVm, err error) {
  141. db := XTReadDB().Table("his_prescription as x").Where("x.status = 1")
  142. if orgid > 0 {
  143. db = db.Where("x.user_org_id = ?", orgid)
  144. }
  145. if recorddate > 0 {
  146. db = db.Where("x.record_date = ? ", recorddate)
  147. }
  148. err = db.Select("x.id,x.user_org_id,x.record_date,x.patient_id,x.his_patient_id,x.number,x.type,x.doctor,x.creator,x.modifier,t.name").Joins("left join his_patient as t on t.id = x.his_patient_id").Scan(&prescription).Error
  149. return prescription, err
  150. }
  151. func GetHisPrescriptionByPatientId(id int64, recordate int64) (prescription []*models.HisPrescription, err error) {
  152. err = XTReadDB().Model(&prescription).Where("his_patient_id = ? and record_date = ? and status= 1", id, recordate).Find(&prescription).Error
  153. return prescription, err
  154. }
  155. func CreateAdditionalCharge(charge *models.HisAdditionalCharge) error {
  156. err = XTWriteDB().Model(&charge).Save(&charge).Error
  157. return err
  158. }
  159. func GetTreatmentList(id int64, startime int64) (prescription []*models.HisPrescription, err error) {
  160. err = XTReadDB().Model(&prescription).Where("id = ? and record_date = ? and status = 1", id, startime).Find(&prescription).Error
  161. return prescription, err
  162. }
  163. //func GetAllProjectList(orgid int64) (project []*models.XtHisProject, err error) {
  164. //
  165. // err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  166. // return project, err
  167. //}
  168. func CreateProjectList(list *models.XtHisProjectList) error {
  169. err := XTWriteDB().Model(&list).Create(&list).Error
  170. return err
  171. }
  172. func GetHisProjectListByOrgId(orgid int64) (projectlist []*models.HisProjectListVm, err error) {
  173. db := XTReadDB().Table("xt_his_project_list as x").Where("x.status = 1")
  174. if orgid > 0 {
  175. db = db.Where("x.user_org_id = ? ", orgid)
  176. }
  177. err = db.Select("x.id,x.number,x.user_org_id,x.project_id,t.price,t.unit,t.cost_classify,t.project_name").Joins("left join xt_his_project as t on t.id = x.project_id").Scan(&projectlist).Error
  178. return projectlist, err
  179. }
  180. func GetHisPatientInformation(id int64) (models.HisPatient, error) {
  181. patient := models.HisPatient{}
  182. err := XTReadDB().Model(&patient).Where("id= ? and status = 1", id).Find(&patient).Error
  183. return patient, err
  184. }
  185. func DeleteProjectList(id int64) error {
  186. list := models.XtHisProjectList{}
  187. err := XTWriteDB().Model(&list).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  188. return err
  189. }
  190. func GetHisProject(orgid int64) (project []*models.XtHisProject, err error) {
  191. err = XTReadDB().Model(&project).Where("user_org_id = ? and status =1 and medical_status!=1", orgid).Find(&project).Error
  192. return project, err
  193. }
  194. func GetProjectTeam(ids []string, orgid int64) (project []*models.XtHisProject, err error) {
  195. err = XTReadDB().Model(&project).Where("user_org_id = ? and id in (?)", orgid, ids).Find(&project).Error
  196. return project, err
  197. }
  198. func GetAllDepartMent(orgid int64) (department []*models.XtHisDepartment, err error) {
  199. err = XTReadDB().Model(&department).Where("user_org_id = ? and status =1", orgid).Find(&department).Error
  200. return department, err
  201. }
  202. func CreateHisPatient(patient *models.XtHisPatient) error {
  203. err := XTWriteDB().Model(&patient).Create(&patient).Error
  204. return err
  205. }
  206. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  207. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  208. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  209. return
  210. }
  211. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  212. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date <= ? AND record_date >= ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  213. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  214. return
  215. }
  216. func GetBloodPatientByIdCard(idcard string, orgid int64) (*models.XtPatients, error) {
  217. var patients models.XtPatients
  218. var err error
  219. err = XTReadDB().Model(&patients).Where("id_card_no = ? and user_org_id = ? and status = 1", idcard, orgid).Find(&patients).Error
  220. if err != nil {
  221. if err == gorm.ErrRecordNotFound {
  222. return nil, err
  223. } else {
  224. return nil, err
  225. }
  226. }
  227. return &patients, nil
  228. }
  229. func GetAllProjectTeam(orgid int64) (project []*models.XtHisProjectTeam, err error) {
  230. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  231. return project, err
  232. }
  233. func GetProjectListById(orgid int64, ids []string) (project []*models.XtHisProjectList, err error) {
  234. err = XTReadDB().Model(&project).Preload("XtHisProject", "status = 1").Preload("GoodInfo", "status=1").Where("user_org_id = ? and id in (?) and status = 1", orgid, ids).Find(&project).Error
  235. return project, err
  236. }
  237. func GetHisPatientHistory(keyword string, startime int64, endtime int64, registtype int64, limit int64, page int64, orgid int64) (hisPatient []*models.XtHisPatient, total int64, err error) {
  238. offset := (page - 1) * limit
  239. likeKey := "%" + keyword + "%"
  240. db := XTReadDB().Table("his_patient as x")
  241. if len(keyword) > 0 {
  242. db = db.Where("x.name like ?", likeKey)
  243. }
  244. if startime > 0 {
  245. db = db.Where("x.record_date >= ?", startime)
  246. }
  247. if endtime > 0 {
  248. db = db.Where("x.record_date<=?", endtime)
  249. }
  250. if registtype > 0 {
  251. db = db.Where("x.register_type = ?", registtype)
  252. }
  253. if orgid > 0 {
  254. db = db.Where("x.user_org_id = ?", orgid)
  255. }
  256. err = db.Select("x.id,x.balance_accounts_type,x.medical_insurance_number,x.name,x.gender,x.id_type,x.medical_treatment_type,x.birthday,x.record_date,x.age,x.phone_number,x.id_card_no,x.register_type,x.admin_user_id,x.departments,x.is_need_cost_of_production,x.register_cost,x.treatment_cost,x.cost_of_production,x.total,x.user_org_id,x.patient_id,x.number,x.is_return,x.doctor,x.ctime,x.social_type,x.phone,x.status").Count(&total).Offset(offset).Limit(limit).Order("x.id desc").Find(&hisPatient).Error
  257. return hisPatient, total, err
  258. }
  259. func ChangePatient(id int64) error {
  260. patient := models.XtHisPatient{}
  261. err := XTWriteDB().Model(&patient).Where("id = ?", id).Updates(map[string]interface{}{"is_return": 2}).Error
  262. return err
  263. }
  264. func GetHisPrescriptionTwo(patientid int64, orgid int64, recorddate int64) (*models.HisPrescription, error) {
  265. prescription := models.HisPrescription{}
  266. err := XTReadDB().Model(&prescription).Where("his_patient_id = ? and user_org_id = ? and record_date = ? and status = 1", patientid, orgid, recorddate).Find(&prescription).Error
  267. if err != nil {
  268. if err == gorm.ErrRecordNotFound {
  269. return nil, err
  270. } else {
  271. return nil, err
  272. }
  273. }
  274. return &prescription, nil
  275. }
  276. func UpdatedHisPatient(hispatientid int64, orgid int64, recorddate int64) error {
  277. hisPatient := models.HisPatient{}
  278. err := XTWriteDB().Model(&hisPatient).Where("id = ? and user_org_id = ? and record_date = ?", hispatientid, orgid, recorddate).Updates(map[string]interface{}{"is_return": 3}).Error
  279. return err
  280. }
  281. func GetBloodPatientInfoById(patientid int64) (models.XtPatients, error) {
  282. patients := models.XtPatients{}
  283. err := XTReadDB().Model(&patients).Where("id = ? and status = 1", patientid).Find(&patients).Error
  284. return patients, err
  285. }
  286. func GetPatientCaseHistory(patientid int64) (models.HisPatientCaseHistory, error) {
  287. history := models.HisPatientCaseHistory{}
  288. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patientid).Last(&history).Error
  289. return history, err
  290. }
  291. func GetBloodPatientByPatient(id int64) (models.XtPatients, error) {
  292. patients := models.XtPatients{}
  293. err := XTReadDB().Model(&patients).Where("id = ? and status = 1", id).Find(&patients).Error
  294. return patients, err
  295. }
  296. func GetHisPatientByIdFour(patientid int64) (models.XtHisPatient, error) {
  297. patient := models.XtHisPatient{}
  298. err := XTReadDB().Model(&patient).Where("patient_id = ? and status=1", patientid).Find(&patient).Error
  299. return patient, err
  300. }
  301. func GetHisPatientById(patientid int64) (models.VMHisPatient, error) {
  302. patient := models.VMHisPatient{}
  303. err := XTReadDB().Model(&patient).Where("patient_id = ? and status = 1", patientid).Find(&patient).Error
  304. return patient, err
  305. }
  306. func GetHisPatientByIdTwo(patientid int64) (models.VMHisPatient, error) {
  307. patient := models.VMHisPatient{}
  308. err := XTReadDB().Model(&patient).Where("patient_id = ? and status = 1", patientid).Limit(&patient).Error
  309. return patient, err
  310. }
  311. func GetTemplateDetail(id int64) (models.HisCaseHistoryTemplate, error) {
  312. template := models.HisCaseHistoryTemplate{}
  313. err := XTReadDB().Model(&template).Where("id= ? and status = 1", id).Find(&template).Error
  314. return template, err
  315. }
  316. func UpdateCaseHistoryTemplate(tem *models.HisCaseHistoryTemplate, id int64) error {
  317. err := XTWriteDB().Model(&tem).Where("id = ? ", id).Updates(map[string]interface{}{"history_of_present_illness": tem.HistoryOfPresentIllness, "past_history": tem.PastHistory, "chief_conplaint": tem.ChiefConplaint, "personal_history": tem.PersonalHistory, "family_history": tem.FamilyHistory, "diagnostic": tem.Diagnostic, "template_name": tem.TemplateName, "template_remark": tem.TemplateRemark, "modifier": tem.Modifier, "doctor_advice": tem.DoctorAdvice, "remark": tem.Remark}).Error
  318. return err
  319. }
  320. func GetHistPatient(orgid int64, keyword string) (hisPatient []*models.HisPatient, err error) {
  321. likeKey := "%" + keyword + "%"
  322. err = XTReadDB().Model(&hisPatient).Where("user_org_id = ? and name like ?", orgid, likeKey).Find(&hisPatient).Error
  323. return hisPatient, err
  324. }
  325. func GetDoctorAdvicePrint(his_patient_id int64, recorddate int64, schIDs []string, orgid int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  326. err = XTReadDB().Model(&prescription).Where("patient_id = ? and record_date = ? and id in(?) and status = 1 and p_type = ? ", his_patient_id, recorddate, schIDs, p_type).Preload("Patients", "status = 1 and user_org_id = ?", orgid).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  327. return db.Where("status = 1 and user_org_id = ?", orgid).Preload("Drug", "status = 1")
  328. }).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  329. return db.Where("status = 1 AND user_org_id = ?", orgid).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  330. }).Preload("HisPrescriptionInfo", "status =1 and user_org_id = ? and p_type = ? AND record_date = ?", orgid, p_type, recorddate).Preload("HisAdditionalCharge", "status = 1 and user_org_id = ?", orgid).Find(&prescription).Error
  331. return prescription, err
  332. }
  333. func GetProjectPrint(his_patient_id int64) (models.HisPrescriptionProject, error) {
  334. project := models.HisPrescriptionProject{}
  335. err := XTReadDB().Model(&project).Where("his_patient_id = ? and status = 1", his_patient_id).Find(&project).Error
  336. return project, err
  337. }
  338. func GetHisTemplateId(templateid int64, orgid int64) (*models.XtHisTemplate, error) {
  339. template := models.XtHisTemplate{}
  340. err := XTReadDB().Model(&template).Where("template_id = ? and user_org_id = ? and status = 1", templateid, orgid).Find(&template).Error
  341. if err != nil {
  342. if err == gorm.ErrRecordNotFound {
  343. return nil, err
  344. } else {
  345. return nil, err
  346. }
  347. }
  348. return &template, nil
  349. }
  350. func CreateHisTemplate(template *models.XtHisTemplate) error {
  351. err := XTWriteDB().Create(&template).Error
  352. return err
  353. }
  354. func UpdateHisTemplate(template *models.XtHisTemplate) error {
  355. err := XTWriteDB().Save(&template).Error
  356. return err
  357. }
  358. func GetHisPrintTemplate(orgid int64) (models.XtHisTemplate, error) {
  359. template := models.XtHisTemplate{}
  360. err := XTReadDB().Model(&template).Where("user_org_id = ? and status = 1", orgid).Find(&template).Error
  361. return template, err
  362. }
  363. func GetPrescriptionTemplate(templateid int64, orgid int64) (*models.XtHisAdviceTemplate, error) {
  364. template := models.XtHisAdviceTemplate{}
  365. err := XTReadDB().Model(&template).Where("template_id = ? and user_org_id = ? and status = 1", templateid, orgid).Find(&template).Error
  366. if err != nil {
  367. if err == gorm.ErrRecordNotFound {
  368. return nil, err
  369. } else {
  370. return nil, err
  371. }
  372. }
  373. return &template, nil
  374. }
  375. func CreatePrescriptionTemplate(template *models.XtHisAdviceTemplate) error {
  376. err = XTWriteDB().Create(&template).Error
  377. return err
  378. }
  379. func UpdatePrescriptionTemplate(template *models.XtHisAdviceTemplate) error {
  380. err := XTWriteDB().Save(&template).Error
  381. return err
  382. }
  383. func GetPrescriptionTemplateById(orgid int64) (models.XtHisAdviceTemplate, error) {
  384. template := models.XtHisAdviceTemplate{}
  385. err := XTReadDB().Model(&template).Where("user_org_id = ? and status = 1", orgid).Find(&template).Error
  386. return template, err
  387. }
  388. func GetTreatPrintTemplate(templateid int64, orgid int64) (*models.XtHisTreatmentTemplate, error) {
  389. template := models.XtHisTreatmentTemplate{}
  390. err := XTReadDB().Model(&template).Where("template_id = ? and user_org_id = ? and status = 1", templateid, orgid).Find(&template).Error
  391. if err != nil {
  392. if err == gorm.ErrRecordNotFound {
  393. return nil, err
  394. } else {
  395. return nil, err
  396. }
  397. }
  398. return &template, nil
  399. }
  400. func CreateTreatPrintTemplate(template *models.XtHisTreatmentTemplate) error {
  401. err := XTWriteDB().Create(&template).Error
  402. return err
  403. }
  404. func UpdatedTreateTemplate(template *models.XtHisTreatmentTemplate) error {
  405. err := XTWriteDB().Save(&template).Error
  406. return err
  407. }
  408. func GetTreatTtreatPrintTemplate(orgid int64) (models.XtHisTreatmentTemplate, error) {
  409. template := models.XtHisTreatmentTemplate{}
  410. err := XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&template).Error
  411. return template, err
  412. }
  413. func GetChargeTemplate(templateid int64, orgid int64) (*models.XtHisChargeTemplate, error) {
  414. template := models.XtHisChargeTemplate{}
  415. err := XTReadDB().Model(&template).Where("template_id = ? and user_org_id = ? and status = 1", templateid, orgid).Find(&template).Error
  416. if err != nil {
  417. if err == gorm.ErrRecordNotFound {
  418. return nil, err
  419. } else {
  420. return nil, err
  421. }
  422. }
  423. return &template, nil
  424. }
  425. func CreateChargePrintTemplate(template *models.XtHisChargeTemplate) error {
  426. err := XTWriteDB().Create(&template).Error
  427. return err
  428. }
  429. func UpdateChargePrintTemplate(template *models.XtHisChargeTemplate) error {
  430. err := XTWriteDB().Save(&template).Error
  431. return err
  432. }
  433. func GetChargePrintTemplate(orgid int64) (models.XtHisChargeTemplate, error) {
  434. template := models.XtHisChargeTemplate{}
  435. err := XTReadDB().Model(&template).Where("user_org_id = ? and status = 1", orgid).Find(&template).Error
  436. return template, err
  437. }
  438. func GetDoctorProjectItem(patientid int64, record_date int64) (models.HisPrescriptionProject, error) {
  439. project := models.HisPrescriptionProject{}
  440. err := XTReadDB().Model(&project).Where("patient_id = ? and record_date = ? and status = 1", patientid, record_date).Preload("HisProject").Find(&project).Error
  441. return project, err
  442. }
  443. func GetChargePrint(record int64, patient_id int64, user_org_id int64) (order XtHisOrder, err error) {
  444. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND settle_accounts_date=?", user_org_id, patient_id, record).
  445. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  446. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  447. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  448. Order("ctime desc").
  449. Find(&order).Error
  450. return
  451. }
  452. func GetLastPatient(orgid int64) (models.HisPatient, error) {
  453. patient := models.HisPatient{}
  454. err := XTReadDB().Model(&patient).Where("user_org_id = ? and status = 1", orgid).Last(&patient).Error
  455. return patient, err
  456. }
  457. func UpdateHisPatient(id int64, patient models.HisPatient) error {
  458. err := XTWriteDB().Model(&patient).Where("id = ? and status = 1", id).Update(map[string]interface{}{"number": patient.Number}).Error
  459. return err
  460. }
  461. func GetTodaySchedulePatient(orgid int64, scheduledata int64) (schedule []*models.Schedules, err error) {
  462. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  463. if orgid > 0 {
  464. db = db.Where("x.user_org_id = ?", orgid)
  465. }
  466. if scheduledata > 0 {
  467. db = db.Where("x.schedule_date = ?", scheduledata)
  468. }
  469. err = db.Select("x.id,x.patient_id,x.schedule_date,t.name").Joins("left join xt_patients as t on t.id = x.patient_id").Scan(&schedule).Error
  470. return schedule, err
  471. }
  472. func GetPrscriptionInfo(patientid int64, recorddata int64) (info []*models.HisPrescriptionInfo, err error) {
  473. err = XTReadDB().Model(&info).Where("patient_id = ? and status = 1 and record_date = ?", patientid, recorddata).Find(&info).Error
  474. return info, err
  475. }
  476. func GetPrescriptionByPatientId(patient_id int64, startime int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  477. err = readDb.Model(&models.HisPrescription{}).
  478. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  479. return db.Where("status = 1").Preload("XtHisAddtionConfig", "status=1")
  480. }).
  481. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  482. return db.Where("status = 1 ").Preload("Drug", "status=1")
  483. }).
  484. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  485. return db.Where("status = 1 ").Preload("HisProject").Preload("GoodInfo", "status=1")
  486. }).
  487. Where("patient_id = ? AND record_date =? AND p_type = ? AND status = 1", patient_id, startime, p_type).
  488. Find(&prescription).Error
  489. return
  490. }
  491. // func GetPrescriptionByPatientId(patient_id int64, startime int64, p_type int64) (prescritpion []*models.HisPrescription, err error) {
  492. // // err = XTReadDB().Model(&prescritpion).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  493. // // return db.Where("status = 1 and user_org_id = ?", orgid).Preload("Drug", "status = 1")
  494. // // }).Where("patient_id = ? AND record_date =? AND p_type = ? AND status = 1", patient_id, startime, p_type).Find(&prescritpion).Error
  495. // // return prescritpion, err
  496. // }
  497. func GetTodayHisPatient(recod_date int64, patientid int64, user_org_id int64) (*models.XtHisPatient, error) {
  498. patient := models.XtHisPatient{}
  499. err := XTReadDB().Model(&patient).Where("record_date = ? and patient_id = ? and user_org_id = ? and is_return = 1 and status = 1", recod_date, patientid, user_org_id).Find(&patient).Error
  500. if err != nil {
  501. if err == gorm.ErrRecordNotFound {
  502. return nil, err
  503. } else {
  504. return nil, err
  505. }
  506. }
  507. return &patient, nil
  508. }
  509. func CreateHisMedicalTemplate(template *models.XtHisMedicalTemplate) error {
  510. err := XTWriteDB().Create(&template).Error
  511. return err
  512. }
  513. func GetMedicalTemplateList(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  514. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 1", orgid).Find(&template).Error
  515. return template, err
  516. }
  517. func GetMedicalTemplateListOne(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  518. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 2", orgid).Find(&template).Error
  519. return template, err
  520. }
  521. func GetMedicalTemplateListTwo(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  522. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 3", orgid).Find(&template).Error
  523. return template, err
  524. }
  525. func GetMedicalTemplateListThree(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  526. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 4", orgid).Find(&template).Error
  527. return template, err
  528. }
  529. func GetMedicalTemplateListFour(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  530. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 5", orgid).Find(&template).Error
  531. return template, err
  532. }
  533. func GetMedicalTemplateListFive(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  534. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 6", orgid).Find(&template).Error
  535. return template, err
  536. }
  537. func GetMedicalTemplateListSix(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  538. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 7", orgid).Find(&template).Error
  539. return template, err
  540. }
  541. func GetMedicalTemplateListSeven(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  542. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 8", orgid).Find(&template).Error
  543. return template, err
  544. }
  545. func GetMainTemplateById(id int64) (models.XtHisMedicalTemplate, error) {
  546. template := models.XtHisMedicalTemplate{}
  547. err := XTReadDB().Model(&template).Where("id=? and status = 1", id).Find(&template).Error
  548. return template, err
  549. }
  550. func UpdateMainTemplate(template *models.XtHisMedicalTemplate, id int64) error {
  551. err := XTWriteDB().Model(&template).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"title": template.Title, "content": template.Content, "remark": template.Remark, "mtime": time.Now().Unix()}).Error
  552. return err
  553. }
  554. func DeleteMainTemplateById(id int64) error {
  555. template := models.XtHisMedicalTemplate{}
  556. err := XTWriteDB().Model(&template).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  557. return err
  558. }
  559. func GetProjectHisList(orgid int64) (hisProjectList []*models.XtHisProjectList, error error) {
  560. error = XTReadDB().Model(&hisProjectList).Where("user_org_id = ? and status = 1", orgid).Group("project_id").Find(&hisProjectList).Error
  561. return hisProjectList, error
  562. }
  563. func GetLastItem(orgid int64) (models.XtHisProjectList, error) {
  564. list := models.XtHisProjectList{}
  565. err := XTReadDB().Model(&list).Where("user_org_id = ? and status = 1", orgid).Last(&list).Error
  566. return list, err
  567. }
  568. func SaveProjectTeam(team *models.XtHisProjectTeam) error {
  569. err := XTWriteDB().Model(&team).Save(&team).Error
  570. return err
  571. }
  572. func GetProjectHisListByIds(ids []string) (hisProjectList []*models.XtHisProjectList, error error) {
  573. error = XTReadDB().Model(&hisProjectList).Preload("XtHisProject").Preload("GoodInfo", "status = 1").Where(" status = 1 and id in (?)", ids).Find(&hisProjectList).Error
  574. return hisProjectList, error
  575. }
  576. func GetHisPatientByIdThree(id int64) (models.HisPatient, error) {
  577. patient := models.HisPatient{}
  578. err := XTReadDB().Model(&patient).Where("id = ? and status = 1", id).First(&patient).Error
  579. return patient, err
  580. }
  581. func GetHisPatientByIdThreeTX(id int64, tx *gorm.DB) (models.HisPatient, error) {
  582. patient := models.HisPatient{}
  583. err := tx.Model(&patient).Where("id = ? and status = 1", id).First(&patient).Error
  584. return patient, err
  585. }
  586. func GetLastHisPatient(patient_id int64, org_id int64) (his models.HisPatient, err error) {
  587. err = XTReadDB().Model(&models.HisPatient{}).Where("user_org_id = ? AND patient_id = ? and status = 1 and patient_info <> ''", org_id, patient_id).First(&his).Error
  588. return
  589. }
  590. func GetNewAdminUserES(orgID int64) (es []*models.AdminUserElectronicSignature, err error) {
  591. err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and status=1", orgID).Find(&es).Error
  592. return
  593. }
  594. func GetPatientVascularAccess(patient_id int64) (models.XtPatientVascularAccess, error) {
  595. access := models.XtPatientVascularAccess{}
  596. err = XTReadDB().Where("patient_id = ? and status = 1", patient_id).Last(&access).Error
  597. return access, err
  598. }
  599. func CreateHisProjectTh11o(project models.HisProject) error {
  600. err := XTWriteDB().Model(&project).Create(&project).Error
  601. return err
  602. }