his_project_service.go 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. package service
  2. import (
  3. "fmt"
  4. "gdyb/models"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. func GetHisProjectIsExist(projectName string, orgid int64) (*models.XtHisProject, error) {
  9. var project models.XtHisProject
  10. var err error
  11. err = XTReadDB().Model(&project).Where("project_name = ? and user_org_id = ? and status = 1", projectName, orgid).Find(&project).Error
  12. if err == gorm.ErrRecordNotFound {
  13. return nil, err
  14. }
  15. if err != nil {
  16. return nil, err
  17. }
  18. return &project, nil
  19. }
  20. func CreateHisProject(project *models.XtHisProject) error {
  21. err := XTWriteDB().Model(&project).Create(&project).Error
  22. return err
  23. }
  24. func GetHisProjectList(orgid int64, limit int64, page int64, charge int64, start int64, keyword string) (hisproject []*models.XtHisProject, total int64, err error) {
  25. offset := (page - 1) * limit
  26. likeKey := "%" + keyword + "%"
  27. db := XTReadDB().Table("xt_his_project as x").Where("x.status = 1")
  28. if orgid > 0 {
  29. db = db.Where("x.user_org_id = ?", orgid)
  30. }
  31. if start > 0 {
  32. db = db.Where("x.medical_status = ?", start)
  33. }
  34. if charge > 0 {
  35. db = db.Where("x.is_estimate = ? ", charge)
  36. }
  37. if len(keyword) > 0 {
  38. db = db.Where("x.project_name like ?", likeKey)
  39. }
  40. 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").Count(&total).Offset(offset).Limit(limit).Find(&hisproject).Error
  41. return hisproject, total, err
  42. }
  43. func GetProjectDetail(id int64) (models.XtHisProject, error) {
  44. project := models.XtHisProject{}
  45. err := XTReadDB().Model(&project).Where("id=? and status = 1", id).Find(&project).Error
  46. return project, err
  47. }
  48. func UpdatedProject(id int64, pro *models.XtHisProject) error {
  49. 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.MedicalCoverage, "disease_directory": pro.DiseaseDirectory, "is_record": pro.DiseaseDirectory, "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.ExecutionFrequency, "number_days": pro.ExecutionFrequency, "total": pro.Total, "updated_time": pro.UpdatedTime}).Error
  50. return err
  51. }
  52. func DeleteHisProject(id int64) error {
  53. project := models.XtHisProject{}
  54. err := XTWriteDB().Model(&project).Where("id=?", id).Updates(map[string]interface{}{"status": 0}).Error
  55. return err
  56. }
  57. func GetHisProjectByNameOne(projectName string, orgid int64) (*models.XtHisProjectTeam, error) {
  58. projectTeam := models.XtHisProjectTeam{}
  59. err := XTReadDB().Model(&projectTeam).Where("project_team = ? and user_org_id = ? and status = 1", projectName, orgid).Find(&projectTeam).Error
  60. if err != nil {
  61. if err == gorm.ErrRecordNotFound {
  62. return nil, err
  63. } else {
  64. return nil, err
  65. }
  66. }
  67. return &projectTeam, nil
  68. }
  69. func CreatedProjectTeam(team *models.XtHisProjectTeam) error {
  70. err := XTWriteDB().Model(&team).Create(&team).Error
  71. return err
  72. }
  73. func GetProjectTeamList(limit int64, page int64, orgid int64, keyword string) (projectTeam []*models.XtHisProjectTeam, total int64, err error) {
  74. offset := (page - 1) * limit
  75. likeKey := "%" + keyword + "%"
  76. db := XTReadDB().Model(&projectTeam)
  77. if len(keyword) > 0 {
  78. db = db.Where("project_team like ?", likeKey)
  79. }
  80. err = db.Where("user_org_id = ? and status = 1", orgid).Count(&total).Offset(offset).Limit(limit).Order("created_time desc").Find(&projectTeam).Error
  81. return projectTeam, total, err
  82. }
  83. func GetProjectTeamDetail(id int64) (models.XtHisProjectTeam, error) {
  84. projectTeam := models.XtHisProjectTeam{}
  85. err := XTReadDB().Model(&projectTeam).Where("id= ? and status = 1", id).Find(&projectTeam).Error
  86. return projectTeam, err
  87. }
  88. func UpdatedProjectTeam(id int64, team *models.XtHisProjectTeam) error {
  89. 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}).Error
  90. return err
  91. }
  92. func DeleteProjectTeam(id int64) error {
  93. team := models.XtHisProjectTeam{}
  94. err := XTWriteDB().Model(&team).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  95. return err
  96. }
  97. func CreateDePartment(department *models.XtHisDepartment) error {
  98. err := XTWriteDB().Model(&department).Create(&department).Error
  99. return err
  100. }
  101. func GetDepartMentList(limit int64, page int64, orgid int64) (departMent []*models.XtHisDepartment, total int64, err error) {
  102. offset := (page - 1) * limit
  103. 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
  104. return departMent, total, err
  105. }
  106. func GetDepartMentDetail(id int64) (models.XtHisDepartment, error) {
  107. department := models.XtHisDepartment{}
  108. err := XTReadDB().Model(&department).Where("id=? and status = 1", id).Find(&department).Error
  109. return department, err
  110. }
  111. func UpdatedDepartment(id int64, department *models.XtHisDepartment) error {
  112. 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
  113. return err
  114. }
  115. func DeleteDepartment(id int64) error {
  116. department := models.XtHisDepartment{}
  117. err := XTReadDB().Model(&department).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  118. return err
  119. }
  120. func GetBloodPatientList(orgid int64, startime int64) (schedule []*models.SchedulesVm, err error) {
  121. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  122. if orgid > 0 {
  123. db = db.Where("x.user_org_id = ?", orgid)
  124. }
  125. if startime > 0 {
  126. db = db.Where("x.schedule_date = ?", startime)
  127. }
  128. 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
  129. return schedule, err
  130. }
  131. func GetHisPatient(orgid int64, recorddate int64) (paitent []*models.HisPatient, err error) {
  132. err = XTReadDB().Model(&paitent).Where("user_org_id = ? and record_date = ? and status = 1", orgid, recorddate).Find(&paitent).Error
  133. return paitent, err
  134. }
  135. func GetHisPrescriptionOther(orgid int64, recorddate int64) (prescription []*models.HisPrescriptionVm, err error) {
  136. db := XTReadDB().Table("his_prescription as x").Where("x.status = 1")
  137. if orgid > 0 {
  138. db = db.Where("x.user_org_id = ?", orgid)
  139. }
  140. if recorddate > 0 {
  141. db = db.Where("x.record_date = ? ", recorddate)
  142. }
  143. 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
  144. return prescription, err
  145. }
  146. func GetHisPrescriptionByPatientId(id int64, recordate int64) (prescription []*models.HisPrescription, err error) {
  147. err = XTReadDB().Model(&prescription).Where("his_patient_id = ? and record_date = ? and status= 1", id, recordate).Find(&prescription).Error
  148. return prescription, err
  149. }
  150. func CreateAdditionalCharge(charge *models.HisAdditionalCharge) error {
  151. err = XTWriteDB().Model(&charge).Save(&charge).Error
  152. return err
  153. }
  154. func GetTreatmentList(id int64, startime int64) (prescription []*models.HisPrescription, err error) {
  155. err = XTReadDB().Model(&prescription).Where("id = ? and record_date = ? and status = 1", id, startime).Find(&prescription).Error
  156. return prescription, err
  157. }
  158. //func GetAllProjectList(orgid int64) (project []*models.XtHisProject, err error) {
  159. //
  160. // err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  161. // return project, err
  162. //}
  163. func CreateProjectList(list *models.XtHisProjectList) error {
  164. err := XTWriteDB().Model(&list).Create(&list).Error
  165. return err
  166. }
  167. func GetHisProjectListByOrgId(orgid int64) (projectlist []*models.HisProjectListVm, err error) {
  168. db := XTReadDB().Table("xt_his_project_list as x").Where("x.status = 1")
  169. if orgid > 0 {
  170. db = db.Where("x.user_org_id = ? ", orgid)
  171. }
  172. 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
  173. return projectlist, err
  174. }
  175. func GetHisPatientInformation(id int64) (models.HisPatient, error) {
  176. patient := models.HisPatient{}
  177. err := XTReadDB().Model(&patient).Where("id= ? and status = 1", id).Find(&patient).Error
  178. return patient, err
  179. }
  180. func DeleteProjectList(id int64) error {
  181. list := models.XtHisProjectList{}
  182. err := XTWriteDB().Model(&list).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  183. return err
  184. }
  185. func GetHisProject(orgid int64) (project []*models.XtHisProject, err error) {
  186. err = XTReadDB().Model(&project).Where("user_org_id = ? and status =1", orgid).Find(&project).Error
  187. return project, err
  188. }
  189. func GetProjectTeam(ids []string, orgid int64) (project []*models.XtHisProject, err error) {
  190. err = XTReadDB().Model(&project).Where("user_org_id = ? and id in (?)", orgid, ids).Find(&project).Error
  191. return project, err
  192. }
  193. func GetAllDepartMent(orgid int64) (department []*models.XtHisDepartment, err error) {
  194. err = XTReadDB().Model(&department).Where("user_org_id = ? and status =1", orgid).Find(&department).Error
  195. return department, err
  196. }
  197. func CreateHisPatient(patient *models.XtHisPatient) error {
  198. err := XTReadDB().Model(&patient).Create(&patient).Error
  199. return err
  200. }
  201. func GetBloodPatientByIdCard(idcard string, orgid int64) (*models.XtPatients, error) {
  202. var patients models.XtPatients
  203. var err error
  204. err = XTReadDB().Model(&patients).Where("id_card_no = ? and user_org_id = ? and status = 1", idcard, orgid).Find(&patients).Error
  205. if err != nil {
  206. if err == gorm.ErrRecordNotFound {
  207. return nil, err
  208. } else {
  209. return nil, err
  210. }
  211. }
  212. return &patients, nil
  213. }
  214. func GetAllProjectTeam(orgid int64) (project []*models.XtHisProjectTeam, err error) {
  215. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  216. return project, err
  217. }
  218. func GetProjectListById(orgid int64, ids []string) (project []*models.XtHisProject, err error) {
  219. err = XTReadDB().Model(&project).Where("user_org_id = ? and id in (?)", orgid, ids).Find(&project).Error
  220. return project, err
  221. }
  222. func GetHisPatientHistory(keyword string, startime int64, endtime int64, registtype int64, limit int64, page int64, orgid int64) (hisPatient []*models.XtHisPatient, total int64, err error) {
  223. offset := (page - 1) * limit
  224. likeKey := "%" + keyword + "%"
  225. db := XTReadDB().Table("his_patient as x").Where("x.status = 1")
  226. if len(keyword) > 0 {
  227. db = db.Where("x.name like ?", likeKey)
  228. }
  229. if startime > 0 {
  230. db = db.Where("x.record_date >= ?", startime)
  231. }
  232. if endtime > 0 {
  233. db = db.Where("x.record_date<=?", endtime)
  234. }
  235. if registtype > 0 {
  236. db = db.Where("x.register_type = ?", registtype)
  237. }
  238. if orgid > 0 {
  239. db = db.Where("x.user_org_id = ?", orgid)
  240. }
  241. 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").Count(&total).Offset(offset).Limit(limit).Order("x.id desc").Find(&hisPatient).Error
  242. return hisPatient, total, err
  243. }
  244. func ChangePatient(id int64) error {
  245. patient := models.XtHisPatient{}
  246. err := XTWriteDB().Model(&patient).Where("id = ?", id).Updates(map[string]interface{}{"is_return": 2}).Error
  247. return err
  248. }
  249. func GetHisPrescriptionTwo(patientid int64, orgid int64, recorddate int64) (*models.HisPrescription, error) {
  250. prescription := models.HisPrescription{}
  251. err := XTReadDB().Model(&prescription).Where("his_patient_id = ? and user_org_id = ? and record_date = ? and status = 1", patientid, orgid, recorddate).Find(&prescription).Error
  252. if err != nil {
  253. if err == gorm.ErrRecordNotFound {
  254. return nil, err
  255. } else {
  256. return nil, err
  257. }
  258. }
  259. return &prescription, nil
  260. }
  261. func UpdatedHisPatient(hispatientid int64, orgid int64, recorddate int64) error {
  262. hisPatient := models.HisPatient{}
  263. err := XTWriteDB().Model(&hisPatient).Where("id = ? and user_org_id = ? and record_date = ?", hispatientid, orgid, recorddate).Updates(map[string]interface{}{"is_return": 3}).Error
  264. return err
  265. }
  266. func GetBloodPatientInfoById(patientid int64) (models.XtPatients, error) {
  267. patients := models.XtPatients{}
  268. err := XTReadDB().Model(&patients).Where("id = ? and status = 1", patientid).Find(&patients).Error
  269. return patients, err
  270. }
  271. func GetPatientCaseHistory(patientid int64) (models.HisPatientCaseHistory, error) {
  272. history := models.HisPatientCaseHistory{}
  273. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patientid).Last(&history).Error
  274. return history, err
  275. }
  276. func GetBloodPatientByPatient(id int64) (models.XtPatients, error) {
  277. patients := models.XtPatients{}
  278. err := XTReadDB().Model(&patients).Where("id = ? and status = 1", id).Find(&patients).Error
  279. return patients, err
  280. }
  281. func GetHisPatientByIdTwo(patientid int64) (models.XtHisPatient, error) {
  282. patient := models.XtHisPatient{}
  283. err := XTReadDB().Model(&patient).Where("patient_id = ? and status=1", patientid).Find(&patient).Error
  284. return patient, err
  285. }
  286. func GetHisPatientById(patientid int64) (models.VMHisPatient, error) {
  287. patient := models.VMHisPatient{}
  288. err := XTReadDB().Model(&patient).Where("patient_id = ? and status = 1", patientid).Find(&patient).Error
  289. return patient, err
  290. }
  291. func GetTemplateDetail(id int64) (models.HisCaseHistoryTemplate, error) {
  292. template := models.HisCaseHistoryTemplate{}
  293. err := XTReadDB().Model(&template).Where("id= ? and status = 1", id).Find(&template).Error
  294. return template, err
  295. }
  296. func UpdateCaseHistoryTemplate(tem *models.HisCaseHistoryTemplate, id int64) error {
  297. 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
  298. return err
  299. }
  300. func GetHistPatient(orgid int64, keyword string) (hisPatient []*models.HisPatient, err error) {
  301. likeKey := "%" + keyword + "%"
  302. err = XTReadDB().Model(&hisPatient).Where("user_org_id = ? and name like ?", orgid, likeKey).Find(&hisPatient).Error
  303. return hisPatient, err
  304. }
  305. func GetDoctorAdvicePrint(his_patient_id int64, recorddate int64, schIDs []string, orgid int64) (prescription []*models.HisPrescription, err error) {
  306. err = XTReadDB().Model(&prescription).Where("patient_id = ? and record_date = ? and id in(?) and status = 1 ", his_patient_id, recorddate, schIDs).Preload("Patients", "status = 1 and user_org_id = ?", orgid).Preload("HisDoctorAdviceInfo", "status = 1 and user_org_id = ?", orgid).Preload("HisPrescriptionProject", "status = 1 and user_org_id = ?", orgid).Preload("VMHisPrescriptionInfo", "status =1 and user_org_id = ?", orgid).Preload("XtHisAdditionalCharge", "status = 1 and user_org_id = ?", orgid).Find(&prescription).Error
  307. return prescription, err
  308. }
  309. func GetProjectPrint(his_patient_id int64) (models.HisPrescriptionProject, error) {
  310. project := models.HisPrescriptionProject{}
  311. err := XTReadDB().Model(&project).Where("his_patient_id = ? and status = 1", his_patient_id).Find(&project).Error
  312. return project, err
  313. }
  314. func GetHisTemplateId(templateid int64, orgid int64) (*models.XtHisTemplate, error) {
  315. template := models.XtHisTemplate{}
  316. err := XTReadDB().Model(&template).Where("template_id = ? and user_org_id = ? and status = 1", templateid, orgid).Find(&template).Error
  317. if err != nil {
  318. if err == gorm.ErrRecordNotFound {
  319. return nil, err
  320. } else {
  321. return nil, err
  322. }
  323. }
  324. return &template, nil
  325. }
  326. func CreateHisTemplate(template *models.XtHisTemplate) error {
  327. err := XTWriteDB().Create(&template).Error
  328. return err
  329. }
  330. func UpdateHisTemplate(template *models.XtHisTemplate) error {
  331. err := XTWriteDB().Save(&template).Error
  332. return err
  333. }
  334. func GetHisPrintTemplate(orgid int64) (models.XtHisTemplate, error) {
  335. template := models.XtHisTemplate{}
  336. err := XTReadDB().Model(&template).Where("user_org_id = ? and status = 1", orgid).Find(&template).Error
  337. return template, err
  338. }
  339. func GetPrescriptionTemplate(templateid int64, orgid int64) (*models.XtHisAdviceTemplate, error) {
  340. template := models.XtHisAdviceTemplate{}
  341. err := XTReadDB().Model(&template).Where("template_id = ? and user_org_id = ? and status = 1", templateid, orgid).Find(&template).Error
  342. if err != nil {
  343. if err == gorm.ErrRecordNotFound {
  344. return nil, err
  345. } else {
  346. return nil, err
  347. }
  348. }
  349. return &template, nil
  350. }
  351. func CreatePrescriptionTemplate(template *models.XtHisAdviceTemplate) error {
  352. err = XTWriteDB().Create(&template).Error
  353. return err
  354. }
  355. func UpdatePrescriptionTemplate(template *models.XtHisAdviceTemplate) error {
  356. err := XTWriteDB().Save(&template).Error
  357. return err
  358. }
  359. func GetPrescriptionTemplateById(orgid int64) (models.XtHisAdviceTemplate, error) {
  360. template := models.XtHisAdviceTemplate{}
  361. err := XTReadDB().Model(&template).Where("user_org_id = ? and status = 1", orgid).Find(&template).Error
  362. return template, err
  363. }
  364. func GetTreatPrintTemplate(templateid int64, orgid int64) (*models.XtHisTreatmentTemplate, error) {
  365. template := models.XtHisTreatmentTemplate{}
  366. err := XTReadDB().Model(&template).Where("template_id = ? and user_org_id = ? and status = 1", templateid, orgid).Find(&template).Error
  367. if err != nil {
  368. if err == gorm.ErrRecordNotFound {
  369. return nil, err
  370. } else {
  371. return nil, err
  372. }
  373. }
  374. return &template, nil
  375. }
  376. func CreateTreatPrintTemplate(template *models.XtHisTreatmentTemplate) error {
  377. err := XTWriteDB().Create(&template).Error
  378. return err
  379. }
  380. func UpdatedTreateTemplate(template *models.XtHisTreatmentTemplate) error {
  381. err := XTWriteDB().Save(&template).Error
  382. return err
  383. }
  384. func GetTreatTtreatPrintTemplate(orgid int64) (models.XtHisTreatmentTemplate, error) {
  385. template := models.XtHisTreatmentTemplate{}
  386. err := XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&template).Error
  387. return template, err
  388. }
  389. func GetChargeTemplate(templateid int64, orgid int64) (*models.XtHisChargeTemplate, error) {
  390. template := models.XtHisChargeTemplate{}
  391. err := XTReadDB().Model(&template).Where("template_id = ? and user_org_id = ? and status = 1", templateid, orgid).Find(&template).Error
  392. if err != nil {
  393. if err == gorm.ErrRecordNotFound {
  394. return nil, err
  395. } else {
  396. return nil, err
  397. }
  398. }
  399. return &template, nil
  400. }
  401. func CreateChargePrintTemplate(template *models.XtHisChargeTemplate) error {
  402. err := XTWriteDB().Create(&template).Error
  403. return err
  404. }
  405. func UpdateChargePrintTemplate(template *models.XtHisChargeTemplate) error {
  406. err := XTWriteDB().Save(&template).Error
  407. return err
  408. }
  409. func GetChargePrintTemplate(orgid int64) (models.XtHisChargeTemplate, error) {
  410. template := models.XtHisChargeTemplate{}
  411. err := XTReadDB().Model(&template).Where("user_org_id = ? and status = 1", orgid).Find(&template).Error
  412. return template, err
  413. }
  414. func GetDoctorProjectItem(patientid int64, record_date int64) (models.HisPrescriptionProject, error) {
  415. project := models.HisPrescriptionProject{}
  416. err := XTReadDB().Model(&project).Where("patient_id = ? and record_date = ? and status = 1", patientid, record_date).Preload("HisProject", "status = 1").Find(&project).Error
  417. return project, err
  418. }
  419. func GetChargePrint(record int64, patient_id int64, user_org_id int64) (order XtHisOrder, err error) {
  420. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND settle_accounts_date=?", user_org_id, patient_id, record).
  421. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  422. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  423. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  424. Order("ctime desc").
  425. Find(&order).Error
  426. return
  427. }
  428. func GetLastPatient(orgid int64) (models.HisPatient, error) {
  429. patient := models.HisPatient{}
  430. err := XTReadDB().Model(&patient).Where("user_org_id = ? and status = 1", orgid).Last(&patient).Error
  431. return patient, err
  432. }
  433. func UpdateHisPatient(id int64, patient models.HisPatient) error {
  434. err := XTWriteDB().Model(&patient).Where("id = ? and status = 1", id).Update(map[string]interface{}{"number": patient.Number}).Error
  435. return err
  436. }
  437. func GetTodaySchedulePatient(orgid int64, scheduledata int64) (schedule []*models.Schedules, err error) {
  438. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  439. if orgid > 0 {
  440. db = db.Where("x.user_org_id = ?", orgid)
  441. }
  442. if scheduledata > 0 {
  443. db = db.Where("x.schedule_date = ?", scheduledata)
  444. }
  445. 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
  446. return schedule, err
  447. }
  448. func GetPrscriptionInfo(patientid int64, recorddata int64) (info []*models.HisPrescriptionInfo, err error) {
  449. err = XTReadDB().Model(&info).Where("patient_id = ? and status = 1 and record_date = ?", patientid, recorddata).Find(&info).Error
  450. return info, err
  451. }
  452. func GetPrescriptionByPatientId(patient_id int64, startime int64) (prescritpion []*models.HisPrescription, err error) {
  453. err = XTReadDB().Model(&prescritpion).Where("patient_id = ? and record_date =?", patient_id, startime).Find(&prescritpion).Error
  454. return prescritpion, err
  455. }
  456. func GetTodayHisPatient(recod_date int64, patientid int64, user_org_id int64) (*models.XtHisPatient, error) {
  457. patient := models.XtHisPatient{}
  458. 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
  459. if err != nil {
  460. if err == gorm.ErrRecordNotFound {
  461. return nil, err
  462. } else {
  463. return nil, err
  464. }
  465. }
  466. return &patient, nil
  467. }
  468. func CreateHisMedicalTemplate(template *models.XtHisMedicalTemplate) error {
  469. err := XTWriteDB().Create(&template).Error
  470. return err
  471. }
  472. func GetMedicalTemplateList(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  473. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 1", orgid).Find(&template).Error
  474. return template, err
  475. }
  476. func GetMedicalTemplateListOne(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  477. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 2", orgid).Find(&template).Error
  478. return template, err
  479. }
  480. func GetMedicalTemplateListTwo(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  481. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 3", orgid).Find(&template).Error
  482. return template, err
  483. }
  484. func GetMedicalTemplateListThree(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  485. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 4", orgid).Find(&template).Error
  486. return template, err
  487. }
  488. func GetMedicalTemplateListFour(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  489. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 5", orgid).Find(&template).Error
  490. return template, err
  491. }
  492. func GetMedicalTemplateListFive(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  493. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 6", orgid).Find(&template).Error
  494. return template, err
  495. }
  496. func GetMedicalTemplateListSix(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  497. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 7", orgid).Find(&template).Error
  498. return template, err
  499. }
  500. func GetMedicalTemplateListSeven(orgid int64) (template []*models.XtHisMedicalTemplate, err error) {
  501. err = XTReadDB().Model(&template).Where("user_org_id =? and status = 1 and template_id = 8", orgid).Find(&template).Error
  502. return template, err
  503. }
  504. func GetMainTemplateById(id int64) (models.XtHisMedicalTemplate, error) {
  505. template := models.XtHisMedicalTemplate{}
  506. err := XTReadDB().Model(&template).Where("id=? and status = 1", id).Find(&template).Error
  507. return template, err
  508. }
  509. func UpdateMainTemplate(template *models.XtHisMedicalTemplate, id int64) error {
  510. 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
  511. return err
  512. }
  513. func DeleteMainTemplateById(id int64) error {
  514. template := models.XtHisMedicalTemplate{}
  515. err := XTWriteDB().Model(&template).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  516. return err
  517. }
  518. func GetProjectHisList(orgid int64) (hisProjectList []*models.XtHisProjectList, error error) {
  519. error = XTReadDB().Model(&hisProjectList).Where("user_org_id = ? and status = 1", orgid).Group("project_id").Find(&hisProjectList).Error
  520. return hisProjectList, error
  521. }
  522. func GetDrugListByDetailOne(id int64) (*models.BaseDrugList, error) {
  523. list := &models.BaseDrugList{}
  524. //err := XTReadDB().Model(&list).Where("id = ?", id).Find(&list).Error
  525. //return list,err
  526. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  527. table := XTReadDB().Table("xt_manufacturer as m")
  528. fmt.Print(table)
  529. if id > 0 {
  530. db = db.Where("x.id = ?", id)
  531. }
  532. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&list).Error
  533. return list, err
  534. }
  535. func GetBatchDrugList(idss []int64) (drug []*models.BaseDrugList, err error) {
  536. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  537. table := XTReadDB().Table("xt_manufacturer as m")
  538. fmt.Print(table)
  539. if len(idss) == 1 {
  540. db = db.Where("x.id = ?", idss[0])
  541. } else {
  542. db = db.Where("x.id IN(?)", idss)
  543. }
  544. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,x.social_security_directory_code,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  545. return drug, err
  546. }
  547. func GetBatchDrugListtw(org_id int64) (drug []*models.BaseDrugList, err error) {
  548. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  549. table := XTReadDB().Table("xt_manufacturer as m")
  550. fmt.Print(table)
  551. db = db.Where("x.org_id = ?", org_id)
  552. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,x.social_security_directory_code,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  553. return drug, err
  554. }
  555. func GetBatchGoodInformationList(idss []int64) (good []*models.GoodInformation, err error) {
  556. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  557. table := XTReadDB().Table("xt_manufacturer as m")
  558. fmt.Println(table)
  559. if len(idss) == 1 {
  560. db = db.Where("x.id = ?", idss[0])
  561. } else {
  562. db = db.Where("x.id IN(?)", idss)
  563. }
  564. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  565. return good, err
  566. }
  567. func GetBatchGoodInformationListtwo(org_id int64) (good []*models.GoodInformation, err error) {
  568. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  569. table := XTReadDB().Table("xt_manufacturer as m")
  570. fmt.Println(table)
  571. db = db.Where("x.org_id = ?", org_id)
  572. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  573. return good, err
  574. }