patient_api_controller.go 115KB

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