his_project_api_controller.go 30KB

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