his_project_api_controller.go 68KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070
  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. adminUserInfo := this.GetAdminUserInfo()
  762. orgId := adminUserInfo.CurrentOrgId
  763. department := models.XtHisDepartment{
  764. Name: name,
  765. Number: number,
  766. UserOrgId: orgId,
  767. CreatedTime: time.Now().Unix(),
  768. Status: 1,
  769. }
  770. err := service.CreateDePartment(&department)
  771. if err != nil {
  772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  773. return
  774. }
  775. department_keys := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + "_department"
  776. redis := service.RedisClient()
  777. defer redis.Close()
  778. redis.Set(department_keys, "", time.Second*60*60*18)
  779. this.ServeSuccessJSON(map[string]interface{}{
  780. "department": department,
  781. })
  782. return
  783. }
  784. func (this *HisProjectApiController) GetDepartMentList() {
  785. limit, _ := this.GetInt64("limit")
  786. page, _ := this.GetInt64("page")
  787. adminUserInfo := this.GetAdminUserInfo()
  788. orgId := adminUserInfo.CurrentOrgId
  789. departMentList, total, err := service.GetDepartMentList(limit, page, orgId)
  790. if err != nil {
  791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  792. return
  793. }
  794. this.ServeSuccessJSON(map[string]interface{}{
  795. "departMentList": departMentList,
  796. "total": total,
  797. })
  798. return
  799. }
  800. func (this *HisProjectApiController) GetDepartMentDetail() {
  801. id, _ := this.GetInt64("id")
  802. departDetail, err := service.GetDepartMentDetail(id)
  803. if err != nil {
  804. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  805. return
  806. }
  807. this.ServeSuccessJSON(map[string]interface{}{
  808. "departDetail": departDetail,
  809. })
  810. return
  811. }
  812. func (this *HisProjectApiController) UpdatedDeparment() {
  813. id, _ := this.GetInt64("id")
  814. name := this.GetString("name")
  815. number := this.GetString("number")
  816. department := models.XtHisDepartment{
  817. Name: name,
  818. Number: number,
  819. }
  820. err := service.UpdatedDepartment(id, &department)
  821. if err != nil {
  822. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  823. return
  824. }
  825. department_keys := strconv.FormatInt(this.GetAdminUserInfo().CurrentOrgId, 10) + "_department"
  826. redis := service.RedisClient()
  827. defer redis.Close()
  828. redis.Set(department_keys, "", time.Second*60*60*18)
  829. this.ServeSuccessJSON(map[string]interface{}{
  830. "department": department,
  831. })
  832. return
  833. }
  834. func (this *HisProjectApiController) DeleteDepartment() {
  835. id, _ := this.GetInt64("id")
  836. err := service.DeleteDepartment(id)
  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. returnData := make(map[string]interface{}, 0)
  846. returnData["msg"] = "ok"
  847. this.ServeSuccessJSON(returnData)
  848. return
  849. }
  850. func (this *HisProjectApiController) GetBloodPatientList() {
  851. adminUserInfo := this.GetAdminUserInfo()
  852. orgId := adminUserInfo.CurrentOrgId
  853. timeStr := time.Now().Format("2006-01-02")
  854. timeLayout := "2006-01-02 15:04:05"
  855. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  856. timenow := timeStringToTime.Unix()
  857. //统计血透排班的患者
  858. scheduleList, err := service.GetBloodPatientList(orgId, timenow)
  859. //统计当日挂号的患者
  860. hisPatient, _ := service.GetHisPatient(orgId, timenow)
  861. //统计今天开处方的患者
  862. prescription, _ := service.GetHisPrescriptionOther(orgId, timenow)
  863. if err != nil {
  864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  865. return
  866. }
  867. this.ServeSuccessJSON(map[string]interface{}{
  868. "scheduleList": scheduleList,
  869. "hisPatient": hisPatient,
  870. "prescription": prescription,
  871. })
  872. return
  873. }
  874. func (this *HisProjectApiController) GetHisPrescription() {
  875. id, _ := this.GetInt64("id")
  876. timeStr := time.Now().Format("2006-01-02")
  877. timeLayout := "2006-01-02 15:04:05"
  878. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  879. timenow := timeStringToTime.Unix()
  880. prescriptionList, err := service.GetHisPrescriptionByPatientId(id, timenow)
  881. if err != nil {
  882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  883. return
  884. }
  885. this.ServeSuccessJSON(map[string]interface{}{
  886. "prescriptionList": prescriptionList,
  887. })
  888. return
  889. }
  890. func (this *HisProjectApiController) GetTreatmentList() {
  891. patient_id, _ := this.GetInt64("patient_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. treatmentList, err := service.GetTreatmentList(patient_id, timenow)
  897. if err != nil {
  898. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  899. return
  900. }
  901. this.ServeSuccessJSON(map[string]interface{}{
  902. "treatmentList": treatmentList,
  903. })
  904. return
  905. }
  906. func (this *HisProjectApiController) GetAllProjectList() {
  907. keyword := this.GetString("keyword")
  908. adminUserInfo := this.GetAdminUserInfo()
  909. orgId := adminUserInfo.CurrentOrgId
  910. projectList, err := service.GetAllProjectList(orgId, keyword)
  911. goodInfos, err := service.GetGoodInfomationList(orgId, keyword)
  912. drug, _ := service.GetDrugInfomationList(orgId, keyword)
  913. //goodInfos, err := service.GetAllDrugList(orgId)
  914. //获取列表数据
  915. hisprojectlist, err := service.GetHisProjectListByOrgId(orgId)
  916. if err != nil {
  917. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  918. return
  919. }
  920. this.ServeSuccessJSON(map[string]interface{}{
  921. "projectList": projectList,
  922. "hisprojectlist": hisprojectlist,
  923. "good_info": goodInfos,
  924. "drug": drug,
  925. })
  926. return
  927. }
  928. func (this *HisProjectApiController) AddProjectList() {
  929. id, _ := this.GetInt64("id")
  930. number, _ := this.GetInt64("number")
  931. adminUserInfo := this.GetAdminUserInfo()
  932. orgId := adminUserInfo.CurrentOrgId
  933. projectList := models.XtHisProjectList{
  934. ProjectId: id,
  935. Number: number,
  936. UserOrgId: orgId,
  937. Status: 1,
  938. CreatedTime: time.Now().Unix(),
  939. }
  940. err := service.CreateProjectList(&projectList)
  941. detail, _ := service.GetProjectDetail(id)
  942. item, err := service.GetLastItem(orgId)
  943. if err != nil {
  944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  945. return
  946. }
  947. this.ServeSuccessJSON(map[string]interface{}{
  948. "projectList": detail,
  949. "item": item,
  950. })
  951. return
  952. }
  953. func (this *HisProjectApiController) GetPatientInformation() {
  954. id, _ := this.GetInt64("id")
  955. information, err := service.GetHisPatientInformation(id)
  956. if err != nil {
  957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  958. return
  959. }
  960. this.ServeSuccessJSON(map[string]interface{}{
  961. "information": information,
  962. })
  963. return
  964. }
  965. func (this *HisProjectApiController) DeleteProject() {
  966. id, _ := this.GetInt64("id")
  967. err := service.DeleteProjectList(id)
  968. if err != nil {
  969. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  970. return
  971. }
  972. returnData := make(map[string]interface{}, 0)
  973. returnData["msg"] = "ok"
  974. this.ServeSuccessJSON(returnData)
  975. return
  976. }
  977. func (this *HisProjectApiController) DeleteDrug() {
  978. id, _ := this.GetInt64("id")
  979. err := service.DeleteDrugList(id)
  980. if err != nil {
  981. this.ServeFailJsonSend(enums.ErrorCodeDataException, "失败")
  982. return
  983. }
  984. returnData := make(map[string]interface{}, 0)
  985. returnData["msg"] = "ok"
  986. this.ServeSuccessJSON(returnData)
  987. return
  988. }
  989. func (this *HisProjectApiController) GetHisProject() {
  990. adminUserInfo := this.GetAdminUserInfo()
  991. orgId := adminUserInfo.CurrentOrgId
  992. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  993. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10215 {
  994. project, err := service.GetHisProject(orgId)
  995. good_info, err := service.GetGoodInfoMationSeven(orgId, houseConfig.StorehouseOutInfo)
  996. _, config := service.FindHisStockPriceRecordByOrgId(orgId)
  997. if config.ID > 0 && config.IsOpen == 1 {
  998. //处理耗材不同批号价格问题
  999. for _, item := range good_info {
  1000. if len(item.GoodSotckInfo) > 0 {
  1001. if item.GoodSotckInfo[0].Price > 0 {
  1002. item.PackingPrice = item.GoodSotckInfo[0].Price
  1003. }
  1004. }
  1005. }
  1006. }
  1007. if err != nil {
  1008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1009. return
  1010. }
  1011. this.ServeSuccessJSON(map[string]interface{}{
  1012. "project": project,
  1013. "good_info": good_info,
  1014. })
  1015. }
  1016. if adminUserInfo.CurrentOrgId != 9671 && adminUserInfo.CurrentOrgId != 9675 && adminUserInfo.CurrentOrgId != 10215 {
  1017. project, err := service.GetHisProject(orgId)
  1018. good_info, err := service.GetGoodInfoMationSix(orgId, houseConfig.StorehouseOutInfo)
  1019. _, config := service.FindHisStockPriceRecordByOrgId(orgId)
  1020. if config.ID > 0 && config.IsOpen == 1 {
  1021. //处理耗材不同批号价格问题
  1022. for _, item := range good_info {
  1023. if len(item.GoodSotckInfo) > 0 {
  1024. if item.GoodSotckInfo[0].Price > 0 {
  1025. item.PackingPrice = item.GoodSotckInfo[0].Price
  1026. }
  1027. }
  1028. }
  1029. }
  1030. if err != nil {
  1031. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1032. return
  1033. }
  1034. this.ServeSuccessJSON(map[string]interface{}{
  1035. "project": project,
  1036. "good_info": good_info,
  1037. })
  1038. }
  1039. }
  1040. func (this *HisProjectApiController) GetProjectTeam() {
  1041. strids := this.GetString("strids")
  1042. idStrs := strings.Split(strids, ",")
  1043. adminUserInfo := this.GetAdminUserInfo()
  1044. orgId := adminUserInfo.CurrentOrgId
  1045. team, err := service.GetProjectTeam(idStrs, orgId)
  1046. if err != nil {
  1047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1048. return
  1049. }
  1050. this.ServeSuccessJSON(map[string]interface{}{
  1051. "team": team,
  1052. })
  1053. }
  1054. func (this *HisProjectApiController) GetAllDoctorList() {
  1055. adminUserInfo := this.GetAdminUserInfo()
  1056. orgId := adminUserInfo.CurrentOrgId
  1057. appId := adminUserInfo.CurrentAppId
  1058. //获取所有的医生
  1059. doctor, err := service.GetAllDoctor(orgId, appId)
  1060. //获取所有的科室
  1061. department, err := service.GetAllDepartMent(orgId)
  1062. if err != nil {
  1063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1064. return
  1065. }
  1066. this.ServeSuccessJSON(map[string]interface{}{
  1067. "doctor": doctor,
  1068. "department": department,
  1069. })
  1070. }
  1071. func (this *HisProjectApiController) SaveHisPatient() {
  1072. timeLayout := "2006-01-02"
  1073. loc, _ := time.LoadLocation("Local")
  1074. age, _ := this.GetInt64("age")
  1075. birthday := this.GetString("birthday")
  1076. patient_id, _ := this.GetInt64("id")
  1077. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1078. birthUnix := birthdays.Unix()
  1079. certificates, _ := this.GetInt64("certificates")
  1080. cost_checked, _ := this.GetInt64("costChecked")
  1081. cost, _ := this.GetInt64("cost")
  1082. costs := strconv.FormatInt(cost, 10)
  1083. cost_float, _ := strconv.ParseFloat(costs, 64)
  1084. department, _ := this.GetInt64("department")
  1085. doctor, _ := this.GetInt64("doctor")
  1086. medicalcare, _ := this.GetInt64("medical_care")
  1087. idcard := this.GetString("id_card")
  1088. medicalExpenses, _ := this.GetInt64("medical_expenses")
  1089. medicalExpense := strconv.FormatInt(medicalExpenses, 10)
  1090. medicalExpense_float, _ := strconv.ParseFloat(medicalExpense, 64)
  1091. medicalinsurancecard := this.GetString("medical_insurance_card")
  1092. name := this.GetString("name")
  1093. register, _ := this.GetInt64("register")
  1094. registrationfee, _ := this.GetInt64("registration_fee")
  1095. registrationfees := strconv.FormatInt(registrationfee, 10)
  1096. registrationfees_float, _ := strconv.ParseFloat(registrationfees, 64)
  1097. settlementValue, _ := this.GetInt64("settlement_value")
  1098. sex, _ := this.GetInt64("sex")
  1099. total, _ := this.GetInt64("total")
  1100. totals := strconv.FormatInt(total, 10)
  1101. totals_float, _ := strconv.ParseFloat(totals, 64)
  1102. adminUserInfo := this.GetAdminUserInfo()
  1103. orgId := adminUserInfo.CurrentOrgId
  1104. recordDateStr := time.Now().Format("2006-01-02")
  1105. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1106. nowtime := recordDate.Unix()
  1107. phone := this.GetString("phone")
  1108. social_type, _ := this.GetInt64("social_type")
  1109. id_card_type, _ := this.GetInt64("id_card_type")
  1110. //diagnosis_id, _ := this.GetInt64("diagnosis")
  1111. diagnosis_ids := this.GetString("diagnosis")
  1112. sick_type, _ := this.GetInt64("sick_type")
  1113. reg_type := this.GetString("p_type")
  1114. tempPatient, _ := service.GetPatientByIDCardAndName(idcard, adminUserInfo.CurrentOrgId, name)
  1115. if tempPatient.ID == 0 {
  1116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  1117. return
  1118. }
  1119. var patient service.Patients
  1120. if patient_id == 0 {
  1121. patient, _ = service.GetPatientByIDCard(idcard, adminUserInfo.CurrentOrgId)
  1122. } else {
  1123. patient, _ = service.GetPatientByIDTwo(adminUserInfo.CurrentOrgId, patient_id)
  1124. }
  1125. if patient.ID == 0 {
  1126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1127. return
  1128. }
  1129. if len(patient.IdCardNo) == 0 {
  1130. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1131. return
  1132. }
  1133. timeStr := time.Now().Format("2006-01-02 15:04:05")
  1134. fmt.Println(timeStr)
  1135. timeArr := strings.Split(timeStr, " ")
  1136. timeArrTwo := strings.Split(timeArr[0], "-")
  1137. timeArrThree := strings.Split(timeArr[1], ":")
  1138. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  1139. //his, _ := service.GetHisPatientInfoTwo(adminUserInfo.CurrentOrgId, patient.ID, recordDate.Unix())
  1140. //if len(his) >= 1 {
  1141. // order, _ := service.GetNewHisOrderTwo(adminUserInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDate.Unix())
  1142. // if len(his) >= 1 && order.ID == 0 {
  1143. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  1144. // return
  1145. // }
  1146. //}
  1147. var hisPatient models.XtHisPatient
  1148. //if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1149. hisPatient = models.XtHisPatient{
  1150. PatientId: patient_id,
  1151. Birthday: birthUnix,
  1152. IdType: certificates,
  1153. CostOfProduction: cost_float,
  1154. Departments: department,
  1155. Doctor: doctor,
  1156. AdminUserId: adminUserInfo.AdminUser.Id,
  1157. MedicalTreatmentType: medicalcare,
  1158. IdCardNo: idcard,
  1159. IsNeedCostOfProduction: cost_checked,
  1160. TreatmentCost: medicalExpense_float,
  1161. MedicalInsuranceNumber: medicalinsurancecard,
  1162. Name: name,
  1163. Age: age,
  1164. Number: str,
  1165. RegisterType: register,
  1166. RegisterCost: registrationfees_float,
  1167. BalanceAccountsType: settlementValue,
  1168. Gender: sex,
  1169. Total: totals_float,
  1170. UserOrgId: orgId,
  1171. Status: 1,
  1172. RecordDate: nowtime,
  1173. IsReturn: 1,
  1174. Ctime: time.Now().Unix(),
  1175. Phone: phone,
  1176. SocialType: social_type,
  1177. IdCardType: id_card_type,
  1178. Diagnosis: diagnosis_ids,
  1179. PType: reg_type,
  1180. SickType: sick_type,
  1181. }
  1182. service.CreateHisPatient(&hisPatient)
  1183. this.ServeSuccessJSON(map[string]interface{}{
  1184. "his_info": hisPatient,
  1185. })
  1186. //}
  1187. //else {
  1188. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisRegisterException)
  1189. // return
  1190. //}
  1191. }
  1192. func (this *HisProjectApiController) GetAllProjectTeam() {
  1193. adminUserInfo := this.GetAdminUserInfo()
  1194. orgId := adminUserInfo.CurrentOrgId
  1195. team, err := service.GetAllProjectTeam(orgId)
  1196. if err != nil {
  1197. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1198. return
  1199. }
  1200. this.ServeSuccessJSON(map[string]interface{}{
  1201. "team": team,
  1202. })
  1203. }
  1204. func (this *HisProjectApiController) GetProjectListById() {
  1205. adminUserInfo := this.GetAdminUserInfo()
  1206. orgId := adminUserInfo.CurrentOrgId
  1207. project_id := this.GetString("project_id")
  1208. drug_id := this.GetString("drug_id")
  1209. idStrs := strings.Split(project_id, ",")
  1210. drug_idStrs := strings.Split(drug_id, ",")
  1211. project, err := service.GetProjectListById(orgId, idStrs)
  1212. advice, _ := service.GetAdviceTeamListById(orgId, drug_idStrs)
  1213. if err != nil {
  1214. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1215. return
  1216. }
  1217. this.ServeSuccessJSON(map[string]interface{}{
  1218. "project": project,
  1219. "advice": advice,
  1220. })
  1221. }
  1222. func (this *HisProjectApiController) GetHisPatientHistory() {
  1223. timeLayout := "2006-01-02"
  1224. loc, _ := time.LoadLocation("Local")
  1225. keyword := this.GetString("keyword")
  1226. start_time := this.GetString("start_time")
  1227. end_time := this.GetString("end_time")
  1228. register_type, _ := this.GetInt64("register_type")
  1229. limit, _ := this.GetInt64("limit")
  1230. page, _ := this.GetInt64("page")
  1231. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+":00", loc)
  1232. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+":59", loc)
  1233. adminUserInfo := this.GetAdminUserInfo()
  1234. orgId := adminUserInfo.CurrentOrgId
  1235. history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
  1236. department, err := service.GetAllDepartMent(orgId)
  1237. appId := adminUserInfo.CurrentAppId
  1238. doctor, err := service.GetAllDoctor(orgId, appId)
  1239. if err != nil {
  1240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1241. return
  1242. }
  1243. this.ServeSuccessJSON(map[string]interface{}{
  1244. "history": history,
  1245. "total": total,
  1246. "department": department,
  1247. "doctor": doctor,
  1248. })
  1249. }
  1250. func (this *HisProjectApiController) ChangePatient() {
  1251. id, _ := this.GetInt64("id")
  1252. //查询该患者今日是否已经就诊
  1253. recordDateStr := time.Now().Format("2006-01-02")
  1254. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1255. nowtime := recordDate.Unix()
  1256. adminUserInfo := this.GetAdminUserInfo()
  1257. orgId := adminUserInfo.CurrentOrgId
  1258. _, errcode := service.GetHisPrescriptionTwo(id, orgId, nowtime)
  1259. if errcode == gorm.ErrRecordNotFound {
  1260. err := service.ChangePatient(id)
  1261. if err != nil {
  1262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1263. return
  1264. }
  1265. returnData := make(map[string]interface{}, 0)
  1266. returnData["msg"] = "ok"
  1267. this.ServeSuccessJSON(returnData)
  1268. return
  1269. } else if errcode == nil {
  1270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1271. return
  1272. }
  1273. }
  1274. func (this *HisProjectApiController) GetPatientcaseHistory() {
  1275. patient_id, _ := this.GetInt64("patient_id")
  1276. record_date := this.GetString("record_date")
  1277. timeLayout := "2006-01-02"
  1278. loc, _ := time.LoadLocation("Local")
  1279. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1280. patient, err := service.GetBloodPatientInfoById(patient_id)
  1281. history, _ := service.GetPatientCaseHistory(patient_id, startTime.Unix())
  1282. hispatient, _ := service.GetHisPatientById(patient_id)
  1283. //获取患者最后一次的血管通路
  1284. accessList, _ := service.GetPatientVascularAccess(patient_id)
  1285. if err != nil {
  1286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1287. return
  1288. }
  1289. this.ServeSuccessJSON(map[string]interface{}{
  1290. "patient": patient,
  1291. "history": history,
  1292. "hispatient": hispatient,
  1293. "accessList": accessList,
  1294. })
  1295. }
  1296. func (this *HisProjectApiController) GetTemplateDetail() {
  1297. id, _ := this.GetInt64("id")
  1298. templateDetail, err := service.GetTemplateDetail(id)
  1299. if err != nil {
  1300. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1301. return
  1302. }
  1303. this.ServeSuccessJSON(map[string]interface{}{
  1304. "templateDetail": templateDetail,
  1305. })
  1306. }
  1307. func (this *HisProjectApiController) UpdateRecordTemplate() {
  1308. id, _ := this.GetInt64("id")
  1309. template_name := this.GetString("template_name")
  1310. template_remark := this.GetString("template_remark")
  1311. diagnostic := this.GetString("diagnostic")
  1312. chief_conplaint := this.GetString("chief_conplaint")
  1313. history_of_present_illness := this.GetString("history_of_present_illness")
  1314. past_history := this.GetString("past_history")
  1315. personal_history := this.GetString("personal_history")
  1316. family_history := this.GetString("family_history")
  1317. doctor_advice := this.GetString("doctor_advice")
  1318. remark := this.GetString("remark")
  1319. adminUserInfo := this.GetAdminUserInfo()
  1320. creater := adminUserInfo.AdminUser.Id
  1321. historyTemplate := models.HisCaseHistoryTemplate{
  1322. HistoryOfPresentIllness: history_of_present_illness,
  1323. PastHistory: past_history,
  1324. ChiefConplaint: chief_conplaint,
  1325. PersonalHistory: personal_history,
  1326. FamilyHistory: family_history,
  1327. Diagnostic: diagnostic,
  1328. Status: 1,
  1329. Mtime: time.Now().Unix(),
  1330. RecordDate: time.Now().Unix(),
  1331. TemplateName: template_name,
  1332. TemplateRemark: template_remark,
  1333. Modifier: creater,
  1334. DoctorAdvice: doctor_advice,
  1335. Remark: remark,
  1336. }
  1337. err := service.UpdateCaseHistoryTemplate(&historyTemplate, id)
  1338. if err != nil {
  1339. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1340. return
  1341. }
  1342. this.ServeSuccessJSON(map[string]interface{}{
  1343. "templateDetail": historyTemplate,
  1344. })
  1345. }
  1346. func (this *HisProjectApiController) GetHisPatient() {
  1347. adminUserInfo := this.GetAdminUserInfo()
  1348. orgId := adminUserInfo.CurrentOrgId
  1349. keyword := this.GetString("keyword")
  1350. patient, err := service.GetHistPatient(orgId, keyword)
  1351. if err != nil {
  1352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1353. return
  1354. }
  1355. this.ServeSuccessJSON(map[string]interface{}{
  1356. "patient": patient,
  1357. })
  1358. }
  1359. func (this *HisProjectApiController) GetDoctorAdvicePrint() {
  1360. patient_id, _ := this.GetInt64("patient_id")
  1361. his_patient_id, _ := this.GetInt64("his_patient_id")
  1362. record_date := this.GetString("record_date")
  1363. schIDStr := this.GetString("ids")
  1364. p_type, _ := this.GetInt64("p_type")
  1365. idStrs := strings.Split(schIDStr, ",")
  1366. timeLayout := "2006-01-02"
  1367. loc, _ := time.LoadLocation("Local")
  1368. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1369. recordDateTime := theTime.Unix()
  1370. //prescription_id, _ := this.GetInt64("prescription_id")
  1371. adminUserInfo := this.GetAdminUserInfo()
  1372. var temp_p_type int64
  1373. if p_type == 1 {
  1374. temp_p_type = 1
  1375. } else {
  1376. temp_p_type = 2
  1377. }
  1378. sch, _ := service.GetScheduleByDate(adminUserInfo.CurrentOrgId, recordDateTime, patient_id)
  1379. advicePrint, err := service.GetDoctorAdvicePrint(patient_id, recordDateTime, idStrs, adminUserInfo.CurrentOrgId, temp_p_type)
  1380. projectlist, err := service.GetAllProjectList(adminUserInfo.CurrentOrgId, "")
  1381. his, _ := service.GetLastHisPatient(patient_id, adminUserInfo.CurrentOrgId)
  1382. prescriptionInfo, _ := service.GetPrscriptionInfo(patient_id, recordDateTime)
  1383. //advicePrint, err := service.GetPre(patient_id, recordDateTime, idStrs, adminUserInfo.CurrentOrgId, temp_p_type)
  1384. hisPatient, _ := service.GetHisPatientInfoFour(adminUserInfo.CurrentOrgId, patient_id, recordDateTime, his_patient_id)
  1385. hisPatient_two, _ := service.GetHisPatientInfoTen(adminUserInfo.CurrentOrgId, patient_id, recordDateTime)
  1386. if hisPatient.ID == 0 {
  1387. hisPatient = hisPatient_two
  1388. }
  1389. //hisPatient, _ := service.GetHisPatientById(patient_id)
  1390. hisHospitalRecord, _ := service.GetLastHospitalRecordTwo(patient_id, adminUserInfo.CurrentOrgId)
  1391. //psn_info, _ := service.GetPsnInfo(patient_id)
  1392. psn_info, _ := service.GetPsnByPatientId(patient_id)
  1393. eles, _ := service.GetNewAdminUserES(adminUserInfo.CurrentOrgId)
  1394. roles, _ := service.GetAllDoctor(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  1395. if err != nil {
  1396. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1397. return
  1398. }
  1399. this.ServeSuccessJSON(map[string]interface{}{
  1400. "advicePrint": advicePrint,
  1401. "projectlist": projectlist,
  1402. "hisPatient": hisPatient,
  1403. "his": his,
  1404. "hisHospitalRecord": hisHospitalRecord,
  1405. "info": prescriptionInfo,
  1406. "eles": eles,
  1407. "psn_info": psn_info,
  1408. "roles": roles,
  1409. "sch": sch,
  1410. })
  1411. }
  1412. func (this *HisProjectApiController) GetProjectPrint() {
  1413. his_patient_id, _ := this.GetInt64("his_patient_id")
  1414. hisPatient, _ := service.GetHisPatientById(his_patient_id)
  1415. projectPrint, err := service.GetProjectPrint(his_patient_id)
  1416. if err != nil {
  1417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1418. return
  1419. }
  1420. this.ServeSuccessJSON(map[string]interface{}{
  1421. "hisPatient": hisPatient,
  1422. "projectPrint": projectPrint,
  1423. })
  1424. }
  1425. func (this *HisProjectApiController) PostPrintHisTemplate() {
  1426. template_id, _ := this.GetInt64("template_id")
  1427. adminUserInfo := this.GetAdminUserInfo()
  1428. orgId := adminUserInfo.CurrentOrgId
  1429. _, errcode := service.GetHisTemplateId(template_id, orgId)
  1430. //fmt.Println("errcode", errcode)
  1431. if errcode == gorm.ErrRecordNotFound {
  1432. template := models.XtHisTemplate{
  1433. TemplateId: template_id,
  1434. UserOrgId: orgId,
  1435. Status: 1,
  1436. Ctime: time.Now().Unix(),
  1437. }
  1438. err := service.CreateHisTemplate(&template)
  1439. if err != nil {
  1440. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1441. return
  1442. }
  1443. this.ServeSuccessJSON(map[string]interface{}{
  1444. "template": template,
  1445. "template_id": template_id,
  1446. })
  1447. } else if errcode == nil {
  1448. template := models.XtHisTemplate{
  1449. TemplateId: template_id,
  1450. UserOrgId: orgId,
  1451. Status: 1,
  1452. Ctime: time.Now().Unix(),
  1453. Mtime: time.Now().Unix(),
  1454. }
  1455. err := service.UpdateHisTemplate(&template)
  1456. if err != nil {
  1457. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1458. return
  1459. }
  1460. this.ServeSuccessJSON(map[string]interface{}{
  1461. "template": template,
  1462. "template_id": template_id,
  1463. })
  1464. }
  1465. }
  1466. func (this *HisProjectApiController) GetHisPrintTemplate() {
  1467. adminUserInfo := this.GetAdminUserInfo()
  1468. orgId := adminUserInfo.CurrentOrgId
  1469. template, err := service.GetHisPrintTemplate(orgId)
  1470. if err != nil {
  1471. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1472. return
  1473. }
  1474. this.ServeSuccessJSON(map[string]interface{}{
  1475. "template": template,
  1476. })
  1477. }
  1478. func (this *HisProjectApiController) PostPrescriptionTempalte() {
  1479. template_id, _ := this.GetInt64("template_id")
  1480. adminUserInfo := this.GetAdminUserInfo()
  1481. orgId := adminUserInfo.CurrentOrgId
  1482. _, errcode := service.GetPrescriptionTemplate(template_id, orgId)
  1483. if errcode == gorm.ErrRecordNotFound {
  1484. template := models.XtHisAdviceTemplate{
  1485. TemplateId: template_id,
  1486. UserOrgId: orgId,
  1487. Status: 1,
  1488. Ctime: time.Now().Unix(),
  1489. }
  1490. err := service.CreatePrescriptionTemplate(&template)
  1491. if err != nil {
  1492. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1493. return
  1494. }
  1495. this.ServeSuccessJSON(map[string]interface{}{
  1496. "template": template,
  1497. "template_id": template_id,
  1498. })
  1499. } else if errcode == nil {
  1500. template := models.XtHisAdviceTemplate{
  1501. TemplateId: template_id,
  1502. UserOrgId: orgId,
  1503. Status: 1,
  1504. Ctime: time.Now().Unix(),
  1505. }
  1506. err := service.UpdatePrescriptionTemplate(&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. }
  1516. }
  1517. func (this *HisProjectApiController) GetPrescriptionTemplate() {
  1518. adminUserInfo := this.GetAdminUserInfo()
  1519. orgId := adminUserInfo.CurrentOrgId
  1520. template, err := service.GetPrescriptionTemplateById(orgId)
  1521. if err != nil {
  1522. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1523. return
  1524. }
  1525. this.ServeSuccessJSON(map[string]interface{}{
  1526. "template": template,
  1527. })
  1528. }
  1529. func (this *HisProjectApiController) PostTreatPrintTemplate() {
  1530. template_id, _ := this.GetInt64("template_id")
  1531. adminUserInfo := this.GetAdminUserInfo()
  1532. orgId := adminUserInfo.CurrentOrgId
  1533. _, errcode := service.GetTreatPrintTemplate(template_id, orgId)
  1534. if errcode == gorm.ErrRecordNotFound {
  1535. template := models.XtHisTreatmentTemplate{
  1536. TemplateId: template_id,
  1537. UserOrgId: orgId,
  1538. Status: 1,
  1539. Ctime: time.Now().Unix(),
  1540. }
  1541. err := service.CreateTreatPrintTemplate(&template)
  1542. if err != nil {
  1543. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1544. return
  1545. }
  1546. this.ServeSuccessJSON(map[string]interface{}{
  1547. "template": template,
  1548. "template_id": template_id,
  1549. })
  1550. } else if errcode == nil {
  1551. template := models.XtHisTreatmentTemplate{
  1552. TemplateId: template_id,
  1553. UserOrgId: orgId,
  1554. Status: 1,
  1555. Ctime: time.Now().Unix(),
  1556. }
  1557. err := service.UpdatedTreateTemplate(&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. }
  1567. }
  1568. func (this *HisProjectApiController) GetTreatPrintTemplate() {
  1569. adminUserInfo := this.GetAdminUserInfo()
  1570. orgId := adminUserInfo.CurrentOrgId
  1571. template, err := service.GetTreatTtreatPrintTemplate(orgId)
  1572. if err != nil {
  1573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1574. return
  1575. }
  1576. this.ServeSuccessJSON(map[string]interface{}{
  1577. "template": template,
  1578. })
  1579. }
  1580. func (this *HisProjectApiController) PostChargePrintTemplate() {
  1581. template_id, _ := this.GetInt64("template_id")
  1582. adminUserInfo := this.GetAdminUserInfo()
  1583. orgId := adminUserInfo.CurrentOrgId
  1584. _, errcode := service.GetChargeTemplate(template_id, orgId)
  1585. if errcode == gorm.ErrRecordNotFound {
  1586. template := models.XtHisChargeTemplate{
  1587. TemplateId: template_id,
  1588. UserOrgId: orgId,
  1589. Ctime: time.Now().Unix(),
  1590. Status: 1,
  1591. }
  1592. err := service.CreateChargePrintTemplate(&template)
  1593. if err != nil {
  1594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1595. return
  1596. }
  1597. this.ServeSuccessJSON(map[string]interface{}{
  1598. "template": template,
  1599. "template_id": template_id,
  1600. })
  1601. } else if errcode == nil {
  1602. template := models.XtHisChargeTemplate{
  1603. TemplateId: template_id,
  1604. UserOrgId: orgId,
  1605. Ctime: time.Now().Unix(),
  1606. Status: 1,
  1607. }
  1608. err := service.UpdateChargePrintTemplate(&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. }
  1618. }
  1619. func (this *HisProjectApiController) GetChargePrintTemplate() {
  1620. adminUserInfo := this.GetAdminUserInfo()
  1621. orgId := adminUserInfo.CurrentOrgId
  1622. template, err := service.GetChargePrintTemplate(orgId)
  1623. if err != nil {
  1624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1625. return
  1626. }
  1627. this.ServeSuccessJSON(map[string]interface{}{
  1628. "template": template,
  1629. })
  1630. }
  1631. func (this *HisProjectApiController) GetAllHisPatient() {
  1632. record_date := this.GetString("record_date")
  1633. timeLayout := "2006-01-02"
  1634. loc, _ := time.LoadLocation("Local")
  1635. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1636. recordDateTime := theTime.Unix()
  1637. adminUserInfo := this.GetAdminUserInfo()
  1638. patients, err := service.GetScheduleHisPatientList(adminUserInfo.CurrentOrgId, "", recordDateTime, 0, 0)
  1639. if err != nil {
  1640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1641. return
  1642. }
  1643. this.ServeSuccessJSON(map[string]interface{}{
  1644. "list": patients,
  1645. })
  1646. }
  1647. func (this *HisProjectApiController) GetChargePrint() {
  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. patient_id, _ := this.GetInt64("patient_id")
  1654. prescription_id, _ := this.GetInt64("prescription_id")
  1655. adminUserInfo := this.GetAdminUserInfo()
  1656. chargePrint, err := service.GetChargePrint(recordDateTime, patient_id, adminUserInfo.CurrentOrgId)
  1657. prescription, err := service.GetHisPrescriptionNight(adminUserInfo.CurrentOrgId, patient_id, recordDateTime, prescription_id)
  1658. patient, err := service.GetFaPiaoPatientByID(adminUserInfo.CurrentOrgId, patient_id)
  1659. hisPatient, err := service.GetHisPatientById(patient_id)
  1660. if err != nil {
  1661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1662. return
  1663. }
  1664. this.ServeSuccessJSON(map[string]interface{}{
  1665. "list": chargePrint,
  1666. "prescription": prescription,
  1667. "patient": patient,
  1668. "hisPatient": hisPatient,
  1669. })
  1670. }
  1671. func (this *HisProjectApiController) GetTodaySchedulePatient() {
  1672. adminUserInfo := this.GetAdminUserInfo()
  1673. orgId := adminUserInfo.CurrentOrgId
  1674. recordDateStr := time.Now().Format("2006-01-02")
  1675. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1676. scheduleDate := recordDate.Unix()
  1677. patient, err := service.GetTodaySchedulePatient(orgId, scheduleDate)
  1678. if err != nil {
  1679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1680. return
  1681. }
  1682. this.ServeSuccessJSON(map[string]interface{}{
  1683. "patient": patient,
  1684. })
  1685. }
  1686. func (this *HisProjectApiController) GetHisPatientDetail() {
  1687. patient_id, _ := this.GetInt64("patient_id")
  1688. hisPatient, _ := service.GetHisPatientByIdFour(patient_id)
  1689. //service.GetLastHospitalRecordTwo(patient_id,this.GetAdminUserInfo().CurrentOrgId)
  1690. hisHospitalRecord, _ := service.GetLastHospitalRecordTwo(patient_id, this.GetAdminUserInfo().CurrentOrgId)
  1691. this.ServeSuccessJSON(map[string]interface{}{
  1692. "hisPatient": hisPatient,
  1693. "hisHospitalRecord": hisHospitalRecord,
  1694. })
  1695. }
  1696. func (this *HisProjectApiController) GetAllDepartmentList() {
  1697. adminUserInfo := this.GetAdminUserInfo()
  1698. orgId := adminUserInfo.CurrentOrgId
  1699. departMent, err := service.GetAllDepartMent(orgId)
  1700. if err != nil {
  1701. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1702. return
  1703. }
  1704. this.ServeSuccessJSON(map[string]interface{}{
  1705. "departMent": departMent,
  1706. })
  1707. }
  1708. func (this *HisProjectApiController) GetPrescription() {
  1709. patient_id, _ := this.GetInt64("patient_id")
  1710. p_type, _ := this.GetInt64("p_type")
  1711. record_date := this.GetString("record_date")
  1712. timeLayout := "2006-01-02"
  1713. loc, _ := time.LoadLocation("Local")
  1714. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1715. if err != nil {
  1716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1717. return
  1718. }
  1719. recordDateTime := theTime.Unix()
  1720. list, err := service.GetPrescriptionByPatientId(patient_id, recordDateTime, p_type)
  1721. if err != nil {
  1722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1723. return
  1724. }
  1725. this.ServeSuccessJSON(map[string]interface{}{
  1726. "list": list,
  1727. })
  1728. }
  1729. func (this *HisProjectApiController) GetPatientDetail() {
  1730. id, _ := this.GetInt64("id")
  1731. adminUserInfo := this.GetAdminUserInfo()
  1732. patient, err := service.GetFaPiaoPatientByID(adminUserInfo.CurrentOrgId, id)
  1733. if err != nil {
  1734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1735. return
  1736. }
  1737. this.ServeSuccessJSON(map[string]interface{}{
  1738. "patient": patient,
  1739. })
  1740. }
  1741. func (this *HisProjectApiController) SaveMainTemplate() {
  1742. title := this.GetString("title")
  1743. content := this.GetString("content")
  1744. remark := this.GetString("remark")
  1745. template_id, _ := this.GetInt64("template_id")
  1746. adminUserInfo := this.GetAdminUserInfo()
  1747. orgId := adminUserInfo.CurrentOrgId
  1748. template := models.XtHisMedicalTemplate{
  1749. Title: title,
  1750. Content: content,
  1751. Remark: remark,
  1752. UserOrgId: orgId,
  1753. TemplateId: template_id,
  1754. Status: 1,
  1755. Ctime: time.Now().Unix(),
  1756. }
  1757. err := service.CreateHisMedicalTemplate(&template)
  1758. if err != nil {
  1759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1760. return
  1761. }
  1762. this.ServeSuccessJSON(map[string]interface{}{
  1763. "template": template,
  1764. })
  1765. }
  1766. func (this *HisProjectApiController) GetMedicalTempalteList() {
  1767. adminUserInfo := this.GetAdminUserInfo()
  1768. orgId := adminUserInfo.CurrentOrgId
  1769. list, err := service.GetMedicalTemplateList(orgId)
  1770. listOne, err := service.GetMedicalTemplateListOne(orgId)
  1771. listTwo, err := service.GetMedicalTemplateListTwo(orgId)
  1772. listThree, err := service.GetMedicalTemplateListThree(orgId)
  1773. listFour, err := service.GetMedicalTemplateListFour(orgId)
  1774. listFive, err := service.GetMedicalTemplateListFive(orgId)
  1775. listSix, err := service.GetMedicalTemplateListSix(orgId)
  1776. listSeven, err := service.GetMedicalTemplateListSeven(orgId)
  1777. if err != nil {
  1778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1779. return
  1780. }
  1781. this.ServeSuccessJSON(map[string]interface{}{
  1782. "list": list,
  1783. "listOne": listOne,
  1784. "listTwo": listTwo,
  1785. "listThree": listThree,
  1786. "listFour": listFour,
  1787. "listFive": listFive,
  1788. "listSix": listSix,
  1789. "listSeven": listSeven,
  1790. })
  1791. }
  1792. func (this *HisProjectApiController) GetMainTemplateById() {
  1793. id, _ := this.GetInt64("id")
  1794. template, err := service.GetMainTemplateById(id)
  1795. if err != nil {
  1796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1797. return
  1798. }
  1799. this.ServeSuccessJSON(map[string]interface{}{
  1800. "template": template,
  1801. })
  1802. }
  1803. func (this *HisProjectApiController) UpdateMainTemplate() {
  1804. title := this.GetString("title")
  1805. content := this.GetString("content")
  1806. remark := this.GetString("remark")
  1807. id, _ := this.GetInt64("id")
  1808. template := models.XtHisMedicalTemplate{
  1809. Title: title,
  1810. Content: content,
  1811. Remark: remark,
  1812. }
  1813. err := service.UpdateMainTemplate(&template, id)
  1814. if err != nil {
  1815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1816. return
  1817. }
  1818. this.ServeSuccessJSON(map[string]interface{}{
  1819. "template": template,
  1820. })
  1821. }
  1822. func (this *HisProjectApiController) DeleteMainTemplate() {
  1823. id, _ := this.GetInt64("id")
  1824. err := service.DeleteMainTemplateById(id)
  1825. if err != nil {
  1826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1827. return
  1828. }
  1829. returnData := make(map[string]interface{}, 0)
  1830. returnData["msg"] = "ok"
  1831. this.ServeSuccessJSON(returnData)
  1832. return
  1833. }