his_project_api_controller.go 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "fmt"
  8. "github.com/astaxie/beego"
  9. "github.com/jinzhu/gorm"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. type HisProjectApiController struct {
  15. BaseAuthAPIController
  16. }
  17. func HisProjectRouters() {
  18. beego.Router("/api/his/saveproject", &HisProjectApiController{}, "Get:SaveProject")
  19. beego.Router("/api/his/getprojectlist", &HisProjectApiController{}, "Get:GetProjectList")
  20. beego.Router("/api/his/getprojectdetail", &HisProjectApiController{}, "Get:GetProjectDetail")
  21. beego.Router("/api/his/updatedproject", &HisProjectApiController{}, "Get:UpdatedProject")
  22. beego.Router("/api/his/deletehisproject", &HisProjectApiController{}, "Get:DeleteHisProject")
  23. beego.Router("/api/his/saveprojectteam", &HisProjectApiController{}, "Get:SaveProjectTeam")
  24. beego.Router("/api/his/getprojectteamlist", &HisProjectApiController{}, "Get:GetProjectTeamList")
  25. beego.Router("/api/his/getprojectteamdetail", &HisProjectApiController{}, "Get:GetProjectTeamDetail")
  26. beego.Router("/api/his/updateprojectteam", &HisProjectApiController{}, "Get:UpdatedProjectTeam")
  27. beego.Router("/api/his/deleteprojectteam", &HisProjectApiController{}, "Get:DeleteProjectTeam")
  28. beego.Router("/api/his/savedepartment", &HisProjectApiController{}, "Get:SaveDePartment")
  29. beego.Router("/api/his/getdepartmentlist", &HisProjectApiController{}, "Get:GetDepartMentList")
  30. beego.Router("/api/his/getdepartmentdetail", &HisProjectApiController{}, "Get:GetDepartMentDetail")
  31. beego.Router("/api/his/updagtedepartment", &HisProjectApiController{}, "Get:UpdatedDeparment")
  32. beego.Router("/api/his/deletedeparment", &HisProjectApiController{}, "Get:DeleteDepartment")
  33. beego.Router("/api/his/getallprojectlist", &HisProjectApiController{}, "Get:GetAllProjectList")
  34. beego.Router("/api/his/addprojectlist", &HisProjectApiController{}, "Get:AddProjectList")
  35. beego.Router("/api/his/deleteproject", &HisProjectApiController{}, "Get:DeleteProject")
  36. beego.Router("/api/his/gethisproject", &HisProjectApiController{}, "Get:GetHisProject")
  37. beego.Router("/api/his/getprojectteam", &HisProjectApiController{}, "Get:GetProjectTeam")
  38. beego.Router("/api/his/getalldoctorlist", &HisProjectApiController{}, "Get:GetAllDoctorList")
  39. beego.Router("/api/his/savehispatient", &HisProjectApiController{}, "Get:SaveHisPatient")
  40. //获取今日血透排班的患者
  41. beego.Router("/api/his/getbloodpatient", &HisProjectApiController{}, "Get:GetBloodPatientList")
  42. //获取患者的今日透析处方
  43. beego.Router("/api/his/gethisprescription", &HisProjectApiController{}, "Get:GetHisPrescription")
  44. //获取治疗单
  45. beego.Router("/api/his/gettreatlist", &HisProjectApiController{}, "Get:GetTreatmentList")
  46. beego.Router("/api/his/getpatientinformation", &HisProjectApiController{}, "Get:GetPatientInformation")
  47. beego.Router("/api/hist/getallprojecteam", &HisProjectApiController{}, "Get:GetAllProjectTeam")
  48. beego.Router("/api/his/getprojectlistbyid", &HisProjectApiController{}, "Get:GetProjectListById")
  49. beego.Router("/api/his/gethispatienthistory", &HisProjectApiController{}, "Get:GetHisPatientHistory")
  50. beego.Router("/api/patient/changepatient", &HisProjectApiController{}, "Get:ChangePatient")
  51. beego.Router("/api/patient/getpatientcasehistory", &HisProjectApiController{}, "Get:GetPatientcaseHistory")
  52. beego.Router("/api/doctorworkstation/gettemplatedetail", &HisProjectApiController{}, "Get:GetTemplateDetail")
  53. beego.Router("/api/doctorworkstation/updaterecordtemplate", &HisProjectApiController{}, "Get:UpdateRecordTemplate")
  54. beego.Router("/api/hispatient/gehispatient", &HisProjectApiController{}, "Get:GetHisPatient")
  55. //获取处方打印单
  56. beego.Router("/api/hispatient/getprescriptionprint", &HisProjectApiController{}, "Get:GetDoctorAdvicePrint")
  57. //获取项目打印单
  58. //beego.Router("/api/hispatient/getprojectprint",&HisApiController{},"Get:GetProjectPrint")
  59. beego.Router("/api/hispatient/postprinthistemplate", &HisProjectApiController{}, "Get:PostPrintHisTemplate")
  60. beego.Router("/api/gethisprinttemplate", &HisProjectApiController{}, "Get:GetHisPrintTemplate")
  61. beego.Router("/api/hispatient/postprescriptiontemplate", &HisProjectApiController{}, "Get:PostPrescriptionTempalte")
  62. beego.Router("/api/hispatient/getprescriptiontemplate", &HisProjectApiController{}, "Get:GetPrescriptionTemplate")
  63. beego.Router("/api/hispatient/posttreatprinttemplate", &HisProjectApiController{}, "Get:PostTreatPrintTemplate")
  64. beego.Router("/api/hispatient/gettreatprinttemplate", &HisProjectApiController{}, "Get:GetTreatPrintTemplate")
  65. beego.Router("/api/hispatient/postchargeprinttemplate", &HisProjectApiController{}, "Get:PostChargePrintTemplate")
  66. beego.Router("/api/hispatient/getchargeprinttemplate", &HisProjectApiController{}, "Get:GetChargePrintTemplate")
  67. beego.Router("/api/hispatient/getallhispatient", &HisProjectApiController{}, "Get:GetAllHisPatient")
  68. beego.Router("/api/hispatient/getchargeprint", &HisProjectApiController{}, "Get:GetChargePrint")
  69. beego.Router("/api/hispatient/gettodayschedulepatient", &HisProjectApiController{}, "Get:GetTodaySchedulePatient")
  70. beego.Router("/api/hispatient/gethispatientdetail", &HisProjectApiController{}, "Get:GetHisPatientDetail")
  71. beego.Router("/api/hispatient/getalldepartmentlist", &HisProjectApiController{}, "Get:GetAllDepartmentList")
  72. beego.Router("/api/hispatient/getprescription", &HisProjectApiController{}, "Get:GetPrescription")
  73. }
  74. func (this *HisProjectApiController) SaveProject() {
  75. project_name := this.GetString("project_name")
  76. pinyin := this.GetString("pinyin")
  77. wubi := this.GetString("wubi")
  78. price := this.GetString("price")
  79. price_float, err := strconv.ParseFloat(price, 64)
  80. unit := this.GetString("unit")
  81. cost_classify, _ := this.GetInt64("cost_classify")
  82. executive_section, _ := this.GetInt64("executive_section")
  83. medical_coverage, _ := this.GetInt64("medical_coverage")
  84. statistical_classification, _ := this.GetInt64("statistical_classification")
  85. disease_directory, _ := this.GetInt64("disease_directory")
  86. is_record, _ := this.GetInt64("is_record")
  87. medical_code := this.GetString("medical_code")
  88. tube_color, _ := this.GetInt64("tube_color")
  89. medical_status, _ := this.GetInt64("medical_status")
  90. remark := this.GetString("remark")
  91. sign, _ := this.GetInt64("sign")
  92. default_number := this.GetString("default_number")
  93. is_charge, _ := this.GetInt64("is_charge")
  94. is_estimate, _ := this.GetInt64("is_estimate")
  95. is_workload, _ := this.GetInt64("is_workload")
  96. sort := this.GetString("sort")
  97. is_advice, _ := this.GetInt64("is_advice")
  98. is_default, _ := this.GetInt64("is_default")
  99. single_dose := this.GetString("single_dose")
  100. delivery_way := this.GetString("delivery_way")
  101. execution_frequency := this.GetString("execution_frequency")
  102. number_days := this.GetString("number_days")
  103. total := this.GetString("total")
  104. adminUserInfo := this.GetAdminUserInfo()
  105. orgId := adminUserInfo.CurrentOrgId
  106. hisProject := models.XtHisProject{
  107. ProjectName: project_name,
  108. Pinyin: pinyin,
  109. Wubi: wubi,
  110. Price: price_float,
  111. Unit: unit,
  112. CostClassify: cost_classify,
  113. ExecutiveSection: executive_section,
  114. MedicalCoverage: medical_coverage,
  115. StatisticalClassification: statistical_classification,
  116. DiseaseDirectory: disease_directory,
  117. IsRecord: is_record,
  118. MedicalCode: medical_code,
  119. TubeColor: tube_color,
  120. MedicalStatus: medical_status,
  121. Remark: remark,
  122. Sign: sign,
  123. DefaultNumber: default_number,
  124. IsCharge: is_charge,
  125. IsEstimate: is_estimate,
  126. IsWorkload: is_workload,
  127. Sort: sort,
  128. DoctorAdvice: is_advice,
  129. IsDefault: is_default,
  130. UserOrgId: orgId,
  131. Status: 1,
  132. CreatedTime: time.Now().Unix(),
  133. SingleDose: single_dose,
  134. DeliveryWay: delivery_way,
  135. ExecutionFrequency: execution_frequency,
  136. NumberDays: number_days,
  137. Total: total,
  138. }
  139. //查询项目名称是否存在
  140. _, errcode := service.GetHisProjectIsExist(project_name, orgId)
  141. if errcode == gorm.ErrRecordNotFound {
  142. err = service.CreateHisProject(&hisProject)
  143. if err != nil {
  144. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  145. return
  146. }
  147. this.ServeSuccessJSON(map[string]interface{}{
  148. "hisProject": hisProject,
  149. })
  150. return
  151. } else if errcode == nil {
  152. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  153. return
  154. }
  155. }
  156. func (this *HisProjectApiController) GetProjectList() {
  157. adminUserInfo := this.GetAdminUserInfo()
  158. orgId := adminUserInfo.CurrentOrgId
  159. limit, _ := this.GetInt64("limit")
  160. page, _ := this.GetInt64("page")
  161. is_charge, _ := this.GetInt64("is_charge")
  162. is_start, _ := this.GetInt64("is_start")
  163. keyword := this.GetString("keyword")
  164. projecList, total, err := service.GetHisProjectList(orgId, limit, page, is_charge, is_start, keyword)
  165. if err != nil {
  166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  167. return
  168. }
  169. this.ServeSuccessJSON(map[string]interface{}{
  170. "projecList": projecList,
  171. "total": total,
  172. })
  173. return
  174. }
  175. func (this *HisProjectApiController) GetProjectDetail() {
  176. id, _ := this.GetInt64("id")
  177. projectDetail, err := service.GetProjectDetail(id)
  178. if err != nil {
  179. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  180. return
  181. }
  182. this.ServeSuccessJSON(map[string]interface{}{
  183. "projecDetail": projectDetail,
  184. })
  185. return
  186. }
  187. func (this *HisProjectApiController) UpdatedProject() {
  188. id, _ := this.GetInt64("id")
  189. project_name := this.GetString("project_name")
  190. pinyin := this.GetString("pinyin")
  191. wubi := this.GetString("wubi")
  192. price := this.GetString("price")
  193. price_float, _ := strconv.ParseFloat(price, 64)
  194. unit := this.GetString("unit")
  195. cost_classify, _ := this.GetInt64("cost_classify")
  196. executive_section, _ := this.GetInt64("executive_section")
  197. medical_coverage, _ := this.GetInt64("medical_coverage")
  198. statistical_classification, _ := this.GetInt64("statistical_classification")
  199. disease_directory, _ := this.GetInt64("disease_directory")
  200. is_record, _ := this.GetInt64("is_record")
  201. medical_code := this.GetString("medical_code")
  202. tube_color, _ := this.GetInt64("tube_color")
  203. medical_status, _ := this.GetInt64("medical_status")
  204. remark := this.GetString("remark")
  205. sign, _ := this.GetInt64("sign")
  206. default_number := this.GetString("default_number")
  207. is_charge, _ := this.GetInt64("is_charge")
  208. is_estimate, _ := this.GetInt64("is_estimate")
  209. is_workload, _ := this.GetInt64("is_workload")
  210. sort := this.GetString("sort")
  211. is_advice, _ := this.GetInt64("is_advice")
  212. is_default, _ := this.GetInt64("is_default")
  213. single_dose := this.GetString("single_dose")
  214. delivery_way := this.GetString("delivery_way")
  215. execution_frequency := this.GetString("execution_frequency")
  216. number_days := this.GetString("number_days")
  217. total := this.GetString("total")
  218. hisProject := models.XtHisProject{
  219. ProjectName: project_name,
  220. Pinyin: pinyin,
  221. Wubi: wubi,
  222. Price: price_float,
  223. Unit: unit,
  224. CostClassify: cost_classify,
  225. ExecutiveSection: executive_section,
  226. MedicalCoverage: medical_coverage,
  227. StatisticalClassification: statistical_classification,
  228. DiseaseDirectory: disease_directory,
  229. IsRecord: is_record,
  230. MedicalCode: medical_code,
  231. TubeColor: tube_color,
  232. MedicalStatus: medical_status,
  233. Remark: remark,
  234. Sign: sign,
  235. DefaultNumber: default_number,
  236. IsCharge: is_charge,
  237. IsEstimate: is_estimate,
  238. IsWorkload: is_workload,
  239. Sort: sort,
  240. DoctorAdvice: is_advice,
  241. IsDefault: is_default,
  242. UpdatedTime: time.Now().Unix(),
  243. SingleDose: single_dose,
  244. DeliveryWay: delivery_way,
  245. ExecutionFrequency: execution_frequency,
  246. NumberDays: number_days,
  247. Total: total,
  248. }
  249. err := service.UpdatedProject(id, &hisProject)
  250. if err != nil {
  251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  252. return
  253. }
  254. this.ServeSuccessJSON(map[string]interface{}{
  255. "hisProject": hisProject,
  256. })
  257. return
  258. }
  259. func (this *HisProjectApiController) DeleteHisProject() {
  260. id, _ := this.GetInt64("id")
  261. err := service.DeleteHisProject(id)
  262. if err != nil {
  263. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  264. return
  265. }
  266. returnData := make(map[string]interface{}, 0)
  267. returnData["msg"] = "ok"
  268. this.ServeSuccessJSON(returnData)
  269. return
  270. }
  271. func (this *HisProjectApiController) SaveProjectTeam() {
  272. project_team := this.GetString("project_team")
  273. price := this.GetString("price")
  274. price_float, _ := strconv.ParseFloat(price, 64)
  275. pinyin := this.GetString("pinyin")
  276. wubi := this.GetString("wubi")
  277. tube_color, _ := this.GetInt64("tube_color")
  278. team_type, _ := this.GetInt64("team_type")
  279. remark := this.GetString("remark")
  280. ids := this.GetString("ids")
  281. adminUserInfo := this.GetAdminUserInfo()
  282. orgId := adminUserInfo.CurrentOrgId
  283. projectTeam := models.XtHisProjectTeam{
  284. ProjectTeam: project_team,
  285. Price: price_float,
  286. Pinyin: pinyin,
  287. Wubi: wubi,
  288. TubeColor: tube_color,
  289. TeamType: team_type,
  290. Remark: remark,
  291. UserOrgId: orgId,
  292. Status: 1,
  293. CreatedTime: time.Now().Unix(),
  294. ProjectId: ids,
  295. }
  296. fmt.Println(projectTeam)
  297. _, errcodes := service.GetHisProjectByNameOne(project_team, orgId)
  298. if errcodes == gorm.ErrRecordNotFound {
  299. err := service.CreatedProjectTeam(&projectTeam)
  300. if err != nil {
  301. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  302. return
  303. }
  304. this.ServeSuccessJSON(map[string]interface{}{
  305. "projectTeam": projectTeam,
  306. })
  307. return
  308. } else if errcodes == nil {
  309. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  310. return
  311. }
  312. }
  313. func (this *HisProjectApiController) GetProjectTeamList() {
  314. limit, _ := this.GetInt64("limit")
  315. page, _ := this.GetInt64("page")
  316. keyword := this.GetString("keyword")
  317. adminUserInfo := this.GetAdminUserInfo()
  318. orgId := adminUserInfo.CurrentOrgId
  319. projectTeamList, total, err := service.GetProjectTeamList(limit, page, orgId, keyword)
  320. if err != nil {
  321. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  322. return
  323. }
  324. this.ServeSuccessJSON(map[string]interface{}{
  325. "projectTeamList": projectTeamList,
  326. "total": total,
  327. })
  328. return
  329. }
  330. func (this *HisProjectApiController) GetProjectTeamDetail() {
  331. id, _ := this.GetInt64("id")
  332. projectTeamDetail, err := service.GetProjectTeamDetail(id)
  333. if err != nil {
  334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  335. return
  336. }
  337. this.ServeSuccessJSON(map[string]interface{}{
  338. "projectTeamDetail": projectTeamDetail,
  339. })
  340. return
  341. }
  342. func (this *HisProjectApiController) UpdatedProjectTeam() {
  343. id, _ := this.GetInt64("id")
  344. project_team := this.GetString("project_team")
  345. price := this.GetString("price")
  346. price_float, _ := strconv.ParseFloat(price, 64)
  347. pinyin := this.GetString("pinyin")
  348. wubi := this.GetString("wubi")
  349. tube_color, _ := this.GetInt64("tube_color")
  350. team_type, _ := this.GetInt64("team_type")
  351. remark := this.GetString("remark")
  352. ids := this.GetString("ids")
  353. projectTeam := models.XtHisProjectTeam{
  354. ProjectTeam: project_team,
  355. Price: price_float,
  356. Pinyin: pinyin,
  357. Wubi: wubi,
  358. TubeColor: tube_color,
  359. TeamType: team_type,
  360. Remark: remark,
  361. ProjectId: ids,
  362. }
  363. err := service.UpdatedProjectTeam(id, &projectTeam)
  364. if err != nil {
  365. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  366. return
  367. }
  368. this.ServeSuccessJSON(map[string]interface{}{
  369. "projectTeam": projectTeam,
  370. })
  371. return
  372. }
  373. func (this *HisProjectApiController) DeleteProjectTeam() {
  374. id, _ := this.GetInt64("id")
  375. err := service.DeleteProjectTeam(id)
  376. if err != nil {
  377. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  378. return
  379. }
  380. returnData := make(map[string]interface{}, 0)
  381. returnData["msg"] = "ok"
  382. this.ServeSuccessJSON(returnData)
  383. return
  384. }
  385. func (this *HisProjectApiController) SaveDePartment() {
  386. name := this.GetString("name")
  387. number := this.GetString("number")
  388. adminUserInfo := this.GetAdminUserInfo()
  389. orgId := adminUserInfo.CurrentOrgId
  390. department := models.XtHisDepartment{
  391. Name: name,
  392. Number: number,
  393. UserOrgId: orgId,
  394. CreatedTime: time.Now().Unix(),
  395. Status: 1,
  396. }
  397. err := service.CreateDePartment(&department)
  398. if err != nil {
  399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  400. return
  401. }
  402. this.ServeSuccessJSON(map[string]interface{}{
  403. "department": department,
  404. })
  405. return
  406. }
  407. func (this *HisProjectApiController) GetDepartMentList() {
  408. limit, _ := this.GetInt64("limit")
  409. page, _ := this.GetInt64("page")
  410. adminUserInfo := this.GetAdminUserInfo()
  411. orgId := adminUserInfo.CurrentOrgId
  412. departMentList, total, err := service.GetDepartMentList(limit, page, orgId)
  413. if err != nil {
  414. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  415. return
  416. }
  417. this.ServeSuccessJSON(map[string]interface{}{
  418. "departMentList": departMentList,
  419. "total": total,
  420. })
  421. return
  422. }
  423. func (this *HisProjectApiController) GetDepartMentDetail() {
  424. id, _ := this.GetInt64("id")
  425. departDetail, err := service.GetDepartMentDetail(id)
  426. if err != nil {
  427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  428. return
  429. }
  430. this.ServeSuccessJSON(map[string]interface{}{
  431. "departDetail": departDetail,
  432. })
  433. return
  434. }
  435. func (this *HisProjectApiController) UpdatedDeparment() {
  436. id, _ := this.GetInt64("id")
  437. name := this.GetString("name")
  438. number := this.GetString("number")
  439. department := models.XtHisDepartment{
  440. Name: name,
  441. Number: number,
  442. }
  443. err := service.UpdatedDepartment(id, &department)
  444. if err != nil {
  445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  446. return
  447. }
  448. this.ServeSuccessJSON(map[string]interface{}{
  449. "department": department,
  450. })
  451. return
  452. }
  453. func (this *HisProjectApiController) DeleteDepartment() {
  454. id, _ := this.GetInt64("id")
  455. err := service.DeleteDepartment(id)
  456. if err != nil {
  457. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  458. return
  459. }
  460. returnData := make(map[string]interface{}, 0)
  461. returnData["msg"] = "ok"
  462. this.ServeSuccessJSON(returnData)
  463. return
  464. }
  465. func (this *HisProjectApiController) GetBloodPatientList() {
  466. adminUserInfo := this.GetAdminUserInfo()
  467. orgId := adminUserInfo.CurrentOrgId
  468. timeStr := time.Now().Format("2006-01-02")
  469. timeLayout := "2006-01-02 15:04:05"
  470. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  471. timenow := timeStringToTime.Unix()
  472. //统计血透排班的患者
  473. scheduleList, err := service.GetBloodPatientList(orgId, timenow)
  474. //统计当日挂号的患者
  475. hisPatient, _ := service.GetHisPatient(orgId, timenow)
  476. //统计今天开处方的患者
  477. prescription, _ := service.GetHisPrescriptionOther(orgId, timenow)
  478. if err != nil {
  479. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  480. return
  481. }
  482. this.ServeSuccessJSON(map[string]interface{}{
  483. "scheduleList": scheduleList,
  484. "hisPatient": hisPatient,
  485. "prescription": prescription,
  486. })
  487. return
  488. }
  489. func (this *HisProjectApiController) GetHisPrescription() {
  490. id, _ := this.GetInt64("id")
  491. timeStr := time.Now().Format("2006-01-02")
  492. timeLayout := "2006-01-02 15:04:05"
  493. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  494. timenow := timeStringToTime.Unix()
  495. prescriptionList, err := service.GetHisPrescriptionByPatientId(id, timenow)
  496. if err != nil {
  497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  498. return
  499. }
  500. this.ServeSuccessJSON(map[string]interface{}{
  501. "prescriptionList": prescriptionList,
  502. })
  503. return
  504. }
  505. func (this *HisProjectApiController) GetTreatmentList() {
  506. patient_id, _ := this.GetInt64("patient_id")
  507. timeStr := time.Now().Format("2006-01-02")
  508. timeLayout := "2006-01-02 15:04:05"
  509. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  510. timenow := timeStringToTime.Unix()
  511. treatmentList, err := service.GetTreatmentList(patient_id, timenow)
  512. if err != nil {
  513. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  514. return
  515. }
  516. this.ServeSuccessJSON(map[string]interface{}{
  517. "treatmentList": treatmentList,
  518. })
  519. return
  520. }
  521. func (this *HisProjectApiController) GetAllProjectList() {
  522. adminUserInfo := this.GetAdminUserInfo()
  523. orgId := adminUserInfo.CurrentOrgId
  524. projectList, err := service.GetAllProjectList(orgId)
  525. //获取列表数据
  526. hisprojectlist, err := service.GetHisProjectListByOrgId(orgId)
  527. if err != nil {
  528. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  529. return
  530. }
  531. this.ServeSuccessJSON(map[string]interface{}{
  532. "projectList": projectList,
  533. "hisprojectlist": hisprojectlist,
  534. })
  535. return
  536. }
  537. func (this *HisProjectApiController) AddProjectList() {
  538. id, _ := this.GetInt64("id")
  539. number, _ := this.GetInt64("number")
  540. adminUserInfo := this.GetAdminUserInfo()
  541. orgId := adminUserInfo.CurrentOrgId
  542. projectList := models.XtHisProjectList{
  543. ProjectId: id,
  544. Number: number,
  545. UserOrgId: orgId,
  546. Status: 1,
  547. CreatedTime: time.Now().Unix(),
  548. }
  549. err := service.CreateProjectList(&projectList)
  550. if err != nil {
  551. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  552. return
  553. }
  554. this.ServeSuccessJSON(map[string]interface{}{
  555. "projectList": projectList,
  556. })
  557. return
  558. }
  559. func (this *HisProjectApiController) GetPatientInformation() {
  560. id, _ := this.GetInt64("id")
  561. information, err := service.GetHisPatientInformation(id)
  562. if err != nil {
  563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  564. return
  565. }
  566. this.ServeSuccessJSON(map[string]interface{}{
  567. "information": information,
  568. })
  569. return
  570. }
  571. func (this *HisProjectApiController) DeleteProject() {
  572. id, _ := this.GetInt64("id")
  573. err := service.DeleteProjectList(id)
  574. if err != nil {
  575. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  576. return
  577. }
  578. returnData := make(map[string]interface{}, 0)
  579. returnData["msg"] = "ok"
  580. this.ServeSuccessJSON(returnData)
  581. return
  582. }
  583. func (this *HisProjectApiController) GetHisProject() {
  584. adminUserInfo := this.GetAdminUserInfo()
  585. orgId := adminUserInfo.CurrentOrgId
  586. project, err := service.GetHisProject(orgId)
  587. if err != nil {
  588. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  589. return
  590. }
  591. this.ServeSuccessJSON(map[string]interface{}{
  592. "project": project,
  593. })
  594. }
  595. func (this *HisProjectApiController) GetProjectTeam() {
  596. strids := this.GetString("strids")
  597. idStrs := strings.Split(strids, ",")
  598. adminUserInfo := this.GetAdminUserInfo()
  599. orgId := adminUserInfo.CurrentOrgId
  600. team, err := service.GetProjectTeam(idStrs, orgId)
  601. if err != nil {
  602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  603. return
  604. }
  605. this.ServeSuccessJSON(map[string]interface{}{
  606. "team": team,
  607. })
  608. }
  609. func (this *HisProjectApiController) GetAllDoctorList() {
  610. adminUserInfo := this.GetAdminUserInfo()
  611. orgId := adminUserInfo.CurrentOrgId
  612. appId := adminUserInfo.CurrentAppId
  613. //获取所有的医生
  614. doctor, err := service.GetAllDoctor(orgId, appId)
  615. //获取所有的科室
  616. department, err := service.GetAllDepartMent(orgId)
  617. if err != nil {
  618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  619. return
  620. }
  621. this.ServeSuccessJSON(map[string]interface{}{
  622. "doctor": doctor,
  623. "department": department,
  624. })
  625. }
  626. func (this *HisProjectApiController) SaveHisPatient() {
  627. timeLayout := "2006-01-02"
  628. loc, _ := time.LoadLocation("Local")
  629. age, _ := this.GetInt64("age")
  630. birthday := this.GetString("birthDay")
  631. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  632. birthUnix := birthdays.Unix()
  633. certificates, _ := this.GetInt64("certificates")
  634. cost_checked, _ := this.GetInt64("costChecked")
  635. cost, _ := this.GetInt64("cost")
  636. costs := strconv.FormatInt(cost, 10)
  637. cost_float, _ := strconv.ParseFloat(costs, 64)
  638. department, _ := this.GetInt64("department")
  639. doctor, _ := this.GetInt64("doctor")
  640. medicalcare, _ := this.GetInt64("medicalCare")
  641. idcard := this.GetString("idCard")
  642. medicalExpenses, _ := this.GetInt64("medicalExpenses")
  643. medicalExpense := strconv.FormatInt(medicalExpenses, 10)
  644. medicalExpense_float, _ := strconv.ParseFloat(medicalExpense, 64)
  645. medicalinsurancecard := this.GetString("medicalInsuranceCard")
  646. name := this.GetString("name")
  647. register, _ := this.GetInt64("register")
  648. registrationfee, _ := this.GetInt64("registrationFee")
  649. registrationfees := strconv.FormatInt(registrationfee, 10)
  650. registrationfees_float, _ := strconv.ParseFloat(registrationfees, 64)
  651. settlementValue, _ := this.GetInt64("settlementValue")
  652. sex, _ := this.GetInt64("sex")
  653. total, _ := this.GetInt64("total")
  654. totals := strconv.FormatInt(total, 10)
  655. totals_float, _ := strconv.ParseFloat(totals, 64)
  656. adminUserInfo := this.GetAdminUserInfo()
  657. orgId := adminUserInfo.CurrentOrgId
  658. recordDateStr := time.Now().Format("2006-01-02")
  659. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  660. nowtime := recordDate.Unix()
  661. fmt.Println("nowtime0000000000", nowtime)
  662. phone := this.GetString("phone")
  663. social_type, _ := this.GetInt64("social_type")
  664. bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
  665. if errcode == gorm.ErrRecordNotFound {
  666. patient := models.XtHisPatient{
  667. Age: age,
  668. Birthday: birthUnix,
  669. IdType: certificates,
  670. CostOfProduction: cost_float,
  671. Departments: department,
  672. Doctor: doctor,
  673. AdminUserId: adminUserInfo.AdminUser.Id,
  674. MedicalTreatmentType: medicalcare,
  675. IdCardNo: idcard,
  676. IsNeedCostOfProduction: cost_checked,
  677. TreatmentCost: medicalExpense_float,
  678. MedicalInsuranceNumber: medicalinsurancecard,
  679. Name: name,
  680. RegisterType: register,
  681. RegisterCost: registrationfees_float,
  682. BalanceAccountsType: settlementValue,
  683. Gender: sex,
  684. Total: totals_float,
  685. UserOrgId: orgId,
  686. Status: 1,
  687. RecordDate: nowtime,
  688. IsReturn: 1,
  689. Ctime: time.Now().Unix(),
  690. Phone: phone,
  691. SocialType: social_type,
  692. }
  693. err := service.CreateHisPatient(&patient)
  694. lastPatient, err := service.GetLastPatient(orgId)
  695. timeStr := time.Now().Format("2006-01-02")
  696. timeArr := strings.Split(timeStr, "-")
  697. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
  698. hisPatient := models.HisPatient{
  699. Number: str,
  700. }
  701. err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
  702. fmt.Println("errr", err)
  703. if err != nil {
  704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  705. return
  706. }
  707. this.ServeSuccessJSON(map[string]interface{}{
  708. "patient": patient,
  709. })
  710. } else if errcode == nil {
  711. patient := models.XtHisPatient{
  712. Age: age,
  713. Birthday: birthUnix,
  714. IdType: certificates,
  715. CostOfProduction: cost_float,
  716. Departments: department,
  717. AdminUserId: doctor,
  718. MedicalTreatmentType: medicalcare,
  719. IdCardNo: idcard,
  720. IsNeedCostOfProduction: cost_checked,
  721. TreatmentCost: medicalExpense_float,
  722. MedicalInsuranceNumber: medicalinsurancecard,
  723. Name: name,
  724. RegisterType: register,
  725. RegisterCost: registrationfees_float,
  726. BalanceAccountsType: settlementValue,
  727. Gender: sex,
  728. Total: totals_float,
  729. UserOrgId: orgId,
  730. PatientId: bloodPatient.ID,
  731. Ctime: time.Now().Unix(),
  732. Phone: phone,
  733. SocialType: social_type,
  734. RecordDate: nowtime,
  735. }
  736. err := service.CreateHisPatient(&patient)
  737. lastPatient, err := service.GetLastPatient(orgId)
  738. timeStr := time.Now().Format("2006-01-02")
  739. timeArr := strings.Split(timeStr, "-")
  740. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
  741. hisPatient := models.HisPatient{
  742. Number: str,
  743. }
  744. err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
  745. fmt.Println("errr", err)
  746. if err != nil {
  747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  748. return
  749. }
  750. this.ServeSuccessJSON(map[string]interface{}{
  751. "patient": patient,
  752. })
  753. }
  754. }
  755. func (this *HisProjectApiController) GetAllProjectTeam() {
  756. adminUserInfo := this.GetAdminUserInfo()
  757. orgId := adminUserInfo.CurrentOrgId
  758. team, err := service.GetAllProjectTeam(orgId)
  759. if err != nil {
  760. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  761. return
  762. }
  763. this.ServeSuccessJSON(map[string]interface{}{
  764. "team": team,
  765. })
  766. }
  767. func (this *HisProjectApiController) GetProjectListById() {
  768. adminUserInfo := this.GetAdminUserInfo()
  769. orgId := adminUserInfo.CurrentOrgId
  770. project_id := this.GetString("project_id")
  771. idStrs := strings.Split(project_id, ",")
  772. project, err := service.GetProjectListById(orgId, idStrs)
  773. if err != nil {
  774. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  775. return
  776. }
  777. this.ServeSuccessJSON(map[string]interface{}{
  778. "project": project,
  779. })
  780. }
  781. func (this *HisProjectApiController) GetHisPatientHistory() {
  782. timeLayout := "2006-01-02"
  783. loc, _ := time.LoadLocation("Local")
  784. keyword := this.GetString("keyword")
  785. start_time := this.GetString("start_time")
  786. end_time := this.GetString("end_time")
  787. register_type, _ := this.GetInt64("register_type")
  788. limit, _ := this.GetInt64("limit")
  789. page, _ := this.GetInt64("page")
  790. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  791. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  792. adminUserInfo := this.GetAdminUserInfo()
  793. orgId := adminUserInfo.CurrentOrgId
  794. history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
  795. department, err := service.GetAllDepartMent(orgId)
  796. appId := adminUserInfo.CurrentAppId
  797. doctor, err := service.GetAllDoctor(orgId, appId)
  798. if err != nil {
  799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  800. return
  801. }
  802. this.ServeSuccessJSON(map[string]interface{}{
  803. "history": history,
  804. "total": total,
  805. "department": department,
  806. "doctor": doctor,
  807. })
  808. }
  809. func (this *HisProjectApiController) ChangePatient() {
  810. id, _ := this.GetInt64("id")
  811. //查询该患者今日是否已经就诊
  812. recordDateStr := time.Now().Format("2006-01-02")
  813. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  814. nowtime := recordDate.Unix()
  815. adminUserInfo := this.GetAdminUserInfo()
  816. orgId := adminUserInfo.CurrentOrgId
  817. _, errcode := service.GetHisPrescriptionTwo(id, orgId, nowtime)
  818. if errcode == gorm.ErrRecordNotFound {
  819. err := service.ChangePatient(id)
  820. if err != nil {
  821. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  822. return
  823. }
  824. returnData := make(map[string]interface{}, 0)
  825. returnData["msg"] = "ok"
  826. this.ServeSuccessJSON(returnData)
  827. return
  828. } else if errcode == nil {
  829. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  830. return
  831. }
  832. }
  833. func (this *HisProjectApiController) GetPatientcaseHistory() {
  834. patient_id, _ := this.GetInt64("patient_id")
  835. patient, _ := service.GetBloodPatientInfoById(patient_id)
  836. history, err := service.GetPatientCaseHistory(patient_id)
  837. hispatient, _ := service.GetHisPatientById(patient_id)
  838. if err != nil {
  839. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  840. return
  841. }
  842. this.ServeSuccessJSON(map[string]interface{}{
  843. "patient": patient,
  844. "history": history,
  845. "hispatient": hispatient,
  846. })
  847. }
  848. func (this *HisProjectApiController) GetTemplateDetail() {
  849. id, _ := this.GetInt64("id")
  850. templateDetail, err := service.GetTemplateDetail(id)
  851. if err != nil {
  852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  853. return
  854. }
  855. this.ServeSuccessJSON(map[string]interface{}{
  856. "templateDetail": templateDetail,
  857. })
  858. }
  859. func (this *HisProjectApiController) UpdateRecordTemplate() {
  860. id, _ := this.GetInt64("id")
  861. template_name := this.GetString("template_name")
  862. template_remark := this.GetString("template_remark")
  863. diagnostic := this.GetString("diagnostic")
  864. chief_conplaint := this.GetString("chief_conplaint")
  865. history_of_present_illness := this.GetString("history_of_present_illness")
  866. past_history := this.GetString("past_history")
  867. personal_history := this.GetString("personal_history")
  868. family_history := this.GetString("family_history")
  869. adminUserInfo := this.GetAdminUserInfo()
  870. creater := adminUserInfo.AdminUser.Id
  871. historyTemplate := models.HisCaseHistoryTemplate{
  872. HistoryOfPresentIllness: history_of_present_illness,
  873. PastHistory: past_history,
  874. ChiefConplaint: chief_conplaint,
  875. PersonalHistory: personal_history,
  876. FamilyHistory: family_history,
  877. Diagnostic: diagnostic,
  878. Status: 1,
  879. Mtime: time.Now().Unix(),
  880. RecordDate: time.Now().Unix(),
  881. TemplateName: template_name,
  882. TemplateRemark: template_remark,
  883. Modifier: creater,
  884. }
  885. err := service.UpdateCaseHistoryTemplate(&historyTemplate, id)
  886. if err != nil {
  887. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  888. return
  889. }
  890. this.ServeSuccessJSON(map[string]interface{}{
  891. "templateDetail": historyTemplate,
  892. })
  893. }
  894. func (this *HisProjectApiController) GetHisPatient() {
  895. adminUserInfo := this.GetAdminUserInfo()
  896. orgId := adminUserInfo.CurrentOrgId
  897. keyword := this.GetString("keyword")
  898. patient, err := service.GetHistPatient(orgId, keyword)
  899. if err != nil {
  900. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  901. return
  902. }
  903. this.ServeSuccessJSON(map[string]interface{}{
  904. "patient": patient,
  905. })
  906. }
  907. func (this *HisProjectApiController) GetDoctorAdvicePrint() {
  908. patient_id, _ := this.GetInt64("patient_id")
  909. record_date := this.GetString("record_date")
  910. schIDStr := this.GetString("ids")
  911. if len(schIDStr) == 0 {
  912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  913. return
  914. }
  915. idStrs := strings.Split(schIDStr, ",")
  916. timeLayout := "2006-01-02"
  917. loc, _ := time.LoadLocation("Local")
  918. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  919. recordDateTime := theTime.Unix()
  920. //prescription_id, _ := this.GetInt64("prescription_id")
  921. adminUserInfo := this.GetAdminUserInfo()
  922. advicePrint, err := service.GetDoctorAdvicePrint(patient_id, recordDateTime, idStrs)
  923. projectlist, err := service.GetAllProjectList(adminUserInfo.CurrentOrgId)
  924. //doctorPorject, err := service.GetDoctorProjectItem(patient_id, recordDateTime)
  925. //patient, err := service.GetBloodPatientByPatient(patient_id)
  926. //prescriptionInfo, err := service.GetPrscriptionInfo(patient_id, recordDateTime)
  927. if err != nil {
  928. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  929. return
  930. }
  931. this.ServeSuccessJSON(map[string]interface{}{
  932. "advicePrint": advicePrint,
  933. "projectlist": projectlist,
  934. //"patient": patient,
  935. //"doctorPorject": doctorPorject,
  936. //"prescriptionInfo": prescriptionInfo,
  937. })
  938. }
  939. func (this *HisProjectApiController) GetProjectPrint() {
  940. his_patient_id, _ := this.GetInt64("his_patient_id")
  941. hisPatient, _ := service.GetHisPatientById(his_patient_id)
  942. projectPrint, err := service.GetProjectPrint(his_patient_id)
  943. if err != nil {
  944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  945. return
  946. }
  947. this.ServeSuccessJSON(map[string]interface{}{
  948. "hisPatient": hisPatient,
  949. "projectPrint": projectPrint,
  950. })
  951. }
  952. func (this *HisProjectApiController) PostPrintHisTemplate() {
  953. template_id, _ := this.GetInt64("template_id")
  954. adminUserInfo := this.GetAdminUserInfo()
  955. orgId := adminUserInfo.CurrentOrgId
  956. _, errcode := service.GetHisTemplateId(template_id, orgId)
  957. fmt.Println("errcode", errcode)
  958. if errcode == gorm.ErrRecordNotFound {
  959. template := models.XtHisTemplate{
  960. TemplateId: template_id,
  961. UserOrgId: orgId,
  962. Status: 1,
  963. Ctime: time.Now().Unix(),
  964. }
  965. err := service.CreateHisTemplate(&template)
  966. if err != nil {
  967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  968. return
  969. }
  970. this.ServeSuccessJSON(map[string]interface{}{
  971. "template": template,
  972. "template_id": template_id,
  973. })
  974. } else if errcode == nil {
  975. template := models.XtHisTemplate{
  976. TemplateId: template_id,
  977. UserOrgId: orgId,
  978. Status: 1,
  979. Ctime: time.Now().Unix(),
  980. Mtime: time.Now().Unix(),
  981. }
  982. err := service.UpdateHisTemplate(&template)
  983. if err != nil {
  984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  985. return
  986. }
  987. this.ServeSuccessJSON(map[string]interface{}{
  988. "template": template,
  989. "template_id": template_id,
  990. })
  991. }
  992. }
  993. func (this *HisProjectApiController) GetHisPrintTemplate() {
  994. adminUserInfo := this.GetAdminUserInfo()
  995. orgId := adminUserInfo.CurrentOrgId
  996. template, err := service.GetHisPrintTemplate(orgId)
  997. if err != nil {
  998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  999. return
  1000. }
  1001. this.ServeSuccessJSON(map[string]interface{}{
  1002. "template": template,
  1003. })
  1004. }
  1005. func (this *HisProjectApiController) PostPrescriptionTempalte() {
  1006. template_id, _ := this.GetInt64("template_id")
  1007. adminUserInfo := this.GetAdminUserInfo()
  1008. orgId := adminUserInfo.CurrentOrgId
  1009. _, errcode := service.GetPrescriptionTemplate(template_id, orgId)
  1010. if errcode == gorm.ErrRecordNotFound {
  1011. template := models.XtHisAdviceTemplate{
  1012. TemplateId: template_id,
  1013. UserOrgId: orgId,
  1014. Status: 1,
  1015. Ctime: time.Now().Unix(),
  1016. }
  1017. err := service.CreatePrescriptionTemplate(&template)
  1018. if err != nil {
  1019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1020. return
  1021. }
  1022. this.ServeSuccessJSON(map[string]interface{}{
  1023. "template": template,
  1024. "template_id": template_id,
  1025. })
  1026. } else if errcode == nil {
  1027. template := models.XtHisAdviceTemplate{
  1028. TemplateId: template_id,
  1029. UserOrgId: orgId,
  1030. Status: 1,
  1031. Ctime: time.Now().Unix(),
  1032. }
  1033. err := service.UpdatePrescriptionTemplate(&template)
  1034. if err != nil {
  1035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1036. return
  1037. }
  1038. this.ServeSuccessJSON(map[string]interface{}{
  1039. "template": template,
  1040. "template_id": template_id,
  1041. })
  1042. }
  1043. }
  1044. func (this *HisProjectApiController) GetPrescriptionTemplate() {
  1045. adminUserInfo := this.GetAdminUserInfo()
  1046. orgId := adminUserInfo.CurrentOrgId
  1047. template, err := service.GetPrescriptionTemplateById(orgId)
  1048. if err != nil {
  1049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1050. return
  1051. }
  1052. this.ServeSuccessJSON(map[string]interface{}{
  1053. "template": template,
  1054. })
  1055. }
  1056. func (this *HisProjectApiController) PostTreatPrintTemplate() {
  1057. template_id, _ := this.GetInt64("template_id")
  1058. adminUserInfo := this.GetAdminUserInfo()
  1059. orgId := adminUserInfo.CurrentOrgId
  1060. _, errcode := service.GetTreatPrintTemplate(template_id, orgId)
  1061. if errcode == gorm.ErrRecordNotFound {
  1062. template := models.XtHisTreatmentTemplate{
  1063. TemplateId: template_id,
  1064. UserOrgId: orgId,
  1065. Status: 1,
  1066. Ctime: time.Now().Unix(),
  1067. }
  1068. err := service.CreateTreatPrintTemplate(&template)
  1069. if err != nil {
  1070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1071. return
  1072. }
  1073. this.ServeSuccessJSON(map[string]interface{}{
  1074. "template": template,
  1075. "template_id": template_id,
  1076. })
  1077. } else if errcode == nil {
  1078. template := models.XtHisTreatmentTemplate{
  1079. TemplateId: template_id,
  1080. UserOrgId: orgId,
  1081. Status: 1,
  1082. Ctime: time.Now().Unix(),
  1083. }
  1084. err := service.UpdatedTreateTemplate(&template)
  1085. if err != nil {
  1086. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1087. return
  1088. }
  1089. this.ServeSuccessJSON(map[string]interface{}{
  1090. "template": template,
  1091. "template_id": template_id,
  1092. })
  1093. }
  1094. }
  1095. func (this *HisProjectApiController) GetTreatPrintTemplate() {
  1096. adminUserInfo := this.GetAdminUserInfo()
  1097. orgId := adminUserInfo.CurrentOrgId
  1098. template, err := service.GetTreatTtreatPrintTemplate(orgId)
  1099. if err != nil {
  1100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1101. return
  1102. }
  1103. this.ServeSuccessJSON(map[string]interface{}{
  1104. "template": template,
  1105. })
  1106. }
  1107. func (this *HisProjectApiController) PostChargePrintTemplate() {
  1108. template_id, _ := this.GetInt64("template_id")
  1109. adminUserInfo := this.GetAdminUserInfo()
  1110. orgId := adminUserInfo.CurrentOrgId
  1111. _, errcode := service.GetChargeTemplate(template_id, orgId)
  1112. if errcode == gorm.ErrRecordNotFound {
  1113. template := models.XtHisChargeTemplate{
  1114. TemplateId: template_id,
  1115. UserOrgId: orgId,
  1116. Ctime: time.Now().Unix(),
  1117. Status: 1,
  1118. }
  1119. err := service.CreateChargePrintTemplate(&template)
  1120. if err != nil {
  1121. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1122. return
  1123. }
  1124. this.ServeSuccessJSON(map[string]interface{}{
  1125. "template": template,
  1126. "template_id": template_id,
  1127. })
  1128. } else if errcode == nil {
  1129. template := models.XtHisChargeTemplate{
  1130. TemplateId: template_id,
  1131. UserOrgId: orgId,
  1132. Ctime: time.Now().Unix(),
  1133. Status: 1,
  1134. }
  1135. err := service.UpdateChargePrintTemplate(&template)
  1136. if err != nil {
  1137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1138. return
  1139. }
  1140. this.ServeSuccessJSON(map[string]interface{}{
  1141. "template": template,
  1142. "template_id": template_id,
  1143. })
  1144. }
  1145. }
  1146. func (this *HisProjectApiController) GetChargePrintTemplate() {
  1147. adminUserInfo := this.GetAdminUserInfo()
  1148. orgId := adminUserInfo.CurrentOrgId
  1149. template, err := service.GetChargePrintTemplate(orgId)
  1150. if err != nil {
  1151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1152. return
  1153. }
  1154. this.ServeSuccessJSON(map[string]interface{}{
  1155. "template": template,
  1156. })
  1157. }
  1158. func (this *HisProjectApiController) GetAllHisPatient() {
  1159. record_date := this.GetString("record_date")
  1160. timeLayout := "2006-01-02"
  1161. loc, _ := time.LoadLocation("Local")
  1162. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1163. recordDateTime := theTime.Unix()
  1164. adminUserInfo := this.GetAdminUserInfo()
  1165. patients, err := service.GetHisPatientList(adminUserInfo.CurrentOrgId, "", recordDateTime)
  1166. if err != nil {
  1167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1168. return
  1169. }
  1170. this.ServeSuccessJSON(map[string]interface{}{
  1171. "list": patients,
  1172. })
  1173. }
  1174. func (this *HisProjectApiController) GetChargePrint() {
  1175. record_date := this.GetString("record_date")
  1176. timeLayout := "2006-01-02"
  1177. loc, _ := time.LoadLocation("Local")
  1178. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1179. recordDateTime := theTime.Unix()
  1180. patient_id, _ := this.GetInt64("patient_id")
  1181. prescription_id, _ := this.GetInt64("prescription_id")
  1182. adminUserInfo := this.GetAdminUserInfo()
  1183. chargePrint, err := service.GetChargePrint(recordDateTime, patient_id, adminUserInfo.CurrentOrgId)
  1184. prescription, err := service.GetHisPrescriptionNight(adminUserInfo.CurrentOrgId, patient_id, recordDateTime, prescription_id)
  1185. patient, err := service.GetPatientByID(adminUserInfo.CurrentOrgId, patient_id)
  1186. if err != nil {
  1187. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1188. return
  1189. }
  1190. this.ServeSuccessJSON(map[string]interface{}{
  1191. "list": chargePrint,
  1192. "prescription": prescription,
  1193. "patient": patient,
  1194. })
  1195. }
  1196. func (this *HisProjectApiController) GetTodaySchedulePatient() {
  1197. adminUserInfo := this.GetAdminUserInfo()
  1198. orgId := adminUserInfo.CurrentOrgId
  1199. recordDateStr := time.Now().Format("2006-01-02")
  1200. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1201. scheduleDate := recordDate.Unix()
  1202. patient, err := service.GetTodaySchedulePatient(orgId, scheduleDate)
  1203. if err != nil {
  1204. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1205. return
  1206. }
  1207. this.ServeSuccessJSON(map[string]interface{}{
  1208. "patient": patient,
  1209. })
  1210. }
  1211. func (this *HisProjectApiController) GetHisPatientDetail() {
  1212. patient_id, _ := this.GetInt64("patient_id")
  1213. hisPatient, err := service.GetHisPatientById(patient_id)
  1214. if err != nil {
  1215. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1216. return
  1217. }
  1218. this.ServeSuccessJSON(map[string]interface{}{
  1219. "hisPatient": hisPatient,
  1220. })
  1221. }
  1222. func (this *HisProjectApiController) GetAllDepartmentList() {
  1223. adminUserInfo := this.GetAdminUserInfo()
  1224. orgId := adminUserInfo.CurrentOrgId
  1225. departMent, err := service.GetAllDepartMent(orgId)
  1226. if err != nil {
  1227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1228. return
  1229. }
  1230. this.ServeSuccessJSON(map[string]interface{}{
  1231. "departMent": departMent,
  1232. })
  1233. }
  1234. func (this *HisProjectApiController) GetPrescription() {
  1235. patient_id, _ := this.GetInt64("patient_id")
  1236. fmt.Println("patient_id", patient_id)
  1237. timeStr := time.Now().Format("2006-01-02")
  1238. timeLayout := "2006-01-02 15:04:05"
  1239. fmt.Println("timeStr:", timeStr)
  1240. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1241. timenow := timeStringToTime.Unix()
  1242. list, err := service.GetPrescriptionByPatientId(patient_id, timenow)
  1243. if err != nil {
  1244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1245. return
  1246. }
  1247. this.ServeSuccessJSON(map[string]interface{}{
  1248. "list": list,
  1249. })
  1250. }