his_project_api_controller.go 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type HisProjectApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func HisProjectRouters() {
  19. beego.Router("/api/his/saveproject", &HisProjectApiController{}, "Get:SaveProject")
  20. beego.Router("/api/his/getprojectlist", &HisProjectApiController{}, "Get:GetProjectList")
  21. beego.Router("/api/his/getprojectdetail", &HisProjectApiController{}, "Get:GetProjectDetail")
  22. beego.Router("/api/his/updatedproject", &HisProjectApiController{}, "Get:UpdatedProject")
  23. beego.Router("/api/his/deletehisproject", &HisProjectApiController{}, "Get:DeleteHisProject")
  24. beego.Router("/api/his/saveprojectteam", &HisProjectApiController{}, "Get:SaveProjectTeam")
  25. beego.Router("/api/his/getprojectteamlist", &HisProjectApiController{}, "Get:GetProjectTeamList")
  26. beego.Router("/api/his/getprojectteamdetail", &HisProjectApiController{}, "Get:GetProjectTeamDetail")
  27. beego.Router("/api/his/updateprojectteam", &HisProjectApiController{}, "Get:UpdatedProjectTeam")
  28. beego.Router("/api/his/deleteprojectteam", &HisProjectApiController{}, "Get:DeleteProjectTeam")
  29. beego.Router("/api/his/savedepartment", &HisProjectApiController{}, "Get:SaveDePartment")
  30. beego.Router("/api/his/getdepartmentlist", &HisProjectApiController{}, "Get:GetDepartMentList")
  31. beego.Router("/api/his/getdepartmentdetail", &HisProjectApiController{}, "Get:GetDepartMentDetail")
  32. beego.Router("/api/his/updagtedepartment", &HisProjectApiController{}, "Get:UpdatedDeparment")
  33. beego.Router("/api/his/deletedeparment", &HisProjectApiController{}, "Get:DeleteDepartment")
  34. beego.Router("/api/his/getallprojectlist", &HisProjectApiController{}, "Get:GetAllProjectList")
  35. beego.Router("/api/his/addprojectlist", &HisProjectApiController{}, "Get:AddProjectList")
  36. beego.Router("/api/his/deleteproject", &HisProjectApiController{}, "Get:DeleteProject")
  37. beego.Router("/api/his/gethisproject", &HisProjectApiController{}, "Get:GetHisProject")
  38. beego.Router("/api/his/getprojectteam", &HisProjectApiController{}, "Get:GetProjectTeam")
  39. beego.Router("/api/his/getalldoctorlist", &HisProjectApiController{}, "Get:GetAllDoctorList")
  40. beego.Router("/api/his/savehispatient", &HisProjectApiController{}, "Get:SaveHisPatient")
  41. //获取今日血透排班的患者
  42. beego.Router("/api/his/getbloodpatient", &HisProjectApiController{}, "Get:GetBloodPatientList")
  43. //获取患者的今日透析处方
  44. beego.Router("/api/his/gethisprescription", &HisProjectApiController{}, "Get:GetHisPrescription")
  45. //新增附加费用
  46. beego.Router("/api/his/additionalcharge", &HisProjectApiController{}, "Post:AdditionalCharge")
  47. //获取治疗单
  48. beego.Router("/api/his/gettreatlist", &HisProjectApiController{}, "Get:GetTreatmentList")
  49. beego.Router("/api/his/getpatientinformation", &HisProjectApiController{}, "Get:GetPatientInformation")
  50. beego.Router("/api/hist/getallprojecteam", &HisProjectApiController{}, "Get:GetAllProjectTeam")
  51. beego.Router("/api/his/getprojectlistbyid", &HisProjectApiController{}, "Get:GetProjectListById")
  52. beego.Router("/api/his/gethispatienthistory", &HisProjectApiController{}, "Get:GetHisPatientHistory")
  53. beego.Router("/api/patient/changepatient", &HisProjectApiController{}, "Get:ChangePatient")
  54. beego.Router("/api/patient/getpatientcasehistory", &HisProjectApiController{}, "Get:GetPatientcaseHistory")
  55. beego.Router("/api/doctorworkstation/gettemplatedetail", &HisProjectApiController{}, "Get:GetTemplateDetail")
  56. beego.Router("/api/doctorworkstation/updaterecordtemplate", &HisProjectApiController{}, "Get:UpdateRecordTemplate")
  57. }
  58. func (this *HisProjectApiController) SaveProject() {
  59. project_name := this.GetString("project_name")
  60. pinyin := this.GetString("pinyin")
  61. wubi := this.GetString("wubi")
  62. price := this.GetString("price")
  63. price_float, err := strconv.ParseFloat(price, 64)
  64. unit := this.GetString("unit")
  65. cost_classify, _ := this.GetInt64("cost_classify")
  66. executive_section, _ := this.GetInt64("executive_section")
  67. medical_coverage, _ := this.GetInt64("medical_coverage")
  68. statistical_classification, _ := this.GetInt64("statistical_classification")
  69. disease_directory, _ := this.GetInt64("disease_directory")
  70. is_record, _ := this.GetInt64("is_record")
  71. medical_code := this.GetString("medical_code")
  72. tube_color, _ := this.GetInt64("tube_color")
  73. medical_status, _ := this.GetInt64("medical_status")
  74. remark := this.GetString("remark")
  75. sign, _ := this.GetInt64("sign")
  76. default_number := this.GetString("default_number")
  77. is_charge, _ := this.GetInt64("is_charge")
  78. is_estimate, _ := this.GetInt64("is_estimate")
  79. is_workload, _ := this.GetInt64("is_workload")
  80. sort := this.GetString("sort")
  81. is_advice, _ := this.GetInt64("is_advice")
  82. is_default, _ := this.GetInt64("is_default")
  83. single_dose := this.GetString("single_dose")
  84. delivery_way := this.GetString("delivery_way")
  85. execution_frequency := this.GetString("execution_frequency")
  86. number_days := this.GetString("number_days")
  87. total := this.GetString("total")
  88. adminUserInfo := this.GetAdminUserInfo()
  89. orgId := adminUserInfo.CurrentOrgId
  90. hisProject := models.XtHisProject{
  91. ProjectName: project_name,
  92. Pinyin: pinyin,
  93. Wubi: wubi,
  94. Price: price_float,
  95. Unit: unit,
  96. CostClassify: cost_classify,
  97. ExecutiveSection: executive_section,
  98. MedicalCoverage: medical_coverage,
  99. StatisticalClassification: statistical_classification,
  100. DiseaseDirectory: disease_directory,
  101. IsRecord: is_record,
  102. MedicalCode: medical_code,
  103. TubeColor: tube_color,
  104. MedicalStatus: medical_status,
  105. Remark: remark,
  106. Sign: sign,
  107. DefaultNumber: default_number,
  108. IsCharge: is_charge,
  109. IsEstimate: is_estimate,
  110. IsWorkload: is_workload,
  111. Sort: sort,
  112. DoctorAdvice: is_advice,
  113. IsDefault: is_default,
  114. UserOrgId: orgId,
  115. Status: 1,
  116. CreatedTime: time.Now().Unix(),
  117. SingleDose: single_dose,
  118. DeliveryWay: delivery_way,
  119. ExecutionFrequency: execution_frequency,
  120. NumberDays: number_days,
  121. Total: total,
  122. }
  123. //查询项目名称是否存在
  124. _, errcode := service.GetHisProjectIsExist(project_name, orgId)
  125. fmt.Println("9999999999999", errcode)
  126. if errcode == gorm.ErrRecordNotFound {
  127. fmt.Println("222")
  128. err = service.CreateHisProject(&hisProject)
  129. if err != nil {
  130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  131. return
  132. }
  133. this.ServeSuccessJSON(map[string]interface{}{
  134. "hisProject": hisProject,
  135. })
  136. return
  137. } else if errcode == nil {
  138. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  139. return
  140. }
  141. }
  142. func (this *HisProjectApiController) GetProjectList() {
  143. adminUserInfo := this.GetAdminUserInfo()
  144. orgId := adminUserInfo.CurrentOrgId
  145. limit, _ := this.GetInt64("limit")
  146. page, _ := this.GetInt64("page")
  147. is_charge, _ := this.GetInt64("is_charge")
  148. fmt.Println("is_charge====================", is_charge)
  149. is_start, _ := this.GetInt64("is_start")
  150. fmt.Println("is_start--------------------", is_start)
  151. keyword := this.GetString("keyword")
  152. projecList, total, err := service.GetHisProjectList(orgId, limit, page, is_charge, is_start, keyword)
  153. fmt.Println("err", err)
  154. if err != nil {
  155. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  156. return
  157. }
  158. this.ServeSuccessJSON(map[string]interface{}{
  159. "projecList": projecList,
  160. "total": total,
  161. })
  162. return
  163. }
  164. func (this *HisProjectApiController) GetProjectDetail() {
  165. id, _ := this.GetInt64("id")
  166. projectDetail, err := service.GetProjectDetail(id)
  167. if err != nil {
  168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  169. return
  170. }
  171. this.ServeSuccessJSON(map[string]interface{}{
  172. "projecDetail": projectDetail,
  173. })
  174. return
  175. }
  176. func (this *HisProjectApiController) UpdatedProject() {
  177. id, _ := this.GetInt64("id")
  178. project_name := this.GetString("project_name")
  179. pinyin := this.GetString("pinyin")
  180. wubi := this.GetString("wubi")
  181. price := this.GetString("price")
  182. price_float, _ := strconv.ParseFloat(price, 64)
  183. unit := this.GetString("unit")
  184. cost_classify, _ := this.GetInt64("cost_classify")
  185. executive_section, _ := this.GetInt64("executive_section")
  186. medical_coverage, _ := this.GetInt64("medical_coverage")
  187. statistical_classification, _ := this.GetInt64("statistical_classification")
  188. disease_directory, _ := this.GetInt64("disease_directory")
  189. is_record, _ := this.GetInt64("is_record")
  190. medical_code := this.GetString("medical_code")
  191. tube_color, _ := this.GetInt64("tube_color")
  192. medical_status, _ := this.GetInt64("medical_status")
  193. remark := this.GetString("remark")
  194. sign, _ := this.GetInt64("sign")
  195. default_number := this.GetString("default_number")
  196. is_charge, _ := this.GetInt64("is_charge")
  197. is_estimate, _ := this.GetInt64("is_estimate")
  198. is_workload, _ := this.GetInt64("is_workload")
  199. sort := this.GetString("sort")
  200. is_advice, _ := this.GetInt64("is_advice")
  201. is_default, _ := this.GetInt64("is_default")
  202. single_dose := this.GetString("single_dose")
  203. delivery_way := this.GetString("delivery_way")
  204. execution_frequency := this.GetString("execution_frequency")
  205. number_days := this.GetString("number_days")
  206. total := this.GetString("total")
  207. hisProject := models.XtHisProject{
  208. ProjectName: project_name,
  209. Pinyin: pinyin,
  210. Wubi: wubi,
  211. Price: price_float,
  212. Unit: unit,
  213. CostClassify: cost_classify,
  214. ExecutiveSection: executive_section,
  215. MedicalCoverage: medical_coverage,
  216. StatisticalClassification: statistical_classification,
  217. DiseaseDirectory: disease_directory,
  218. IsRecord: is_record,
  219. MedicalCode: medical_code,
  220. TubeColor: tube_color,
  221. MedicalStatus: medical_status,
  222. Remark: remark,
  223. Sign: sign,
  224. DefaultNumber: default_number,
  225. IsCharge: is_charge,
  226. IsEstimate: is_estimate,
  227. IsWorkload: is_workload,
  228. Sort: sort,
  229. DoctorAdvice: is_advice,
  230. IsDefault: is_default,
  231. UpdatedTime: time.Now().Unix(),
  232. SingleDose: single_dose,
  233. DeliveryWay: delivery_way,
  234. ExecutionFrequency: execution_frequency,
  235. NumberDays: number_days,
  236. Total: total,
  237. }
  238. err := service.UpdatedProject(id, &hisProject)
  239. if err != nil {
  240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  241. return
  242. }
  243. this.ServeSuccessJSON(map[string]interface{}{
  244. "hisProject": hisProject,
  245. })
  246. return
  247. }
  248. func (this *HisProjectApiController) DeleteHisProject() {
  249. id, _ := this.GetInt64("id")
  250. err := service.DeleteHisProject(id)
  251. if err != nil {
  252. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  253. return
  254. }
  255. returnData := make(map[string]interface{}, 0)
  256. returnData["msg"] = "ok"
  257. this.ServeSuccessJSON(returnData)
  258. return
  259. }
  260. func (this *HisProjectApiController) SaveProjectTeam() {
  261. project_team := this.GetString("project_team")
  262. price := this.GetString("price")
  263. price_float, _ := strconv.ParseFloat(price, 64)
  264. pinyin := this.GetString("pinyin")
  265. wubi := this.GetString("wubi")
  266. tube_color, _ := this.GetInt64("tube_color")
  267. team_type, _ := this.GetInt64("team_type")
  268. remark := this.GetString("remark")
  269. ids := this.GetString("ids")
  270. adminUserInfo := this.GetAdminUserInfo()
  271. orgId := adminUserInfo.CurrentOrgId
  272. projectTeam := models.XtHisProjectTeam{
  273. ProjectTeam: project_team,
  274. Price: price_float,
  275. Pinyin: pinyin,
  276. Wubi: wubi,
  277. TubeColor: tube_color,
  278. TeamType: team_type,
  279. Remark: remark,
  280. UserOrgId: orgId,
  281. Status: 1,
  282. CreatedTime: time.Now().Unix(),
  283. ProjectId: ids,
  284. }
  285. fmt.Println(projectTeam)
  286. _, errcodes := service.GetHisProjectByNameOne(project_team, orgId)
  287. if errcodes == gorm.ErrRecordNotFound {
  288. err := service.CreatedProjectTeam(&projectTeam)
  289. if err != nil {
  290. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  291. return
  292. }
  293. this.ServeSuccessJSON(map[string]interface{}{
  294. "projectTeam": projectTeam,
  295. })
  296. return
  297. } else if errcodes == nil {
  298. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  299. return
  300. }
  301. }
  302. func (this *HisProjectApiController) GetProjectTeamList() {
  303. limit, _ := this.GetInt64("limit")
  304. page, _ := this.GetInt64("page")
  305. keyword := this.GetString("keyword")
  306. adminUserInfo := this.GetAdminUserInfo()
  307. orgId := adminUserInfo.CurrentOrgId
  308. projectTeamList, total, err := service.GetProjectTeamList(limit, page, orgId, keyword)
  309. if err != nil {
  310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  311. return
  312. }
  313. this.ServeSuccessJSON(map[string]interface{}{
  314. "projectTeamList": projectTeamList,
  315. "total": total,
  316. })
  317. return
  318. }
  319. func (this *HisProjectApiController) GetProjectTeamDetail() {
  320. id, _ := this.GetInt64("id")
  321. projectTeamDetail, err := service.GetProjectTeamDetail(id)
  322. if err != nil {
  323. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  324. return
  325. }
  326. this.ServeSuccessJSON(map[string]interface{}{
  327. "projectTeamDetail": projectTeamDetail,
  328. })
  329. return
  330. }
  331. func (this *HisProjectApiController) UpdatedProjectTeam() {
  332. id, _ := this.GetInt64("id")
  333. project_team := this.GetString("project_team")
  334. price := this.GetString("price")
  335. price_float, _ := strconv.ParseFloat(price, 64)
  336. pinyin := this.GetString("pinyin")
  337. wubi := this.GetString("wubi")
  338. tube_color, _ := this.GetInt64("tube_color")
  339. team_type, _ := this.GetInt64("team_type")
  340. remark := this.GetString("remark")
  341. ids := this.GetString("ids")
  342. projectTeam := models.XtHisProjectTeam{
  343. ProjectTeam: project_team,
  344. Price: price_float,
  345. Pinyin: pinyin,
  346. Wubi: wubi,
  347. TubeColor: tube_color,
  348. TeamType: team_type,
  349. Remark: remark,
  350. ProjectId: ids,
  351. }
  352. err := service.UpdatedProjectTeam(id, &projectTeam)
  353. if err != nil {
  354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  355. return
  356. }
  357. this.ServeSuccessJSON(map[string]interface{}{
  358. "projectTeam": projectTeam,
  359. })
  360. return
  361. }
  362. func (this *HisProjectApiController) DeleteProjectTeam() {
  363. id, _ := this.GetInt64("id")
  364. err := service.DeleteProjectTeam(id)
  365. if err != nil {
  366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  367. return
  368. }
  369. returnData := make(map[string]interface{}, 0)
  370. returnData["msg"] = "ok"
  371. this.ServeSuccessJSON(returnData)
  372. return
  373. }
  374. func (this *HisProjectApiController) SaveDePartment() {
  375. name := this.GetString("name")
  376. number := this.GetString("number")
  377. adminUserInfo := this.GetAdminUserInfo()
  378. orgId := adminUserInfo.CurrentOrgId
  379. department := models.XtHisDepartment{
  380. Name: name,
  381. Number: number,
  382. UserOrgId: orgId,
  383. CreatedTime: time.Now().Unix(),
  384. Status: 1,
  385. }
  386. err := service.CreateDePartment(&department)
  387. if err != nil {
  388. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  389. return
  390. }
  391. this.ServeSuccessJSON(map[string]interface{}{
  392. "department": department,
  393. })
  394. return
  395. }
  396. func (this *HisProjectApiController) GetDepartMentList() {
  397. limit, _ := this.GetInt64("limit")
  398. page, _ := this.GetInt64("page")
  399. adminUserInfo := this.GetAdminUserInfo()
  400. orgId := adminUserInfo.CurrentOrgId
  401. departMentList, total, err := service.GetDepartMentList(limit, page, orgId)
  402. if err != nil {
  403. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  404. return
  405. }
  406. this.ServeSuccessJSON(map[string]interface{}{
  407. "departMentList": departMentList,
  408. "total": total,
  409. })
  410. return
  411. }
  412. func (this *HisProjectApiController) GetDepartMentDetail() {
  413. id, _ := this.GetInt64("id")
  414. departDetail, err := service.GetDepartMentDetail(id)
  415. if err != nil {
  416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  417. return
  418. }
  419. this.ServeSuccessJSON(map[string]interface{}{
  420. "departDetail": departDetail,
  421. })
  422. return
  423. }
  424. func (this *HisProjectApiController) UpdatedDeparment() {
  425. id, _ := this.GetInt64("id")
  426. name := this.GetString("name")
  427. number := this.GetString("number")
  428. department := models.XtHisDepartment{
  429. Name: name,
  430. Number: number,
  431. }
  432. err := service.UpdatedDepartment(id, &department)
  433. if err != nil {
  434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  435. return
  436. }
  437. this.ServeSuccessJSON(map[string]interface{}{
  438. "department": department,
  439. })
  440. return
  441. }
  442. func (this *HisProjectApiController) DeleteDepartment() {
  443. id, _ := this.GetInt64("id")
  444. err := service.DeleteDepartment(id)
  445. if err != nil {
  446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  447. return
  448. }
  449. returnData := make(map[string]interface{}, 0)
  450. returnData["msg"] = "ok"
  451. this.ServeSuccessJSON(returnData)
  452. return
  453. }
  454. func (this *HisProjectApiController) GetBloodPatientList() {
  455. adminUserInfo := this.GetAdminUserInfo()
  456. orgId := adminUserInfo.CurrentOrgId
  457. fmt.Println("org", orgId)
  458. timeStr := time.Now().Format("2006-01-02")
  459. timeLayout := "2006-01-02 15:04:05"
  460. fmt.Println("timeStr:", timeStr)
  461. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  462. timenow := timeStringToTime.Unix()
  463. //统计血透排班的患者
  464. scheduleList, err := service.GetBloodPatientList(orgId, timenow)
  465. //统计当日挂号的患者
  466. hisPatient, _ := service.GetHisPatient(orgId, timenow)
  467. //统计今天开处方的患者
  468. prescription, _ := service.GetHisPrescriptionOther(orgId, timenow)
  469. if err != nil {
  470. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  471. return
  472. }
  473. this.ServeSuccessJSON(map[string]interface{}{
  474. "scheduleList": scheduleList,
  475. "hisPatient": hisPatient,
  476. "prescription": prescription,
  477. })
  478. return
  479. }
  480. func (this *HisProjectApiController) GetHisPrescription() {
  481. id, _ := this.GetInt64("id")
  482. timeStr := time.Now().Format("2006-01-02")
  483. timeLayout := "2006-01-02 15:04:05"
  484. fmt.Println("timeStr:", timeStr)
  485. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  486. timenow := timeStringToTime.Unix()
  487. prescriptionList, err := service.GetHisPrescriptionByPatientId(id, timenow)
  488. if err != nil {
  489. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  490. return
  491. }
  492. this.ServeSuccessJSON(map[string]interface{}{
  493. "prescriptionList": prescriptionList,
  494. })
  495. return
  496. }
  497. func (this *HisProjectApiController) AdditionalCharge() {
  498. dataBody := make(map[string]interface{}, 0)
  499. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  500. fmt.Println(err)
  501. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  502. patient_id := int64(dataBody["patient_id"].(float64))
  503. fmt.Println("patient_id2222222222", patient_id)
  504. medicineData, _ := dataBody["medicineData"].([]interface{})
  505. adminUserInfo := this.GetAdminUserInfo()
  506. orgId := adminUserInfo.CurrentOrgId
  507. admin_user_id := adminUserInfo.AdminUser.Id
  508. timeStr := time.Now().Format("2006-01-02")
  509. timeLayout := "2006-01-02 15:04:05"
  510. fmt.Println("timeStr:", timeStr)
  511. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  512. timenow := timeStringToTime.Unix()
  513. for _, item := range medicineData {
  514. items := item.(map[string]interface{})
  515. //drug_id := int64(items["id"].(float64))
  516. money := items["money"].(string)
  517. moneys, _ := strconv.ParseInt(money, 10, 64)
  518. monStr := strconv.FormatInt(moneys, 10)
  519. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  520. additionalCharge := models.HisAdditionalCharge{
  521. HisPatientId: his_patient_id,
  522. UserOrgId: orgId,
  523. PatientId: patient_id,
  524. RecordDate: timenow,
  525. Price: monneyStr,
  526. Status: 1,
  527. AdminUserId: admin_user_id,
  528. CreatedTime: time.Now().Unix(),
  529. }
  530. err := service.CreateAdditionalCharge(&additionalCharge)
  531. if err != nil {
  532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  533. return
  534. }
  535. this.ServeSuccessJSON(map[string]interface{}{
  536. "additionalCharge": additionalCharge,
  537. })
  538. return
  539. }
  540. }
  541. func (this *HisProjectApiController) GetTreatmentList() {
  542. patient_id, _ := this.GetInt64("patient_id")
  543. timeStr := time.Now().Format("2006-01-02")
  544. timeLayout := "2006-01-02 15:04:05"
  545. fmt.Println("timeStr:", timeStr)
  546. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  547. timenow := timeStringToTime.Unix()
  548. treatmentList, err := service.GetTreatmentList(patient_id, timenow)
  549. if err != nil {
  550. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  551. return
  552. }
  553. this.ServeSuccessJSON(map[string]interface{}{
  554. "treatmentList": treatmentList,
  555. })
  556. return
  557. }
  558. func (this *HisProjectApiController) GetAllProjectList() {
  559. adminUserInfo := this.GetAdminUserInfo()
  560. orgId := adminUserInfo.CurrentOrgId
  561. projectList, err := service.GetAllProjectList(orgId)
  562. //获取列表数据
  563. hisprojectlist, err := service.GetHisProjectListByOrgId(orgId)
  564. if err != nil {
  565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  566. return
  567. }
  568. this.ServeSuccessJSON(map[string]interface{}{
  569. "projectList": projectList,
  570. "hisprojectlist": hisprojectlist,
  571. })
  572. return
  573. }
  574. func (this *HisProjectApiController) AddProjectList() {
  575. id, _ := this.GetInt64("id")
  576. number, _ := this.GetInt64("number")
  577. adminUserInfo := this.GetAdminUserInfo()
  578. orgId := adminUserInfo.CurrentOrgId
  579. projectList := models.XtHisProjectList{
  580. ProjectId: id,
  581. Number: number,
  582. UserOrgId: orgId,
  583. Status: 1,
  584. CreatedTime: time.Now().Unix(),
  585. }
  586. err := service.CreateProjectList(&projectList)
  587. if err != nil {
  588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  589. return
  590. }
  591. this.ServeSuccessJSON(map[string]interface{}{
  592. "projectList": projectList,
  593. })
  594. return
  595. }
  596. func (this *HisProjectApiController) GetPatientInformation() {
  597. id, _ := this.GetInt64("id")
  598. information, err := service.GetHisPatientInformation(id)
  599. if err != nil {
  600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  601. return
  602. }
  603. this.ServeSuccessJSON(map[string]interface{}{
  604. "information": information,
  605. })
  606. return
  607. }
  608. func (this *HisProjectApiController) DeleteProject() {
  609. id, _ := this.GetInt64("id")
  610. err := service.DeleteProjectList(id)
  611. if err != nil {
  612. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  613. return
  614. }
  615. returnData := make(map[string]interface{}, 0)
  616. returnData["msg"] = "ok"
  617. this.ServeSuccessJSON(returnData)
  618. return
  619. }
  620. func (this *HisProjectApiController) GetHisProject() {
  621. adminUserInfo := this.GetAdminUserInfo()
  622. orgId := adminUserInfo.CurrentOrgId
  623. project, err := service.GetHisProject(orgId)
  624. if err != nil {
  625. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  626. return
  627. }
  628. this.ServeSuccessJSON(map[string]interface{}{
  629. "project": project,
  630. })
  631. }
  632. func (this *HisProjectApiController) GetProjectTeam() {
  633. strids := this.GetString("strids")
  634. idStrs := strings.Split(strids, ",")
  635. adminUserInfo := this.GetAdminUserInfo()
  636. orgId := adminUserInfo.CurrentOrgId
  637. team, err := service.GetProjectTeam(idStrs, orgId)
  638. if err != nil {
  639. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  640. return
  641. }
  642. this.ServeSuccessJSON(map[string]interface{}{
  643. "team": team,
  644. })
  645. }
  646. func (this *HisProjectApiController) GetAllDoctorList() {
  647. adminUserInfo := this.GetAdminUserInfo()
  648. orgId := adminUserInfo.CurrentOrgId
  649. appId := adminUserInfo.CurrentAppId
  650. //获取所有的医生
  651. doctor, err := service.GetAllDoctor(orgId, appId)
  652. //获取所有的科室
  653. department, err := service.GetAllDepartMent(orgId)
  654. if err != nil {
  655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  656. return
  657. }
  658. this.ServeSuccessJSON(map[string]interface{}{
  659. "doctor": doctor,
  660. "department": department,
  661. })
  662. }
  663. func (this *HisProjectApiController) SaveHisPatient() {
  664. timeLayout := "2006-01-02"
  665. loc, _ := time.LoadLocation("Local")
  666. age, _ := this.GetInt64("age")
  667. birthday := this.GetString("birthDay")
  668. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  669. birthUnix := birthdays.Unix()
  670. certificates, _ := this.GetInt64("certificates")
  671. cost_checked, _ := this.GetInt64("costChecked")
  672. cost, _ := this.GetInt64("cost")
  673. costs := strconv.FormatInt(cost, 10)
  674. cost_float, _ := strconv.ParseFloat(costs, 64)
  675. department, _ := this.GetInt64("department")
  676. doctor, _ := this.GetInt64("doctor")
  677. medicalcare, _ := this.GetInt64("medicalCare")
  678. idcard := this.GetString("idCard")
  679. medicalExpenses, _ := this.GetInt64("medicalExpenses")
  680. medicalExpense := strconv.FormatInt(medicalExpenses, 10)
  681. medicalExpense_float, _ := strconv.ParseFloat(medicalExpense, 64)
  682. medicalinsurancecard := this.GetString("medicalInsuranceCard")
  683. name := this.GetString("name")
  684. register, _ := this.GetInt64("register")
  685. registrationfee, _ := this.GetInt64("registrationFee")
  686. registrationfees := strconv.FormatInt(registrationfee, 10)
  687. registrationfees_float, _ := strconv.ParseFloat(registrationfees, 64)
  688. settlementValue, _ := this.GetInt64("settlementValue")
  689. sex, _ := this.GetInt64("sex")
  690. total, _ := this.GetInt64("total")
  691. totals := strconv.FormatInt(total, 10)
  692. totals_float, _ := strconv.ParseFloat(totals, 64)
  693. adminUserInfo := this.GetAdminUserInfo()
  694. orgId := adminUserInfo.CurrentOrgId
  695. recordDateStr := time.Now().Format("2006-01-02")
  696. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  697. fmt.Println("parseDateErr", parseDateErr)
  698. nowtime := recordDate.Unix()
  699. bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
  700. if errcode == gorm.ErrRecordNotFound {
  701. patient := models.XtHisPatient{
  702. Age: age,
  703. Birthday: birthUnix,
  704. IdType: certificates,
  705. CostOfProduction: cost_float,
  706. Departments: department,
  707. Doctor: doctor,
  708. AdminUserId: adminUserInfo.AdminUser.Id,
  709. MedicalTreatmentType: medicalcare,
  710. IdCardNo: idcard,
  711. IsNeedCostOfProduction: cost_checked,
  712. TreatmentCost: medicalExpense_float,
  713. MedicalInsuranceNumber: medicalinsurancecard,
  714. Name: name,
  715. RegisterType: register,
  716. RegisterCost: registrationfees_float,
  717. BalanceAccountsType: settlementValue,
  718. Gender: sex,
  719. Total: totals_float,
  720. UserOrgId: orgId,
  721. Status: 1,
  722. RecordDate: nowtime,
  723. IsReturn: 1,
  724. }
  725. err := service.CreateHisPatient(&patient)
  726. if err != nil {
  727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  728. return
  729. }
  730. this.ServeSuccessJSON(map[string]interface{}{
  731. "patient": patient,
  732. })
  733. } else if errcode == nil {
  734. patient := models.XtHisPatient{
  735. Age: age,
  736. Birthday: birthUnix,
  737. IdType: certificates,
  738. CostOfProduction: cost_float,
  739. Departments: department,
  740. AdminUserId: doctor,
  741. MedicalTreatmentType: medicalcare,
  742. IdCardNo: idcard,
  743. IsNeedCostOfProduction: cost_checked,
  744. TreatmentCost: medicalExpense_float,
  745. MedicalInsuranceNumber: medicalinsurancecard,
  746. Name: name,
  747. RegisterType: register,
  748. RegisterCost: registrationfees_float,
  749. BalanceAccountsType: settlementValue,
  750. Gender: sex,
  751. Total: totals_float,
  752. UserOrgId: orgId,
  753. PatientId: bloodPatient.ID,
  754. }
  755. err := service.CreateHisPatient(&patient)
  756. if err != nil {
  757. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  758. return
  759. }
  760. this.ServeSuccessJSON(map[string]interface{}{
  761. "patient": patient,
  762. })
  763. }
  764. }
  765. func (this *HisProjectApiController) GetAllProjectTeam() {
  766. adminUserInfo := this.GetAdminUserInfo()
  767. orgId := adminUserInfo.CurrentOrgId
  768. fmt.Println("aaa")
  769. team, err := service.GetAllProjectTeam(orgId)
  770. if err != nil {
  771. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  772. return
  773. }
  774. this.ServeSuccessJSON(map[string]interface{}{
  775. "team": team,
  776. })
  777. }
  778. func (this *HisProjectApiController) GetProjectListById() {
  779. adminUserInfo := this.GetAdminUserInfo()
  780. orgId := adminUserInfo.CurrentOrgId
  781. project_id := this.GetString("project_id")
  782. idStrs := strings.Split(project_id, ",")
  783. project, err := service.GetProjectListById(orgId, idStrs)
  784. if err != nil {
  785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  786. return
  787. }
  788. this.ServeSuccessJSON(map[string]interface{}{
  789. "project": project,
  790. })
  791. }
  792. func (this *HisProjectApiController) GetHisPatientHistory() {
  793. timeLayout := "2006-01-02"
  794. loc, _ := time.LoadLocation("Local")
  795. keyword := this.GetString("keyword")
  796. start_time := this.GetString("start_time")
  797. end_time := this.GetString("end_time")
  798. register_type, _ := this.GetInt64("register_type")
  799. limit, _ := this.GetInt64("limit")
  800. page, _ := this.GetInt64("page")
  801. fmt.Println(keyword, start_time, end_time, register_type, limit, page)
  802. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  803. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  804. adminUserInfo := this.GetAdminUserInfo()
  805. orgId := adminUserInfo.CurrentOrgId
  806. history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
  807. department, err := service.GetAllDepartMent(orgId)
  808. appId := adminUserInfo.CurrentAppId
  809. doctor, err := service.GetAllDoctor(orgId, appId)
  810. if err != nil {
  811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  812. return
  813. }
  814. this.ServeSuccessJSON(map[string]interface{}{
  815. "history": history,
  816. "total": total,
  817. "department": department,
  818. "doctor": doctor,
  819. })
  820. }
  821. func (this *HisProjectApiController) ChangePatient() {
  822. id, _ := this.GetInt64("id")
  823. //查询该患者今日是否已经就诊
  824. recordDateStr := time.Now().Format("2006-01-02")
  825. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  826. fmt.Println("parseDateErr", parseDateErr)
  827. nowtime := recordDate.Unix()
  828. adminUserInfo := this.GetAdminUserInfo()
  829. orgId := adminUserInfo.CurrentOrgId
  830. _, errcode := service.GetHisPrescriptionTwo(id, orgId, nowtime)
  831. if errcode == gorm.ErrRecordNotFound {
  832. err := service.ChangePatient(id)
  833. if err != nil {
  834. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  835. return
  836. }
  837. returnData := make(map[string]interface{}, 0)
  838. returnData["msg"] = "ok"
  839. this.ServeSuccessJSON(returnData)
  840. return
  841. } else if errcode == nil {
  842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  843. return
  844. }
  845. }
  846. func (this *HisProjectApiController) GetPatientcaseHistory() {
  847. patient_id, _ := this.GetInt64("patient_id")
  848. patient, _ := service.GetBloodPatientInfoById(patient_id)
  849. history, err := service.GetPatientCaseHistory(patient_id)
  850. hispatient, _ := service.GetHisPatientById(patient_id)
  851. if err != nil {
  852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  853. return
  854. }
  855. this.ServeSuccessJSON(map[string]interface{}{
  856. "patient": patient,
  857. "history": history,
  858. "hispatient": hispatient,
  859. })
  860. }
  861. func (this *HisProjectApiController) GetTemplateDetail() {
  862. id, _ := this.GetInt64("id")
  863. templateDetail, err := service.GetTemplateDetail(id)
  864. if err != nil {
  865. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  866. return
  867. }
  868. this.ServeSuccessJSON(map[string]interface{}{
  869. "templateDetail": templateDetail,
  870. })
  871. }
  872. func (this *HisProjectApiController) UpdateRecordTemplate() {
  873. id, _ := this.GetInt64("id")
  874. template_name := this.GetString("template_name")
  875. fmt.Println("template_name22222222222222", template_name)
  876. template_remark := this.GetString("template_remark")
  877. diagnostic := this.GetString("diagnostic")
  878. chief_conplaint := this.GetString("chief_conplaint")
  879. history_of_present_illness := this.GetString("history_of_present_illness")
  880. past_history := this.GetString("past_history")
  881. personal_history := this.GetString("personal_history")
  882. family_history := this.GetString("family_history")
  883. adminUserInfo := this.GetAdminUserInfo()
  884. creater := adminUserInfo.AdminUser.Id
  885. historyTemplate := models.HisCaseHistoryTemplate{
  886. HistoryOfPresentIllness: history_of_present_illness,
  887. PastHistory: past_history,
  888. ChiefConplaint: chief_conplaint,
  889. PersonalHistory: personal_history,
  890. FamilyHistory: family_history,
  891. Diagnostic: diagnostic,
  892. Status: 1,
  893. Mtime: time.Now().Unix(),
  894. RecordDate: time.Now().Unix(),
  895. TemplateName: template_name,
  896. TemplateRemark: template_remark,
  897. Modifier: creater,
  898. }
  899. err := service.UpdateCaseHistoryTemplate(&historyTemplate, id)
  900. if err != nil {
  901. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  902. return
  903. }
  904. this.ServeSuccessJSON(map[string]interface{}{
  905. "templateDetail": historyTemplate,
  906. })
  907. }