his_project_api_controller.go 69KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "XT_New/enums"
  6. "XT_New/models"
  7. "XT_New/service"
  8. "XT_New/utils"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/mozillazg/go-pinyin"
  12. "reflect"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type HisProjectApiController struct {
  18. BaseAuthAPIController
  19. }
  20. func HisProjectRouters() {
  21. beego.Router("/api/his/saveproject", &HisProjectApiController{}, "Get:SaveProject")
  22. beego.Router("/api/his/getprojectlist", &HisProjectApiController{}, "Get:GetProjectList")
  23. beego.Router("/api/his/getprojectdetail", &HisProjectApiController{}, "Get:GetProjectDetail")
  24. beego.Router("/api/his/updatedproject", &HisProjectApiController{}, "Get:UpdatedProject")
  25. beego.Router("/api/his/deletehisproject", &HisProjectApiController{}, "Get:DeleteHisProject")
  26. beego.Router("/api/his/saveprojectteam", &HisProjectApiController{}, "post:SaveProjectTeam")
  27. beego.Router("/api/his/getprojectteamlist", &HisProjectApiController{}, "Get:GetProjectTeamList")
  28. beego.Router("/api/his/getprojectteamdetail", &HisProjectApiController{}, "Get:GetProjectTeamDetail")
  29. beego.Router("/api/his/updateprojectteam", &HisProjectApiController{}, "post:UpdatedProjectTeam")
  30. beego.Router("/api/his/deleteprojectteam", &HisProjectApiController{}, "Get:DeleteProjectTeam")
  31. beego.Router("/api/his/savedepartment", &HisProjectApiController{}, "Get:SaveDePartment")
  32. beego.Router("/api/his/getdepartmentlist", &HisProjectApiController{}, "Get:GetDepartMentList")
  33. beego.Router("/api/his/getdepartmentdetail", &HisProjectApiController{}, "Get:GetDepartMentDetail")
  34. beego.Router("/api/his/updagtedepartment", &HisProjectApiController{}, "Get:UpdatedDeparment")
  35. beego.Router("/api/his/deletedeparment", &HisProjectApiController{}, "Get:DeleteDepartment")
  36. beego.Router("/api/his/getallprojectlist", &HisProjectApiController{}, "Get:GetAllProjectList")
  37. beego.Router("/api/his/addprojectlist", &HisProjectApiController{}, "Get:AddProjectList")
  38. beego.Router("/api/his/deleteproject", &HisProjectApiController{}, "Get:DeleteProject")
  39. beego.Router("/api/his/deletedrug", &HisProjectApiController{}, "Get:DeleteDrug")
  40. beego.Router("/api/his/gethisproject", &HisProjectApiController{}, "Get:GetHisProject")
  41. beego.Router("/api/his/getprojectteam", &HisProjectApiController{}, "Get:GetProjectTeam")
  42. beego.Router("/api/his/getalldoctorlist", &HisProjectApiController{}, "Get:GetAllDoctorList")
  43. beego.Router("/api/his/savehispatient", &HisProjectApiController{}, "Get:SaveHisPatient")
  44. //获取今日血透排班的患者
  45. beego.Router("/api/his/getbloodpatient", &HisProjectApiController{}, "Get:GetBloodPatientList")
  46. //获取患者的今日透析处方
  47. beego.Router("/api/his/gethisprescription", &HisProjectApiController{}, "Get:GetHisPrescription")
  48. //获取治疗单
  49. beego.Router("/api/his/gettreatlist", &HisProjectApiController{}, "Get:GetTreatmentList")
  50. beego.Router("/api/his/getpatientinformation", &HisProjectApiController{}, "Get:GetPatientInformation")
  51. beego.Router("/api/hist/getallprojecteam", &HisProjectApiController{}, "Get:GetAllProjectTeam")
  52. beego.Router("/api/his/getprojectlistbyid", &HisProjectApiController{}, "Get:GetProjectListById")
  53. beego.Router("/api/his/gethispatienthistory", &HisProjectApiController{}, "Get:GetHisPatientHistory")
  54. beego.Router("/api/patient/changepatient", &HisProjectApiController{}, "Get:ChangePatient")
  55. beego.Router("/api/patient/getpatientcasehistory", &HisProjectApiController{}, "Get:GetPatientcaseHistory")
  56. beego.Router("/api/doctorworkstation/gettemplatedetail", &HisProjectApiController{}, "Get:GetTemplateDetail")
  57. beego.Router("/api/doctorworkstation/updaterecordtemplate", &HisProjectApiController{}, "Get:UpdateRecordTemplate")
  58. beego.Router("/api/hispatient/gehispatient", &HisProjectApiController{}, "Get:GetHisPatient")
  59. //获取处方打印单
  60. beego.Router("/api/hispatient/getprescriptionprint", &HisProjectApiController{}, "Get:GetDoctorAdvicePrint")
  61. //获取项目打印单
  62. //beego.Router("/api/hispatient/getprojectprint",&HisApiController{},"Get:GetProjectPrint")
  63. beego.Router("/api/hispatient/postprinthistemplate", &HisProjectApiController{}, "Get:PostPrintHisTemplate")
  64. beego.Router("/api/gethisprinttemplate", &HisProjectApiController{}, "Get:GetHisPrintTemplate")
  65. beego.Router("/api/hispatient/postprescriptiontemplate", &HisProjectApiController{}, "Get:PostPrescriptionTempalte")
  66. beego.Router("/api/hispatient/getprescriptiontemplate", &HisProjectApiController{}, "Get:GetPrescriptionTemplate")
  67. beego.Router("/api/hispatient/posttreatprinttemplate", &HisProjectApiController{}, "Get:PostTreatPrintTemplate")
  68. beego.Router("/api/hispatient/gettreatprinttemplate", &HisProjectApiController{}, "Get:GetTreatPrintTemplate")
  69. beego.Router("/api/hispatient/postchargeprinttemplate", &HisProjectApiController{}, "Get:PostChargePrintTemplate")
  70. beego.Router("/api/hispatient/getchargeprinttemplate", &HisProjectApiController{}, "Get:GetChargePrintTemplate")
  71. beego.Router("/api/hispatient/getallhispatient", &HisProjectApiController{}, "Get:GetAllHisPatient")
  72. beego.Router("/api/hispatient/getchargeprint", &HisProjectApiController{}, "Get:GetChargePrint")
  73. beego.Router("/api/hispatient/gettodayschedulepatient", &HisProjectApiController{}, "Get:GetTodaySchedulePatient")
  74. beego.Router("/api/hispatient/gethispatientdetail", &HisProjectApiController{}, "Get:GetHisPatientDetail")
  75. beego.Router("/api/hispatient/getalldepartmentlist", &HisProjectApiController{}, "Get:GetAllDepartmentList")
  76. beego.Router("/api/hispatient/getprescription", &HisProjectApiController{}, "Get:GetPrescription")
  77. beego.Router("/api/histpatient/getpatientdetail", &HisProjectApiController{}, "Get:GetPatientDetail")
  78. beego.Router("/api/hispatient/savemaintemplate", &HisProjectApiController{}, "Get:SaveMainTemplate")
  79. beego.Router("/api/hispatient/getmedicaltemplatelist", &HisProjectApiController{}, "Get:GetMedicalTempalteList")
  80. beego.Router("/api/hispatient/getmaintemplatebyid", &HisProjectApiController{}, "Get:GetMainTemplateById")
  81. beego.Router("/api/hispatient/updatemaintemplate", &HisProjectApiController{}, "Get:UpdateMainTemplate")
  82. beego.Router("/api/hispatient/deletemaintemplate", &HisProjectApiController{}, "Get:DeleteMainTemplate")
  83. }
  84. func (this *HisProjectApiController) SaveProject() {
  85. timeLayout := "2006-01-02"
  86. loc, _ := time.LoadLocation("Local")
  87. project_name := this.GetString("project_name")
  88. wubi := this.GetString("wubi")
  89. price := this.GetString("price")
  90. price_float, err := strconv.ParseFloat(price, 64)
  91. unit := this.GetString("unit")
  92. cost_classify, _ := this.GetInt64("cost_classify")
  93. executive_section, _ := this.GetInt64("executive_section")
  94. medical_coverage, _ := this.GetInt64("medical_coverage")
  95. statistical_classification, _ := this.GetInt64("statistical_classification")
  96. disease_directory, _ := this.GetInt64("disease_directory")
  97. is_record, _ := this.GetInt64("is_record")
  98. medical_code := this.GetString("medical_code")
  99. tube_color, _ := this.GetInt64("tube_color")
  100. medical_status, _ := this.GetInt64("medical_status")
  101. remark := this.GetString("remark")
  102. sign, _ := this.GetInt64("sign")
  103. default_number := this.GetString("default_number")
  104. is_charge, _ := this.GetInt64("is_charge")
  105. is_estimate, _ := this.GetInt64("is_estimate")
  106. is_workload, _ := this.GetInt64("is_workload")
  107. sort := this.GetString("sort")
  108. is_advice, _ := this.GetInt64("is_advice")
  109. is_default, _ := this.GetInt64("is_default")
  110. single_dose := this.GetString("single_dose")
  111. delivery_way := this.GetString("delivery_way")
  112. execution_frequency := this.GetString("execution_frequency")
  113. number_days := this.GetString("number_days")
  114. total := this.GetString("total")
  115. category, _ := this.GetInt64("category")
  116. specail_project, _ := this.GetInt64("specail_project")
  117. social_security_directory_code := this.GetString("social_security_directory_code")
  118. record_date := this.GetString("record_date")
  119. bbx01 := this.GetString("bbx01")
  120. bby01 := this.GetString("bby01")
  121. is_print, _ := this.GetInt64("is_print")
  122. is_show, _ := this.GetInt64("is_show")
  123. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  124. adminUserInfo := this.GetAdminUserInfo()
  125. orgId := adminUserInfo.CurrentOrgId
  126. // 创建一个拼音转换器
  127. p := pinyin.NewArgs()
  128. // 将汉字转为拼音
  129. pinyinSlice := pinyin.Pinyin(project_name, p)
  130. // 获取首字母
  131. firstLetter := ""
  132. for _, py := range pinyinSlice {
  133. if len(py) > 0 {
  134. firstLetter += string(py[0][0])
  135. }
  136. }
  137. hisProject := models.XtHisProject{
  138. ProjectName: project_name,
  139. Pinyin: firstLetter,
  140. Wubi: wubi,
  141. Price: price_float,
  142. Unit: unit,
  143. CostClassify: cost_classify,
  144. ExecutiveSection: executive_section,
  145. MedicalCoverage: medical_coverage,
  146. StatisticalClassification: statistical_classification,
  147. DiseaseDirectory: disease_directory,
  148. IsRecord: is_record,
  149. MedicalCode: medical_code,
  150. TubeColor: tube_color,
  151. MedicalStatus: medical_status,
  152. Remark: remark,
  153. Sign: sign,
  154. DefaultNumber: default_number,
  155. IsCharge: is_charge,
  156. IsEstimate: is_estimate,
  157. IsWorkload: is_workload,
  158. Sort: sort,
  159. DoctorAdvice: is_advice,
  160. IsDefault: is_default,
  161. UserOrgId: orgId,
  162. Status: 1,
  163. CreatedTime: time.Now().Unix(),
  164. SingleDose: single_dose,
  165. DeliveryWay: delivery_way,
  166. ExecutionFrequency: execution_frequency,
  167. NumberDays: number_days,
  168. Total: total,
  169. Category: category,
  170. SpecailProject: specail_project,
  171. SocialSecurityDirectoryCode: social_security_directory_code,
  172. RecordDate: theTime.Unix(),
  173. IsPrint: is_print,
  174. Bbx01: bbx01,
  175. Bby01: bby01,
  176. ZuobiaoId: bbx01,
  177. FirstLetter: firstLetter,
  178. IsShow: is_show,
  179. }
  180. if this.GetAdminUserInfo().CurrentOrgId == 10206 {
  181. de, _ := service.GetDepartMentDetail(executive_section)
  182. hisProject.Bck01b = de.Number
  183. }
  184. //查询项目名称是否存在
  185. _, errcode := service.GetHisProjectIsExist(project_name, orgId)
  186. if errcode == gorm.ErrRecordNotFound {
  187. err = service.CreateHisProject(&hisProject)
  188. if err != nil {
  189. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  190. return
  191. }
  192. this.ServeSuccessJSON(map[string]interface{}{
  193. "hisProject": hisProject,
  194. })
  195. return
  196. } else if errcode == nil {
  197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  198. return
  199. }
  200. }
  201. func (this *HisProjectApiController) GetProjectList() {
  202. adminUserInfo := this.GetAdminUserInfo()
  203. orgId := adminUserInfo.CurrentOrgId
  204. limit, _ := this.GetInt64("limit")
  205. page, _ := this.GetInt64("page")
  206. is_charge, _ := this.GetInt64("is_charge")
  207. is_start, _ := this.GetInt64("is_start")
  208. keyword := this.GetString("keyword")
  209. is_mark, _ := this.GetInt64("is_mark")
  210. projecList, total, err := service.GetHisProjectList(orgId, limit, page, is_charge, is_start, keyword, is_mark)
  211. if err != nil {
  212. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  213. return
  214. }
  215. this.ServeSuccessJSON(map[string]interface{}{
  216. "projecList": projecList,
  217. "total": total,
  218. })
  219. return
  220. }
  221. func (this *HisProjectApiController) GetProjectDetail() {
  222. id, _ := this.GetInt64("id")
  223. projectDetail, err := service.GetProjectDetail(id)
  224. if err != nil {
  225. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  226. return
  227. }
  228. this.ServeSuccessJSON(map[string]interface{}{
  229. "projecDetail": projectDetail,
  230. })
  231. return
  232. }
  233. func (this *HisProjectApiController) UpdatedProject() {
  234. timeLayout := "2006-01-02"
  235. loc, _ := time.LoadLocation("Local")
  236. id, _ := this.GetInt64("id")
  237. project_name := this.GetString("project_name")
  238. wubi := this.GetString("wubi")
  239. price := this.GetString("price")
  240. price_float, _ := strconv.ParseFloat(price, 64)
  241. unit := this.GetString("unit")
  242. cost_classify, _ := this.GetInt64("cost_classify")
  243. executive_section, _ := this.GetInt64("executive_section")
  244. medical_coverage, _ := this.GetInt64("medical_coverage")
  245. statistical_classification, _ := this.GetInt64("statistical_classification")
  246. disease_directory, _ := this.GetInt64("disease_directory")
  247. is_record, _ := this.GetInt64("is_record")
  248. medical_code := this.GetString("medical_code")
  249. tube_color, _ := this.GetInt64("tube_color")
  250. medical_status, _ := this.GetInt64("medical_status")
  251. remark := this.GetString("remark")
  252. sign, _ := this.GetInt64("sign")
  253. default_number := this.GetString("default_number")
  254. is_charge, _ := this.GetInt64("is_charge")
  255. is_estimate, _ := this.GetInt64("is_estimate")
  256. is_workload, _ := this.GetInt64("is_workload")
  257. sort := this.GetString("sort")
  258. is_advice, _ := this.GetInt64("is_advice")
  259. is_default, _ := this.GetInt64("is_default")
  260. single_dose := this.GetString("single_dose")
  261. delivery_way := this.GetString("delivery_way")
  262. execution_frequency := this.GetString("execution_frequency")
  263. number_days := this.GetString("number_days")
  264. category, _ := this.GetInt64("category")
  265. total := this.GetString("total")
  266. specail_project, _ := this.GetInt64("specail_project")
  267. social_security_directory_code := this.GetString("social_security_directory_code")
  268. record_date := this.GetString("record_date")
  269. is_print, _ := this.GetInt64("is_print")
  270. bbx01 := this.GetString("bbx01")
  271. bby01 := this.GetString("bby01")
  272. is_show, _ := this.GetInt64("is_show")
  273. // 创建一个拼音转换器
  274. p := pinyin.NewArgs()
  275. // 将汉字转为拼音
  276. pinyinSlice := pinyin.Pinyin(project_name, p)
  277. // 获取首字母
  278. firstLetter := ""
  279. for _, py := range pinyinSlice {
  280. if len(py) > 0 {
  281. firstLetter += string(py[0][0])
  282. }
  283. }
  284. orgId := this.GetAdminUserInfo().CurrentOrgId
  285. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  286. hisProject := models.XtHisProject{
  287. ProjectName: project_name,
  288. Pinyin: firstLetter,
  289. FirstLetter: firstLetter,
  290. Wubi: wubi,
  291. Price: price_float,
  292. Unit: unit,
  293. CostClassify: cost_classify,
  294. ExecutiveSection: executive_section,
  295. MedicalCoverage: medical_coverage,
  296. StatisticalClassification: statistical_classification,
  297. DiseaseDirectory: disease_directory,
  298. IsRecord: is_record,
  299. MedicalCode: medical_code,
  300. TubeColor: tube_color,
  301. MedicalStatus: medical_status,
  302. Remark: remark,
  303. Sign: sign,
  304. DefaultNumber: default_number,
  305. IsCharge: is_charge,
  306. IsEstimate: is_estimate,
  307. IsWorkload: is_workload,
  308. Sort: sort,
  309. DoctorAdvice: is_advice,
  310. IsDefault: is_default,
  311. UpdatedTime: time.Now().Unix(),
  312. SingleDose: single_dose,
  313. DeliveryWay: delivery_way,
  314. ExecutionFrequency: execution_frequency,
  315. NumberDays: number_days,
  316. Total: total,
  317. Category: category,
  318. SpecailProject: specail_project,
  319. SocialSecurityDirectoryCode: social_security_directory_code,
  320. RecordDate: theTime.Unix(),
  321. IsPrint: is_print,
  322. Bbx01: bbx01,
  323. Bby01: bby01,
  324. ZuobiaoId: bbx01,
  325. UserOrgId: orgId,
  326. IsShow: is_show,
  327. }
  328. if this.GetAdminUserInfo().CurrentOrgId == 10206 {
  329. de, _ := service.GetDepartMentDetail(executive_section)
  330. hisProject.Bck01b = de.Number
  331. }
  332. err := service.UpdatedProject(id, &hisProject)
  333. list, _ := service.GetHisPrescripionProjectListOne(id, orgId)
  334. for _, item := range list {
  335. service.UpdateHisPrescriptionProjectList(item.ID, price_float)
  336. }
  337. if err != nil {
  338. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  339. return
  340. }
  341. this.ServeSuccessJSON(map[string]interface{}{
  342. "hisProject": hisProject,
  343. })
  344. return
  345. }
  346. func (this *HisProjectApiController) DeleteHisProject() {
  347. id, _ := this.GetInt64("id")
  348. err := service.DeleteHisProject(id)
  349. if err != nil {
  350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  351. return
  352. }
  353. returnData := make(map[string]interface{}, 0)
  354. returnData["msg"] = "ok"
  355. this.ServeSuccessJSON(returnData)
  356. return
  357. }
  358. func (this *HisProjectApiController) SaveProjectTeam() {
  359. project_team := this.GetString("project_team")
  360. price := this.GetString("price")
  361. price_float, _ := strconv.ParseFloat(price, 64)
  362. pinyin := this.GetString("pinyin")
  363. wubi := this.GetString("wubi")
  364. tube_color, _ := this.GetInt64("tube_color")
  365. team_type, _ := this.GetInt64("team_type")
  366. remark := this.GetString("remark")
  367. sort, _ := this.GetInt64("sort")
  368. //ids := this.GetString("ids")
  369. //item_id := this.GetString("item_id")
  370. dataBody := make(map[string]interface{}, 0)
  371. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  372. if err != nil {
  373. utils.ErrorLog(err.Error())
  374. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  375. return
  376. }
  377. adminUserInfo := this.GetAdminUserInfo()
  378. orgId := adminUserInfo.CurrentOrgId
  379. projectTeam := models.XtHisProjectTeam{
  380. ProjectTeam: project_team,
  381. Price: price_float,
  382. Pinyin: pinyin,
  383. Wubi: wubi,
  384. TubeColor: tube_color,
  385. TeamType: team_type,
  386. Remark: remark,
  387. UserOrgId: orgId,
  388. Status: 1,
  389. CreatedTime: time.Now().Unix(),
  390. Sort: sort,
  391. //ProjectId: ids,
  392. //ItemId: item_id,
  393. }
  394. //fmt.Println(projectTeam)
  395. _, errcodes := service.GetHisProjectByNameOne(project_team, orgId)
  396. if errcodes == gorm.ErrRecordNotFound {
  397. err := service.CreatedProjectTeam(&projectTeam)
  398. if err != nil {
  399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  400. return
  401. }
  402. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  403. infos, _ := dataBody["info"].([]interface{})
  404. if len(infos) > 0 {
  405. var ids []string
  406. for _, item := range infos {
  407. items := item.(map[string]interface{})
  408. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  409. utils.ErrorLog("id")
  410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  411. return
  412. }
  413. id := int64(items["id"].(float64))
  414. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  415. utils.ErrorLog("type")
  416. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  417. return
  418. }
  419. types := int64(items["type"].(float64))
  420. if items["prescribing_number"] == nil || reflect.TypeOf(items["prescribing_number"]).String() != "string" {
  421. utils.ErrorLog("prescribing_number")
  422. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  423. return
  424. }
  425. number, _ := strconv.ParseInt(items["prescribing_number"].(string), 10, 64)
  426. list := models.XtHisProjectList{
  427. Number: number,
  428. UserOrgId: adminUserInfo.CurrentOrgId,
  429. ProjectId: id,
  430. Status: 1,
  431. CreatedTime: time.Now().Unix(),
  432. UpdatedTime: time.Now().Unix(),
  433. TeamId: projectTeam.ID,
  434. Type: types,
  435. }
  436. service.CreateProjectList(&list)
  437. ids = append(ids, strconv.FormatInt(list.ID, 10))
  438. }
  439. ids_str := strings.Join(ids, ",")
  440. projectTeam.ItemId = ids_str
  441. service.SaveProjectTeam(&projectTeam)
  442. }
  443. }
  444. if dataBody["drug_info"] != nil && reflect.TypeOf(dataBody["drug_info"]).String() == "[]interface {}" {
  445. infos, _ := dataBody["drug_info"].([]interface{})
  446. if len(infos) > 0 {
  447. var ids []string
  448. for _, item := range infos {
  449. var advice models.HisDoctorAdviceTeamInfo
  450. items := item.(map[string]interface{})
  451. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  452. utils.ErrorLog("id")
  453. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  454. return
  455. }
  456. id := int64(items["id"].(float64))
  457. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  458. utils.ErrorLog("drug_name")
  459. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  460. return
  461. }
  462. if items["min_unit"] != nil && reflect.TypeOf(items["min_unit"]).String() == "string" {
  463. drugSpecUnit, _ := items["min_unit"].(string)
  464. advice.DrugSpecUnit = drugSpecUnit
  465. }
  466. if items["remark"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
  467. remark, _ := items["remark"].(string)
  468. advice.Remark = remark
  469. }
  470. if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "string" {
  471. singleDose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  472. advice.SingleDose = singleDose
  473. }
  474. if items["single_dose_unit"] != nil && reflect.TypeOf(items["single_dose_unit"]).String() == "string" {
  475. singleDoseUnit, _ := items["single_dose_unit"].(string)
  476. advice.SingleDoseUnit = singleDoseUnit
  477. }
  478. if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "string" {
  479. prescribingNumber, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  480. advice.PrescribingNumber = prescribingNumber
  481. }
  482. if items["prescribing_number_unit"] != nil && reflect.TypeOf(items["prescribing_number_unit"]).String() == "string" {
  483. prescribingNumberUnit, _ := items["prescribing_number_unit"].(string)
  484. advice.PrescribingNumberUnit = prescribingNumberUnit
  485. }
  486. if items["delivery_way"] != nil && reflect.TypeOf(items["delivery_way"]).String() == "string" {
  487. deliveryWay, _ := items["delivery_way"].(string)
  488. advice.DeliveryWay = deliveryWay
  489. }
  490. if items["execution_frequency"] != nil && reflect.TypeOf(items["execution_frequency"]).String() == "string" {
  491. executionFrequency, _ := items["execution_frequency"].(string)
  492. advice.ExecutionFrequency = executionFrequency
  493. }
  494. if items["day"] != nil && reflect.TypeOf(items["day"]).String() == "string" {
  495. day, _ := items["day"].(string)
  496. daycount, _ := strconv.ParseInt(day, 10, 64)
  497. advice.DayCount = daycount
  498. }
  499. adviceName, _ := items["drug_name"].(string)
  500. adviceDesc, _ := items["advice_desc"].(string)
  501. advice.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  502. advice.AdviceName = adviceName
  503. advice.AdviceDesc = adviceDesc
  504. advice.DrugId = id
  505. advice.Status = 1
  506. service.CreateDoctorAdviceTeamList(&advice)
  507. ids = append(ids, strconv.FormatInt(advice.ID, 10))
  508. }
  509. ids_str := strings.Join(ids, ",")
  510. projectTeam.DrugItemId = ids_str
  511. service.SaveProjectTeam(&projectTeam)
  512. this.ServeSuccessJSON(map[string]interface{}{
  513. "projectTeam": projectTeam,
  514. })
  515. }
  516. }
  517. this.ServeSuccessJSON(map[string]interface{}{
  518. "projectTeam": projectTeam,
  519. })
  520. return
  521. } else if errcodes == nil {
  522. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  523. return
  524. }
  525. }
  526. func (this *HisProjectApiController) GetProjectTeamList() {
  527. limit, _ := this.GetInt64("limit")
  528. page, _ := this.GetInt64("page")
  529. keyword := this.GetString("keyword")
  530. adminUserInfo := this.GetAdminUserInfo()
  531. orgId := adminUserInfo.CurrentOrgId
  532. projectTeamList, total, err := service.GetProjectTeamList(limit, page, orgId, keyword)
  533. if err != nil {
  534. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  535. return
  536. }
  537. this.ServeSuccessJSON(map[string]interface{}{
  538. "projectTeamList": projectTeamList,
  539. "total": total,
  540. })
  541. return
  542. }
  543. func (this *HisProjectApiController) GetProjectTeamDetail() {
  544. id, _ := this.GetInt64("id")
  545. //adminUserInfo := this.GetAdminUserInfo()
  546. //orgId := adminUserInfo.CurrentOrgId
  547. projectTeamDetail, err := service.GetProjectTeamDetail(id)
  548. ids := strings.Split(projectTeamDetail.ItemId, ",")
  549. hisList, err := service.GetProjectHisListByIds(ids)
  550. ids_drug := strings.Split(projectTeamDetail.DrugItemId, ",")
  551. hisList_drug, err := service.GetDrugHisListByIds(ids_drug)
  552. //list, err := service.GetAllProjectList(orgId)
  553. if err != nil {
  554. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  555. return
  556. }
  557. this.ServeSuccessJSON(map[string]interface{}{
  558. "projectTeamDetail": projectTeamDetail,
  559. //"list": list,
  560. "hisList": hisList,
  561. "hisList_drug": hisList_drug,
  562. })
  563. return
  564. }
  565. func (this *HisProjectApiController) UpdatedProjectTeam() {
  566. id, _ := this.GetInt64("id")
  567. project_team := this.GetString("project_team")
  568. price := this.GetString("price")
  569. price_float, _ := strconv.ParseFloat(price, 64)
  570. pinyin := this.GetString("pinyin")
  571. wubi := this.GetString("wubi")
  572. tube_color, _ := this.GetInt64("tube_color")
  573. team_type, _ := this.GetInt64("team_type")
  574. remark := this.GetString("remark")
  575. sort, _ := this.GetInt64("sort")
  576. projectTeam, _ := service.GetProjectTeamDetail(id)
  577. projectTeam.ProjectTeam = project_team
  578. projectTeam.Price = price_float
  579. projectTeam.Pinyin = pinyin
  580. projectTeam.Wubi = wubi
  581. projectTeam.TubeColor = tube_color
  582. projectTeam.TeamType = team_type
  583. projectTeam.Remark = remark
  584. projectTeam.Sort = sort
  585. dataBody := make(map[string]interface{}, 0)
  586. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  587. if err != nil {
  588. utils.ErrorLog(err.Error())
  589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  590. return
  591. }
  592. err = service.UpdatedProjectTeam(id, &projectTeam)
  593. if err != nil {
  594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  595. return
  596. }
  597. if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  598. infos, _ := dataBody["info"].([]interface{})
  599. if len(infos) > 0 {
  600. var ids []string
  601. for _, item := range infos {
  602. items := item.(map[string]interface{})
  603. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  604. utils.ErrorLog("id")
  605. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  606. return
  607. }
  608. id := int64(items["id"].(float64))
  609. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  610. utils.ErrorLog("type")
  611. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  612. return
  613. }
  614. types := int64(items["type"].(float64))
  615. if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  616. utils.ErrorLog("number")
  617. }
  618. number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  619. list := models.XtHisProjectList{
  620. Number: number,
  621. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  622. ProjectId: id,
  623. Status: 1,
  624. CreatedTime: time.Now().Unix(),
  625. UpdatedTime: time.Now().Unix(),
  626. TeamId: projectTeam.ID,
  627. Type: types,
  628. }
  629. if items["m_id"] == nil || reflect.TypeOf(items["m_id"]).String() != "float64" {
  630. utils.ErrorLog("m_id")
  631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  632. return
  633. }
  634. m_id := int64(items["m_id"].(float64))
  635. list.ID = m_id
  636. service.SaveProjectList(&list)
  637. ids = append(ids, strconv.FormatInt(list.ID, 10))
  638. }
  639. ids_str := strings.Join(ids, ",")
  640. projectTeam.ItemId = projectTeam.ItemId + "," + ids_str
  641. service.SaveProjectTeam(&projectTeam)
  642. }
  643. }
  644. if dataBody["drug_info"] != nil && reflect.TypeOf(dataBody["drug_info"]).String() == "[]interface {}" {
  645. infos, _ := dataBody["drug_info"].([]interface{})
  646. if len(infos) > 0 {
  647. var ids []string
  648. for _, item := range infos {
  649. var advice models.HisDoctorAdviceTeamInfo
  650. items := item.(map[string]interface{})
  651. if items["m_id"] == nil || reflect.TypeOf(items["m_id"]).String() != "float64" {
  652. utils.ErrorLog("id")
  653. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  654. return
  655. }
  656. m_id := int64(items["m_id"].(float64))
  657. advice, _ = service.GetHisDrugByID(m_id)
  658. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  659. utils.ErrorLog("id")
  660. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  661. return
  662. }
  663. id := int64(items["id"].(float64))
  664. if items["drug_name"] == nil || reflect.TypeOf(items["drug_name"]).String() != "string" {
  665. utils.ErrorLog("drug_name")
  666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  667. return
  668. }
  669. if items["min_unit"] != nil && reflect.TypeOf(items["min_unit"]).String() == "string" {
  670. drugSpecUnit, _ := items["min_unit"].(string)
  671. advice.DrugSpecUnit = drugSpecUnit
  672. }
  673. if items["remark"] != nil && reflect.TypeOf(items["remark"]).String() == "string" {
  674. remark, _ := items["remark"].(string)
  675. advice.Remark = remark
  676. }
  677. if items["single_dose"] != nil && reflect.TypeOf(items["single_dose"]).String() == "string" {
  678. singleDose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  679. fmt.Println("singleDose")
  680. fmt.Println(singleDose)
  681. advice.SingleDose = singleDose
  682. }
  683. if items["single_dose_unit"] != nil && reflect.TypeOf(items["single_dose_unit"]).String() == "string" {
  684. singleDoseUnit, _ := items["single_dose_unit"].(string)
  685. fmt.Println("singleDoseUnit")
  686. fmt.Println(singleDoseUnit)
  687. advice.SingleDoseUnit = singleDoseUnit
  688. }
  689. if items["prescribing_number"] != nil && reflect.TypeOf(items["prescribing_number"]).String() == "string" {
  690. prescribingNumber, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  691. advice.PrescribingNumber = prescribingNumber
  692. fmt.Println("prescribingNumber")
  693. fmt.Println(prescribingNumber)
  694. }
  695. if items["prescribing_number_unit"] != nil && reflect.TypeOf(items["prescribing_number_unit"]).String() == "string" {
  696. prescribingNumberUnit, _ := items["prescribing_number_unit"].(string)
  697. advice.PrescribingNumberUnit = prescribingNumberUnit
  698. fmt.Println("prescribing_number_unit")
  699. fmt.Println(prescribingNumberUnit)
  700. }
  701. if items["delivery_way"] != nil && reflect.TypeOf(items["delivery_way"]).String() == "string" {
  702. deliveryWay, _ := items["delivery_way"].(string)
  703. advice.DeliveryWay = deliveryWay
  704. fmt.Println("delivery_way")
  705. fmt.Println(deliveryWay)
  706. }
  707. if items["execution_frequency"] != nil && reflect.TypeOf(items["execution_frequency"]).String() == "string" {
  708. executionFrequency, _ := items["execution_frequency"].(string)
  709. advice.ExecutionFrequency = executionFrequency
  710. fmt.Println("execution_frequency")
  711. fmt.Println(executionFrequency)
  712. }
  713. if items["day"] != nil && reflect.TypeOf(items["day"]).String() == "string" {
  714. day, _ := items["day"].(string)
  715. daycount, _ := strconv.ParseInt(day, 10, 64)
  716. advice.DayCount = daycount
  717. fmt.Println("day")
  718. fmt.Println(day)
  719. }
  720. adviceName, _ := items["drug_name"].(string)
  721. //adviceDesc, _ := items["advice_desc"].(string)
  722. advice.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  723. advice.AdviceName = adviceName
  724. //advice.AdviceDesc = adviceDesc
  725. advice.Status = 1
  726. advice.DrugId = id
  727. advice.ID = m_id
  728. if m_id > 0 {
  729. service.CreateDoctorAdviceTeamList(&advice)
  730. ids = append(ids, strconv.FormatInt(advice.ID, 10))
  731. } else {
  732. service.CreateDoctorAdviceTeamList(&advice)
  733. ids = append(ids, strconv.FormatInt(advice.ID, 10))
  734. }
  735. }
  736. ids_str := strings.Join(ids, ",")
  737. projectTeam.DrugItemId = ids_str
  738. service.SaveProjectTeam(&projectTeam)
  739. }
  740. }
  741. this.ServeSuccessJSON(map[string]interface{}{
  742. "projectTeam": projectTeam,
  743. })
  744. return
  745. }
  746. func (this *HisProjectApiController) DeleteProjectTeam() {
  747. id, _ := this.GetInt64("id")
  748. err := service.DeleteProjectTeam(id)
  749. if err != nil {
  750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  751. return
  752. }
  753. returnData := make(map[string]interface{}, 0)
  754. returnData["msg"] = "ok"
  755. this.ServeSuccessJSON(returnData)
  756. return
  757. }
  758. func (this *HisProjectApiController) SaveDePartment() {
  759. name := this.GetString("name")
  760. number := this.GetString("number")
  761. department_type := this.GetString("department_type")
  762. lender := this.GetString("lender")
  763. phone := this.GetString("phone")
  764. start_time := this.GetString("start_time")
  765. adminUserInfo := this.GetAdminUserInfo()
  766. orgId := adminUserInfo.CurrentOrgId
  767. department := models.XtHisDepartment{
  768. Name: name,
  769. Number: number,
  770. UserOrgId: orgId,
  771. CreatedTime: time.Now().Unix(),
  772. Status: 1,
  773. DepartmentType: department_type,
  774. Lender: lender,
  775. Phone: phone,
  776. StartTime: start_time,
  777. }
  778. err := service.CreateDePartment(&department)
  779. if err != nil {
  780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  781. return
  782. }
  783. department_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_department"
  784. redis := service.RedisClient()
  785. defer redis.Close()
  786. redis.Set(department_keys, "", time.Second*60*60*18)
  787. this.ServeSuccessJSON(map[string]interface{}{
  788. "department": department,
  789. })
  790. return
  791. }
  792. func (this *HisProjectApiController) GetDepartMentList() {
  793. limit, _ := this.GetInt64("limit")
  794. page, _ := this.GetInt64("page")
  795. adminUserInfo := this.GetAdminUserInfo()
  796. orgId := adminUserInfo.CurrentOrgId
  797. departMentList, total, err := service.GetDepartMentList(limit, page, orgId)
  798. if err != nil {
  799. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  800. return
  801. }
  802. this.ServeSuccessJSON(map[string]interface{}{
  803. "departMentList": departMentList,
  804. "total": total,
  805. })
  806. return
  807. }
  808. func (this *HisProjectApiController) GetDepartMentDetail() {
  809. id, _ := this.GetInt64("id")
  810. departDetail, err := service.GetDepartMentDetail(id)
  811. if err != nil {
  812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  813. return
  814. }
  815. this.ServeSuccessJSON(map[string]interface{}{
  816. "departDetail": departDetail,
  817. })
  818. return
  819. }
  820. func (this *HisProjectApiController) UpdatedDeparment() {
  821. id, _ := this.GetInt64("id")
  822. name := this.GetString("name")
  823. number := this.GetString("number")
  824. department_type := this.GetString("department_type")
  825. lender := this.GetString("lender")
  826. phone := this.GetString("phone")
  827. start_time := this.GetString("start_time")
  828. department := models.XtHisDepartment{
  829. Name: name,
  830. Number: number,
  831. DepartmentType: department_type,
  832. Lender: lender,
  833. Phone: phone,
  834. StartTime: start_time,
  835. }
  836. err := service.UpdatedDepartment(id, &department)
  837. if err != nil {
  838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  839. return
  840. }
  841. department_keys := strconv.FormatInt(this.GetAdminUserInfo().CurrentOrgId, 10) + "_department"
  842. redis := service.RedisClient()
  843. defer redis.Close()
  844. redis.Set(department_keys, "", time.Second*60*60*18)
  845. this.ServeSuccessJSON(map[string]interface{}{
  846. "department": department,
  847. })
  848. return
  849. }
  850. func (this *HisProjectApiController) DeleteDepartment() {
  851. id, _ := this.GetInt64("id")
  852. err := service.DeleteDepartment(id)
  853. if err != nil {
  854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  855. return
  856. }
  857. department_keys := strconv.FormatInt(this.GetAdminUserInfo().CurrentOrgId, 10) + "_department"
  858. redis := service.RedisClient()
  859. defer redis.Close()
  860. redis.Set(department_keys, "", time.Second*60*60*18)
  861. returnData := make(map[string]interface{}, 0)
  862. returnData["msg"] = "ok"
  863. this.ServeSuccessJSON(returnData)
  864. return
  865. }
  866. func (this *HisProjectApiController) GetBloodPatientList() {
  867. adminUserInfo := this.GetAdminUserInfo()
  868. orgId := adminUserInfo.CurrentOrgId
  869. timeStr := time.Now().Format("2006-01-02")
  870. timeLayout := "2006-01-02 15:04:05"
  871. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  872. timenow := timeStringToTime.Unix()
  873. //统计血透排班的患者
  874. scheduleList, err := service.GetBloodPatientList(orgId, timenow)
  875. //统计当日挂号的患者
  876. hisPatient, _ := service.GetHisPatient(orgId, timenow)
  877. //统计今天开处方的患者
  878. prescription, _ := service.GetHisPrescriptionOther(orgId, timenow)
  879. if err != nil {
  880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  881. return
  882. }
  883. this.ServeSuccessJSON(map[string]interface{}{
  884. "scheduleList": scheduleList,
  885. "hisPatient": hisPatient,
  886. "prescription": prescription,
  887. })
  888. return
  889. }
  890. func (this *HisProjectApiController) GetHisPrescription() {
  891. id, _ := this.GetInt64("id")
  892. timeStr := time.Now().Format("2006-01-02")
  893. timeLayout := "2006-01-02 15:04:05"
  894. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  895. timenow := timeStringToTime.Unix()
  896. prescriptionList, err := service.GetHisPrescriptionByPatientId(id, timenow)
  897. if err != nil {
  898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  899. return
  900. }
  901. this.ServeSuccessJSON(map[string]interface{}{
  902. "prescriptionList": prescriptionList,
  903. })
  904. return
  905. }
  906. func (this *HisProjectApiController) GetTreatmentList() {
  907. patient_id, _ := this.GetInt64("patient_id")
  908. timeStr := time.Now().Format("2006-01-02")
  909. timeLayout := "2006-01-02 15:04:05"
  910. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  911. timenow := timeStringToTime.Unix()
  912. treatmentList, err := service.GetTreatmentList(patient_id, timenow)
  913. if err != nil {
  914. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  915. return
  916. }
  917. this.ServeSuccessJSON(map[string]interface{}{
  918. "treatmentList": treatmentList,
  919. })
  920. return
  921. }
  922. func (this *HisProjectApiController) GetAllProjectList() {
  923. keyword := this.GetString("keyword")
  924. adminUserInfo := this.GetAdminUserInfo()
  925. orgId := adminUserInfo.CurrentOrgId
  926. projectList, err := service.GetAllProjectList(orgId, keyword)
  927. goodInfos, err := service.GetGoodInfomationList(orgId, keyword)
  928. drug, _ := service.GetDrugInfomationList(orgId, keyword)
  929. //goodInfos, err := service.GetAllDrugList(orgId)
  930. //获取列表数据
  931. hisprojectlist, err := service.GetHisProjectListByOrgId(orgId)
  932. if err != nil {
  933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  934. return
  935. }
  936. this.ServeSuccessJSON(map[string]interface{}{
  937. "projectList": projectList,
  938. "hisprojectlist": hisprojectlist,
  939. "good_info": goodInfos,
  940. "drug": drug,
  941. })
  942. return
  943. }
  944. func (this *HisProjectApiController) AddProjectList() {
  945. id, _ := this.GetInt64("id")
  946. number, _ := this.GetInt64("number")
  947. adminUserInfo := this.GetAdminUserInfo()
  948. orgId := adminUserInfo.CurrentOrgId
  949. projectList := models.XtHisProjectList{
  950. ProjectId: id,
  951. Number: number,
  952. UserOrgId: orgId,
  953. Status: 1,
  954. CreatedTime: time.Now().Unix(),
  955. }
  956. err := service.CreateProjectList(&projectList)
  957. detail, _ := service.GetProjectDetail(id)
  958. item, err := service.GetLastItem(orgId)
  959. if err != nil {
  960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  961. return
  962. }
  963. this.ServeSuccessJSON(map[string]interface{}{
  964. "projectList": detail,
  965. "item": item,
  966. })
  967. return
  968. }
  969. func (this *HisProjectApiController) GetPatientInformation() {
  970. id, _ := this.GetInt64("id")
  971. information, err := service.GetHisPatientInformation(id)
  972. if err != nil {
  973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  974. return
  975. }
  976. this.ServeSuccessJSON(map[string]interface{}{
  977. "information": information,
  978. })
  979. return
  980. }
  981. func (this *HisProjectApiController) DeleteProject() {
  982. id, _ := this.GetInt64("id")
  983. err := service.DeleteProjectList(id)
  984. if err != nil {
  985. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  986. return
  987. }
  988. returnData := make(map[string]interface{}, 0)
  989. returnData["msg"] = "ok"
  990. this.ServeSuccessJSON(returnData)
  991. return
  992. }
  993. func (this *HisProjectApiController) DeleteDrug() {
  994. id, _ := this.GetInt64("id")
  995. err := service.DeleteDrugList(id)
  996. if err != nil {
  997. this.ServeFailJsonSend(enums.ErrorCodeDataException, "失败")
  998. return
  999. }
  1000. returnData := make(map[string]interface{}, 0)
  1001. returnData["msg"] = "ok"
  1002. this.ServeSuccessJSON(returnData)
  1003. return
  1004. }
  1005. func (this *HisProjectApiController) GetHisProject() {
  1006. adminUserInfo := this.GetAdminUserInfo()
  1007. orgId := adminUserInfo.CurrentOrgId
  1008. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  1009. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10215 {
  1010. project, err := service.GetHisProject(orgId)
  1011. good_info, err := service.GetGoodInfoMationSeven(orgId, houseConfig.StorehouseOutInfo)
  1012. _, config := service.FindHisStockPriceRecordByOrgId(orgId)
  1013. if config.ID > 0 && config.IsOpen == 1 {
  1014. //处理耗材不同批号价格问题
  1015. for _, item := range good_info {
  1016. if len(item.GoodSotckInfo) > 0 {
  1017. if item.GoodSotckInfo[0].Price > 0 {
  1018. item.PackingPrice = item.GoodSotckInfo[0].Price
  1019. }
  1020. }
  1021. }
  1022. }
  1023. if err != nil {
  1024. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1025. return
  1026. }
  1027. this.ServeSuccessJSON(map[string]interface{}{
  1028. "project": project,
  1029. "good_info": good_info,
  1030. })
  1031. }
  1032. if adminUserInfo.CurrentOrgId != 9671 && adminUserInfo.CurrentOrgId != 9675 && adminUserInfo.CurrentOrgId != 10215 {
  1033. project, err := service.GetHisProject(orgId)
  1034. good_info, err := service.GetGoodInfoMationSix(orgId, houseConfig.StorehouseOutInfo)
  1035. _, config := service.FindHisStockPriceRecordByOrgId(orgId)
  1036. if config.ID > 0 && config.IsOpen == 1 {
  1037. //处理耗材不同批号价格问题
  1038. for _, item := range good_info {
  1039. if len(item.GoodSotckInfo) > 0 {
  1040. if item.GoodSotckInfo[0].Price > 0 {
  1041. item.PackingPrice = item.GoodSotckInfo[0].Price
  1042. }
  1043. }
  1044. }
  1045. }
  1046. if err != nil {
  1047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1048. return
  1049. }
  1050. this.ServeSuccessJSON(map[string]interface{}{
  1051. "project": project,
  1052. "good_info": good_info,
  1053. })
  1054. }
  1055. }
  1056. func (this *HisProjectApiController) GetProjectTeam() {
  1057. strids := this.GetString("strids")
  1058. idStrs := strings.Split(strids, ",")
  1059. adminUserInfo := this.GetAdminUserInfo()
  1060. orgId := adminUserInfo.CurrentOrgId
  1061. team, err := service.GetProjectTeam(idStrs, orgId)
  1062. if err != nil {
  1063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1064. return
  1065. }
  1066. this.ServeSuccessJSON(map[string]interface{}{
  1067. "team": team,
  1068. })
  1069. }
  1070. func (this *HisProjectApiController) GetAllDoctorList() {
  1071. adminUserInfo := this.GetAdminUserInfo()
  1072. orgId := adminUserInfo.CurrentOrgId
  1073. appId := adminUserInfo.CurrentAppId
  1074. //获取所有的医生
  1075. doctor, err := service.GetAllDoctor(orgId, appId)
  1076. //获取所有的科室
  1077. department, err := service.GetAllDepartMent(orgId)
  1078. if err != nil {
  1079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1080. return
  1081. }
  1082. this.ServeSuccessJSON(map[string]interface{}{
  1083. "doctor": doctor,
  1084. "department": department,
  1085. })
  1086. }
  1087. func (this *HisProjectApiController) SaveHisPatient() {
  1088. timeLayout := "2006-01-02"
  1089. loc, _ := time.LoadLocation("Local")
  1090. age, _ := this.GetInt64("age")
  1091. birthday := this.GetString("birthday")
  1092. patient_id, _ := this.GetInt64("id")
  1093. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1094. birthUnix := birthdays.Unix()
  1095. certificates, _ := this.GetInt64("certificates")
  1096. cost_checked, _ := this.GetInt64("costChecked")
  1097. cost, _ := this.GetInt64("cost")
  1098. costs := strconv.FormatInt(cost, 10)
  1099. cost_float, _ := strconv.ParseFloat(costs, 64)
  1100. department, _ := this.GetInt64("department")
  1101. doctor, _ := this.GetInt64("doctor")
  1102. medicalcare, _ := this.GetInt64("medical_care")
  1103. idcard := this.GetString("id_card")
  1104. medicalExpenses, _ := this.GetInt64("medical_expenses")
  1105. medicalExpense := strconv.FormatInt(medicalExpenses, 10)
  1106. medicalExpense_float, _ := strconv.ParseFloat(medicalExpense, 64)
  1107. medicalinsurancecard := this.GetString("medical_insurance_card")
  1108. name := this.GetString("name")
  1109. register, _ := this.GetInt64("register")
  1110. registrationfee, _ := this.GetInt64("registration_fee")
  1111. registrationfees := strconv.FormatInt(registrationfee, 10)
  1112. registrationfees_float, _ := strconv.ParseFloat(registrationfees, 64)
  1113. settlementValue, _ := this.GetInt64("settlement_value")
  1114. sex, _ := this.GetInt64("sex")
  1115. total, _ := this.GetInt64("total")
  1116. totals := strconv.FormatInt(total, 10)
  1117. totals_float, _ := strconv.ParseFloat(totals, 64)
  1118. adminUserInfo := this.GetAdminUserInfo()
  1119. orgId := adminUserInfo.CurrentOrgId
  1120. recordDateStr := time.Now().Format("2006-01-02")
  1121. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1122. nowtime := recordDate.Unix()
  1123. phone := this.GetString("phone")
  1124. social_type, _ := this.GetInt64("social_type")
  1125. id_card_type, _ := this.GetInt64("id_card_type")
  1126. //diagnosis_id, _ := this.GetInt64("diagnosis")
  1127. diagnosis_ids := this.GetString("diagnosis")
  1128. sick_type, _ := this.GetInt64("sick_type")
  1129. reg_type := this.GetString("p_type")
  1130. tempPatient, _ := service.GetPatientByIDCardAndName(idcard, adminUserInfo.CurrentOrgId, name)
  1131. if tempPatient.ID == 0 {
  1132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  1133. return
  1134. }
  1135. var patient service.Patients
  1136. if patient_id == 0 {
  1137. patient, _ = service.GetPatientByIDCard(idcard, adminUserInfo.CurrentOrgId)
  1138. } else {
  1139. patient, _ = service.GetPatientByIDTwo(adminUserInfo.CurrentOrgId, patient_id)
  1140. }
  1141. if patient.ID == 0 {
  1142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1143. return
  1144. }
  1145. if len(patient.IdCardNo) == 0 {
  1146. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1147. return
  1148. }
  1149. timeStr := time.Now().Format("2006-01-02 15:04:05")
  1150. fmt.Println(timeStr)
  1151. timeArr := strings.Split(timeStr, " ")
  1152. timeArrTwo := strings.Split(timeArr[0], "-")
  1153. timeArrThree := strings.Split(timeArr[1], ":")
  1154. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  1155. //his, _ := service.GetHisPatientInfoTwo(adminUserInfo.CurrentOrgId, patient.ID, recordDate.Unix())
  1156. //if len(his) >= 1 {
  1157. // order, _ := service.GetNewHisOrderTwo(adminUserInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDate.Unix())
  1158. // if len(his) >= 1 && order.ID == 0 {
  1159. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  1160. // return
  1161. // }
  1162. //}
  1163. var hisPatient models.XtHisPatient
  1164. //if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1165. hisPatient = models.XtHisPatient{
  1166. PatientId: patient_id,
  1167. Birthday: birthUnix,
  1168. IdType: certificates,
  1169. CostOfProduction: cost_float,
  1170. Departments: department,
  1171. Doctor: doctor,
  1172. AdminUserId: adminUserInfo.AdminUser.Id,
  1173. MedicalTreatmentType: medicalcare,
  1174. IdCardNo: idcard,
  1175. IsNeedCostOfProduction: cost_checked,
  1176. TreatmentCost: medicalExpense_float,
  1177. MedicalInsuranceNumber: medicalinsurancecard,
  1178. Name: name,
  1179. Age: age,
  1180. Number: str,
  1181. RegisterType: register,
  1182. RegisterCost: registrationfees_float,
  1183. BalanceAccountsType: settlementValue,
  1184. Gender: sex,
  1185. Total: totals_float,
  1186. UserOrgId: orgId,
  1187. Status: 1,
  1188. RecordDate: nowtime,
  1189. IsReturn: 1,
  1190. Ctime: time.Now().Unix(),
  1191. Phone: phone,
  1192. SocialType: social_type,
  1193. IdCardType: id_card_type,
  1194. Diagnosis: diagnosis_ids,
  1195. PType: reg_type,
  1196. SickType: sick_type,
  1197. }
  1198. service.CreateHisPatient(&hisPatient)
  1199. this.ServeSuccessJSON(map[string]interface{}{
  1200. "his_info": hisPatient,
  1201. })
  1202. //}
  1203. //else {
  1204. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisRegisterException)
  1205. // return
  1206. //}
  1207. }
  1208. func (this *HisProjectApiController) GetAllProjectTeam() {
  1209. adminUserInfo := this.GetAdminUserInfo()
  1210. orgId := adminUserInfo.CurrentOrgId
  1211. team, err := service.GetAllProjectTeam(orgId)
  1212. if err != nil {
  1213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1214. return
  1215. }
  1216. this.ServeSuccessJSON(map[string]interface{}{
  1217. "team": team,
  1218. })
  1219. }
  1220. func (this *HisProjectApiController) GetProjectListById() {
  1221. adminUserInfo := this.GetAdminUserInfo()
  1222. orgId := adminUserInfo.CurrentOrgId
  1223. project_id := this.GetString("project_id")
  1224. drug_id := this.GetString("drug_id")
  1225. idStrs := strings.Split(project_id, ",")
  1226. drug_idStrs := strings.Split(drug_id, ",")
  1227. project, err := service.GetProjectListById(orgId, idStrs)
  1228. advice, _ := service.GetAdviceTeamListById(orgId, drug_idStrs)
  1229. if err != nil {
  1230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1231. return
  1232. }
  1233. this.ServeSuccessJSON(map[string]interface{}{
  1234. "project": project,
  1235. "advice": advice,
  1236. })
  1237. }
  1238. func (this *HisProjectApiController) GetHisPatientHistory() {
  1239. timeLayout := "2006-01-02"
  1240. loc, _ := time.LoadLocation("Local")
  1241. keyword := this.GetString("keyword")
  1242. start_time := this.GetString("start_time")
  1243. end_time := this.GetString("end_time")
  1244. register_type, _ := this.GetInt64("register_type")
  1245. limit, _ := this.GetInt64("limit")
  1246. page, _ := this.GetInt64("page")
  1247. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+":00", loc)
  1248. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+":59", loc)
  1249. adminUserInfo := this.GetAdminUserInfo()
  1250. orgId := adminUserInfo.CurrentOrgId
  1251. history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
  1252. department, err := service.GetAllDepartMent(orgId)
  1253. appId := adminUserInfo.CurrentAppId
  1254. doctor, err := service.GetAllDoctor(orgId, appId)
  1255. if err != nil {
  1256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1257. return
  1258. }
  1259. this.ServeSuccessJSON(map[string]interface{}{
  1260. "history": history,
  1261. "total": total,
  1262. "department": department,
  1263. "doctor": doctor,
  1264. })
  1265. }
  1266. func (this *HisProjectApiController) ChangePatient() {
  1267. id, _ := this.GetInt64("id")
  1268. //查询该患者今日是否已经就诊
  1269. recordDateStr := time.Now().Format("2006-01-02")
  1270. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1271. nowtime := recordDate.Unix()
  1272. adminUserInfo := this.GetAdminUserInfo()
  1273. orgId := adminUserInfo.CurrentOrgId
  1274. _, errcode := service.GetHisPrescriptionTwo(id, orgId, nowtime)
  1275. if errcode == gorm.ErrRecordNotFound {
  1276. err := service.ChangePatient(id)
  1277. if err != nil {
  1278. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1279. return
  1280. }
  1281. returnData := make(map[string]interface{}, 0)
  1282. returnData["msg"] = "ok"
  1283. this.ServeSuccessJSON(returnData)
  1284. return
  1285. } else if errcode == nil {
  1286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1287. return
  1288. }
  1289. }
  1290. func (this *HisProjectApiController) GetPatientcaseHistory() {
  1291. patient_id, _ := this.GetInt64("patient_id")
  1292. record_date := this.GetString("record_date")
  1293. timeLayout := "2006-01-02"
  1294. loc, _ := time.LoadLocation("Local")
  1295. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1296. patient, err := service.GetBloodPatientInfoById(patient_id)
  1297. history, _ := service.GetPatientCaseHistory(patient_id, startTime.Unix())
  1298. hispatient, _ := service.GetHisPatientById(patient_id)
  1299. //获取患者最后一次的血管通路
  1300. accessList, _ := service.GetPatientVascularAccess(patient_id)
  1301. if err != nil {
  1302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1303. return
  1304. }
  1305. this.ServeSuccessJSON(map[string]interface{}{
  1306. "patient": patient,
  1307. "history": history,
  1308. "hispatient": hispatient,
  1309. "accessList": accessList,
  1310. })
  1311. }
  1312. func (this *HisProjectApiController) GetTemplateDetail() {
  1313. id, _ := this.GetInt64("id")
  1314. templateDetail, err := service.GetTemplateDetail(id)
  1315. if err != nil {
  1316. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1317. return
  1318. }
  1319. this.ServeSuccessJSON(map[string]interface{}{
  1320. "templateDetail": templateDetail,
  1321. })
  1322. }
  1323. func (this *HisProjectApiController) UpdateRecordTemplate() {
  1324. id, _ := this.GetInt64("id")
  1325. template_name := this.GetString("template_name")
  1326. template_remark := this.GetString("template_remark")
  1327. diagnostic := this.GetString("diagnostic")
  1328. chief_conplaint := this.GetString("chief_conplaint")
  1329. history_of_present_illness := this.GetString("history_of_present_illness")
  1330. past_history := this.GetString("past_history")
  1331. personal_history := this.GetString("personal_history")
  1332. family_history := this.GetString("family_history")
  1333. doctor_advice := this.GetString("doctor_advice")
  1334. remark := this.GetString("remark")
  1335. adminUserInfo := this.GetAdminUserInfo()
  1336. creater := adminUserInfo.AdminUser.Id
  1337. historyTemplate := models.HisCaseHistoryTemplate{
  1338. HistoryOfPresentIllness: history_of_present_illness,
  1339. PastHistory: past_history,
  1340. ChiefConplaint: chief_conplaint,
  1341. PersonalHistory: personal_history,
  1342. FamilyHistory: family_history,
  1343. Diagnostic: diagnostic,
  1344. Status: 1,
  1345. Mtime: time.Now().Unix(),
  1346. RecordDate: time.Now().Unix(),
  1347. TemplateName: template_name,
  1348. TemplateRemark: template_remark,
  1349. Modifier: creater,
  1350. DoctorAdvice: doctor_advice,
  1351. Remark: remark,
  1352. }
  1353. err := service.UpdateCaseHistoryTemplate(&historyTemplate, id)
  1354. if err != nil {
  1355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1356. return
  1357. }
  1358. this.ServeSuccessJSON(map[string]interface{}{
  1359. "templateDetail": historyTemplate,
  1360. })
  1361. }
  1362. func (this *HisProjectApiController) GetHisPatient() {
  1363. adminUserInfo := this.GetAdminUserInfo()
  1364. orgId := adminUserInfo.CurrentOrgId
  1365. keyword := this.GetString("keyword")
  1366. patient, err := service.GetHistPatient(orgId, keyword)
  1367. if err != nil {
  1368. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1369. return
  1370. }
  1371. this.ServeSuccessJSON(map[string]interface{}{
  1372. "patient": patient,
  1373. })
  1374. }
  1375. func (this *HisProjectApiController) GetDoctorAdvicePrint() {
  1376. patient_id, _ := this.GetInt64("patient_id")
  1377. his_patient_id, _ := this.GetInt64("his_patient_id")
  1378. record_date := this.GetString("record_date")
  1379. schIDStr := this.GetString("ids")
  1380. p_type, _ := this.GetInt64("p_type")
  1381. idStrs := strings.Split(schIDStr, ",")
  1382. timeLayout := "2006-01-02"
  1383. loc, _ := time.LoadLocation("Local")
  1384. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1385. recordDateTime := theTime.Unix()
  1386. //prescription_id, _ := this.GetInt64("prescription_id")
  1387. adminUserInfo := this.GetAdminUserInfo()
  1388. var temp_p_type int64
  1389. if p_type == 1 {
  1390. temp_p_type = 1
  1391. } else {
  1392. temp_p_type = 2
  1393. }
  1394. sch, _ := service.GetScheduleByDate(adminUserInfo.CurrentOrgId, recordDateTime, patient_id)
  1395. advicePrint, err := service.GetDoctorAdvicePrint(patient_id, recordDateTime, idStrs, adminUserInfo.CurrentOrgId, temp_p_type)
  1396. projectlist, err := service.GetAllProjectList(adminUserInfo.CurrentOrgId, "")
  1397. his, _ := service.GetLastHisPatient(patient_id, adminUserInfo.CurrentOrgId)
  1398. prescriptionInfo, _ := service.GetPrscriptionInfo(patient_id, recordDateTime)
  1399. //advicePrint, err := service.GetPre(patient_id, recordDateTime, idStrs, adminUserInfo.CurrentOrgId, temp_p_type)
  1400. hisPatient, _ := service.GetHisPatientInfoFour(adminUserInfo.CurrentOrgId, patient_id, recordDateTime, his_patient_id)
  1401. hisPatient_two, _ := service.GetHisPatientInfoTen(adminUserInfo.CurrentOrgId, patient_id, recordDateTime)
  1402. if hisPatient.ID == 0 {
  1403. hisPatient = hisPatient_two
  1404. }
  1405. //hisPatient, _ := service.GetHisPatientById(patient_id)
  1406. hisHospitalRecord, _ := service.GetLastHospitalRecordTwo(patient_id, adminUserInfo.CurrentOrgId)
  1407. //psn_info, _ := service.GetPsnInfo(patient_id)
  1408. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1409. eles, _ := service.GetNewAdminUserES(adminUserInfo.CurrentOrgId)
  1410. roles, _ := service.GetAllDoctor(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  1411. if err != nil {
  1412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1413. return
  1414. }
  1415. this.ServeSuccessJSON(map[string]interface{}{
  1416. "advicePrint": advicePrint,
  1417. "projectlist": projectlist,
  1418. "hisPatient": hisPatient,
  1419. "his": his,
  1420. "hisHospitalRecord": hisHospitalRecord,
  1421. "info": prescriptionInfo,
  1422. "eles": eles,
  1423. "psn_info": psn_info,
  1424. "roles": roles,
  1425. "sch": sch,
  1426. })
  1427. }
  1428. func (this *HisProjectApiController) GetProjectPrint() {
  1429. his_patient_id, _ := this.GetInt64("his_patient_id")
  1430. hisPatient, _ := service.GetHisPatientById(his_patient_id)
  1431. projectPrint, err := service.GetProjectPrint(his_patient_id)
  1432. if err != nil {
  1433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1434. return
  1435. }
  1436. this.ServeSuccessJSON(map[string]interface{}{
  1437. "hisPatient": hisPatient,
  1438. "projectPrint": projectPrint,
  1439. })
  1440. }
  1441. func (this *HisProjectApiController) PostPrintHisTemplate() {
  1442. template_id, _ := this.GetInt64("template_id")
  1443. adminUserInfo := this.GetAdminUserInfo()
  1444. orgId := adminUserInfo.CurrentOrgId
  1445. _, errcode := service.GetHisTemplateId(template_id, orgId)
  1446. //fmt.Println("errcode", errcode)
  1447. if errcode == gorm.ErrRecordNotFound {
  1448. template := models.XtHisTemplate{
  1449. TemplateId: template_id,
  1450. UserOrgId: orgId,
  1451. Status: 1,
  1452. Ctime: time.Now().Unix(),
  1453. }
  1454. err := service.CreateHisTemplate(&template)
  1455. if err != nil {
  1456. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1457. return
  1458. }
  1459. this.ServeSuccessJSON(map[string]interface{}{
  1460. "template": template,
  1461. "template_id": template_id,
  1462. })
  1463. } else if errcode == nil {
  1464. template := models.XtHisTemplate{
  1465. TemplateId: template_id,
  1466. UserOrgId: orgId,
  1467. Status: 1,
  1468. Ctime: time.Now().Unix(),
  1469. Mtime: time.Now().Unix(),
  1470. }
  1471. err := service.UpdateHisTemplate(&template)
  1472. if err != nil {
  1473. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1474. return
  1475. }
  1476. this.ServeSuccessJSON(map[string]interface{}{
  1477. "template": template,
  1478. "template_id": template_id,
  1479. })
  1480. }
  1481. }
  1482. func (this *HisProjectApiController) GetHisPrintTemplate() {
  1483. adminUserInfo := this.GetAdminUserInfo()
  1484. orgId := adminUserInfo.CurrentOrgId
  1485. template, err := service.GetHisPrintTemplate(orgId)
  1486. if err != nil {
  1487. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1488. return
  1489. }
  1490. this.ServeSuccessJSON(map[string]interface{}{
  1491. "template": template,
  1492. })
  1493. }
  1494. func (this *HisProjectApiController) PostPrescriptionTempalte() {
  1495. template_id, _ := this.GetInt64("template_id")
  1496. adminUserInfo := this.GetAdminUserInfo()
  1497. orgId := adminUserInfo.CurrentOrgId
  1498. _, errcode := service.GetPrescriptionTemplate(template_id, orgId)
  1499. if errcode == gorm.ErrRecordNotFound {
  1500. template := models.XtHisAdviceTemplate{
  1501. TemplateId: template_id,
  1502. UserOrgId: orgId,
  1503. Status: 1,
  1504. Ctime: time.Now().Unix(),
  1505. }
  1506. err := service.CreatePrescriptionTemplate(&template)
  1507. if err != nil {
  1508. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1509. return
  1510. }
  1511. this.ServeSuccessJSON(map[string]interface{}{
  1512. "template": template,
  1513. "template_id": template_id,
  1514. })
  1515. } else if errcode == nil {
  1516. template := models.XtHisAdviceTemplate{
  1517. TemplateId: template_id,
  1518. UserOrgId: orgId,
  1519. Status: 1,
  1520. Ctime: time.Now().Unix(),
  1521. }
  1522. err := service.UpdatePrescriptionTemplate(&template)
  1523. if err != nil {
  1524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1525. return
  1526. }
  1527. this.ServeSuccessJSON(map[string]interface{}{
  1528. "template": template,
  1529. "template_id": template_id,
  1530. })
  1531. }
  1532. }
  1533. func (this *HisProjectApiController) GetPrescriptionTemplate() {
  1534. adminUserInfo := this.GetAdminUserInfo()
  1535. orgId := adminUserInfo.CurrentOrgId
  1536. template, err := service.GetPrescriptionTemplateById(orgId)
  1537. if err != nil {
  1538. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1539. return
  1540. }
  1541. this.ServeSuccessJSON(map[string]interface{}{
  1542. "template": template,
  1543. })
  1544. }
  1545. func (this *HisProjectApiController) PostTreatPrintTemplate() {
  1546. template_id, _ := this.GetInt64("template_id")
  1547. adminUserInfo := this.GetAdminUserInfo()
  1548. orgId := adminUserInfo.CurrentOrgId
  1549. _, errcode := service.GetTreatPrintTemplate(template_id, orgId)
  1550. if errcode == gorm.ErrRecordNotFound {
  1551. template := models.XtHisTreatmentTemplate{
  1552. TemplateId: template_id,
  1553. UserOrgId: orgId,
  1554. Status: 1,
  1555. Ctime: time.Now().Unix(),
  1556. }
  1557. err := service.CreateTreatPrintTemplate(&template)
  1558. if err != nil {
  1559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1560. return
  1561. }
  1562. this.ServeSuccessJSON(map[string]interface{}{
  1563. "template": template,
  1564. "template_id": template_id,
  1565. })
  1566. } else if errcode == nil {
  1567. template := models.XtHisTreatmentTemplate{
  1568. TemplateId: template_id,
  1569. UserOrgId: orgId,
  1570. Status: 1,
  1571. Ctime: time.Now().Unix(),
  1572. }
  1573. err := service.UpdatedTreateTemplate(&template)
  1574. if err != nil {
  1575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1576. return
  1577. }
  1578. this.ServeSuccessJSON(map[string]interface{}{
  1579. "template": template,
  1580. "template_id": template_id,
  1581. })
  1582. }
  1583. }
  1584. func (this *HisProjectApiController) GetTreatPrintTemplate() {
  1585. adminUserInfo := this.GetAdminUserInfo()
  1586. orgId := adminUserInfo.CurrentOrgId
  1587. template, err := service.GetTreatTtreatPrintTemplate(orgId)
  1588. if err != nil {
  1589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1590. return
  1591. }
  1592. this.ServeSuccessJSON(map[string]interface{}{
  1593. "template": template,
  1594. })
  1595. }
  1596. func (this *HisProjectApiController) PostChargePrintTemplate() {
  1597. template_id, _ := this.GetInt64("template_id")
  1598. adminUserInfo := this.GetAdminUserInfo()
  1599. orgId := adminUserInfo.CurrentOrgId
  1600. _, errcode := service.GetChargeTemplate(template_id, orgId)
  1601. if errcode == gorm.ErrRecordNotFound {
  1602. template := models.XtHisChargeTemplate{
  1603. TemplateId: template_id,
  1604. UserOrgId: orgId,
  1605. Ctime: time.Now().Unix(),
  1606. Status: 1,
  1607. }
  1608. err := service.CreateChargePrintTemplate(&template)
  1609. if err != nil {
  1610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1611. return
  1612. }
  1613. this.ServeSuccessJSON(map[string]interface{}{
  1614. "template": template,
  1615. "template_id": template_id,
  1616. })
  1617. } else if errcode == nil {
  1618. template := models.XtHisChargeTemplate{
  1619. TemplateId: template_id,
  1620. UserOrgId: orgId,
  1621. Ctime: time.Now().Unix(),
  1622. Status: 1,
  1623. }
  1624. err := service.UpdateChargePrintTemplate(&template)
  1625. if err != nil {
  1626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1627. return
  1628. }
  1629. this.ServeSuccessJSON(map[string]interface{}{
  1630. "template": template,
  1631. "template_id": template_id,
  1632. })
  1633. }
  1634. }
  1635. func (this *HisProjectApiController) GetChargePrintTemplate() {
  1636. adminUserInfo := this.GetAdminUserInfo()
  1637. orgId := adminUserInfo.CurrentOrgId
  1638. template, err := service.GetChargePrintTemplate(orgId)
  1639. if err != nil {
  1640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1641. return
  1642. }
  1643. this.ServeSuccessJSON(map[string]interface{}{
  1644. "template": template,
  1645. })
  1646. }
  1647. func (this *HisProjectApiController) GetAllHisPatient() {
  1648. record_date := this.GetString("record_date")
  1649. timeLayout := "2006-01-02"
  1650. loc, _ := time.LoadLocation("Local")
  1651. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1652. recordDateTime := theTime.Unix()
  1653. adminUserInfo := this.GetAdminUserInfo()
  1654. patients, err := service.GetScheduleHisPatientList(adminUserInfo.CurrentOrgId, "", recordDateTime, 0, 0)
  1655. if err != nil {
  1656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1657. return
  1658. }
  1659. this.ServeSuccessJSON(map[string]interface{}{
  1660. "list": patients,
  1661. })
  1662. }
  1663. func (this *HisProjectApiController) GetChargePrint() {
  1664. record_date := this.GetString("record_date")
  1665. timeLayout := "2006-01-02"
  1666. loc, _ := time.LoadLocation("Local")
  1667. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1668. recordDateTime := theTime.Unix()
  1669. patient_id, _ := this.GetInt64("patient_id")
  1670. prescription_id, _ := this.GetInt64("prescription_id")
  1671. adminUserInfo := this.GetAdminUserInfo()
  1672. chargePrint, err := service.GetChargePrint(recordDateTime, patient_id, adminUserInfo.CurrentOrgId)
  1673. prescription, err := service.GetHisPrescriptionNight(adminUserInfo.CurrentOrgId, patient_id, recordDateTime, prescription_id)
  1674. patient, err := service.GetFaPiaoPatientByID(adminUserInfo.CurrentOrgId, patient_id)
  1675. hisPatient, err := service.GetHisPatientById(patient_id)
  1676. if err != nil {
  1677. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1678. return
  1679. }
  1680. this.ServeSuccessJSON(map[string]interface{}{
  1681. "list": chargePrint,
  1682. "prescription": prescription,
  1683. "patient": patient,
  1684. "hisPatient": hisPatient,
  1685. })
  1686. }
  1687. func (this *HisProjectApiController) GetTodaySchedulePatient() {
  1688. adminUserInfo := this.GetAdminUserInfo()
  1689. orgId := adminUserInfo.CurrentOrgId
  1690. recordDateStr := time.Now().Format("2006-01-02")
  1691. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1692. scheduleDate := recordDate.Unix()
  1693. patient, err := service.GetTodaySchedulePatient(orgId, scheduleDate)
  1694. if err != nil {
  1695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1696. return
  1697. }
  1698. this.ServeSuccessJSON(map[string]interface{}{
  1699. "patient": patient,
  1700. })
  1701. }
  1702. func (this *HisProjectApiController) GetHisPatientDetail() {
  1703. patient_id, _ := this.GetInt64("patient_id")
  1704. hisPatient, _ := service.GetHisPatientByIdFour(patient_id)
  1705. //service.GetLastHospitalRecordTwo(patient_id,this.GetAdminUserInfo().CurrentOrgId)
  1706. hisHospitalRecord, _ := service.GetLastHospitalRecordTwo(patient_id, this.GetAdminUserInfo().CurrentOrgId)
  1707. this.ServeSuccessJSON(map[string]interface{}{
  1708. "hisPatient": hisPatient,
  1709. "hisHospitalRecord": hisHospitalRecord,
  1710. })
  1711. }
  1712. func (this *HisProjectApiController) GetAllDepartmentList() {
  1713. adminUserInfo := this.GetAdminUserInfo()
  1714. orgId := adminUserInfo.CurrentOrgId
  1715. departMent, err := service.GetAllDepartMent(orgId)
  1716. if err != nil {
  1717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1718. return
  1719. }
  1720. this.ServeSuccessJSON(map[string]interface{}{
  1721. "departMent": departMent,
  1722. })
  1723. }
  1724. func (this *HisProjectApiController) GetPrescription() {
  1725. patient_id, _ := this.GetInt64("patient_id")
  1726. p_type, _ := this.GetInt64("p_type")
  1727. record_date := this.GetString("record_date")
  1728. timeLayout := "2006-01-02"
  1729. loc, _ := time.LoadLocation("Local")
  1730. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1731. if err != nil {
  1732. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1733. return
  1734. }
  1735. recordDateTime := theTime.Unix()
  1736. list, err := service.GetPrescriptionByPatientId(patient_id, recordDateTime, p_type)
  1737. if err != nil {
  1738. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1739. return
  1740. }
  1741. this.ServeSuccessJSON(map[string]interface{}{
  1742. "list": list,
  1743. })
  1744. }
  1745. func (this *HisProjectApiController) GetPatientDetail() {
  1746. id, _ := this.GetInt64("id")
  1747. adminUserInfo := this.GetAdminUserInfo()
  1748. patient, err := service.GetFaPiaoPatientByID(adminUserInfo.CurrentOrgId, id)
  1749. if err != nil {
  1750. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1751. return
  1752. }
  1753. this.ServeSuccessJSON(map[string]interface{}{
  1754. "patient": patient,
  1755. })
  1756. }
  1757. func (this *HisProjectApiController) SaveMainTemplate() {
  1758. title := this.GetString("title")
  1759. content := this.GetString("content")
  1760. remark := this.GetString("remark")
  1761. template_id, _ := this.GetInt64("template_id")
  1762. adminUserInfo := this.GetAdminUserInfo()
  1763. orgId := adminUserInfo.CurrentOrgId
  1764. template := models.XtHisMedicalTemplate{
  1765. Title: title,
  1766. Content: content,
  1767. Remark: remark,
  1768. UserOrgId: orgId,
  1769. TemplateId: template_id,
  1770. Status: 1,
  1771. Ctime: time.Now().Unix(),
  1772. }
  1773. err := service.CreateHisMedicalTemplate(&template)
  1774. if err != nil {
  1775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1776. return
  1777. }
  1778. this.ServeSuccessJSON(map[string]interface{}{
  1779. "template": template,
  1780. })
  1781. }
  1782. func (this *HisProjectApiController) GetMedicalTempalteList() {
  1783. adminUserInfo := this.GetAdminUserInfo()
  1784. orgId := adminUserInfo.CurrentOrgId
  1785. list, err := service.GetMedicalTemplateList(orgId)
  1786. listOne, err := service.GetMedicalTemplateListOne(orgId)
  1787. listTwo, err := service.GetMedicalTemplateListTwo(orgId)
  1788. listThree, err := service.GetMedicalTemplateListThree(orgId)
  1789. listFour, err := service.GetMedicalTemplateListFour(orgId)
  1790. listFive, err := service.GetMedicalTemplateListFive(orgId)
  1791. listSix, err := service.GetMedicalTemplateListSix(orgId)
  1792. listSeven, err := service.GetMedicalTemplateListSeven(orgId)
  1793. if err != nil {
  1794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1795. return
  1796. }
  1797. this.ServeSuccessJSON(map[string]interface{}{
  1798. "list": list,
  1799. "listOne": listOne,
  1800. "listTwo": listTwo,
  1801. "listThree": listThree,
  1802. "listFour": listFour,
  1803. "listFive": listFive,
  1804. "listSix": listSix,
  1805. "listSeven": listSeven,
  1806. })
  1807. }
  1808. func (this *HisProjectApiController) GetMainTemplateById() {
  1809. id, _ := this.GetInt64("id")
  1810. template, err := service.GetMainTemplateById(id)
  1811. if err != nil {
  1812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1813. return
  1814. }
  1815. this.ServeSuccessJSON(map[string]interface{}{
  1816. "template": template,
  1817. })
  1818. }
  1819. func (this *HisProjectApiController) UpdateMainTemplate() {
  1820. title := this.GetString("title")
  1821. content := this.GetString("content")
  1822. remark := this.GetString("remark")
  1823. id, _ := this.GetInt64("id")
  1824. template := models.XtHisMedicalTemplate{
  1825. Title: title,
  1826. Content: content,
  1827. Remark: remark,
  1828. }
  1829. err := service.UpdateMainTemplate(&template, id)
  1830. if err != nil {
  1831. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1832. return
  1833. }
  1834. this.ServeSuccessJSON(map[string]interface{}{
  1835. "template": template,
  1836. })
  1837. }
  1838. func (this *HisProjectApiController) DeleteMainTemplate() {
  1839. id, _ := this.GetInt64("id")
  1840. err := service.DeleteMainTemplateById(id)
  1841. if err != nil {
  1842. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1843. return
  1844. }
  1845. returnData := make(map[string]interface{}, 0)
  1846. returnData["msg"] = "ok"
  1847. this.ServeSuccessJSON(returnData)
  1848. return
  1849. }