patient_api_controller.go 115KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "math"
  11. "strings"
  12. // "fmt"
  13. "reflect"
  14. "strconv"
  15. "time"
  16. )
  17. type PatientApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *PatientApiController) GetPatientInfoWithDiseases() {
  21. id, _ := c.GetInt64("patient", 0)
  22. if id <= 0 {
  23. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  24. return
  25. }
  26. adminUserInfo := c.GetMobileAdminUserInfo()
  27. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  28. if patient.ID == 0 {
  29. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  30. return
  31. }
  32. Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
  33. if err != nil {
  34. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. return
  36. }
  37. if Registrars != nil {
  38. patient.Registrars = Registrars.Name
  39. }
  40. c.ServeSuccessJSON(map[string]interface{}{
  41. "patient": patient,
  42. })
  43. return
  44. }
  45. func (c *PatientApiController) CreateDialysisSolution() {
  46. id, _ := c.GetInt64("patient", 0)
  47. if id <= 0 {
  48. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  49. return
  50. }
  51. adminUserInfo := c.GetMobileAdminUserInfo()
  52. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  53. if patient.ID == 0 {
  54. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  55. return
  56. }
  57. //根据路由来做权限
  58. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  59. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  60. //if template.TemplateId == 2 || template.TemplateId == 6 {
  61. // if appRole.UserType == 3 {
  62. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  63. // if getPermissionErr != nil {
  64. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  65. // return
  66. // } else if headNursePermission == nil {
  67. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  68. // return
  69. // }
  70. // }
  71. //}
  72. var solution models.DialysisSolution
  73. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  74. if code > 0 {
  75. c.ServeFailJSONWithSGJErrorCode(code)
  76. return
  77. }
  78. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  79. solution.Doctor = adminUserInfo.AdminUser.Id
  80. solution.Status = 1
  81. solution.PatientId = id
  82. solution.CreatedTime = time.Now().Unix()
  83. solution.UserOrgId = adminUserInfo.Org.Id
  84. solution.UpdatedTime = time.Now().Unix()
  85. solution.SubName = ""
  86. solution.ParentId = 0
  87. err := service.CreatePatientDialysisSolution(&solution)
  88. if err != nil {
  89. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  90. return
  91. }
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "msg": "ok",
  94. "solution": solution,
  95. })
  96. return
  97. }
  98. func (c *PatientApiController) EditDialysisSolution() {
  99. id, _ := c.GetInt64("id", 0)
  100. if id <= 0 {
  101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  102. return
  103. }
  104. adminUserInfo := c.GetMobileAdminUserInfo()
  105. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
  106. if solution.ID == 0 {
  107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  108. return
  109. }
  110. //if solution.Doctor != adminUserInfo.AdminUser.Id {
  111. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  112. // if getPermissionErr != nil {
  113. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  114. // return
  115. // } else if headNursePermission == nil {
  116. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  117. // return
  118. // }
  119. //}
  120. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
  121. if code > 0 {
  122. c.ServeFailJSONWithSGJErrorCode(code)
  123. return
  124. }
  125. // solution.RegistrarsId = adminUserInfo.AdminUser.Id
  126. solution.Doctor = adminUserInfo.AdminUser.Id
  127. solution.Status = 1
  128. // solution.PatientId = id
  129. // solution.CreatedTime = time.Now().Unix()
  130. // solution.UserOrgId = adminUserInfo.Org.Id
  131. solution.UpdatedTime = time.Now().Unix()
  132. // solution.SubName = ""
  133. // solution.ParentId = 0
  134. err := service.UpdatePatientDialysisSolution(&solution)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  137. return
  138. }
  139. c.ServeSuccessJSON(map[string]interface{}{
  140. "msg": "ok",
  141. "solution": solution,
  142. })
  143. return
  144. }
  145. func (c *PatientApiController) CreateDoctorAdvice() {
  146. fmt.Println("进来了吗-----------------------------")
  147. patient, _ := c.GetInt64("id", 0)
  148. if patient <= 0 {
  149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  150. return
  151. }
  152. adminUserInfo := c.GetMobileAdminUserInfo()
  153. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  154. if patientInfo.ID == 0 {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  156. return
  157. }
  158. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  159. //if appRole.UserType == 3{
  160. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  161. // return
  162. //}
  163. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  164. //
  165. //if appRole.UserType == 3 {
  166. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  167. // if getPermissionErr != nil {
  168. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  169. // return
  170. // } else if headNursePermission == nil {
  171. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  172. // return
  173. // }
  174. //}
  175. var advice models.DoctorAdvice
  176. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  177. if code > 0 {
  178. c.ServeFailJSONWithSGJErrorCode(code)
  179. return
  180. }
  181. if advice.ParentId > 0 {
  182. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  183. if old.ID == 0 || old.PatientId != patient {
  184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  185. return
  186. }
  187. if old.StopState == 1 || old.ExecutionState == 1 {
  188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  189. return
  190. }
  191. if old.ParentId > 0 {
  192. advice.ParentId = old.ParentId
  193. }
  194. advice.StartTime = old.StartTime
  195. advice.AdviceDoctor = old.AdviceDoctor
  196. advice.DeliveryWay = old.DeliveryWay
  197. advice.ExecutionFrequency = old.ExecutionFrequency
  198. advice.GroupNo = old.GroupNo
  199. }
  200. advice.Status = 1
  201. advice.CreatedTime = time.Now().Unix()
  202. advice.UpdatedTime = time.Now().Unix()
  203. advice.StopState = 2
  204. advice.ExecutionState = 2
  205. advice.UserOrgId = adminUserInfo.Org.Id
  206. advice.PatientId = patient
  207. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  208. err := service.CreateDoctorAdvice(&advice)
  209. if err != nil {
  210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  211. return
  212. }
  213. c.ServeSuccessJSON(map[string]interface{}{
  214. "msg": "ok",
  215. "advice": advice,
  216. })
  217. return
  218. }
  219. func (c *PatientApiController) EditDoctorAdvice() {
  220. id, _ := c.GetInt64("id", 0)
  221. if id <= 0 {
  222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  223. return
  224. }
  225. adminUserInfo := c.GetMobileAdminUserInfo()
  226. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  227. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  228. //
  229. //if appRole.UserType == 3 {
  230. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  231. // if getPermissionErr != nil {
  232. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. // return
  234. // } else if headNursePermission == nil {
  235. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  236. // return
  237. // }
  238. //}
  239. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  240. if advice.ID == 0 {
  241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  242. return
  243. }
  244. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  245. if code > 0 {
  246. c.ServeFailJSONWithSGJErrorCode(code)
  247. return
  248. }
  249. advice.Status = 1
  250. advice.UpdatedTime = time.Now().Unix()
  251. advice.UserOrgId = adminUserInfo.Org.Id
  252. advice.Modifier = adminUserInfo.AdminUser.Id
  253. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  254. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  255. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  256. var err error
  257. var isChangeGroup bool
  258. if advice.ParentId == 0 {
  259. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  260. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  261. if len(adviceSlice) == 1 {
  262. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  263. if advice.StartTime == sourceAdvice.StartTime {
  264. err = service.UpdateDoctorAdvice(&advice)
  265. isChangeGroup = false
  266. } else {
  267. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  268. isChangeGroup = false
  269. }
  270. } else if len(adviceSlice) > 1 {
  271. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  272. if advice.StartTime == sourceAdvice.StartTime {
  273. err = service.UpdateDoctorAdvice(&advice)
  274. isChangeGroup = false
  275. } else {
  276. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  277. gruopNo = gruopNo + 1
  278. advice.GroupNo = gruopNo
  279. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  280. isChangeGroup = true
  281. }
  282. }
  283. } else {
  284. isChangeGroup = false
  285. err = service.UpdateDoctorAdvice(&advice)
  286. }
  287. if err != nil {
  288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  289. return
  290. }
  291. if !isChangeGroup {
  292. c.ServeSuccessJSON(map[string]interface{}{
  293. "msg": "ok",
  294. "advice": advice,
  295. "isChange": isChangeGroup, //方便前端处理数据
  296. })
  297. } else {
  298. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  299. if err != nil {
  300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  301. return
  302. }
  303. c.ServeSuccessJSON(map[string]interface{}{
  304. "msg": "ok",
  305. "advice": newGroupAdvice,
  306. "isChange": isChangeGroup, //方便前端处理数据
  307. })
  308. }
  309. return
  310. }
  311. func (c *PatientApiController) StopDoctorAdvice() {
  312. id, _ := c.GetInt64("id", 0)
  313. if id <= 0 {
  314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  315. return
  316. }
  317. adminUserInfo := c.GetMobileAdminUserInfo()
  318. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  319. if advice.ID == 0 {
  320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  321. return
  322. }
  323. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  324. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  325. // return
  326. //}
  327. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  328. //
  329. //if appRole.UserType == 3 {
  330. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  331. // if getPermissionErr != nil {
  332. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  333. // return
  334. // } else if headNursePermission == nil {
  335. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  336. // return
  337. // }
  338. //}
  339. if advice.StopState == 1 {
  340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  341. return
  342. }
  343. dataBody := make(map[string]interface{}, 0)
  344. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  345. if err != nil {
  346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  347. return
  348. }
  349. timeLayout := "2006-01-02"
  350. loc, _ := time.LoadLocation("Local")
  351. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  352. utils.ErrorLog("stop_time")
  353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  354. return
  355. }
  356. stopTime, _ := dataBody["stop_time"].(string)
  357. if len(stopTime) == 0 {
  358. utils.ErrorLog("len(stop_time) == 0")
  359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  360. return
  361. }
  362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  363. if err != nil {
  364. utils.ErrorLog(err.Error())
  365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  366. return
  367. }
  368. advice.StopTime = theTime.Unix()
  369. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  370. utils.ErrorLog("stop_reason")
  371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  372. return
  373. }
  374. stopReason, _ := dataBody["stop_reason"].(string)
  375. if len(stopReason) == 0 {
  376. utils.ErrorLog("len(stop_reason) == 0")
  377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  378. return
  379. }
  380. advice.StopReason = stopReason
  381. advice.Status = 1
  382. advice.UpdatedTime = time.Now().Unix()
  383. advice.StopDoctor = adminUserInfo.AdminUser.Id
  384. advice.StopState = 1
  385. advice.StopTime = time.Now().Unix()
  386. advice.Modifier = adminUserInfo.AdminUser.Id
  387. err = service.StopDoctorAdvice(&advice)
  388. if err != nil {
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  390. return
  391. }
  392. c.ServeSuccessJSON(map[string]interface{}{
  393. "msg": "ok",
  394. "advice": advice,
  395. })
  396. return
  397. }
  398. func (c *PatientApiController) DeleteDoctorAdvice() {
  399. id, _ := c.GetInt64("id", 0)
  400. if id <= 0 {
  401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  402. return
  403. }
  404. adminUserInfo := c.GetMobileAdminUserInfo()
  405. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  406. if advice.ID == 0 {
  407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  408. return
  409. }
  410. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  411. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  412. // return
  413. //}
  414. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  415. //
  416. //if appRole.UserType == 3 {
  417. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  418. // if getPermissionErr != nil {
  419. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  420. // return
  421. // } else if headNursePermission == nil {
  422. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  423. // return
  424. // }
  425. //}
  426. advice.UpdatedTime = time.Now().Unix()
  427. advice.Status = 0
  428. advice.Modifier = adminUserInfo.AdminUser.Id
  429. err := service.DeleteDoctorAdvice(&advice)
  430. if err != nil {
  431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  432. return
  433. }
  434. c.ServeSuccessJSON(map[string]interface{}{
  435. "msg": "ok",
  436. })
  437. return
  438. }
  439. func (c *PatientApiController) ExecDoctorAdvice() {
  440. execution_time := c.GetString("execution_time")
  441. groupno, _ := c.GetInt64("groupno", -1)
  442. var ids []string
  443. if groupno == 0 {
  444. advice_ids := c.GetString("advice_id")
  445. ids = strings.Split(advice_ids, ",")
  446. }
  447. if groupno < 0 {
  448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  449. return
  450. }
  451. if len(execution_time) <= 0 {
  452. utils.ErrorLog("execution_time")
  453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  454. return
  455. }
  456. timeLayout2 := "2006-01-02 15:04:05"
  457. loc, _ := time.LoadLocation("Local")
  458. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  459. if errs != nil {
  460. utils.ErrorLog(errs.Error())
  461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  462. return
  463. }
  464. adminUserInfo := c.GetMobileAdminUserInfo()
  465. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  466. //
  467. //if appRole.UserType == 2 || appRole.UserType == 1 {
  468. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  469. // if getPermissionErr != nil {
  470. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  471. // return
  472. // } else if headNursePermission == nil {
  473. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  474. // return
  475. // }
  476. //}
  477. var advice models.DoctorAdvice
  478. if groupno > 0 {
  479. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  480. for _, item := range advices {
  481. if item.ExecutionState == 2 {
  482. advice = item
  483. }
  484. }
  485. } else {
  486. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  487. for _, item := range advices {
  488. if item.ExecutionState == 2 {
  489. advice = item
  490. }
  491. }
  492. }
  493. if advice.ExecutionState == 1 {
  494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  495. return
  496. }
  497. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  499. return
  500. }
  501. if advice.StartTime > theTime.Unix() {
  502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  503. return
  504. }
  505. execution_staff := adminUserInfo.AdminUser.Id
  506. advices := models.DoctorAdvice{
  507. ExecutionStaff: execution_staff,
  508. ExecutionTime: theTime.Unix(),
  509. UpdatedTime: time.Now().Unix(),
  510. }
  511. var err error
  512. if groupno > 0 {
  513. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  514. } else {
  515. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  516. }
  517. if err != nil {
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  519. return
  520. }
  521. advice.ExecutionStaff = execution_staff
  522. advice.ExecutionTime = theTime.Unix()
  523. advice.ExecutionState = 1
  524. advice.Modifier = adminUserInfo.AdminUser.Id
  525. //处理出库相关逻辑
  526. //1.判断是否启用药品管理和自备药出库功能
  527. //药品管理信息
  528. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  529. //自备药信息
  530. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  531. if drugStockConfig.IsOpen == 1 {
  532. if groupno > 0 {
  533. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  534. isHasWay := false //用来判断是否包含来自药品库的医嘱
  535. record_time := int64(0)
  536. for _, item := range advices {
  537. if item.Way == 1 {
  538. isHasWay = true
  539. record_time = item.RecordDate
  540. }
  541. }
  542. if isHasWay {
  543. out, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
  544. if err == gorm.ErrRecordNotFound {
  545. //没有记录,则创建出库单
  546. timeStr := time.Now().Format("2006-01-02")
  547. timeArr := strings.Split(timeStr, "-")
  548. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  549. total = total + 1
  550. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  551. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  552. number = number + total
  553. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  554. creater := adminUserInfo.AdminUser.Id
  555. warehouseOut := models.DrugWarehouseOut{
  556. WarehouseOutOrderNumber: warehousing_out_order,
  557. OperationTime: time.Now().Unix(),
  558. OrgId: adminUserInfo.Org.Id,
  559. Creater: creater,
  560. Ctime: time.Now().Unix(),
  561. Status: 1,
  562. WarehouseOutTime: record_time,
  563. Dealer: 0,
  564. Manufacturer: 0,
  565. Type: 1,
  566. IsSys: 1,
  567. }
  568. err := service.AddSigleDrugWarehouseOut(&warehouseOut)
  569. if err != nil {
  570. utils.TraceLog("创建出库单失败 err = %v", err)
  571. } else {
  572. for _, item := range advices {
  573. if item.Way == 1 {
  574. if item.PrescribingNumber > 0 {
  575. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  576. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  577. WarehouseOutId: warehouseOut.ID,
  578. Status: 1,
  579. Ctime: time.Now().Unix(),
  580. Remark: "",
  581. OrgId: adminUserInfo.Org.Id,
  582. Type: 1,
  583. Manufacturer: 0,
  584. Dealer: 0,
  585. IsSys: 1,
  586. SysRecordTime: record_time,
  587. DrugId: item.DrugId,
  588. }
  589. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  590. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  591. warehouseOutInfo.Count = count
  592. stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
  593. warehouseOutInfo.Price = stockInInfo.Price
  594. err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  595. if err == nil {
  596. details := &models.DrugAutomaticReduceDetail{
  597. WarehouseOutId: warehouseOutInfo.ID,
  598. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  599. PatientId: item.PatientId,
  600. Ctime: time.Now().Unix(),
  601. Mtime: time.Now().Unix(),
  602. Status: 1,
  603. RecordTime: record_time,
  604. OrgId: adminUserInfo.Org.Id,
  605. DrugId: item.DrugId,
  606. Count: count,
  607. }
  608. service.AddSigleDrugAutoReduceRecordInfo(details)
  609. }
  610. }
  611. }
  612. }
  613. }
  614. } else if err == nil {
  615. for _, item := range advices {
  616. if item.Way == 1 {
  617. outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
  618. if err == gorm.ErrRecordNotFound {
  619. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  620. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  621. WarehouseOutId: out.ID,
  622. Status: 1,
  623. Ctime: time.Now().Unix(),
  624. Remark: "",
  625. OrgId: adminUserInfo.Org.Id,
  626. Type: 1,
  627. Manufacturer: 0,
  628. Dealer: 0,
  629. IsSys: 1,
  630. SysRecordTime: record_time,
  631. }
  632. stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
  633. warehouseOutInfo.Price = stockInInfo.Price
  634. warehouseOutInfo.DrugId = item.DrugId
  635. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  636. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  637. warehouseOutInfo.Count = count
  638. err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  639. if err == nil {
  640. details := &models.DrugAutomaticReduceDetail{
  641. WarehouseOutId: warehouseOutInfo.ID,
  642. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  643. PatientId: item.PatientId,
  644. Ctime: time.Now().Unix(),
  645. Mtime: time.Now().Unix(),
  646. Status: 1,
  647. RecordTime: record_time,
  648. OrgId: adminUserInfo.Org.Id,
  649. DrugId: item.DrugId,
  650. Count: count,
  651. }
  652. service.AddSigleDrugAutoReduceRecordInfo(details)
  653. }
  654. } else if err == nil { //记录存在,则将增加数量
  655. if outInfo.ID > 0 {
  656. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  657. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  658. service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
  659. }
  660. //count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
  661. //if count == 0 {
  662. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  663. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  664. details := &models.DrugAutomaticReduceDetail{
  665. WarehouseOutId: outInfo.ID,
  666. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  667. PatientId: item.PatientId,
  668. Ctime: time.Now().Unix(),
  669. Mtime: time.Now().Unix(),
  670. Status: 1,
  671. RecordTime: record_time,
  672. OrgId: adminUserInfo.Org.Id,
  673. DrugId: item.DrugId,
  674. Count: count,
  675. }
  676. service.AddSigleDrugAutoReduceRecordInfo(details)
  677. }
  678. }
  679. }
  680. }
  681. }
  682. } else {
  683. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  684. isHasWay := false //用来判断是否包含来自药品库的医嘱
  685. record_time := int64(0)
  686. for _, item := range advices {
  687. if item.Way == 1 {
  688. isHasWay = true
  689. record_time = item.RecordDate
  690. }
  691. }
  692. if isHasWay {
  693. out, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
  694. if err == gorm.ErrRecordNotFound {
  695. //没有记录,则创建出库单
  696. timeStr := time.Now().Format("2006-01-02")
  697. timeArr := strings.Split(timeStr, "-")
  698. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  699. total = total + 1
  700. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  701. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  702. number = number + total
  703. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  704. creater := adminUserInfo.AdminUser.Id
  705. warehouseOut := models.DrugWarehouseOut{
  706. WarehouseOutOrderNumber: warehousing_out_order,
  707. OperationTime: time.Now().Unix(),
  708. OrgId: adminUserInfo.Org.Id,
  709. Creater: creater,
  710. Ctime: time.Now().Unix(),
  711. Status: 1,
  712. WarehouseOutTime: record_time,
  713. Dealer: 0,
  714. Manufacturer: 0,
  715. Type: 1,
  716. IsSys: 1,
  717. }
  718. err := service.AddSigleDrugWarehouseOut(&warehouseOut)
  719. if err != nil {
  720. utils.TraceLog("创建出库单失败 err = %v", err)
  721. } else {
  722. for _, item := range advices {
  723. if item.Way == 1 {
  724. if item.PrescribingNumber > 0 {
  725. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  726. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  727. WarehouseOutId: warehouseOut.ID,
  728. Status: 1,
  729. Ctime: time.Now().Unix(),
  730. Remark: "",
  731. OrgId: adminUserInfo.Org.Id,
  732. Type: 1,
  733. Manufacturer: 0,
  734. Dealer: 0,
  735. IsSys: 1,
  736. SysRecordTime: record_time,
  737. DrugId: item.DrugId,
  738. }
  739. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  740. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  741. warehouseOutInfo.Count = count
  742. stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
  743. warehouseOutInfo.Price = stockInInfo.Price
  744. err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  745. if err == nil {
  746. details := &models.DrugAutomaticReduceDetail{
  747. WarehouseOutId: warehouseOutInfo.ID,
  748. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  749. PatientId: item.PatientId,
  750. Ctime: time.Now().Unix(),
  751. Mtime: time.Now().Unix(),
  752. Status: 1,
  753. RecordTime: record_time,
  754. OrgId: adminUserInfo.Org.Id,
  755. DrugId: item.DrugId,
  756. Count: count,
  757. }
  758. service.AddSigleDrugAutoReduceRecordInfo(details)
  759. }
  760. }
  761. }
  762. }
  763. }
  764. } else if err == nil {
  765. for _, item := range advices {
  766. if item.Way == 1 {
  767. outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
  768. if err == gorm.ErrRecordNotFound {
  769. warehouseOutInfo := &models.DrugWarehouseOutInfo{
  770. WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
  771. WarehouseOutId: out.ID,
  772. Status: 1,
  773. Ctime: time.Now().Unix(),
  774. Remark: "",
  775. OrgId: adminUserInfo.Org.Id,
  776. Type: 1,
  777. Manufacturer: 0,
  778. Dealer: 0,
  779. IsSys: 1,
  780. SysRecordTime: record_time,
  781. }
  782. stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
  783. warehouseOutInfo.Price = stockInInfo.Price
  784. warehouseOutInfo.DrugId = item.DrugId
  785. //warehouseOutInfo.Count = item.
  786. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  787. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  788. err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
  789. if err == nil {
  790. details := &models.DrugAutomaticReduceDetail{
  791. WarehouseOutId: warehouseOutInfo.ID,
  792. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  793. PatientId: item.PatientId,
  794. Ctime: time.Now().Unix(),
  795. Mtime: time.Now().Unix(),
  796. Status: 1,
  797. RecordTime: record_time,
  798. OrgId: adminUserInfo.Org.Id,
  799. DrugId: item.DrugId,
  800. Count: count,
  801. }
  802. service.AddSigleDrugAutoReduceRecordInfo(details)
  803. }
  804. } else if err == nil { //记录存在,则将增加数量
  805. if outInfo.ID > 0 {
  806. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  807. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  808. service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
  809. }
  810. //count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
  811. //if count == 0 {
  812. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  813. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  814. details := &models.DrugAutomaticReduceDetail{
  815. WarehouseOutId: outInfo.ID,
  816. WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
  817. PatientId: item.PatientId,
  818. Ctime: time.Now().Unix(),
  819. Mtime: time.Now().Unix(),
  820. Status: 1,
  821. RecordTime: record_time,
  822. OrgId: adminUserInfo.Org.Id,
  823. DrugId: item.DrugId,
  824. Count: count,
  825. }
  826. service.AddSigleDrugAutoReduceRecordInfo(details)
  827. //}
  828. //else if count == 1 {
  829. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  830. // count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  831. // service.UpdateDrugUserInfoDetails(item.DrugId, record_time, adminUserInfo.Org.Id, item.PatientId, count, &outInfo)
  832. //}
  833. }
  834. }
  835. }
  836. }
  837. }
  838. }
  839. }
  840. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  841. if groupno > 0 {
  842. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  843. for _, item := range advices {
  844. fmt.Println("------------进来没有22222222", item.ExecutionState)
  845. if item.ExecutionState == 1 {
  846. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  847. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  848. timeStr := time.Now().Format("2006-01-02")
  849. timeArr := strings.Split(timeStr, "-")
  850. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  851. total = total + 1
  852. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  853. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  854. number = number + total
  855. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  856. //插入自备药出库单
  857. outStock := models.XtSelfOutStock{
  858. DrugName: item.AdviceName,
  859. DrugNameId: item.DrugNameId,
  860. DrugSpec: item.AdviceDesc,
  861. OutstoreNumber: count,
  862. AdminUserId: adminUserInfo.AdminUser.Id,
  863. StorckTime: item.AdviceDate,
  864. UserOrgId: adminUserInfo.Org.Id,
  865. CreatedTime: time.Now().Unix(),
  866. Status: 1,
  867. PatientId: item.PatientId,
  868. ExitMode: 2,
  869. MedicId: item.DrugId,
  870. StockOutNumber: warehousing_out_order,
  871. }
  872. service.CreateOutStock(&outStock)
  873. }
  874. }
  875. } else {
  876. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  877. for _, item := range advices {
  878. if item.ExecutionState == 1 {
  879. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  880. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  881. timeStr := time.Now().Format("2006-01-02")
  882. timeArr := strings.Split(timeStr, "-")
  883. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  884. total = total + 1
  885. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  886. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  887. number = number + total
  888. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  889. //插入自备药出库单
  890. outStock := models.XtSelfOutStock{
  891. DrugName: item.AdviceName,
  892. DrugNameId: item.DrugNameId,
  893. DrugSpec: item.AdviceDesc,
  894. OutstoreNumber: count,
  895. AdminUserId: adminUserInfo.AdminUser.Id,
  896. StorckTime: item.AdviceDate,
  897. UserOrgId: adminUserInfo.Org.Id,
  898. CreatedTime: time.Now().Unix(),
  899. Status: 1,
  900. PatientId: item.PatientId,
  901. ExitMode: 2,
  902. MedicId: item.DrugId,
  903. StockOutNumber: warehousing_out_order,
  904. }
  905. service.CreateOutStock(&outStock)
  906. }
  907. }
  908. }
  909. }
  910. c.ServeSuccessJSON(map[string]interface{}{
  911. "msg": "ok",
  912. "advice": advice,
  913. "ids": ids,
  914. })
  915. return
  916. //查询医嘱是否已经实行
  917. //if groupno > 0 {
  918. // advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  919. // for _, item := range advices {
  920. // //如果医嘱已经执行生成自备药出库单
  921. // if item.ExecutionState == 1 {
  922. //
  923. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  924. // outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  925. //
  926. // timeStr := time.Now().Format("2006-01-02")
  927. // timeArr := strings.Split(timeStr, "-")
  928. // total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
  929. // total = total + 1
  930. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  931. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  932. // number = number + total
  933. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  934. //
  935. // medicalName, errcode := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
  936. // if errcode == gorm.ErrRecordNotFound {
  937. // c.ServeSuccessJSON(map[string]interface{}{
  938. // "msg": "ok",
  939. // "advice": advice,
  940. // "ids": ids,
  941. // })
  942. // return
  943. // } else if errcode == nil {
  944. // stock := models.XtSelfOutStock{
  945. // DrugName: item.AdviceName,
  946. // DrugNameId: medicalName.DrugNameId,
  947. // DrugSpec: item.AdviceDesc,
  948. // OutstoreNumber: outStoreNumber,
  949. // AdminUserId: adminUserInfo.AdminUser.Id,
  950. // StorckTime: item.AdviceDate,
  951. // UserOrgId: adminUserInfo.Org.Id,
  952. // CreatedTime: time.Now().Unix(),
  953. // Status: 1,
  954. // PatientId: item.PatientId,
  955. // StockOutNumber: warehousing_out_order,
  956. // ExitMode: 2,
  957. // MedicId: medicalName.ID,
  958. // }
  959. //
  960. // //创建出库单
  961. // service.CreateOutStock(&stock)
  962. //
  963. // c.ServeSuccessJSON(map[string]interface{}{
  964. // "msg": "ok",
  965. // "advice": advice,
  966. // "ids": ids,
  967. // })
  968. // return
  969. // }
  970. //
  971. // }
  972. // }
  973. //} else {
  974. // advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  975. // for _, item := range advices {
  976. // if item.ExecutionState == 1 {
  977. // prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  978. // outStoreNumber, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  979. // timeStr := time.Now().Format("2006-01-02")
  980. // timeArr := strings.Split(timeStr, "-")
  981. // total, _ := service.FindAllWarehouseOut(adminUserInfo.Org.Id)
  982. // total = total + 1
  983. // warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  984. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  985. // number = number + total
  986. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  987. //
  988. // medicalName, errc := service.GetSelfMedicalByDrugName(item.AdviceName, item.AdviceDesc, item.PatientId)
  989. // if errc == gorm.ErrRecordNotFound {
  990. //
  991. // } else if errc == nil {
  992. //
  993. // stock := models.XtSelfOutStock{
  994. // DrugName: item.AdviceName,
  995. // DrugNameId: medicalName.DrugNameId,
  996. // DrugSpec: item.AdviceDesc,
  997. // OutstoreNumber: outStoreNumber,
  998. // AdminUserId: adminUserInfo.AdminUser.Id,
  999. // StorckTime: item.AdviceDate,
  1000. // UserOrgId: adminUserInfo.Org.Id,
  1001. // CreatedTime: time.Now().Unix(),
  1002. // Status: 1,
  1003. // PatientId: item.PatientId,
  1004. // StockOutNumber: warehousing_out_order,
  1005. // ExitMode: 2,
  1006. // MedicId: medicalName.ID,
  1007. // }
  1008. //
  1009. // //创建出库单
  1010. // service.CreateOutStock(&stock)
  1011. //
  1012. // c.ServeSuccessJSON(map[string]interface{}{
  1013. // "msg": "ok",
  1014. // "advice": advice,
  1015. // "ids": ids,
  1016. // })
  1017. // return
  1018. // }
  1019. //
  1020. // }
  1021. // }
  1022. //}
  1023. }
  1024. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1025. execution_time := c.GetString("execution_time")
  1026. groupno, _ := c.GetInt64("groupno", -1)
  1027. var ids []string
  1028. if groupno == 0 {
  1029. advice_ids := c.GetString("advice_id")
  1030. ids = strings.Split(advice_ids, ",")
  1031. }
  1032. if groupno < 0 {
  1033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1034. return
  1035. }
  1036. if len(execution_time) <= 0 {
  1037. utils.ErrorLog("execution_time")
  1038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1039. return
  1040. }
  1041. timeLayout2 := "2006-01-02 15:04:05"
  1042. loc, _ := time.LoadLocation("Local")
  1043. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1044. if errs != nil {
  1045. utils.ErrorLog(errs.Error())
  1046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1047. return
  1048. }
  1049. adminUserInfo := c.GetMobileAdminUserInfo()
  1050. var advice models.DoctorAdvice
  1051. if groupno > 0 {
  1052. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1053. for _, item := range advices {
  1054. if item.ExecutionState == 1 {
  1055. advice = item
  1056. }
  1057. }
  1058. } else {
  1059. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1060. for _, item := range advices {
  1061. if item.ExecutionState == 1 {
  1062. advice = item
  1063. }
  1064. }
  1065. }
  1066. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1067. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1068. // if getPermissionErr != nil {
  1069. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1070. // return
  1071. // } else if headNursePermission == nil {
  1072. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1073. // return
  1074. // }
  1075. //}
  1076. if advice.StartTime > theTime.Unix() {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1078. return
  1079. }
  1080. advices := models.DoctorAdvice{
  1081. ExecutionTime: theTime.Unix(),
  1082. UpdatedTime: time.Now().Unix(),
  1083. }
  1084. var err error
  1085. if groupno > 0 {
  1086. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1087. } else {
  1088. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1089. }
  1090. if err != nil {
  1091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1092. return
  1093. }
  1094. advice.ExecutionTime = theTime.Unix()
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "msg": "ok",
  1097. "advice": advice,
  1098. "ids": ids,
  1099. })
  1100. return
  1101. }
  1102. func (c *PatientApiController) CheckDoctorAdvice() {
  1103. groupno, _ := c.GetInt64("groupno", -1)
  1104. var ids []string
  1105. if groupno == 0 {
  1106. advice_ids := c.GetString("advice_id")
  1107. if advice_ids == "" {
  1108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1109. return
  1110. } else {
  1111. ids = strings.Split(advice_ids, ",")
  1112. if len(ids) <= 0 {
  1113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1114. return
  1115. }
  1116. }
  1117. }
  1118. if groupno < 0 {
  1119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1120. return
  1121. }
  1122. adminUserInfo := c.GetMobileAdminUserInfo()
  1123. var advice models.DoctorAdvice
  1124. if groupno > 0 {
  1125. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1126. for _, item := range advices {
  1127. if item.CheckState == 0 {
  1128. advice = item
  1129. }
  1130. }
  1131. if advice.CheckState == 1 {
  1132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1133. return
  1134. }
  1135. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1137. return
  1138. }
  1139. } else {
  1140. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1141. for _, item := range advices {
  1142. if item.CheckState == 0 {
  1143. advice = item
  1144. }
  1145. }
  1146. if advice.CheckState == 1 {
  1147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1148. return
  1149. }
  1150. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1152. return
  1153. }
  1154. }
  1155. checker := adminUserInfo.AdminUser.Id
  1156. theTime := time.Now()
  1157. advices := models.DoctorAdvice{
  1158. CheckTime: theTime.Unix(),
  1159. Checker: checker,
  1160. UpdatedTime: time.Now().Unix(),
  1161. }
  1162. var err error
  1163. if groupno > 0 {
  1164. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1165. } else {
  1166. if len(ids[0]) <= 0 {
  1167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1168. return
  1169. } else {
  1170. //t := time.Now().Format("2006-01-02")/**/
  1171. //timeLayout2 := "2006-01-02"
  1172. //loc, _ := time.LoadLocation("Local")
  1173. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1174. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1175. }
  1176. }
  1177. if err != nil {
  1178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1179. return
  1180. }
  1181. advice.Checker = checker
  1182. advice.CheckTime = theTime.Unix()
  1183. advice.CheckState = 1
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "msg": "ok",
  1186. "advice": advice,
  1187. })
  1188. return
  1189. }
  1190. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1191. id, _ := c.GetInt64("patient", 0)
  1192. assessmentDate := c.GetString("assessment_date", "")
  1193. if id <= 0 || len(assessmentDate) != 10 {
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1195. return
  1196. }
  1197. timeLayout := "2006-01-02"
  1198. loc, _ := time.LoadLocation("Local")
  1199. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1200. if err != nil {
  1201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1202. return
  1203. }
  1204. theAssessmentDateTime := theTime.Unix()
  1205. adminUserInfo := c.GetMobileAdminUserInfo()
  1206. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1207. if patient.ID == 0 {
  1208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1209. return
  1210. }
  1211. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1212. if getPEErr != nil {
  1213. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1215. return
  1216. }
  1217. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1218. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1219. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1220. var evaluation models.PredialysisEvaluation
  1221. if theEvaluation != nil {
  1222. evaluation = *theEvaluation
  1223. }
  1224. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1225. if code > 0 {
  1226. c.ServeFailJSONWithSGJErrorCode(code)
  1227. return
  1228. }
  1229. if theEvaluation == nil {
  1230. evaluation.CreatedTime = time.Now().Unix()
  1231. evaluation.Status = 1
  1232. evaluation.AssessmentDate = theAssessmentDateTime
  1233. evaluation.PatientId = id
  1234. evaluation.UserOrgId = adminUserInfo.Org.Id
  1235. if appRole.UserType == 2 || appRole.UserType == 1 {
  1236. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1237. evaluation.AssessmentTime = time.Now().Unix()
  1238. } else {
  1239. evaluation.Creater = adminUserInfo.AdminUser.Id
  1240. }
  1241. } else {
  1242. evaluation.UpdatedTime = time.Now().Unix()
  1243. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1244. if appRole.UserType == 2 || appRole.UserType == 1 {
  1245. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1246. evaluation.AssessmentTime = time.Now().Unix()
  1247. } else {
  1248. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1249. if evaluation.Creater == 0 {
  1250. evaluation.Creater = adminUserInfo.AdminUser.Id
  1251. }
  1252. }
  1253. }
  1254. //新增逻辑
  1255. var dewater_amount float64
  1256. dewater_amount = 0
  1257. if evaluation.DryWeight > 0 {
  1258. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1259. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 {
  1260. dewater_amount = dewater_amount * 1000
  1261. }
  1262. if dewater_amount <= 0 {
  1263. dewater_amount = 0
  1264. }
  1265. } else {
  1266. dewater_amount = 0
  1267. }
  1268. // 计算透析处方的相关超滤量
  1269. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1270. var lastDialysisPrescribe *models.DialysisPrescription
  1271. var dialysisSolution *models.DialysisSolution
  1272. var dialysisPrescribe *models.DialysisPrescription
  1273. var system_dialysisPrescribe *models.SystemPrescription
  1274. var mode_id int64
  1275. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1276. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  1277. if schedual != nil {
  1278. // 获取透析模版
  1279. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  1280. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  1281. mode_id = schedual.ModeId
  1282. } else {
  1283. // 获取透析模版
  1284. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1285. if dialysisPrescribe == nil && dialysisSolution != nil {
  1286. mode_id = dialysisSolution.ModeId
  1287. }
  1288. if dialysisPrescribe == nil && dialysisSolution == nil {
  1289. mode_id = 0
  1290. }
  1291. }
  1292. // 插入透析处方
  1293. if dialysisPrescribe == nil && dialysisSolution != nil {
  1294. var newprescribe models.DialysisPrescription
  1295. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1296. newprescribe.PatientId = dialysisSolution.PatientId
  1297. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1298. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1299. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1300. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1301. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1302. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1303. newprescribe.ModeId = dialysisSolution.ModeId
  1304. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1305. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1306. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1307. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1308. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1309. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1310. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1311. newprescribe.Glucose = dialysisSolution.Glucose
  1312. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1313. newprescribe.Kalium = dialysisSolution.Kalium
  1314. newprescribe.Sodium = dialysisSolution.Sodium
  1315. newprescribe.Calcium = dialysisSolution.Calcium
  1316. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1317. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1318. newprescribe.Conductivity = dialysisSolution.Conductivity
  1319. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1320. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1321. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1322. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1323. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1324. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1325. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1326. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1327. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1328. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1329. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1330. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1331. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1332. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1333. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1334. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1335. newprescribe.CreatedTime = time.Now().Unix()
  1336. newprescribe.UpdatedTime = time.Now().Unix()
  1337. newprescribe.RecordDate = theAssessmentDateTime
  1338. newprescribe.DewaterAmount = dewater_amount
  1339. newprescribe.TargetUltrafiltration = dewater_amount
  1340. newprescribe.Status = 1
  1341. err := service.AddSigleRecord(&newprescribe)
  1342. if err != nil {
  1343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1344. }
  1345. }
  1346. if dialysisPrescribe == nil && dialysisSolution == nil {
  1347. if lastDialysisPrescribe != nil {
  1348. var newprescribe models.DialysisPrescription
  1349. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1350. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1351. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1352. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1353. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1354. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1355. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1356. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1357. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1358. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1359. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1360. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1361. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1362. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1363. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1364. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1365. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1366. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1367. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1368. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1369. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1370. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1371. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1372. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1373. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1374. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1375. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1376. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1377. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1378. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1379. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1380. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1381. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1382. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1383. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1384. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1385. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1386. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1387. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1388. newprescribe.CreatedTime = time.Now().Unix()
  1389. newprescribe.UpdatedTime = time.Now().Unix()
  1390. newprescribe.RecordDate = theAssessmentDateTime
  1391. newprescribe.DewaterAmount = dewater_amount
  1392. newprescribe.TargetUltrafiltration = dewater_amount
  1393. newprescribe.Status = 1
  1394. err := service.AddSigleRecord(&newprescribe)
  1395. if err != nil {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1397. }
  1398. } else if system_dialysisPrescribe != nil {
  1399. var newprescribe models.DialysisPrescription
  1400. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  1401. newprescribe.PatientId = id
  1402. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  1403. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  1404. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  1405. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  1406. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  1407. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  1408. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  1409. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  1410. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  1411. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  1412. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  1413. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  1414. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  1415. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  1416. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  1417. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  1418. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  1419. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  1420. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  1421. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  1422. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  1423. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  1424. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  1425. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  1426. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  1427. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  1428. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  1429. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  1430. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  1431. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  1432. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  1433. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  1434. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  1435. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  1436. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  1437. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  1438. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  1439. newprescribe.CreatedTime = time.Now().Unix()
  1440. newprescribe.UpdatedTime = time.Now().Unix()
  1441. newprescribe.RecordDate = theAssessmentDateTime
  1442. newprescribe.DewaterAmount = dewater_amount
  1443. newprescribe.TargetUltrafiltration = dewater_amount
  1444. newprescribe.Status = 1
  1445. err := service.AddSigleRecord(&newprescribe)
  1446. if err != nil {
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1448. }
  1449. } else {
  1450. var newprescribe models.DialysisPrescription
  1451. newprescribe.UserOrgId = adminUserInfo.Org.Id
  1452. newprescribe.PatientId = id
  1453. newprescribe.ModeId = mode_id
  1454. newprescribe.CreatedTime = time.Now().Unix()
  1455. newprescribe.UpdatedTime = time.Now().Unix()
  1456. newprescribe.RecordDate = theAssessmentDateTime
  1457. newprescribe.DewaterAmount = dewater_amount
  1458. newprescribe.TargetUltrafiltration = dewater_amount
  1459. newprescribe.Status = 1
  1460. err := service.AddSigleRecord(&newprescribe)
  1461. if err != nil {
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1463. }
  1464. }
  1465. }
  1466. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  1467. // if dialysisPrescribe != nil {
  1468. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  1469. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  1470. // dialysisPrescribe.DewaterAmount = dewater_amount
  1471. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  1472. // dialysisPrescribe.Status = 1
  1473. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  1474. // if updateErr != nil {
  1475. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1476. // }
  1477. // }
  1478. err = service.UpadatePredialysisEvaluation(&evaluation)
  1479. if err != nil {
  1480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1481. return
  1482. }
  1483. c.ServeSuccessJSON(map[string]interface{}{
  1484. "msg": "ok",
  1485. "evaluation": evaluation,
  1486. })
  1487. return
  1488. }
  1489. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  1490. dataBody := make(map[string]interface{}, 0)
  1491. err := json.Unmarshal(data, &dataBody)
  1492. utils.InfoLog(string(data))
  1493. if err != nil {
  1494. utils.ErrorLog(err.Error())
  1495. code = enums.ErrorCodeParamWrong
  1496. return
  1497. }
  1498. // if method == "create" {
  1499. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1500. utils.ErrorLog("mode")
  1501. code = enums.ErrorCodeParamWrong
  1502. return
  1503. }
  1504. mode := int64(dataBody["mode"].(float64))
  1505. if mode <= 0 {
  1506. utils.ErrorLog("mode <= 0")
  1507. code = enums.ErrorCodeParamWrong
  1508. return
  1509. }
  1510. solution.ModeId = mode
  1511. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1512. utils.ErrorLog("mode_name")
  1513. code = enums.ErrorCodeParamWrong
  1514. return
  1515. }
  1516. modeName, _ := dataBody["mode_name"].(string)
  1517. if len(modeName) == 0 {
  1518. utils.ErrorLog("len(mode_name) == 0")
  1519. code = enums.ErrorCodeParamWrong
  1520. return
  1521. }
  1522. solution.ModeName = modeName
  1523. solution.Name = modeName
  1524. // }
  1525. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1526. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1527. solution.DialysisDuration = dialysisDuration
  1528. }
  1529. if dataBody["dialysis_duration"] != nil {
  1530. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1531. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1532. solution.DialysisDuration = dialysisDuration
  1533. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1534. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1535. solution.DialysisDuration = dialysisDuration
  1536. }
  1537. }
  1538. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1539. dialyzer := int64(dataBody["dialyzer"].(float64))
  1540. solution.Dialyzer = dialyzer
  1541. }
  1542. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1543. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1544. solution.PerfusionApparatus = perfusionApparatus
  1545. }
  1546. if dataBody["blood_flow_volume"] != nil {
  1547. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1548. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1549. solution.BloodFlowVolume = bloodFlowVolume
  1550. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1551. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1552. solution.BloodFlowVolume = bloodFlowVolume
  1553. }
  1554. }
  1555. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1556. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1557. solution.HemodialysisMachine = hemodialysisMachine
  1558. }
  1559. if dataBody["dewater"] != nil {
  1560. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1561. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1562. solution.Dewater = dewater
  1563. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1564. dewater := dataBody["dewater"].(float64)
  1565. solution.Dewater = dewater
  1566. }
  1567. }
  1568. if dataBody["replacement_total"] != nil {
  1569. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1570. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  1571. solution.ReplacementTotal = replacementTotal
  1572. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  1573. replacementTotal := dataBody["replacement_total"].(float64)
  1574. solution.ReplacementTotal = replacementTotal
  1575. }
  1576. }
  1577. if dataBody["displace_liqui"] != nil {
  1578. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  1579. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  1580. solution.DisplaceLiqui = displaceLiqui
  1581. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  1582. displaceLiqui := dataBody["displace_liqui"].(float64)
  1583. solution.DisplaceLiqui = displaceLiqui
  1584. }
  1585. }
  1586. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  1587. replacementWay := int64(dataBody["replacement_way"].(float64))
  1588. solution.ReplacementWay = replacementWay
  1589. }
  1590. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  1591. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  1592. solution.Anticoagulant = anticoagulant
  1593. }
  1594. if dataBody["anticoagulant_shouji"] != nil {
  1595. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  1596. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  1597. solution.AnticoagulantShouji = anticoagulantShouji
  1598. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  1599. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  1600. solution.AnticoagulantShouji = anticoagulantShouji
  1601. }
  1602. }
  1603. if dataBody["anticoagulant_weichi"] != nil {
  1604. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  1605. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  1606. solution.AnticoagulantWeichi = anticoagulantWeichi
  1607. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  1608. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  1609. solution.AnticoagulantWeichi = anticoagulantWeichi
  1610. }
  1611. }
  1612. if dataBody["anticoagulant_zongliang"] != nil {
  1613. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  1614. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  1615. solution.AnticoagulantZongliang = anticoagulantZongliang
  1616. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  1617. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  1618. solution.AnticoagulantZongliang = anticoagulantZongliang
  1619. }
  1620. }
  1621. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  1622. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  1623. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  1624. }
  1625. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  1626. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  1627. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  1628. }
  1629. if dataBody["kalium"] != nil {
  1630. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  1631. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  1632. solution.Kalium = kalium
  1633. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  1634. kalium := dataBody["kalium"].(float64)
  1635. solution.Kalium = kalium
  1636. }
  1637. }
  1638. if dataBody["sodium"] != nil {
  1639. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  1640. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  1641. solution.Sodium = sodium
  1642. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  1643. sodium := dataBody["sodium"].(float64)
  1644. solution.Sodium = sodium
  1645. }
  1646. }
  1647. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1648. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  1649. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  1650. solution.Calcium = calcium
  1651. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  1652. calcium := dataBody["calcium"].(float64)
  1653. solution.Calcium = calcium
  1654. }
  1655. }
  1656. if dataBody["bicarbonate"] != nil {
  1657. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  1658. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  1659. solution.Bicarbonate = bicarbonate
  1660. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  1661. bicarbonate := dataBody["bicarbonate"].(float64)
  1662. solution.Bicarbonate = bicarbonate
  1663. }
  1664. }
  1665. if dataBody["glucose"] != nil {
  1666. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  1667. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  1668. solution.Glucose = glucose
  1669. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  1670. glucose := dataBody["glucose"].(float64)
  1671. solution.Glucose = glucose
  1672. }
  1673. }
  1674. // if dataBody["dry_weight"] != nil {
  1675. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1676. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1677. // solution.DryWeight = dryWeight
  1678. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  1679. // dryWeight := dataBody["dry_weight"].(float64)
  1680. // solution.DryWeight = dryWeight
  1681. // }
  1682. // }
  1683. if dataBody["dialysate_flow"] != nil {
  1684. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  1685. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  1686. solution.DialysateFlow = dialysateFlow
  1687. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  1688. dialysateFlow := dataBody["dialysate_flow"].(float64)
  1689. solution.DialysateFlow = dialysateFlow
  1690. }
  1691. }
  1692. if dataBody["dialysate_temperature"] != nil {
  1693. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  1694. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  1695. solution.DialysateTemperature = dialysateTemperature
  1696. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  1697. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  1698. solution.DialysateTemperature = dialysateTemperature
  1699. }
  1700. }
  1701. if dataBody["conductivity"] != nil {
  1702. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  1703. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  1704. solution.Conductivity = conductivity
  1705. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  1706. conductivity := dataBody["conductivity"].(float64)
  1707. solution.Conductivity = conductivity
  1708. }
  1709. }
  1710. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1711. remark := dataBody["remark"].(string)
  1712. solution.Remark = remark
  1713. }
  1714. if dataBody["dialysis_duration_hour"] != nil {
  1715. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  1716. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  1717. solution.DialysisDurationHour = dialysisDurationHour
  1718. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  1719. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  1720. solution.DialysisDurationHour = int64(dialysisDurationHour)
  1721. }
  1722. }
  1723. if dataBody["dialysis_duration_minute"] != nil {
  1724. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  1725. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  1726. solution.DialysisDurationMinute = dialysisDurationMinute
  1727. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  1728. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  1729. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  1730. }
  1731. }
  1732. if dataBody["target_ultrafiltration"] != nil {
  1733. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  1734. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  1735. solution.TargetUltrafiltration = targetUltrafiltration
  1736. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  1737. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  1738. solution.TargetUltrafiltration = targetUltrafiltration
  1739. }
  1740. }
  1741. if dataBody["dialysate_formulation"] != nil {
  1742. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  1743. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  1744. solution.DialysateFormulation = dialysateFormulation
  1745. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  1746. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  1747. solution.DialysateFormulation = int64(dialysateFormulation)
  1748. }
  1749. }
  1750. return
  1751. }
  1752. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  1753. dataBody := make(map[string]interface{}, 0)
  1754. err := json.Unmarshal(data, &dataBody)
  1755. utils.InfoLog(string(data))
  1756. if err != nil {
  1757. utils.ErrorLog(err.Error())
  1758. code = enums.ErrorCodeParamWrong
  1759. return
  1760. }
  1761. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  1762. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  1763. evaluation.WeightBefore = weightVefore
  1764. }
  1765. // fmt.Println(dataBody["dry_weight"])
  1766. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  1767. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  1768. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  1769. fmt.Println(additionalWeight)
  1770. evaluation.DryWeight = additionalWeight
  1771. }
  1772. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  1773. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  1774. fmt.Println(additionalWeight)
  1775. evaluation.AdditionalWeight = additionalWeight
  1776. }
  1777. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  1778. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  1779. evaluation.Temperature = Temperature
  1780. }
  1781. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  1782. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  1783. evaluation.SystolicBloodPressure = systolicBloodPressure
  1784. }
  1785. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  1786. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  1787. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  1788. }
  1789. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  1790. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  1791. evaluation.PulseFrequency = pulseFrequency
  1792. }
  1793. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  1794. breathingRate, _ := strconv.ParseFloat(dataBody["breathing_rate"].(string), 64)
  1795. evaluation.BreathingRate = breathingRate
  1796. }
  1797. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  1798. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  1799. evaluation.LastPostDialysis = lastPostDialysis
  1800. }
  1801. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  1802. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  1803. evaluation.DialysisInterphase = dialysisInterphase
  1804. }
  1805. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  1806. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  1807. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  1808. }
  1809. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  1810. catheter, _ := dataBody["catheter"].(string)
  1811. evaluation.Catheter = catheter
  1812. }
  1813. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  1814. catheter_bend := int(dataBody["catheter_bend"].(float64))
  1815. evaluation.CatheterBend = catheter_bend
  1816. }
  1817. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  1818. Complication, _ := dataBody["complication"].(string)
  1819. evaluation.Complication = Complication
  1820. }
  1821. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1822. remark := dataBody["remark"].(string)
  1823. evaluation.Remark = remark
  1824. }
  1825. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  1826. machine_type := dataBody["machine_type"].(string)
  1827. evaluation.MachineType = machine_type
  1828. }
  1829. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  1830. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  1831. evaluation.BloodAccessPartId = blood_access_part_id
  1832. }
  1833. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  1834. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  1835. // evaluation.BloodAccessPartId = blood_access_part_id
  1836. //}
  1837. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  1838. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  1839. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  1840. }
  1841. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  1842. internal_fistula, _ := dataBody["internal_fistula"].(string)
  1843. evaluation.InternalFistula = internal_fistula
  1844. }
  1845. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  1846. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  1847. evaluation.InternalFistulaSkin = internal_fistula_skin
  1848. }
  1849. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  1850. is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  1851. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  1852. is_hemorrhage = 0
  1853. }
  1854. evaluation.IsHemorrhage = is_hemorrhage
  1855. if is_hemorrhage == 1 {
  1856. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  1857. hemorrhage, _ := dataBody["hemorrhage"].(string)
  1858. evaluation.Hemorrhage = hemorrhage
  1859. }
  1860. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  1861. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  1862. evaluation.HemorrhageOther = hemorrhage_other
  1863. }
  1864. }
  1865. } else {
  1866. evaluation.IsHemorrhage = 0
  1867. }
  1868. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  1869. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  1870. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  1871. }
  1872. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  1873. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  1874. evaluation.InternalFistulaOther = internal_fistula_other
  1875. }
  1876. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  1877. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  1878. evaluation.BloodAccessNoise = blood_access_noise
  1879. }
  1880. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  1881. //puncture_way := int64(dataBody["puncture_way"].(float64))
  1882. puncture_way := dataBody["puncture_way"].(string)
  1883. evaluation.PunctureWay = puncture_way
  1884. }
  1885. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  1886. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  1887. evaluation.VenousCatheterization = venous_catheterization
  1888. }
  1889. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  1890. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  1891. evaluation.VenousCatheterizationPart = venous_catheterization_part
  1892. }
  1893. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  1894. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  1895. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  1896. }
  1897. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  1898. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  1899. evaluation.DuctusArantii = ductus_arantii
  1900. }
  1901. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  1902. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  1903. evaluation.EmergencyTreatment = emergency_treatment
  1904. }
  1905. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  1906. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  1907. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  1908. }
  1909. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  1910. dialysis_count, _ := dataBody["dialysis_count"].(string)
  1911. count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  1912. evaluation.DialysisCount = count
  1913. }
  1914. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  1915. is_infect, _ := dataBody["is_infect"].(string)
  1916. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  1917. evaluation.IsInfect = infect
  1918. }
  1919. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  1920. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  1921. evaluation.Exposed = exposed
  1922. }
  1923. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  1924. skin, _ := dataBody["skin"].(string)
  1925. //skins, _ := strconv.ParseInt(skin, 10, 64)
  1926. evaluation.Skin = skin
  1927. }
  1928. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  1929. skin_other, _ := dataBody["skin_other"].(string)
  1930. evaluation.SkinOther = skin_other
  1931. }
  1932. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  1933. infect_other, _ := dataBody["infect_other"].(string)
  1934. evaluation.InfectOther = infect_other
  1935. }
  1936. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  1937. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  1938. evaluation.DuctusArantiiOther = ductus_arantii_other
  1939. }
  1940. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  1941. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  1942. evaluation.PunctureNeedle = punctureNeedle
  1943. }
  1944. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "float64" {
  1945. humor_excessive_symptom := int64(dataBody["humor_excessive_symptom"].(float64))
  1946. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  1947. }
  1948. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  1949. pinholing := dataBody["pinholing"].(string)
  1950. evaluation.Phinholing = pinholing
  1951. }
  1952. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  1953. catheter_suture := dataBody["catheter_suture"].(string)
  1954. evaluation.CatheterSuture = catheter_suture
  1955. }
  1956. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  1957. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  1958. evaluation.CatheterSutureOther = catheter_suture_other
  1959. }
  1960. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  1961. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  1962. evaluation.UrineVolume = urine_volume
  1963. }
  1964. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  1965. edema := dataBody["edema"].(string)
  1966. evaluation.Edema = edema
  1967. }
  1968. return
  1969. }
  1970. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  1971. dataBody := make(map[string]interface{}, 0)
  1972. err := json.Unmarshal(data, &dataBody)
  1973. if err != nil {
  1974. utils.ErrorLog(err.Error())
  1975. code = enums.ErrorCodeParamWrong
  1976. return
  1977. }
  1978. timeLayout := "2006-01-02"
  1979. loc, _ := time.LoadLocation("Local")
  1980. isChild := false
  1981. if action == "create" {
  1982. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  1983. utils.ErrorLog("advice_type")
  1984. code = enums.ErrorCodeParamWrong
  1985. return
  1986. }
  1987. adviceType := int64(dataBody["advice_type"].(float64))
  1988. if adviceType != 1 && adviceType != 2 {
  1989. utils.ErrorLog("advice_type != 1&&2")
  1990. code = enums.ErrorCodeParamWrong
  1991. return
  1992. }
  1993. advice.AdviceType = adviceType
  1994. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1995. utils.ErrorLog("advice_date")
  1996. code = enums.ErrorCodeParamWrong
  1997. return
  1998. }
  1999. adviceDate, _ := dataBody["advice_date"].(string)
  2000. if len(adviceDate) == 0 {
  2001. utils.ErrorLog("len(adviceDate) == 0")
  2002. code = enums.ErrorCodeParamWrong
  2003. return
  2004. }
  2005. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2006. if err != nil {
  2007. utils.ErrorLog(err.Error())
  2008. code = enums.ErrorCodeParamWrong
  2009. return
  2010. }
  2011. advice.AdviceDate = theTime.Unix()
  2012. advice.RecordDate = theTime.Unix()
  2013. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2014. parentId := int64(dataBody["parent_id"].(float64))
  2015. advice.ParentId = parentId
  2016. if parentId > 0 {
  2017. isChild = true
  2018. }
  2019. }
  2020. } else {
  2021. isChild = advice.ParentId > 0
  2022. }
  2023. if !isChild {
  2024. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2025. utils.ErrorLog("start_time")
  2026. code = enums.ErrorCodeParamWrong
  2027. return
  2028. }
  2029. startTime, _ := dataBody["start_time"].(string)
  2030. if len(startTime) == 0 {
  2031. utils.ErrorLog("len(start_time) == 0")
  2032. code = enums.ErrorCodeParamWrong
  2033. return
  2034. }
  2035. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2036. if err != nil {
  2037. utils.ErrorLog(err.Error())
  2038. code = enums.ErrorCodeParamWrong
  2039. return
  2040. }
  2041. advice.StartTime = theTime.Unix()
  2042. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2043. deliveryWay, _ := dataBody["delivery_way"].(string)
  2044. advice.DeliveryWay = deliveryWay
  2045. }
  2046. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2047. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2048. advice.ExecutionFrequency = executionFrequency
  2049. }
  2050. }
  2051. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2052. deliveryWay, _ := dataBody["delivery_way"].(string)
  2053. advice.DeliveryWay = deliveryWay
  2054. }
  2055. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2056. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2057. advice.ExecutionFrequency = executionFrequency
  2058. }
  2059. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2060. utils.ErrorLog("advice_name")
  2061. code = enums.ErrorCodeParamWrong
  2062. return
  2063. }
  2064. adviceName, _ := dataBody["advice_name"].(string)
  2065. if len(adviceName) == 0 {
  2066. utils.ErrorLog("len(advice_name) == 0")
  2067. code = enums.ErrorCodeParamWrong
  2068. return
  2069. }
  2070. advice.AdviceName = adviceName
  2071. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2072. adviceDsc, _ := dataBody["advice_desc"].(string)
  2073. advice.AdviceDesc = adviceDsc
  2074. }
  2075. if dataBody["way"] == nil {
  2076. advice.Way = 0
  2077. } else {
  2078. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2079. way := int64(dataBody["way"].(float64))
  2080. advice.Way = way
  2081. }
  2082. }
  2083. if dataBody["drug_id"] == nil {
  2084. advice.DrugId = 0
  2085. } else {
  2086. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2087. drug_id := int64(dataBody["drug_id"].(float64))
  2088. advice.DrugId = drug_id
  2089. }
  2090. }
  2091. if dataBody["drug_name_id"] == nil {
  2092. advice.DrugNameId = 0
  2093. } else {
  2094. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2095. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  2096. advice.DrugNameId = drug_name_id
  2097. fmt.Println("0000000000", advice.DrugNameId)
  2098. }
  2099. }
  2100. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2101. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2102. advice.SingleDose = singleDose
  2103. }
  2104. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2105. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2106. advice.SingleDoseUnit = singleDoseUnit
  2107. }
  2108. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2109. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2110. advice.DrugSpec = drugSpec
  2111. }
  2112. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2113. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2114. advice.DrugSpecUnit = drugSpecUnit
  2115. }
  2116. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2117. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2118. advice.PrescribingNumber = prescribingNumber
  2119. }
  2120. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2121. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2122. advice.PrescribingNumberUnit = prescribingNumberUnit
  2123. }
  2124. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2125. remark, _ := dataBody["remark"].(string)
  2126. advice.Remark = remark
  2127. }
  2128. return
  2129. }
  2130. func (c *PatientApiController) GetPatientEducation() {
  2131. patientID, _ := c.GetInt64("patient_id", 0)
  2132. page, _ := c.GetInt64("page", 0)
  2133. limit, _ := c.GetInt64("limit", 0)
  2134. startTime := c.GetString("start_time", "")
  2135. endTime := c.GetString("end_time", "")
  2136. if page <= 0 {
  2137. page = 1
  2138. }
  2139. if limit <= 0 {
  2140. limit = 10
  2141. }
  2142. if patientID <= 0 {
  2143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2144. return
  2145. }
  2146. timeLayout := "2006-01-02"
  2147. loc, _ := time.LoadLocation("Local")
  2148. var theStartTIme int64
  2149. if len(startTime) > 0 {
  2150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2151. if err != nil {
  2152. theStartTIme = 0
  2153. }
  2154. theStartTIme = theTime.Unix()
  2155. }
  2156. var theEndtTIme int64
  2157. if len(endTime) > 0 {
  2158. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2159. if err != nil {
  2160. theEndtTIme = 0
  2161. }
  2162. theEndtTIme = theTime.Unix()
  2163. }
  2164. adminUserInfo := c.GetMobileAdminUserInfo()
  2165. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  2166. c.ServeSuccessJSON(map[string]interface{}{
  2167. "total": total,
  2168. "edus": edus,
  2169. })
  2170. return
  2171. }
  2172. func (c *PatientApiController) GetPatientSchedulesList() {
  2173. patientID, _ := c.GetInt64("patient_id", 0)
  2174. page, _ := c.GetInt64("page", 0)
  2175. limit, _ := c.GetInt64("limit", 0)
  2176. if patientID <= 0 {
  2177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2178. return
  2179. }
  2180. adminUserInfo := c.GetMobileAdminUserInfo()
  2181. todayTime := time.Now().Format("2006-01-02")
  2182. timeLayout := "2006-01-02 15:04:05"
  2183. loc, _ := time.LoadLocation("Local")
  2184. var theStartTime int64
  2185. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2186. theStartTime = theTime.Unix()
  2187. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  2188. if len(schedules) > 0 {
  2189. for index, item := range schedules {
  2190. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2191. schedules[index].Week = int64(week)
  2192. }
  2193. }
  2194. c.ServeSuccessJSON(map[string]interface{}{
  2195. "schedules": schedules,
  2196. })
  2197. return
  2198. }
  2199. func (c *PatientApiController) GetRecords() {
  2200. patientID, _ := c.GetInt64("patient_id", 0)
  2201. page, _ := c.GetInt64("page", 0)
  2202. limit, _ := c.GetInt64("limit", 0)
  2203. startTime := c.GetString("start_time", "")
  2204. endTime := c.GetString("end_time", "")
  2205. mode_id, _ := c.GetInt64("mode_id", 0)
  2206. if page <= 0 {
  2207. page = 1
  2208. }
  2209. if limit <= 0 {
  2210. limit = 10
  2211. }
  2212. if patientID <= 0 {
  2213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2214. return
  2215. }
  2216. timeLayout := "2006-01-02"
  2217. loc, _ := time.LoadLocation("Local")
  2218. var theStartTIme int64
  2219. if len(startTime) > 0 {
  2220. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2221. if err != nil {
  2222. theStartTIme = 0
  2223. }
  2224. theStartTIme = theTime.Unix()
  2225. }
  2226. var theEndtTIme int64
  2227. if len(endTime) > 0 {
  2228. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2229. if err != nil {
  2230. theEndtTIme = 0
  2231. }
  2232. theEndtTIme = theTime.Unix()
  2233. }
  2234. adminUserInfo := c.GetMobileAdminUserInfo()
  2235. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2236. c.ServeSuccessJSON(map[string]interface{}{
  2237. "total": total,
  2238. "records": records,
  2239. })
  2240. return
  2241. }
  2242. func (c *PatientApiController) GetPatientMonitor() {
  2243. partition, _ := c.GetInt64("partition")
  2244. monitorDate := c.GetString("date")
  2245. timeLayout := "2006-01-02"
  2246. loc, _ := time.LoadLocation("Local")
  2247. var theStartTime int64
  2248. if len(monitorDate) > 0 {
  2249. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  2250. if err != nil {
  2251. theStartTime = 0
  2252. }
  2253. theStartTime = theTime.Unix()
  2254. }
  2255. adminInfo := c.GetMobileAdminUserInfo()
  2256. orgID := adminInfo.Org.Id
  2257. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition)
  2258. if err == nil {
  2259. c.ServeSuccessJSON(map[string]interface{}{
  2260. "monitor": monitor,
  2261. })
  2262. } else {
  2263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2264. }
  2265. }
  2266. // /m/api/monitor/patient [get] 搜索病人的测量记录
  2267. // @param keyword:string 病人姓名或透析号
  2268. // @param page:int
  2269. func (this *PatientApiController) SearchMonitorPatient() {
  2270. keyword := this.GetString("keyword")
  2271. page, _ := this.GetInt("page")
  2272. if page <= 0 {
  2273. page = 1
  2274. }
  2275. if len(keyword) == 0 {
  2276. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2277. return
  2278. }
  2279. adminUserInfo := this.GetMobileAdminUserInfo()
  2280. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  2281. if getMonitorErr != nil {
  2282. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2283. return
  2284. } else {
  2285. this.ServeSuccessJSON(map[string]interface{}{
  2286. "monitor": monitors,
  2287. })
  2288. }
  2289. }
  2290. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  2291. id, _ := c.GetInt64("id", 0)
  2292. page, _ := c.GetInt64("page", 0)
  2293. limit, _ := c.GetInt64("limit", 0)
  2294. if id <= 0 {
  2295. c.ServeSuccessJSON(map[string]interface{}{
  2296. "solutions": nil,
  2297. })
  2298. return
  2299. }
  2300. if page <= 0 {
  2301. page = 1
  2302. }
  2303. if limit <= 0 {
  2304. limit = 10
  2305. }
  2306. adminInfo := c.GetMobileAdminUserInfo()
  2307. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  2308. c.ServeSuccessJSON(map[string]interface{}{
  2309. "solutions": solutions,
  2310. "total": total,
  2311. })
  2312. return
  2313. }
  2314. //GetDoctorAdvices 医嘱列表
  2315. func (c *PatientApiController) GetDoctorAdvices() {
  2316. id, _ := c.GetInt64("id", 0)
  2317. adviceType, _ := c.GetInt64("advice_type", 0)
  2318. stopType, _ := c.GetInt64("stop_state", 0)
  2319. startTime := c.GetString("start_time", "")
  2320. endTime := c.GetString("end_time", "")
  2321. keywords := c.GetString("keywords", "")
  2322. need, _ := c.GetInt64("need_doctor", 0)
  2323. adminUserInfo := c.GetMobileAdminUserInfo()
  2324. timeLayout := "2006-01-02"
  2325. loc, _ := time.LoadLocation("Local")
  2326. var theStartTIme int64
  2327. if len(startTime) > 0 {
  2328. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2329. if err != nil {
  2330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2331. return
  2332. }
  2333. theStartTIme = theTime.Unix()
  2334. }
  2335. var theEndtTIme int64
  2336. if len(endTime) > 0 {
  2337. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2338. if err != nil {
  2339. utils.ErrorLog(err.Error())
  2340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2341. return
  2342. }
  2343. theEndtTIme = theTime.Unix()
  2344. }
  2345. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  2346. if need == 1 {
  2347. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2348. c.ServeSuccessJSON(map[string]interface{}{
  2349. "advices": advices,
  2350. "total": total,
  2351. "users": users,
  2352. })
  2353. } else {
  2354. c.ServeSuccessJSON(map[string]interface{}{
  2355. "advices": advices,
  2356. "total": total,
  2357. "users": []string{},
  2358. })
  2359. }
  2360. return
  2361. }
  2362. func (c *PatientApiController) GetPrintDialysisOrder() {
  2363. xtno := c.GetString("xtno")
  2364. xtdate := c.GetString("xtdate")
  2365. timeLayout := "2006-01-02"
  2366. loc, _ := time.LoadLocation("Local")
  2367. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2368. if err != nil {
  2369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2370. return
  2371. }
  2372. xttime := theTime.Unix()
  2373. //获取当前日期月份的第一天
  2374. firstmonth := service.GetFirstDateOfMonth(theTime)
  2375. firstMonthDate := firstmonth.Unix()
  2376. operatorIDs := make([]int64, 0)
  2377. adminUserInfo := c.GetMobileAdminUserInfo()
  2378. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2379. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  2380. //透析单
  2381. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2382. if dialysisOrder != nil {
  2383. if dialysisOrder.FinishNurse > 0 {
  2384. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2385. }
  2386. if dialysisOrder.StartNurse > 0 {
  2387. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2388. }
  2389. }
  2390. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2391. //透前评估
  2392. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2393. //透后评估
  2394. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2395. if AssessmentAfterDislysis.Modifier > 0 {
  2396. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2397. }
  2398. //透析处方
  2399. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2400. if dialysisPrescription.PrescriptionDoctor > 0 {
  2401. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2402. }
  2403. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2404. patientInfo.TotalDialysis = dialysis_count
  2405. //临时医嘱
  2406. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2407. if len(DoctorAdvice) > 0 {
  2408. for _, item := range DoctorAdvice {
  2409. if item.AdviceDoctor > 0 {
  2410. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2411. }
  2412. if item.ExecutionStaff > 0 {
  2413. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2414. }
  2415. if item.Checker > 0 {
  2416. operatorIDs = append(operatorIDs, item.Checker)
  2417. }
  2418. }
  2419. }
  2420. //透析监测
  2421. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2422. //透析小结
  2423. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2424. //接诊评估
  2425. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2426. //相关操作对应的操作人
  2427. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  2428. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  2429. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2430. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2431. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  2432. c.ServeSuccessJSON(map[string]interface{}{
  2433. "users": adminUser,
  2434. "patientInfo": patientInfo,
  2435. "PredialysisEvaluation": PredialysisEvaluation,
  2436. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  2437. "dialysisPrescription": dialysisPrescription,
  2438. "advices": DoctorAdvice,
  2439. "monitors": Record,
  2440. "summary": TreatmentSummary,
  2441. "receiverTreatmentAccess": receiverTreatmentAccess,
  2442. "dialysisOrder": dialysisOrder,
  2443. "operators": operators,
  2444. "org_template_info": templateInfo,
  2445. "check": check,
  2446. "dialysiscount": dialysiscount,
  2447. "last_order": last_order,
  2448. })
  2449. }
  2450. func (c *PatientApiController) CreateGroupAdvice() {
  2451. is_child, _ := c.GetInt64("is_child", 0)
  2452. fmt.Println("is_child------------------------------", is_child)
  2453. if is_child == 1 {
  2454. patient, _ := c.GetInt64("id", 0)
  2455. if patient <= 0 {
  2456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2457. return
  2458. }
  2459. adminUserInfo := c.GetMobileAdminUserInfo()
  2460. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2461. if patientInfo.ID == 0 {
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2463. return
  2464. }
  2465. group_no, _ := c.GetInt64("group_no")
  2466. if group_no <= 0 {
  2467. group_no = 0
  2468. }
  2469. dataBody := make(map[string]interface{}, 0)
  2470. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2471. if err != nil {
  2472. utils.ErrorLog(err.Error())
  2473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2474. return
  2475. }
  2476. timeLayout := "2006-01-02"
  2477. loc, _ := time.LoadLocation("Local")
  2478. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2479. utils.ErrorLog("advice_type")
  2480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2481. return
  2482. }
  2483. adviceType := int64(dataBody["advice_type"].(float64))
  2484. if adviceType != 1 && adviceType != 2 {
  2485. utils.ErrorLog("advice_type != 1&&2")
  2486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2487. return
  2488. }
  2489. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2490. utils.ErrorLog("start_time")
  2491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2492. return
  2493. }
  2494. startTime2, _ := dataBody["start_time"].(string)
  2495. time_arr := strings.Split(startTime2, " ")
  2496. if len(time_arr) > 0 {
  2497. startTime2 = time_arr[0]
  2498. }
  2499. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2500. utils.ErrorLog("advice_date")
  2501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2502. return
  2503. }
  2504. adviceDate := startTime2
  2505. if len(adviceDate) == 0 {
  2506. utils.ErrorLog("len(adviceDate) == 0")
  2507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2508. return
  2509. }
  2510. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2511. if err != nil {
  2512. utils.ErrorLog(err.Error())
  2513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2514. return
  2515. }
  2516. AdviceDate := theTime.Unix()
  2517. RecordDate := theTime.Unix()
  2518. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2519. utils.ErrorLog("start_time")
  2520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2521. return
  2522. }
  2523. startTime, _ := dataBody["start_time"].(string)
  2524. if len(startTime) == 0 {
  2525. utils.ErrorLog("len(start_time) == 0")
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2527. return
  2528. }
  2529. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2530. if err != nil {
  2531. utils.ErrorLog(err.Error())
  2532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2533. return
  2534. }
  2535. StartTime := theTime.Unix()
  2536. Remark := ""
  2537. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2538. remark, _ := dataBody["remark"].(string)
  2539. Remark = remark
  2540. }
  2541. var advices []*models.GroupAdvice
  2542. // utils.TraceLog("%+v", dataBody["adviceNames"])
  2543. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  2544. utils.ErrorLog("adviceNames")
  2545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2546. return
  2547. }
  2548. adviceNames := dataBody["adviceNames"].([]interface{})
  2549. for _, adviceNameMap := range adviceNames {
  2550. adviceNameM := adviceNameMap.(map[string]interface{})
  2551. var advice models.GroupAdvice
  2552. advice.Remark = Remark
  2553. advice.AdviceType = adviceType
  2554. advice.StartTime = StartTime
  2555. advice.AdviceDate = AdviceDate
  2556. advice.RecordDate = RecordDate
  2557. advice.Status = 1
  2558. advice.CreatedTime = time.Now().Unix()
  2559. advice.UpdatedTime = time.Now().Unix()
  2560. advice.StopState = 2
  2561. advice.ExecutionState = 2
  2562. advice.UserOrgId = adminUserInfo.Org.Id
  2563. advice.PatientId = patientInfo.ID
  2564. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2565. //入口
  2566. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  2567. if errcode > 0 {
  2568. c.ServeFailJSONWithSGJErrorCode(errcode)
  2569. return
  2570. }
  2571. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  2572. subdrugs := adviceNameM["subdrugs"].([]interface{})
  2573. if len(subdrugs) > 0 {
  2574. for _, subdrug := range subdrugs {
  2575. var s models.GroupAdvice
  2576. s.Remark = Remark
  2577. s.AdviceType = adviceType
  2578. s.StartTime = StartTime
  2579. s.AdviceDate = AdviceDate
  2580. s.RecordDate = RecordDate
  2581. s.Status = 1
  2582. s.CreatedTime = time.Now().Unix()
  2583. s.UpdatedTime = time.Now().Unix()
  2584. s.StopState = 2
  2585. s.ExecutionState = 2
  2586. s.UserOrgId = adminUserInfo.Org.Id
  2587. s.PatientId = patientInfo.ID
  2588. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  2589. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  2590. if errcode > 0 {
  2591. c.ServeFailJSONWithSGJErrorCode(errcode)
  2592. return
  2593. }
  2594. advice.Children = append(advice.Children, &s)
  2595. }
  2596. }
  2597. }
  2598. advices = append(advices, &advice)
  2599. }
  2600. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  2601. if createErr != nil {
  2602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2603. return
  2604. }
  2605. c.ServeSuccessJSON(map[string]interface{}{
  2606. "msg": "ok",
  2607. "advices": newAdvices,
  2608. })
  2609. return
  2610. } else if is_child == 2 {
  2611. patient, _ := c.GetInt64("id", 0)
  2612. if patient <= 0 {
  2613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2614. return
  2615. }
  2616. adminUserInfo := c.GetMobileAdminUserInfo()
  2617. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  2618. if patientInfo.ID == 0 {
  2619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2620. return
  2621. }
  2622. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2623. //if appRole.UserType == 3{
  2624. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
  2625. // return
  2626. //}
  2627. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  2628. //
  2629. //if appRole.UserType == 3 {
  2630. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2631. // if getPermissionErr != nil {
  2632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2633. // return
  2634. // } else if headNursePermission == nil {
  2635. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2636. // return
  2637. // }
  2638. //}
  2639. var advice models.DoctorAdvice
  2640. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  2641. if code > 0 {
  2642. c.ServeFailJSONWithSGJErrorCode(code)
  2643. return
  2644. }
  2645. if advice.ParentId > 0 {
  2646. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  2647. if old.ID == 0 || old.PatientId != patient {
  2648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2649. return
  2650. }
  2651. if old.StopState == 1 || old.ExecutionState == 1 {
  2652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2653. return
  2654. }
  2655. if old.ParentId > 0 {
  2656. advice.ParentId = old.ParentId
  2657. }
  2658. advice.StartTime = old.StartTime
  2659. advice.AdviceDoctor = old.AdviceDoctor
  2660. advice.DeliveryWay = old.DeliveryWay
  2661. advice.ExecutionFrequency = old.ExecutionFrequency
  2662. advice.GroupNo = old.GroupNo
  2663. }
  2664. advice.Status = 1
  2665. advice.CreatedTime = time.Now().Unix()
  2666. advice.UpdatedTime = time.Now().Unix()
  2667. advice.StopState = 2
  2668. advice.ExecutionState = 2
  2669. advice.UserOrgId = adminUserInfo.Org.Id
  2670. advice.PatientId = patient
  2671. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2672. err := service.CreateDoctorAdvice(&advice)
  2673. if err != nil {
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2675. return
  2676. }
  2677. c.ServeSuccessJSON(map[string]interface{}{
  2678. "msg": "ok",
  2679. "advice": advice,
  2680. })
  2681. return
  2682. }
  2683. }
  2684. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  2685. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  2686. utils.ErrorLog("advice_name")
  2687. return enums.ErrorCodeParamWrong
  2688. }
  2689. adviceName, _ := json["advice_name"].(string)
  2690. if len(adviceName) == 0 {
  2691. utils.ErrorLog("len(advice_name) == 0")
  2692. return enums.ErrorCodeParamWrong
  2693. }
  2694. advice.AdviceName = adviceName
  2695. adviceDesc, _ := json["advice_desc"].(string)
  2696. advice.AdviceDesc = adviceDesc
  2697. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2698. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2699. advice.DrugSpec = drugSpec
  2700. }
  2701. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2702. remark, _ := json["remark"].(string)
  2703. advice.Remark = remark
  2704. }
  2705. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  2706. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  2707. // advice.Way = src_type
  2708. //}
  2709. if json["way"] == nil {
  2710. advice.Way = 0
  2711. } else {
  2712. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  2713. way := int64(json["way"].(float64))
  2714. advice.Way = way
  2715. }
  2716. }
  2717. if json["drug_id"] == nil {
  2718. advice.DrugId = 0
  2719. } else {
  2720. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  2721. drug_id := int64(json["drug_id"].(float64))
  2722. advice.DrugId = drug_id
  2723. }
  2724. }
  2725. if json["drug_name_id"] == nil {
  2726. advice.DrugNameId = 0
  2727. } else {
  2728. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  2729. drug_name_id := int64(json["drug_name_id"].(float64))
  2730. advice.DrugNameId = drug_name_id
  2731. }
  2732. }
  2733. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  2734. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  2735. advice.DrugSpecUnit = drugSpecUnit
  2736. }
  2737. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2738. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2739. advice.SingleDose = singleDose
  2740. }
  2741. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2742. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2743. advice.SingleDoseUnit = singleDoseUnit
  2744. }
  2745. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2746. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2747. advice.PrescribingNumber = prescribingNumber
  2748. }
  2749. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2750. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2751. advice.PrescribingNumberUnit = prescribingNumberUnit
  2752. }
  2753. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2754. deliveryWay, _ := json["delivery_way"].(string)
  2755. advice.DeliveryWay = deliveryWay
  2756. }
  2757. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2758. executionFrequency, _ := json["execution_frequency"].(string)
  2759. advice.ExecutionFrequency = executionFrequency
  2760. }
  2761. return 0
  2762. }
  2763. func (c *PatientApiController) DelDoctorAdvice() {
  2764. groupno, _ := c.GetInt64("groupno", -1)
  2765. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  2766. if is_sub == 1 { //是
  2767. advice_id, _ := c.GetInt64("advice_id")
  2768. adminUserInfo := c.GetMobileAdminUserInfo()
  2769. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2770. if advice.ID == 0 {
  2771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2772. return
  2773. }
  2774. advice.Status = 0
  2775. advice.UpdatedTime = time.Now().Unix()
  2776. advice.Modifier = adminUserInfo.AdminUser.Id
  2777. err := service.DeleteDoctorAdvice(&advice)
  2778. if err != nil {
  2779. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2780. return
  2781. }
  2782. c.ServeSuccessJSON(map[string]interface{}{
  2783. "msg": "ok",
  2784. })
  2785. return
  2786. } else { //
  2787. var ids []string
  2788. if groupno == 0 {
  2789. advice_id := c.GetString("advice_id")
  2790. ids = strings.Split(advice_id, ",")
  2791. if len(ids) <= 0 {
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2793. return
  2794. }
  2795. }
  2796. if groupno < 0 {
  2797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2798. return
  2799. }
  2800. adminUserInfo := c.GetMobileAdminUserInfo()
  2801. var advice models.DoctorAdvice
  2802. if groupno > 0 {
  2803. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  2804. if advice.ID == 0 {
  2805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2806. return
  2807. }
  2808. } else {
  2809. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  2810. for _, item := range advices {
  2811. if item.ID == 0 {
  2812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2813. return
  2814. }
  2815. }
  2816. }
  2817. advice.UpdatedTime = time.Now().Unix()
  2818. advice.Status = 0
  2819. advice.GroupNo = groupno
  2820. advice.Modifier = adminUserInfo.AdminUser.Id
  2821. var err error
  2822. if groupno > 0 {
  2823. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  2824. } else {
  2825. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  2826. }
  2827. if err != nil {
  2828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2829. return
  2830. }
  2831. c.ServeSuccessJSON(map[string]interface{}{
  2832. "msg": "ok",
  2833. })
  2834. return
  2835. }
  2836. }
  2837. // /m/api/advice/group/modify_starttime [post]
  2838. // @param group_no:int
  2839. // @param start_time:string yyyy-MM-dd hh:mm:ss
  2840. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  2841. group_no, _ := this.GetInt64("group_no")
  2842. start_time_str := this.GetString("start_time")
  2843. if group_no <= 0 || len(start_time_str) == 0 {
  2844. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2845. return
  2846. }
  2847. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  2848. if parseTimeErr != nil {
  2849. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  2850. return
  2851. }
  2852. adminUserInfo := this.GetMobileAdminUserInfo()
  2853. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  2854. if updateStartTimeErr != nil {
  2855. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  2856. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2857. return
  2858. }
  2859. this.ServeSuccessJSON(map[string]interface{}{
  2860. "start_time": startTime.Unix(),
  2861. })
  2862. }
  2863. func (this *PatientApiController) DelSubDoctorAdvice() {
  2864. advice_id, _ := this.GetInt64("advice_id")
  2865. adminUserInfo := this.GetMobileAdminUserInfo()
  2866. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  2867. if advice.ID == 0 {
  2868. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2869. return
  2870. }
  2871. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2872. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  2873. // return
  2874. //}
  2875. advice.Status = 0
  2876. advice.UpdatedTime = time.Now().Unix()
  2877. advice.Modifier = adminUserInfo.AdminUser.Id
  2878. err := service.DeleteDoctorAdvice(&advice)
  2879. if err != nil {
  2880. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2881. return
  2882. }
  2883. this.ServeSuccessJSON(map[string]interface{}{
  2884. "msg": "ok",
  2885. })
  2886. return
  2887. }
  2888. func (this *PatientApiController) GetAdviceUnReadMessage() {
  2889. //adminUserInfo := this.GetMobileAdminUserInfo()
  2890. //service.FindUnReadDoctorAdviceMessage()
  2891. }
  2892. func (this *PatientApiController) GetPatientsByKeyWord() {
  2893. keyWord := this.GetString("keyword")
  2894. adminUserInfo := this.GetMobileAdminUserInfo()
  2895. today := utils.ZeroHourTimeOfDay(time.Now())
  2896. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  2897. if err != nil {
  2898. utils.ErrorLog(err.Error())
  2899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2900. return
  2901. }
  2902. this.ServeSuccessJSON(map[string]interface{}{
  2903. "patient": patient,
  2904. })
  2905. }
  2906. func (this *PatientApiController) GetSearchPatient() {
  2907. keyWord := this.GetString("keyword")
  2908. adminUserInfo := this.GetMobileAdminUserInfo()
  2909. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  2910. if err != nil {
  2911. utils.ErrorLog(err.Error())
  2912. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2913. return
  2914. }
  2915. this.ServeSuccessJSON(map[string]interface{}{
  2916. "patient": patient,
  2917. })
  2918. }