patient_api_controller.go 156KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371
  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. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  209. redis := service.RedisClient()
  210. defer redis.Close()
  211. redis.Set(key, "", time.Second)
  212. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  213. redis.Set(keyOne, "", time.Second)
  214. if err != nil {
  215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  216. return
  217. }
  218. c.ServeSuccessJSON(map[string]interface{}{
  219. "msg": "ok",
  220. "advice": advice,
  221. })
  222. return
  223. }
  224. func (c *PatientApiController) EditDoctorAdvice() {
  225. id, _ := c.GetInt64("id", 0)
  226. patient_id, _ := c.GetInt64("patient_id")
  227. doc_advice_date, _ := c.GetInt64("advice_date")
  228. if id <= 0 {
  229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  230. return
  231. }
  232. redis := service.RedisClient()
  233. adminUserInfo := c.GetMobileAdminUserInfo()
  234. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  235. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  236. //
  237. //if appRole.UserType == 3 {
  238. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  239. // if getPermissionErr != nil {
  240. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  241. // return
  242. // } else if headNursePermission == nil {
  243. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  244. // return
  245. // }
  246. //}
  247. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  248. if advice.ID == 0 {
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  250. return
  251. }
  252. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  253. if code > 0 {
  254. c.ServeFailJSONWithSGJErrorCode(code)
  255. return
  256. }
  257. advice.Status = 1
  258. advice.UpdatedTime = time.Now().Unix()
  259. advice.UserOrgId = adminUserInfo.Org.Id
  260. advice.Modifier = adminUserInfo.AdminUser.Id
  261. //处理修改医嘱开始时间逻辑(不包括子医嘱)
  262. //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
  263. //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
  264. var err error
  265. var isChangeGroup bool
  266. if advice.ParentId == 0 {
  267. adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  268. sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
  269. if len(adviceSlice) == 1 {
  270. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
  271. if advice.StartTime == sourceAdvice.StartTime {
  272. err = service.UpdateDoctorAdvice(&advice)
  273. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  274. defer redis.Close()
  275. redis.Set(key, "", time.Second)
  276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
  277. redis.Set(keyOne, "", time.Second)
  278. isChangeGroup = false
  279. } else {
  280. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  281. isChangeGroup = false
  282. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  283. defer redis.Close()
  284. redis.Set(key, "", time.Second)
  285. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  286. redis.Set(keyOne, "", time.Second)
  287. }
  288. } else if len(adviceSlice) > 1 {
  289. //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
  290. if advice.StartTime == sourceAdvice.StartTime {
  291. err = service.UpdateDoctorAdvice(&advice)
  292. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  293. defer redis.Close()
  294. redis.Set(key, "", time.Second)
  295. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  296. redis.Set(keyOne, "", time.Second)
  297. isChangeGroup = false
  298. } else {
  299. gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
  300. gruopNo = gruopNo + 1
  301. advice.GroupNo = gruopNo
  302. err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
  303. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  304. defer redis.Close()
  305. redis.Set(key, "", time.Second)
  306. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  307. redis.Set(keyOne, "", time.Second)
  308. isChangeGroup = true
  309. }
  310. }
  311. } else {
  312. isChangeGroup = false
  313. err = service.UpdateDoctorAdvice(&advice)
  314. redis := service.RedisClient()
  315. defer redis.Close()
  316. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  317. redis.Set(key, "", time.Second)
  318. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  319. redis.Set(keyOne, "", time.Second)
  320. }
  321. if err != nil {
  322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  323. return
  324. }
  325. if !isChangeGroup {
  326. c.ServeSuccessJSON(map[string]interface{}{
  327. "msg": "ok",
  328. "advice": advice,
  329. "isChange": isChangeGroup, //方便前端处理数据
  330. })
  331. } else {
  332. newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
  333. if err != nil {
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  335. return
  336. }
  337. c.ServeSuccessJSON(map[string]interface{}{
  338. "msg": "ok",
  339. "advice": newGroupAdvice,
  340. "isChange": isChangeGroup, //方便前端处理数据
  341. })
  342. }
  343. return
  344. }
  345. func (c *PatientApiController) StopDoctorAdvice() {
  346. id, _ := c.GetInt64("id", 0)
  347. if id <= 0 {
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  349. return
  350. }
  351. adminUserInfo := c.GetMobileAdminUserInfo()
  352. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  353. if advice.ID == 0 {
  354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  355. return
  356. }
  357. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  358. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  359. // return
  360. //}
  361. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  362. //
  363. //if appRole.UserType == 3 {
  364. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  365. // if getPermissionErr != nil {
  366. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  367. // return
  368. // } else if headNursePermission == nil {
  369. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  370. // return
  371. // }
  372. //}
  373. if advice.StopState == 1 {
  374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  375. return
  376. }
  377. dataBody := make(map[string]interface{}, 0)
  378. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  379. if err != nil {
  380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  381. return
  382. }
  383. timeLayout := "2006-01-02"
  384. loc, _ := time.LoadLocation("Local")
  385. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  386. utils.ErrorLog("stop_time")
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. stopTime, _ := dataBody["stop_time"].(string)
  391. if len(stopTime) == 0 {
  392. utils.ErrorLog("len(stop_time) == 0")
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  394. return
  395. }
  396. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  397. if err != nil {
  398. utils.ErrorLog(err.Error())
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  400. return
  401. }
  402. advice.StopTime = theTime.Unix()
  403. if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
  404. utils.ErrorLog("stop_reason")
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  406. return
  407. }
  408. stopReason, _ := dataBody["stop_reason"].(string)
  409. if len(stopReason) == 0 {
  410. utils.ErrorLog("len(stop_reason) == 0")
  411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  412. return
  413. }
  414. advice.StopReason = stopReason
  415. advice.Status = 1
  416. advice.UpdatedTime = time.Now().Unix()
  417. advice.StopDoctor = adminUserInfo.AdminUser.Id
  418. advice.StopState = 1
  419. advice.StopTime = time.Now().Unix()
  420. advice.Modifier = adminUserInfo.AdminUser.Id
  421. err = service.StopDoctorAdvice(&advice)
  422. if err != nil {
  423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  424. return
  425. }
  426. c.ServeSuccessJSON(map[string]interface{}{
  427. "msg": "ok",
  428. "advice": advice,
  429. })
  430. return
  431. }
  432. func (c *PatientApiController) DeleteDoctorAdvice() {
  433. id, _ := c.GetInt64("id", 0)
  434. if id <= 0 {
  435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  436. return
  437. }
  438. adminUserInfo := c.GetMobileAdminUserInfo()
  439. advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
  440. if advice.ID == 0 {
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  442. return
  443. }
  444. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  445. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  446. // return
  447. //}
  448. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  449. //
  450. //if appRole.UserType == 3 {
  451. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  452. // if getPermissionErr != nil {
  453. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  454. // return
  455. // } else if headNursePermission == nil {
  456. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  457. // return
  458. // }
  459. //}
  460. advice.UpdatedTime = time.Now().Unix()
  461. advice.Status = 0
  462. advice.Modifier = adminUserInfo.AdminUser.Id
  463. err := service.DeleteDoctorAdvice(&advice)
  464. if err != nil {
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  466. return
  467. }
  468. c.ServeSuccessJSON(map[string]interface{}{
  469. "msg": "ok",
  470. })
  471. return
  472. }
  473. func (c *PatientApiController) ExecDoctorAdvice() {
  474. execution_time := c.GetString("execution_time")
  475. origin, _ := c.GetInt64("origin", 0)
  476. groupno, _ := c.GetInt64("groupno", -1)
  477. if origin != 2 {
  478. adminUserInfo := c.GetMobileAdminUserInfo()
  479. execution_staff := adminUserInfo.AdminUser.Id
  480. var ids []string
  481. advice_ids := c.GetString("advice_id")
  482. if groupno == 0 {
  483. ids = strings.Split(advice_ids, ",")
  484. }
  485. if groupno < 0 {
  486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  487. return
  488. }
  489. if len(execution_time) <= 0 {
  490. utils.ErrorLog("execution_time")
  491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  492. return
  493. }
  494. timeLayout2 := "2006-01-02 15:04:05"
  495. loc, _ := time.LoadLocation("Local")
  496. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  497. if errs != nil {
  498. utils.ErrorLog(errs.Error())
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  500. return
  501. }
  502. var advice models.DoctorAdvice
  503. if groupno > 0 {
  504. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  505. for _, item := range advices {
  506. if item.ExecutionState == 2 {
  507. advice = item
  508. }
  509. }
  510. } else {
  511. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  512. for _, item := range advices {
  513. if item.ExecutionState == 2 {
  514. advice = item
  515. }
  516. }
  517. }
  518. if advice.ExecutionState == 1 {
  519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  520. return
  521. }
  522. if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  524. return
  525. }
  526. if advice.StartTime > theTime.Unix() {
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  528. return
  529. }
  530. advices := models.DoctorAdvice{
  531. ExecutionStaff: execution_staff,
  532. ExecutionTime: theTime.Unix(),
  533. UpdatedTime: time.Now().Unix(),
  534. }
  535. var err error
  536. if groupno > 0 {
  537. err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  538. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  539. redis := service.RedisClient()
  540. //清空key 值
  541. redis.Set(key, "", time.Second)
  542. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  543. redis.Set(keyTwo, "", time.Second)
  544. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  545. redis.Set(keyThree, "", time.Second)
  546. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  547. theTime := toTime.Format("2006-01-02")
  548. fmt.Println("theTIME", theTime)
  549. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  550. redis.Set(keyFour, "", time.Second)
  551. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  552. redis.Set(keyFive, "", time.Second)
  553. defer redis.Close()
  554. } else {
  555. err = service.BatchExceOldDoctorAdvice(&advices, ids)
  556. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  557. redis := service.RedisClient()
  558. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  559. redis.Set(keyTwo, "", time.Second)
  560. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  561. redis.Set(keyThree, "", time.Second)
  562. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
  563. theTime := toTime.Format("2006-01-02")
  564. fmt.Println("theTIME", theTime)
  565. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  566. redis.Set(keyFour, "", time.Second)
  567. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  568. redis.Set(keySix, "", time.Second)
  569. defer redis.Close()
  570. //清空key 值
  571. redis.Set(key, "", time.Second)
  572. }
  573. if err != nil {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  575. return
  576. }
  577. advice.ExecutionStaff = execution_staff
  578. advice.ExecutionTime = theTime.Unix()
  579. advice.ExecutionState = 1
  580. advice.Modifier = adminUserInfo.AdminUser.Id
  581. //处理出库相关逻辑
  582. //1.判断是否启用药品管理和自备药出库功能
  583. //药品管理信息
  584. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
  585. //自备药信息
  586. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
  587. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
  588. fmt.Println("drugStockConfig.IsOpen32232323232", drugStockConfig.IsOpen)
  589. if drugStockConfig.IsOpen == 1 {
  590. if groupno > 0 {
  591. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  592. isHasWay := false //用来判断是否包含来自药品库的医嘱
  593. for _, item := range advices {
  594. if item.Way == 1 {
  595. isHasWay = true
  596. }
  597. }
  598. if isHasWay {
  599. var total int64
  600. var prescribing_number_total int64
  601. fmt.Println("advicesssssssssssssssss", len(advices))
  602. for _, item := range advices {
  603. if item.Way == 1 {
  604. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  605. //查询该药品的剩余库存
  606. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  607. //查询改药品信息
  608. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  609. //判断单位是否相等
  610. if medical.MaxUnit == item.PrescribingNumberUnit {
  611. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  612. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  613. //转化为最小单位
  614. total = list.Count * medical.MinNumber
  615. prescribing_number_total = count * medical.MinNumber
  616. }
  617. if medical.MinUnit == item.PrescribingNumberUnit {
  618. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  619. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  620. total = list.Count*medical.MinNumber + list.StockMinNumber
  621. prescribing_number_total = count
  622. }
  623. if medical.IsUse == 1 {
  624. c.ServeSuccessJSON(map[string]interface{}{
  625. "msg": "1",
  626. "advice": advice,
  627. "ids": ids,
  628. })
  629. return
  630. }
  631. if medical.IsUse != 1 {
  632. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  633. c.ServeSuccessJSON(map[string]interface{}{
  634. "msg": "3",
  635. "advice": advice,
  636. "ids": ids,
  637. })
  638. return
  639. }
  640. if prescribing_number_total > total {
  641. c.ServeSuccessJSON(map[string]interface{}{
  642. "msg": "2",
  643. "advice": advice,
  644. "ids": ids,
  645. })
  646. return
  647. }
  648. }
  649. if prescribing_number_total <= total {
  650. //查询是否出库按钮开启
  651. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  652. if adviceSetting.IsAdviceOpen == 1 {
  653. //查询是否出库按钮开启
  654. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  655. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  656. if prescriptionConfig.IsOpen == 1 {
  657. if medical.IsUse == 2 {
  658. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  659. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  660. }
  661. if pharmacyConfig.IsOpen != 1 {
  662. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  663. }
  664. //更新字典里面的库存
  665. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  666. var sum_count int64
  667. for _, its := range stockInfo {
  668. if its.MaxUnit == medical.MaxUnit {
  669. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  670. }
  671. sum_count += its.StockMaxNumber + its.StockMinNumber
  672. }
  673. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  674. //剩余库存
  675. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  676. }
  677. }
  678. } else {
  679. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  680. if medical.IsUse == 2 {
  681. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  682. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  683. }
  684. if pharmacyConfig.IsOpen != 1 {
  685. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  686. }
  687. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  688. var sum_count int64
  689. for _, its := range stockInfo {
  690. if its.MaxUnit == medical.MaxUnit {
  691. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  692. }
  693. sum_count += its.StockMaxNumber + its.StockMinNumber
  694. }
  695. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  696. //剩余库存
  697. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  698. }
  699. }
  700. }
  701. }
  702. }
  703. }
  704. } else {
  705. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  706. isHasWay := false //用来判断是否包含来自药品库的医嘱
  707. for _, item := range advices {
  708. if item.Way == 1 {
  709. isHasWay = true
  710. }
  711. }
  712. if isHasWay {
  713. var total int64
  714. var prescribing_number_total int64
  715. for _, item := range advices {
  716. if item.Way == 1 {
  717. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  718. //查询该药品的剩余库存
  719. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
  720. //查询改药品信息
  721. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  722. //判断单位是否相等
  723. if medical.MaxUnit == item.PrescribingNumberUnit {
  724. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  725. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  726. //转化为最小单位
  727. total = list.Count*medical.MinNumber + list.StockMinNumber
  728. prescribing_number_total = count * medical.MinNumber
  729. }
  730. if medical.MinUnit == item.PrescribingNumberUnit {
  731. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  732. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  733. total = list.Count*medical.MinNumber + list.StockMinNumber
  734. prescribing_number_total = count
  735. }
  736. if medical.IsUse == 1 {
  737. c.ServeSuccessJSON(map[string]interface{}{
  738. "msg": "1",
  739. "advice": advice,
  740. "ids": ids,
  741. })
  742. return
  743. }
  744. if medical.IsUse != 1 {
  745. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  746. c.ServeSuccessJSON(map[string]interface{}{
  747. "msg": "3",
  748. "advice": advice,
  749. "ids": ids,
  750. })
  751. return
  752. }
  753. if prescribing_number_total > total {
  754. c.ServeSuccessJSON(map[string]interface{}{
  755. "msg": "2",
  756. "advice": advice,
  757. "ids": ids,
  758. })
  759. return
  760. }
  761. }
  762. if prescribing_number_total <= total {
  763. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  764. if medical.IsUse == 2 {
  765. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  766. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  767. }
  768. if pharmacyConfig.IsOpen != 1 {
  769. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  770. }
  771. //更新字典里面的库存
  772. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  773. var sum_count int64
  774. for _, its := range stockInfo {
  775. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  776. if its.MaxUnit == baseDrug.MaxUnit {
  777. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  778. }
  779. sum_count += its.StockMaxNumber + its.StockMinNumber
  780. }
  781. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  782. //剩余库存
  783. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  784. }
  785. if medical.IsUse == 1 {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "msg": "1",
  788. "advice": advice,
  789. "ids": ids,
  790. })
  791. return
  792. }
  793. }
  794. }
  795. }
  796. }
  797. }
  798. c.ServeSuccessJSON(map[string]interface{}{
  799. "msg": "1",
  800. "advice": advice,
  801. "ids": ids,
  802. })
  803. return
  804. }
  805. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  806. if groupno > 0 {
  807. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  808. for _, item := range advices {
  809. if item.ExecutionState == 1 && item.Way == 2 {
  810. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  811. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  812. timeStr := time.Now().Format("2006-01-02")
  813. timeArr := strings.Split(timeStr, "-")
  814. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  815. total = total + 1
  816. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  817. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  818. number = number + total
  819. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  820. //插入自备药出库单
  821. outStock := models.XtSelfOutStock{
  822. DrugName: item.AdviceName,
  823. DrugNameId: item.DrugNameId,
  824. DrugSpec: item.AdviceDesc,
  825. OutstoreNumber: count,
  826. AdminUserId: adminUserInfo.AdminUser.Id,
  827. StorckTime: item.AdviceDate,
  828. UserOrgId: adminUserInfo.Org.Id,
  829. CreatedTime: time.Now().Unix(),
  830. Status: 1,
  831. PatientId: item.PatientId,
  832. ExitMode: 2,
  833. MedicId: item.DrugId,
  834. StockOutNumber: warehousing_out_order,
  835. }
  836. //查询 该患者是否已出库
  837. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  838. if errcode == gorm.ErrRecordNotFound {
  839. service.CreateOutStock(&outStock)
  840. } else if errcode == nil {
  841. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  842. fmt.Println("err", err)
  843. }
  844. }
  845. }
  846. } else {
  847. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  848. for _, item := range advices {
  849. if item.ExecutionState == 1 && item.Way == 2 {
  850. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  851. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  852. timeStr := time.Now().Format("2006-01-02")
  853. timeArr := strings.Split(timeStr, "-")
  854. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
  855. total = total + 1
  856. warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  857. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  858. number = number + total
  859. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  860. //插入自备药出库单
  861. outStock := models.XtSelfOutStock{
  862. DrugName: item.AdviceName,
  863. DrugNameId: item.DrugNameId,
  864. DrugSpec: item.AdviceDesc,
  865. OutstoreNumber: count,
  866. AdminUserId: adminUserInfo.AdminUser.Id,
  867. StorckTime: item.AdviceDate,
  868. UserOrgId: adminUserInfo.Org.Id,
  869. CreatedTime: time.Now().Unix(),
  870. Status: 1,
  871. PatientId: item.PatientId,
  872. ExitMode: 2,
  873. MedicId: item.DrugId,
  874. StockOutNumber: warehousing_out_order,
  875. }
  876. //查询 该患者是否已出库
  877. out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
  878. if errcode == gorm.ErrRecordNotFound {
  879. service.CreateOutStock(&outStock)
  880. } else if errcode == nil {
  881. err := service.UpdatedSelfOutSatock(out.ID, &outStock)
  882. fmt.Println("err", err)
  883. }
  884. }
  885. }
  886. c.ServeSuccessJSON(map[string]interface{}{
  887. "msg": "1",
  888. "advice": advice,
  889. "ids": ids,
  890. })
  891. return
  892. }
  893. }
  894. c.ServeSuccessJSON(map[string]interface{}{
  895. "msg": "1",
  896. "advice": advice,
  897. "ids": ids,
  898. })
  899. return
  900. } else if origin == 2 {
  901. adminInfo := c.GetMobileAdminUserInfo()
  902. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  903. var ids []string
  904. advice_ids := c.GetString("advice_id")
  905. ids = strings.Split(advice_ids, ",")
  906. if len(execution_time) <= 0 {
  907. utils.ErrorLog("execution_time")
  908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  909. return
  910. }
  911. timeLayout2 := "2006-01-02 15:04:05"
  912. loc, _ := time.LoadLocation("Local")
  913. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  914. if errs != nil {
  915. utils.ErrorLog(errs.Error())
  916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  917. return
  918. }
  919. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  920. var err error
  921. for _, item := range advices {
  922. if item.ExecutionState == 1 {
  923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  924. return
  925. }
  926. if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
  927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  928. return
  929. }
  930. if item.StartTime > theTime.Unix() {
  931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  932. return
  933. }
  934. item.ExecutionState = 1
  935. item.ExecutionStaff = adminInfo.AdminUser.Id
  936. item.ExecutionTime = theTime.Unix()
  937. err = service.SaveHisDoctorAdvice(item)
  938. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  939. redis := service.RedisClient()
  940. //清空key 值
  941. redis.Set(key, "", time.Second)
  942. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  943. redis.Set(keyTwo, "", time.Second)
  944. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  945. redis.Set(keyThree, "", time.Second)
  946. recordDate := theTime.Format("2006-01-02")
  947. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  948. redis.Set(keyFour, "", time.Second)
  949. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  950. redis.Set(keyFive, "", time.Second)
  951. defer redis.Close()
  952. }
  953. if err == nil {
  954. //药品管理信息
  955. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  956. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  957. if drugStockConfig.IsOpen == 1 {
  958. for _, item := range advices {
  959. //查询改药品信息
  960. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  961. //查询这个患者这个患者这个药已经出库的所有数量
  962. advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  963. drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
  964. var total_count int64
  965. var drug_count int64
  966. for _, it := range advicelist {
  967. if it.PrescribingNumberUnit == medical.MaxUnit {
  968. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  969. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  970. total_count += prenumber * medical.MinNumber
  971. }
  972. if it.PrescribingNumberUnit == medical.MinUnit {
  973. prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
  974. prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  975. total_count += prenumber
  976. }
  977. }
  978. for _, its := range drugoutlist {
  979. if its.CountUnit == medical.MaxUnit {
  980. drug_count += its.Count * medical.MinNumber
  981. }
  982. if its.CountUnit == medical.MinUnit {
  983. drug_count += its.Count
  984. }
  985. }
  986. if total_count == drug_count {
  987. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  988. c.ServeSuccessJSON(map[string]interface{}{
  989. "msg": "1",
  990. "advice": advice,
  991. "ids": ids,
  992. })
  993. return
  994. }
  995. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  996. var total int64
  997. var prescribing_number_total int64
  998. config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
  999. if config.IsOpen != 1 {
  1000. //查询该药品是否有库存
  1001. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  1002. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
  1003. //判断单位是否相等
  1004. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1005. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1006. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1007. //转化为最小单位
  1008. total = list.Count*medical.MinNumber + list.StockMinNumber
  1009. prescribing_number_total = count * medical.MinNumber
  1010. }
  1011. //fmt.Println("医嘱开的数量", total)
  1012. if medical.MinUnit == advice.PrescribingNumberUnit {
  1013. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1014. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1015. total = list.Count*medical.MinNumber + list.StockMinNumber
  1016. prescribing_number_total = count
  1017. }
  1018. if medical.IsUse == 1 {
  1019. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1020. c.ServeSuccessJSON(map[string]interface{}{
  1021. "msg": "1",
  1022. "advice": advice,
  1023. "ids": ids,
  1024. })
  1025. return
  1026. }
  1027. }
  1028. if medical.IsUse != 1 {
  1029. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1030. c.ServeSuccessJSON(map[string]interface{}{
  1031. "msg": "3",
  1032. "advice": advice,
  1033. "ids": ids,
  1034. })
  1035. return
  1036. }
  1037. if prescribing_number_total > total {
  1038. c.ServeSuccessJSON(map[string]interface{}{
  1039. "msg": "2",
  1040. "advice": advice,
  1041. "ids": ids,
  1042. })
  1043. return
  1044. }
  1045. }
  1046. if prescribing_number_total <= total {
  1047. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  1048. if medical.IsUse == 2 {
  1049. if config.IsOpen != 1 {
  1050. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  1051. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1052. }
  1053. if pharmacyConfig.IsOpen != 1 {
  1054. service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1055. }
  1056. //更新字典里面的库存
  1057. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1058. var sum_count int64
  1059. for _, its := range stockInfo {
  1060. if its.MaxUnit == medical.MaxUnit {
  1061. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1062. }
  1063. sum_count += its.StockMaxNumber + its.StockMinNumber
  1064. }
  1065. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1066. //剩余库存
  1067. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1068. }
  1069. }
  1070. }
  1071. }
  1072. //
  1073. //if config.IsOpen == 1 && item.UserOrgId == 10088 {
  1074. //
  1075. // service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
  1076. // //更新字典里面的库存
  1077. // stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1078. // var sum_count int64
  1079. // for _, its := range stockInfo {
  1080. // if its.MaxUnit == medical.MaxUnit {
  1081. // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  1082. // }
  1083. // sum_count += its.StockMaxNumber + its.StockMinNumber
  1084. // }
  1085. // service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1086. // //剩余库存
  1087. // service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  1088. //}
  1089. }
  1090. }
  1091. for _, item := range advices {
  1092. advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
  1093. c.ServeSuccessJSON(map[string]interface{}{
  1094. "msg": "1",
  1095. "advice": advice,
  1096. "ids": ids,
  1097. })
  1098. }
  1099. } else {
  1100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1101. }
  1102. }
  1103. }
  1104. func (c *PatientApiController) ModifyExecDoctorAdvice() {
  1105. execution_time := c.GetString("execution_time")
  1106. fmt.Println("execution_time", execution_time)
  1107. groupno, _ := c.GetInt64("groupno", -1)
  1108. //patient_id, _ := c.GetInt64("patient_id")
  1109. advice_date, _ := c.GetInt64("advice_date")
  1110. var ids []string
  1111. if groupno == 0 {
  1112. advice_ids := c.GetString("advice_id")
  1113. ids = strings.Split(advice_ids, ",")
  1114. }
  1115. if groupno < 0 {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. if len(execution_time) <= 0 {
  1120. utils.ErrorLog("execution_time")
  1121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1122. return
  1123. }
  1124. timeLayout2 := "2006-01-02 15:04:05"
  1125. loc, _ := time.LoadLocation("Local")
  1126. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  1127. if errs != nil {
  1128. utils.ErrorLog(errs.Error())
  1129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1130. return
  1131. }
  1132. adminUserInfo := c.GetMobileAdminUserInfo()
  1133. var advice models.DoctorAdvice
  1134. if groupno > 0 {
  1135. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1136. for _, item := range advices {
  1137. if item.ExecutionState == 1 {
  1138. advice = item
  1139. }
  1140. }
  1141. } else {
  1142. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1143. for _, item := range advices {
  1144. if item.ExecutionState == 1 {
  1145. advice = item
  1146. }
  1147. }
  1148. }
  1149. //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
  1150. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1151. // if getPermissionErr != nil {
  1152. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1153. // return
  1154. // } else if headNursePermission == nil {
  1155. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1156. // return
  1157. // }
  1158. //}
  1159. if advice.StartTime > theTime.Unix() {
  1160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1161. return
  1162. }
  1163. advices := models.DoctorAdvice{
  1164. ExecutionTime: theTime.Unix(),
  1165. UpdatedTime: time.Now().Unix(),
  1166. }
  1167. var err error
  1168. if groupno > 0 {
  1169. err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1170. redis := service.RedisClient()
  1171. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1172. redis.Set(key, "", time.Second)
  1173. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1174. redis.Set(keyOne, "", time.Second)
  1175. defer redis.Close()
  1176. } else {
  1177. err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
  1178. err = service.ModifyExceDoctorAdviceByGroupNoOne(&advices, ids)
  1179. redis := service.RedisClient()
  1180. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1181. redis.Set(key, "", time.Second)
  1182. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice_date, 10) + ":advice_list_all"
  1183. redis.Set(keyOne, "", time.Second)
  1184. defer redis.Close()
  1185. }
  1186. //判断是否开启his
  1187. errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  1188. //如果开启去修改执行时间
  1189. if config.IsOpen == 1 {
  1190. advicesinfo := models.HisDoctorAdviceInfo{
  1191. ExecutionTime: theTime.Unix(),
  1192. UpdatedTime: time.Now().Unix(),
  1193. }
  1194. var advicehis models.HisDoctorAdviceInfo
  1195. service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
  1196. his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
  1197. for _, item := range his_advices {
  1198. if item.ExecutionState == 1 {
  1199. advicehis = item
  1200. }
  1201. }
  1202. redis := service.RedisClient()
  1203. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
  1204. redis.Set(keyThree, "", time.Second)
  1205. recordDate := theTime.Format("2006-01-02")
  1206. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1207. redis.Set(keyFour, "", time.Second)
  1208. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
  1209. redis.Set(keyFive, "", time.Second)
  1210. defer redis.Close()
  1211. project := models.HisPrescriptionProject{
  1212. ExecutionTime: theTime.Unix(),
  1213. Mtime: time.Now().Unix(),
  1214. }
  1215. service.ModifyHisPrescriptionProject(&project, ids)
  1216. keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
  1217. redis.Set(keyEnd, "", time.Second)
  1218. keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1219. redis.Set(keyFours, "", time.Second)
  1220. keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
  1221. redis.Set(keyFives, "", time.Second)
  1222. defer redis.Close()
  1223. }
  1224. if err != nil {
  1225. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1226. return
  1227. }
  1228. advice.ExecutionTime = theTime.Unix()
  1229. c.ServeSuccessJSON(map[string]interface{}{
  1230. "msg": "ok",
  1231. "advice": advice,
  1232. "ids": ids,
  1233. })
  1234. return
  1235. }
  1236. func (c *PatientApiController) CheckDoctorAdvice() {
  1237. origin, _ := c.GetInt64("origin", 0)
  1238. if origin != 2 {
  1239. groupno, _ := c.GetInt64("groupno", -1)
  1240. var ids []string
  1241. if groupno == 0 {
  1242. advice_ids := c.GetString("advice_id")
  1243. if advice_ids == "" {
  1244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1245. return
  1246. } else {
  1247. ids = strings.Split(advice_ids, ",")
  1248. if len(ids) <= 0 {
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1250. return
  1251. }
  1252. }
  1253. }
  1254. if groupno < 0 {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. adminUserInfo := c.GetMobileAdminUserInfo()
  1259. var advice models.DoctorAdvice
  1260. if groupno > 0 {
  1261. advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  1262. for _, item := range advices {
  1263. if item.CheckState == 0 {
  1264. advice = item
  1265. }
  1266. }
  1267. if advice.CheckState == 1 {
  1268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1269. return
  1270. }
  1271. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1273. return
  1274. }
  1275. } else {
  1276. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  1277. for _, item := range advices {
  1278. if item.CheckState == 0 {
  1279. advice = item
  1280. }
  1281. }
  1282. if advice.CheckState == 1 {
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1284. return
  1285. }
  1286. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1288. return
  1289. }
  1290. }
  1291. checker := adminUserInfo.AdminUser.Id
  1292. theTime := time.Now()
  1293. advices := models.DoctorAdvice{
  1294. CheckTime: theTime.Unix(),
  1295. Checker: checker,
  1296. UpdatedTime: time.Now().Unix(),
  1297. }
  1298. var err error
  1299. if groupno > 0 {
  1300. err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
  1301. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1302. redis := service.RedisClient()
  1303. //清空key 值
  1304. redis.Set(key, "", time.Second)
  1305. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1306. redis.Set(keyTwo, "", time.Second)
  1307. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1308. redis.Set(keyThree, "", time.Second)
  1309. recordDate := theTime.Format("2006-01-02")
  1310. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1311. redis.Set(keyFour, "", time.Second)
  1312. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1313. redis.Set(keyFive, "", time.Second)
  1314. defer redis.Close()
  1315. } else {
  1316. if len(ids[0]) <= 0 {
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1318. return
  1319. } else {
  1320. //t := time.Now().Format("2006-01-02")/**/
  1321. //timeLayout2 := "2006-01-02"
  1322. //loc, _ := time.LoadLocation("Local")
  1323. //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
  1324. err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
  1325. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1326. redis := service.RedisClient()
  1327. //清空key 值
  1328. redis.Set(key, "", time.Second)
  1329. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1330. redis.Set(keyTwo, "", time.Second)
  1331. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1332. redis.Set(keyThree, "", time.Second)
  1333. recordDate := theTime.Format("2006-01-02")
  1334. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1335. redis.Set(keyFour, "", time.Second)
  1336. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1337. redis.Set(keyFive, "", time.Second)
  1338. defer redis.Close()
  1339. }
  1340. }
  1341. if err != nil {
  1342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1343. return
  1344. }
  1345. advice.Checker = checker
  1346. advice.CheckTime = theTime.Unix()
  1347. advice.CheckState = 1
  1348. c.ServeSuccessJSON(map[string]interface{}{
  1349. "msg": "ok",
  1350. "advice": advice,
  1351. })
  1352. } else if origin == 2 {
  1353. adminInfo := c.GetMobileAdminUserInfo()
  1354. var ids []string
  1355. advice_ids := c.GetString("advice_id")
  1356. ids = strings.Split(advice_ids, ",")
  1357. advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
  1358. var err error
  1359. for _, item := range advices {
  1360. if item.CheckState == 1 {
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1362. return
  1363. }
  1364. if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
  1365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1366. return
  1367. }
  1368. item.Checker = adminInfo.AdminUser.Id
  1369. item.CheckTime = time.Now().Unix()
  1370. item.CheckState = 1
  1371. err = service.SaveHisDoctorAdvice(item)
  1372. redis := service.RedisClient()
  1373. key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1374. //清空key 值
  1375. redis.Set(key, "", time.Second)
  1376. keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1377. redis.Set(keyTwo, "", time.Second)
  1378. keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1379. redis.Set(keyThree, "", time.Second)
  1380. theTime := time.Now()
  1381. recordDate := theTime.Format("2006-01-02")
  1382. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
  1383. redis.Set(keyFour, "", time.Second)
  1384. keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1385. redis.Set(keyFive, "", time.Second)
  1386. defer redis.Close()
  1387. }
  1388. if err == nil {
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "msg": "ok",
  1391. "advice": advices,
  1392. })
  1393. } else {
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1395. return
  1396. }
  1397. }
  1398. return
  1399. }
  1400. func (c *PatientApiController) EditAssessmentBeforeDislysis() {
  1401. id, _ := c.GetInt64("patient", 0)
  1402. assessmentDate := c.GetString("assessment_date", "")
  1403. if id <= 0 || len(assessmentDate) != 10 {
  1404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1405. return
  1406. }
  1407. timeLayout := "2006-01-02"
  1408. loc, _ := time.LoadLocation("Local")
  1409. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
  1410. if err != nil {
  1411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1412. return
  1413. }
  1414. theAssessmentDateTime := theTime.Unix()
  1415. adminUserInfo := c.GetMobileAdminUserInfo()
  1416. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1417. if patient.ID == 0 {
  1418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1419. return
  1420. }
  1421. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1422. if getPEErr != nil {
  1423. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  1424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1425. return
  1426. }
  1427. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1428. //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1429. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1430. var evaluation models.PredialysisEvaluation
  1431. if theEvaluation != nil {
  1432. evaluation = *theEvaluation
  1433. }
  1434. code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
  1435. if code > 0 {
  1436. c.ServeFailJSONWithSGJErrorCode(code)
  1437. return
  1438. }
  1439. if theEvaluation == nil {
  1440. evaluation.CreatedTime = time.Now().Unix()
  1441. evaluation.Status = 1
  1442. evaluation.AssessmentDate = theAssessmentDateTime
  1443. evaluation.PatientId = id
  1444. evaluation.UserOrgId = adminUserInfo.Org.Id
  1445. if appRole.UserType == 2 || appRole.UserType == 1 {
  1446. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1447. evaluation.AssessmentTime = time.Now().Unix()
  1448. } else {
  1449. evaluation.Creater = adminUserInfo.AdminUser.Id
  1450. }
  1451. } else {
  1452. evaluation.UpdatedTime = time.Now().Unix()
  1453. evaluation.Evaluator = adminUserInfo.AdminUser.Id
  1454. if appRole.UserType == 2 || appRole.UserType == 1 {
  1455. evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1456. evaluation.AssessmentTime = time.Now().Unix()
  1457. } else {
  1458. evaluation.Modifier = adminUserInfo.AdminUser.Id
  1459. if evaluation.Creater == 0 {
  1460. evaluation.Creater = adminUserInfo.AdminUser.Id
  1461. }
  1462. }
  1463. }
  1464. //新增逻辑
  1465. var dewater_amount float64
  1466. dewater_amount = 0
  1467. if evaluation.DryWeight > 0 {
  1468. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  1469. if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 {
  1470. dewater_amount = dewater_amount * 1000
  1471. }
  1472. if dewater_amount <= 0 {
  1473. dewater_amount = 0
  1474. }
  1475. } else {
  1476. dewater_amount = 0
  1477. }
  1478. // 计算透析处方的相关超滤量
  1479. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
  1480. lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
  1481. var lastDialysisPrescribe *models.DialysisPrescription
  1482. var dialysisSolution *models.DialysisSolution
  1483. var dialysisPrescribe *models.DialysisPrescription
  1484. var system_dialysisPrescribe *models.SystemPrescription
  1485. var mode_id int64
  1486. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  1487. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1488. if schedual != nil {
  1489. // 获取透析模版
  1490. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  1491. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  1492. mode_id = schedual.ModeId
  1493. } else {
  1494. // 获取透析模版
  1495. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  1496. if dialysisPrescribe == nil && dialysisSolution != nil {
  1497. mode_id = dialysisSolution.ModeId
  1498. }
  1499. if dialysisPrescribe == nil && dialysisSolution == nil {
  1500. mode_id = 0
  1501. }
  1502. }
  1503. // 插入透析处方
  1504. if dialysisPrescribe == nil && dialysisSolution != nil {
  1505. var newprescribe models.DialysisPrescription
  1506. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1507. newprescribe.PatientId = dialysisSolution.PatientId
  1508. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1509. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1510. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1511. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1512. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1513. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1514. newprescribe.ModeId = dialysisSolution.ModeId
  1515. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1516. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1517. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1518. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1519. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1520. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1521. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1522. newprescribe.Glucose = dialysisSolution.Glucose
  1523. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1524. newprescribe.Kalium = dialysisSolution.Kalium
  1525. newprescribe.Sodium = dialysisSolution.Sodium
  1526. newprescribe.Calcium = dialysisSolution.Calcium
  1527. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1528. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1529. newprescribe.Conductivity = dialysisSolution.Conductivity
  1530. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1531. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1532. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1533. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1534. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1535. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1536. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1537. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1538. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1539. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1540. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1541. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1542. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1543. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1544. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1545. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1546. newprescribe.CreatedTime = time.Now().Unix()
  1547. newprescribe.UpdatedTime = time.Now().Unix()
  1548. newprescribe.RecordDate = theAssessmentDateTime
  1549. newprescribe.DewaterAmount = dewater_amount
  1550. newprescribe.TargetUltrafiltration = dewater_amount
  1551. newprescribe.Status = 1
  1552. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  1553. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  1554. newprescribe.Remark = lastDialysisPrescription.Remark
  1555. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1556. newprescribe.ID = dialysisPrescription.ID
  1557. if dialysisPrescription.ID == 0 {
  1558. if adminUserInfo.Org.Id == 10340 {
  1559. newprescribe.Sodium = 138
  1560. newprescribe.Bicarbonate = 31.1
  1561. newprescribe.DialysateFlow = 500
  1562. }
  1563. err := service.AddSigleRecord(&newprescribe)
  1564. //获取key,清空redis
  1565. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1566. redis := service.RedisClient()
  1567. //清空key 值
  1568. redis.Set(key, "", time.Second)
  1569. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1570. //清空key 值
  1571. redis.Set(keyOne, "", time.Second)
  1572. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1573. //清空key 值
  1574. redis.Set(keyTwo, "", time.Second)
  1575. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1576. redis.Set(keySix, "", time.Second)
  1577. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1578. redis.Set(keySeven, "", time.Second)
  1579. if err != nil {
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1581. }
  1582. } else {
  1583. if adminUserInfo.Org.Id == 10340 {
  1584. newprescribe.Sodium = 138
  1585. newprescribe.Bicarbonate = 31.1
  1586. newprescribe.DialysateFlow = 500
  1587. }
  1588. err := service.UpDateDialysisPrescription(&newprescribe)
  1589. //获取key,清空redis
  1590. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1591. redis := service.RedisClient()
  1592. //清空key 值
  1593. redis.Set(key, "", time.Second)
  1594. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1595. //清空key 值
  1596. redis.Set(keyOne, "", time.Second)
  1597. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1598. //清空key 值
  1599. redis.Set(keyTwo, "", time.Second)
  1600. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1601. redis.Set(keySix, "", time.Second)
  1602. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1603. redis.Set(keySeven, "", time.Second)
  1604. if err != nil {
  1605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1606. }
  1607. }
  1608. }
  1609. if dialysisPrescribe == nil && dialysisSolution == nil {
  1610. if lastDialysisPrescribe != nil {
  1611. var newprescribe models.DialysisPrescription
  1612. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1613. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1614. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1615. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1616. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1617. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1618. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1619. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1620. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1621. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1622. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1623. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1624. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1625. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1626. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1627. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1628. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1629. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1630. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1631. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1632. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1633. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1634. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1635. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1636. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1637. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1638. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1639. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1640. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1641. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1642. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1643. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1644. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1645. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1646. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1647. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1648. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1649. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1650. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1651. newprescribe.CreatedTime = time.Now().Unix()
  1652. newprescribe.UpdatedTime = time.Now().Unix()
  1653. newprescribe.RecordDate = theAssessmentDateTime
  1654. newprescribe.DewaterAmount = dewater_amount
  1655. newprescribe.TargetUltrafiltration = dewater_amount
  1656. newprescribe.Status = 1
  1657. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  1658. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  1659. newprescribe.Remark = lastDialysisPrescription.Remark
  1660. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1661. newprescribe.ID = dialysisPrescription.ID
  1662. if dialysisPrescription.ID == 0 {
  1663. if adminUserInfo.Org.Id == 10340 {
  1664. newprescribe.Sodium = 138
  1665. newprescribe.Bicarbonate = 31.1
  1666. newprescribe.DialysateFlow = 500
  1667. }
  1668. err := service.AddSigleRecord(&newprescribe)
  1669. //获取key,清空redis
  1670. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1671. redis := service.RedisClient()
  1672. //清空key 值
  1673. redis.Set(key, "", time.Second)
  1674. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1675. //清空key 值
  1676. redis.Set(keyOne, "", time.Second)
  1677. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1678. //清空key 值
  1679. redis.Set(keyTwo, "", time.Second)
  1680. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1681. redis.Set(keySix, "", time.Second)
  1682. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1683. redis.Set(keySeven, "", time.Second)
  1684. if err != nil {
  1685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1686. }
  1687. } else {
  1688. err := service.UpDateDialysisPrescription(&newprescribe)
  1689. //获取key,清空redis
  1690. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1691. redis := service.RedisClient()
  1692. //清空key 值
  1693. redis.Set(key, "", time.Second)
  1694. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1695. //清空key 值
  1696. redis.Set(keyOne, "", time.Second)
  1697. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1698. //清空key 值
  1699. redis.Set(keyTwo, "", time.Second)
  1700. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1701. redis.Set(keySix, "", time.Second)
  1702. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1703. redis.Set(keySeven, "", time.Second)
  1704. if err != nil {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1706. }
  1707. }
  1708. if err != nil {
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1710. }
  1711. } else if system_dialysisPrescribe != nil {
  1712. var newprescribe models.DialysisPrescription
  1713. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  1714. newprescribe.PatientId = id
  1715. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  1716. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  1717. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  1718. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  1719. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  1720. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  1721. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  1722. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  1723. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  1724. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  1725. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  1726. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  1727. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  1728. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  1729. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  1730. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  1731. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  1732. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  1733. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  1734. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  1735. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  1736. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  1737. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  1738. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  1739. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  1740. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  1741. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  1742. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  1743. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  1744. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  1745. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  1746. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  1747. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  1748. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  1749. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  1750. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  1751. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  1752. newprescribe.CreatedTime = time.Now().Unix()
  1753. newprescribe.UpdatedTime = time.Now().Unix()
  1754. newprescribe.RecordDate = theAssessmentDateTime
  1755. newprescribe.DewaterAmount = dewater_amount
  1756. newprescribe.TargetUltrafiltration = dewater_amount
  1757. newprescribe.Status = 1
  1758. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  1759. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  1760. newprescribe.Remark = lastDialysisPrescription.Remark
  1761. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1762. newprescribe.ID = dialysisPrescription.ID
  1763. if dialysisPrescription.ID == 0 {
  1764. if adminUserInfo.Org.Id == 10340 {
  1765. newprescribe.Sodium = 138
  1766. newprescribe.Bicarbonate = 31.1
  1767. newprescribe.DialysateFlow = 500
  1768. }
  1769. err := service.AddSigleRecord(&newprescribe)
  1770. //获取key,清空redis
  1771. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1772. redis := service.RedisClient()
  1773. //清空key 值
  1774. redis.Set(key, "", time.Second)
  1775. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1776. //清空key 值
  1777. redis.Set(keyOne, "", time.Second)
  1778. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1779. //清空key 值
  1780. redis.Set(keyTwo, "", time.Second)
  1781. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1782. redis.Set(keySix, "", time.Second)
  1783. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1784. redis.Set(keySeven, "", time.Second)
  1785. if err != nil {
  1786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1787. }
  1788. } else {
  1789. if adminUserInfo.Org.Id == 10340 {
  1790. newprescribe.Sodium = 138
  1791. newprescribe.Bicarbonate = 31.1
  1792. newprescribe.DialysateFlow = 500
  1793. }
  1794. err := service.UpDateDialysisPrescription(&newprescribe)
  1795. //获取key,清空redis
  1796. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1797. redis := service.RedisClient()
  1798. //清空key 值
  1799. redis.Set(key, "", time.Second)
  1800. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1801. //清空key 值
  1802. redis.Set(keyOne, "", time.Second)
  1803. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1804. //清空key 值
  1805. redis.Set(keyTwo, "", time.Second)
  1806. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1807. redis.Set(keySix, "", time.Second)
  1808. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1809. redis.Set(keySeven, "", time.Second)
  1810. if err != nil {
  1811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1812. }
  1813. }
  1814. if err != nil {
  1815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1816. }
  1817. } else {
  1818. var newprescribe models.DialysisPrescription
  1819. newprescribe.UserOrgId = adminUserInfo.Org.Id
  1820. newprescribe.PatientId = id
  1821. newprescribe.ModeId = mode_id
  1822. newprescribe.CreatedTime = time.Now().Unix()
  1823. newprescribe.UpdatedTime = time.Now().Unix()
  1824. newprescribe.RecordDate = theAssessmentDateTime
  1825. newprescribe.DewaterAmount = dewater_amount
  1826. newprescribe.TargetUltrafiltration = dewater_amount
  1827. newprescribe.Status = 1
  1828. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
  1829. newprescribe.ID = dialysisPrescription.ID
  1830. if dialysisPrescription.ID == 0 {
  1831. if adminUserInfo.Org.Id == 10340 {
  1832. newprescribe.Sodium = 138
  1833. newprescribe.Bicarbonate = 31.1
  1834. newprescribe.DialysateFlow = 500
  1835. }
  1836. err := service.AddSigleRecord(&newprescribe)
  1837. //获取key,清空redis
  1838. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1839. redis := service.RedisClient()
  1840. //清空key 值
  1841. redis.Set(key, "", time.Second)
  1842. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1843. //清空key 值
  1844. redis.Set(keyOne, "", time.Second)
  1845. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1846. //清空key 值
  1847. redis.Set(keyTwo, "", time.Second)
  1848. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1849. redis.Set(keySix, "", time.Second)
  1850. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1851. redis.Set(keySeven, "", time.Second)
  1852. if err != nil {
  1853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1854. }
  1855. } else {
  1856. if adminUserInfo.Org.Id == 10340 {
  1857. newprescribe.Sodium = 138
  1858. newprescribe.Bicarbonate = 31.1
  1859. newprescribe.DialysateFlow = 500
  1860. }
  1861. err := service.UpDateDialysisPrescription(&newprescribe)
  1862. //获取key,清空redis
  1863. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1864. redis := service.RedisClient()
  1865. //清空key 值
  1866. redis.Set(key, "", time.Second)
  1867. keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1868. //清空key 值
  1869. redis.Set(keyOne, "", time.Second)
  1870. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1871. //清空key 值
  1872. redis.Set(keyTwo, "", time.Second)
  1873. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  1874. redis.Set(keySix, "", time.Second)
  1875. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
  1876. redis.Set(keySeven, "", time.Second)
  1877. if err != nil {
  1878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1879. }
  1880. }
  1881. if err != nil {
  1882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1883. }
  1884. }
  1885. }
  1886. // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
  1887. // if dialysisPrescribe != nil {
  1888. // dialysisPrescribe.UpdatedTime = time.Now().Unix()
  1889. // dialysisPrescribe.RecordDate = theAssessmentDateTime
  1890. // dialysisPrescribe.DewaterAmount = dewater_amount
  1891. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  1892. // dialysisPrescribe.Status = 1
  1893. // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  1894. // if updateErr != nil {
  1895. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1896. // }
  1897. // }
  1898. err = service.UpadatePredialysisEvaluation(&evaluation)
  1899. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  1900. redis := service.RedisClient()
  1901. defer redis.Close()
  1902. //清空key 值
  1903. redis.Set(key, "", time.Second)
  1904. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  1905. redis.Set(keyOne, "", time.Second)
  1906. keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1907. redis.Set(keyTwo, "", time.Second)
  1908. if err != nil {
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  1910. return
  1911. }
  1912. c.ServeSuccessJSON(map[string]interface{}{
  1913. "msg": "ok",
  1914. "evaluation": evaluation,
  1915. })
  1916. return
  1917. }
  1918. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  1919. dataBody := make(map[string]interface{}, 0)
  1920. err := json.Unmarshal(data, &dataBody)
  1921. utils.InfoLog(string(data))
  1922. if err != nil {
  1923. utils.ErrorLog(err.Error())
  1924. code = enums.ErrorCodeParamWrong
  1925. return
  1926. }
  1927. // if method == "create" {
  1928. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  1929. utils.ErrorLog("mode")
  1930. code = enums.ErrorCodeParamWrong
  1931. return
  1932. }
  1933. mode := int64(dataBody["mode"].(float64))
  1934. if mode <= 0 {
  1935. utils.ErrorLog("mode <= 0")
  1936. code = enums.ErrorCodeParamWrong
  1937. return
  1938. }
  1939. solution.ModeId = mode
  1940. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  1941. utils.ErrorLog("mode_name")
  1942. code = enums.ErrorCodeParamWrong
  1943. return
  1944. }
  1945. modeName, _ := dataBody["mode_name"].(string)
  1946. if len(modeName) == 0 {
  1947. utils.ErrorLog("len(mode_name) == 0")
  1948. code = enums.ErrorCodeParamWrong
  1949. return
  1950. }
  1951. solution.ModeName = modeName
  1952. solution.Name = modeName
  1953. // }
  1954. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1955. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1956. solution.DialysisDuration = dialysisDuration
  1957. }
  1958. if dataBody["dialysis_duration"] != nil {
  1959. if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  1960. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  1961. solution.DialysisDuration = dialysisDuration
  1962. } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
  1963. dialysisDuration := dataBody["dialysis_duration"].(float64)
  1964. solution.DialysisDuration = dialysisDuration
  1965. }
  1966. }
  1967. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  1968. dialyzer := int64(dataBody["dialyzer"].(float64))
  1969. solution.Dialyzer = dialyzer
  1970. }
  1971. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  1972. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  1973. solution.PerfusionApparatus = perfusionApparatus
  1974. }
  1975. if dataBody["blood_flow_volume"] != nil {
  1976. if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  1977. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  1978. solution.BloodFlowVolume = bloodFlowVolume
  1979. } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
  1980. bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
  1981. solution.BloodFlowVolume = bloodFlowVolume
  1982. }
  1983. }
  1984. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  1985. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  1986. solution.HemodialysisMachine = hemodialysisMachine
  1987. }
  1988. if dataBody["dewater"] != nil {
  1989. if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  1990. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  1991. solution.Dewater = dewater
  1992. } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
  1993. dewater := dataBody["dewater"].(float64)
  1994. solution.Dewater = dewater
  1995. }
  1996. }
  1997. if dataBody["replacement_total"] != nil {
  1998. if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  1999. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2000. solution.ReplacementTotal = replacementTotal
  2001. } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
  2002. replacementTotal := dataBody["replacement_total"].(float64)
  2003. solution.ReplacementTotal = replacementTotal
  2004. }
  2005. }
  2006. if dataBody["displace_liqui"] != nil {
  2007. if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2008. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2009. solution.DisplaceLiqui = displaceLiqui
  2010. } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
  2011. displaceLiqui := dataBody["displace_liqui"].(float64)
  2012. solution.DisplaceLiqui = displaceLiqui
  2013. }
  2014. }
  2015. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2016. replacementWay := int64(dataBody["replacement_way"].(float64))
  2017. solution.ReplacementWay = replacementWay
  2018. }
  2019. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2020. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2021. solution.Anticoagulant = anticoagulant
  2022. }
  2023. if dataBody["anticoagulant_shouji"] != nil {
  2024. if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2025. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2026. solution.AnticoagulantShouji = anticoagulantShouji
  2027. } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
  2028. anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
  2029. solution.AnticoagulantShouji = anticoagulantShouji
  2030. }
  2031. }
  2032. if dataBody["anticoagulant_weichi"] != nil {
  2033. if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2034. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2035. solution.AnticoagulantWeichi = anticoagulantWeichi
  2036. } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
  2037. anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
  2038. solution.AnticoagulantWeichi = anticoagulantWeichi
  2039. }
  2040. }
  2041. if dataBody["anticoagulant_zongliang"] != nil {
  2042. if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2043. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2044. solution.AnticoagulantZongliang = anticoagulantZongliang
  2045. } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
  2046. anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
  2047. solution.AnticoagulantZongliang = anticoagulantZongliang
  2048. }
  2049. }
  2050. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2051. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2052. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2053. }
  2054. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2055. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2056. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2057. }
  2058. if dataBody["kalium"] != nil {
  2059. if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2060. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2061. solution.Kalium = kalium
  2062. } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
  2063. kalium := dataBody["kalium"].(float64)
  2064. solution.Kalium = kalium
  2065. }
  2066. }
  2067. if dataBody["sodium"] != nil {
  2068. if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2069. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2070. solution.Sodium = sodium
  2071. } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
  2072. sodium := dataBody["sodium"].(float64)
  2073. solution.Sodium = sodium
  2074. }
  2075. }
  2076. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2077. if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2078. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2079. solution.Calcium = calcium
  2080. } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
  2081. calcium := dataBody["calcium"].(float64)
  2082. solution.Calcium = calcium
  2083. }
  2084. }
  2085. if dataBody["bicarbonate"] != nil {
  2086. if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2087. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2088. solution.Bicarbonate = bicarbonate
  2089. } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
  2090. bicarbonate := dataBody["bicarbonate"].(float64)
  2091. solution.Bicarbonate = bicarbonate
  2092. }
  2093. }
  2094. if dataBody["glucose"] != nil {
  2095. if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2096. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2097. solution.Glucose = glucose
  2098. } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
  2099. glucose := dataBody["glucose"].(float64)
  2100. solution.Glucose = glucose
  2101. }
  2102. }
  2103. // if dataBody["dry_weight"] != nil {
  2104. // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2105. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2106. // solution.DryWeight = dryWeight
  2107. // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
  2108. // dryWeight := dataBody["dry_weight"].(float64)
  2109. // solution.DryWeight = dryWeight
  2110. // }
  2111. // }
  2112. if dataBody["dialysate_flow"] != nil {
  2113. if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2114. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2115. solution.DialysateFlow = dialysateFlow
  2116. } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
  2117. dialysateFlow := dataBody["dialysate_flow"].(float64)
  2118. solution.DialysateFlow = dialysateFlow
  2119. }
  2120. }
  2121. if dataBody["dialysate_temperature"] != nil {
  2122. if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2123. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2124. solution.DialysateTemperature = dialysateTemperature
  2125. } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
  2126. dialysateTemperature := dataBody["dialysate_temperature"].(float64)
  2127. solution.DialysateTemperature = dialysateTemperature
  2128. }
  2129. }
  2130. if dataBody["conductivity"] != nil {
  2131. if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2132. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2133. solution.Conductivity = conductivity
  2134. } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
  2135. conductivity := dataBody["conductivity"].(float64)
  2136. solution.Conductivity = conductivity
  2137. }
  2138. }
  2139. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2140. remark := dataBody["remark"].(string)
  2141. solution.Remark = remark
  2142. }
  2143. if dataBody["dialysis_duration_hour"] != nil {
  2144. if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2145. dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
  2146. solution.DialysisDurationHour = dialysisDurationHour
  2147. } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
  2148. dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
  2149. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2150. }
  2151. }
  2152. if dataBody["dialysis_duration_minute"] != nil {
  2153. if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2154. dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
  2155. solution.DialysisDurationMinute = dialysisDurationMinute
  2156. } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
  2157. dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
  2158. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2159. }
  2160. }
  2161. if dataBody["target_ultrafiltration"] != nil {
  2162. if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2163. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2164. solution.TargetUltrafiltration = targetUltrafiltration
  2165. } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
  2166. targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
  2167. solution.TargetUltrafiltration = targetUltrafiltration
  2168. }
  2169. }
  2170. if dataBody["dialysate_formulation"] != nil {
  2171. if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
  2172. dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
  2173. solution.DialysateFormulation = dialysateFormulation
  2174. } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2175. dialysateFormulation := dataBody["dialysate_formulation"].(float64)
  2176. solution.DialysateFormulation = int64(dialysateFormulation)
  2177. }
  2178. }
  2179. return
  2180. }
  2181. func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
  2182. dataBody := make(map[string]interface{}, 0)
  2183. err := json.Unmarshal(data, &dataBody)
  2184. utils.InfoLog(string(data))
  2185. if err != nil {
  2186. utils.ErrorLog(err.Error())
  2187. code = enums.ErrorCodeParamWrong
  2188. return
  2189. }
  2190. if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
  2191. weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
  2192. evaluation.WeightBefore = weightVefore
  2193. }
  2194. // fmt.Println(dataBody["dry_weight"])
  2195. // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
  2196. if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2197. additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2198. fmt.Println(additionalWeight)
  2199. evaluation.DryWeight = additionalWeight
  2200. }
  2201. if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
  2202. additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
  2203. fmt.Println(additionalWeight)
  2204. evaluation.AdditionalWeight = additionalWeight
  2205. }
  2206. if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
  2207. Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
  2208. evaluation.Temperature = Temperature
  2209. }
  2210. if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
  2211. systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
  2212. evaluation.SystolicBloodPressure = systolicBloodPressure
  2213. }
  2214. if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
  2215. diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
  2216. evaluation.DiastolicBloodPressure = diastolicBloodPressure
  2217. }
  2218. if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
  2219. pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
  2220. evaluation.PulseFrequency = pulseFrequency
  2221. }
  2222. if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
  2223. breathingRate := dataBody["breathing_rate"].(string)
  2224. evaluation.BreathingRate = breathingRate
  2225. }
  2226. if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
  2227. lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
  2228. evaluation.LastPostDialysis = lastPostDialysis
  2229. }
  2230. if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
  2231. dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
  2232. evaluation.DialysisInterphase = dialysisInterphase
  2233. }
  2234. if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
  2235. symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
  2236. evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
  2237. }
  2238. if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
  2239. catheter, _ := dataBody["catheter"].(string)
  2240. evaluation.Catheter = catheter
  2241. }
  2242. if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
  2243. catheter_bend := int(dataBody["catheter_bend"].(float64))
  2244. evaluation.CatheterBend = catheter_bend
  2245. }
  2246. if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
  2247. Complication, _ := dataBody["complication"].(string)
  2248. evaluation.Complication = Complication
  2249. }
  2250. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2251. remark := dataBody["remark"].(string)
  2252. evaluation.Remark = remark
  2253. }
  2254. if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
  2255. machine_type := dataBody["machine_type"].(string)
  2256. evaluation.MachineType = machine_type
  2257. }
  2258. if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
  2259. blood_access_part_id := dataBody["blood_access_part_id"].(string)
  2260. evaluation.BloodAccessPartId = blood_access_part_id
  2261. }
  2262. //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
  2263. // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
  2264. // evaluation.BloodAccessPartId = blood_access_part_id
  2265. //}
  2266. if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
  2267. blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
  2268. evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
  2269. }
  2270. if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
  2271. internal_fistula, _ := dataBody["internal_fistula"].(string)
  2272. evaluation.InternalFistula = internal_fistula
  2273. }
  2274. if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
  2275. internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
  2276. evaluation.InternalFistulaSkin = internal_fistula_skin
  2277. }
  2278. if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
  2279. ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
  2280. is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
  2281. evaluation.IsHemorrhage = is_hemorrhage
  2282. //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
  2283. // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
  2284. // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
  2285. if is_hemorrhage != 1 && is_hemorrhage != 2 {
  2286. is_hemorrhage = 0
  2287. }
  2288. evaluation.IsHemorrhage = is_hemorrhage
  2289. if is_hemorrhage == 1 {
  2290. if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
  2291. hemorrhage, _ := dataBody["hemorrhage"].(string)
  2292. evaluation.Hemorrhage = hemorrhage
  2293. }
  2294. if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
  2295. hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
  2296. evaluation.HemorrhageOther = hemorrhage_other
  2297. }
  2298. }
  2299. } else {
  2300. evaluation.IsHemorrhage = 0
  2301. }
  2302. if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
  2303. blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
  2304. evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
  2305. }
  2306. if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
  2307. internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
  2308. evaluation.InternalFistulaOther = internal_fistula_other
  2309. }
  2310. if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
  2311. blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
  2312. evaluation.BloodAccessNoise = blood_access_noise
  2313. }
  2314. if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
  2315. //puncture_way := int64(dataBody["puncture_way"].(float64))
  2316. puncture_way := dataBody["puncture_way"].(string)
  2317. evaluation.PunctureWay = puncture_way
  2318. }
  2319. if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
  2320. venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
  2321. evaluation.VenousCatheterization = venous_catheterization
  2322. }
  2323. if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
  2324. venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
  2325. evaluation.VenousCatheterizationPart = venous_catheterization_part
  2326. }
  2327. if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
  2328. venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
  2329. evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
  2330. }
  2331. if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
  2332. ductus_arantii, _ := dataBody["ductus_arantii"].(string)
  2333. evaluation.DuctusArantii = ductus_arantii
  2334. }
  2335. if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
  2336. emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
  2337. evaluation.EmergencyTreatment = emergency_treatment
  2338. }
  2339. if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
  2340. emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
  2341. evaluation.EmergencyTreatmentOther = emergency_treatment_other
  2342. }
  2343. if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
  2344. dialysis_count, _ := dataBody["dialysis_count"].(string)
  2345. //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
  2346. evaluation.DialysisCount = dialysis_count
  2347. }
  2348. if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
  2349. is_infect, _ := dataBody["is_infect"].(string)
  2350. infect, _ := strconv.ParseInt(is_infect, 10, 64)
  2351. evaluation.IsInfect = infect
  2352. }
  2353. if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
  2354. exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
  2355. evaluation.Exposed = exposed
  2356. }
  2357. if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
  2358. skin, _ := dataBody["skin"].(string)
  2359. //skins, _ := strconv.ParseInt(skin, 10, 64)
  2360. evaluation.Skin = skin
  2361. }
  2362. if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
  2363. skin_other, _ := dataBody["skin_other"].(string)
  2364. evaluation.SkinOther = skin_other
  2365. }
  2366. if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
  2367. infect_other, _ := dataBody["infect_other"].(string)
  2368. evaluation.InfectOther = infect_other
  2369. }
  2370. if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
  2371. ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
  2372. evaluation.DuctusArantiiOther = ductus_arantii_other
  2373. }
  2374. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2375. punctureNeedle, _ := dataBody["puncture_needle"].(string)
  2376. evaluation.PunctureNeedle = punctureNeedle
  2377. }
  2378. if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
  2379. humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
  2380. evaluation.HumorExcessiveSymptom = humor_excessive_symptom
  2381. }
  2382. if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
  2383. pinholing := dataBody["pinholing"].(string)
  2384. evaluation.Phinholing = pinholing
  2385. }
  2386. if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
  2387. catheter_suture := dataBody["catheter_suture"].(string)
  2388. evaluation.CatheterSuture = catheter_suture
  2389. }
  2390. if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
  2391. catheter_suture_other := dataBody["catheter_suture_other"].(string)
  2392. evaluation.CatheterSutureOther = catheter_suture_other
  2393. }
  2394. if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
  2395. urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
  2396. evaluation.UrineVolume = urine_volume
  2397. }
  2398. if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
  2399. edema := dataBody["edema"].(string)
  2400. evaluation.Edema = edema
  2401. }
  2402. if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
  2403. specialTreatment := dataBody["special_treatment"].(string)
  2404. evaluation.SpecialTreatment = specialTreatment
  2405. }
  2406. if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
  2407. catheter_maintenance := dataBody["catheter_maintenance"].(string)
  2408. evaluation.CatheterMaintenance = catheter_maintenance
  2409. }
  2410. if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
  2411. thromubusType := int64(dataBody["thromubus_type"].(float64))
  2412. evaluation.ThromubusType = thromubusType
  2413. }
  2414. if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
  2415. thrombus_av := dataBody["thrombus_av"].(string)
  2416. evaluation.ThrombusAv = thrombus_av
  2417. }
  2418. if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
  2419. thromubus_a := dataBody["thromubus_a"].(string)
  2420. evaluation.ThromubusA = thromubus_a
  2421. }
  2422. if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
  2423. thromubus_v := dataBody["thromubus_v"].(string)
  2424. evaluation.ThromubusV = thromubus_v
  2425. }
  2426. if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
  2427. dehydration := dataBody["dehydration"].(string)
  2428. evaluation.Dehydration = dehydration
  2429. }
  2430. if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
  2431. period := int64(dataBody["period"].(float64))
  2432. evaluation.Period = period
  2433. }
  2434. if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
  2435. estimated_food_intake := dataBody["estimated_food_intake"].(string)
  2436. evaluation.EstimatedFoodIntake = estimated_food_intake
  2437. }
  2438. if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
  2439. blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
  2440. evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
  2441. }
  2442. if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
  2443. pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
  2444. evaluation.PreDialysisDrugs = pre_dialysis_drugs
  2445. }
  2446. if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
  2447. urea_befor := dataBody["urea_befor"].(string)
  2448. evaluation.UreaBefor = urea_befor
  2449. }
  2450. if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
  2451. suction := dataBody["suction"].(string)
  2452. evaluation.Suction = suction
  2453. }
  2454. if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
  2455. weight_befor_remake := dataBody["weight_befor_remake"].(string)
  2456. evaluation.WeightBeforRemake = weight_befor_remake
  2457. }
  2458. if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
  2459. height := dataBody["height"].(string)
  2460. evaluation.Height = height
  2461. }
  2462. if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
  2463. age := dataBody["age"].(string)
  2464. evaluation.Age = age
  2465. }
  2466. if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
  2467. his_department := dataBody["his_department"].(string)
  2468. evaluation.HisDepartment = his_department
  2469. }
  2470. if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
  2471. his_bed := dataBody["his_bed"].(string)
  2472. evaluation.HisBed = his_bed
  2473. }
  2474. return
  2475. }
  2476. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2477. dataBody := make(map[string]interface{}, 0)
  2478. err := json.Unmarshal(data, &dataBody)
  2479. if err != nil {
  2480. utils.ErrorLog(err.Error())
  2481. code = enums.ErrorCodeParamWrong
  2482. return
  2483. }
  2484. timeLayout := "2006-01-02"
  2485. loc, _ := time.LoadLocation("Local")
  2486. isChild := false
  2487. if action == "create" {
  2488. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2489. utils.ErrorLog("advice_type")
  2490. code = enums.ErrorCodeParamWrong
  2491. return
  2492. }
  2493. adviceType := int64(dataBody["advice_type"].(float64))
  2494. if adviceType != 1 && adviceType != 2 {
  2495. utils.ErrorLog("advice_type != 1&&2")
  2496. code = enums.ErrorCodeParamWrong
  2497. return
  2498. }
  2499. advice.AdviceType = adviceType
  2500. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2501. utils.ErrorLog("advice_date")
  2502. code = enums.ErrorCodeParamWrong
  2503. return
  2504. }
  2505. adviceDate, _ := dataBody["advice_date"].(string)
  2506. if len(adviceDate) == 0 {
  2507. utils.ErrorLog("len(adviceDate) == 0")
  2508. code = enums.ErrorCodeParamWrong
  2509. return
  2510. }
  2511. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2512. if err != nil {
  2513. utils.ErrorLog(err.Error())
  2514. code = enums.ErrorCodeParamWrong
  2515. return
  2516. }
  2517. advice.AdviceDate = theTime.Unix()
  2518. advice.RecordDate = theTime.Unix()
  2519. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2520. parentId := int64(dataBody["parent_id"].(float64))
  2521. advice.ParentId = parentId
  2522. if parentId > 0 {
  2523. isChild = true
  2524. }
  2525. }
  2526. } else {
  2527. isChild = advice.ParentId > 0
  2528. }
  2529. if !isChild {
  2530. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2531. utils.ErrorLog("start_time")
  2532. code = enums.ErrorCodeParamWrong
  2533. return
  2534. }
  2535. startTime, _ := dataBody["start_time"].(string)
  2536. if len(startTime) == 0 {
  2537. utils.ErrorLog("len(start_time) == 0")
  2538. code = enums.ErrorCodeParamWrong
  2539. return
  2540. }
  2541. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  2542. if err != nil {
  2543. utils.ErrorLog(err.Error())
  2544. code = enums.ErrorCodeParamWrong
  2545. return
  2546. }
  2547. advice.StartTime = theTime.Unix()
  2548. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2549. deliveryWay, _ := dataBody["delivery_way"].(string)
  2550. advice.DeliveryWay = deliveryWay
  2551. }
  2552. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2553. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2554. advice.ExecutionFrequency = executionFrequency
  2555. }
  2556. }
  2557. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2558. deliveryWay, _ := dataBody["delivery_way"].(string)
  2559. advice.DeliveryWay = deliveryWay
  2560. }
  2561. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2562. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2563. advice.ExecutionFrequency = executionFrequency
  2564. }
  2565. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2566. utils.ErrorLog("advice_name")
  2567. code = enums.ErrorCodeParamWrong
  2568. return
  2569. }
  2570. adviceName, _ := dataBody["advice_name"].(string)
  2571. if len(adviceName) == 0 {
  2572. utils.ErrorLog("len(advice_name) == 0")
  2573. code = enums.ErrorCodeParamWrong
  2574. return
  2575. }
  2576. advice.AdviceName = adviceName
  2577. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2578. adviceDsc, _ := dataBody["advice_desc"].(string)
  2579. advice.AdviceDesc = adviceDsc
  2580. }
  2581. if dataBody["way"] == nil {
  2582. advice.Way = 0
  2583. } else {
  2584. if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2585. way := int64(dataBody["way"].(float64))
  2586. advice.Way = way
  2587. }
  2588. }
  2589. if dataBody["drug_id"] == nil {
  2590. advice.DrugId = 0
  2591. } else {
  2592. if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2593. drug_id := int64(dataBody["drug_id"].(float64))
  2594. advice.DrugId = drug_id
  2595. }
  2596. }
  2597. if dataBody["drug_name_id"] == nil {
  2598. advice.DrugNameId = 0
  2599. } else {
  2600. if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2601. drug_name_id := int64(dataBody["drug_name_id"].(float64))
  2602. advice.DrugNameId = drug_name_id
  2603. }
  2604. }
  2605. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2606. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2607. advice.SingleDose = singleDose
  2608. }
  2609. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2610. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2611. advice.SingleDoseUnit = singleDoseUnit
  2612. }
  2613. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2614. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2615. advice.DrugSpec = drugSpec
  2616. }
  2617. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2618. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2619. advice.DrugSpecUnit = drugSpecUnit
  2620. }
  2621. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2622. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2623. advice.PrescribingNumber = prescribingNumber
  2624. }
  2625. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2626. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2627. advice.PrescribingNumberUnit = prescribingNumberUnit
  2628. }
  2629. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2630. remark, _ := dataBody["remark"].(string)
  2631. advice.Remark = remark
  2632. }
  2633. return
  2634. }
  2635. func (c *PatientApiController) GetPatientEducation() {
  2636. patientID, _ := c.GetInt64("patient_id", 0)
  2637. page, _ := c.GetInt64("page", 0)
  2638. limit, _ := c.GetInt64("limit", 0)
  2639. startTime := c.GetString("start_time", "")
  2640. endTime := c.GetString("end_time", "")
  2641. if page <= 0 {
  2642. page = 1
  2643. }
  2644. if limit <= 0 {
  2645. limit = 10
  2646. }
  2647. if patientID <= 0 {
  2648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2649. return
  2650. }
  2651. timeLayout := "2006-01-02"
  2652. loc, _ := time.LoadLocation("Local")
  2653. var theStartTIme int64
  2654. if len(startTime) > 0 {
  2655. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2656. if err != nil {
  2657. theStartTIme = 0
  2658. }
  2659. theStartTIme = theTime.Unix()
  2660. }
  2661. var theEndtTIme int64
  2662. if len(endTime) > 0 {
  2663. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2664. if err != nil {
  2665. theEndtTIme = 0
  2666. }
  2667. theEndtTIme = theTime.Unix()
  2668. }
  2669. adminUserInfo := c.GetMobileAdminUserInfo()
  2670. edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
  2671. c.ServeSuccessJSON(map[string]interface{}{
  2672. "total": total,
  2673. "edus": edus,
  2674. })
  2675. return
  2676. }
  2677. func (c *PatientApiController) GetPatientSchedulesList() {
  2678. patientID, _ := c.GetInt64("patient_id", 0)
  2679. page, _ := c.GetInt64("page", 0)
  2680. limit, _ := c.GetInt64("limit", 0)
  2681. if patientID <= 0 {
  2682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2683. return
  2684. }
  2685. adminUserInfo := c.GetMobileAdminUserInfo()
  2686. todayTime := time.Now().Format("2006-01-02")
  2687. timeLayout := "2006-01-02 15:04:05"
  2688. loc, _ := time.LoadLocation("Local")
  2689. var theStartTime int64
  2690. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2691. theStartTime = theTime.Unix()
  2692. schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
  2693. if len(schedules) > 0 {
  2694. for index, item := range schedules {
  2695. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2696. schedules[index].Week = int64(week)
  2697. }
  2698. }
  2699. c.ServeSuccessJSON(map[string]interface{}{
  2700. "schedules": schedules,
  2701. })
  2702. return
  2703. }
  2704. func (c *PatientApiController) GetRecords() {
  2705. patientID, _ := c.GetInt64("patient_id", 0)
  2706. page, _ := c.GetInt64("page", 0)
  2707. limit, _ := c.GetInt64("limit", 0)
  2708. startTime := c.GetString("start_time", "")
  2709. endTime := c.GetString("end_time", "")
  2710. mode_id, _ := c.GetInt64("mode_id", 0)
  2711. if page <= 0 {
  2712. page = 1
  2713. }
  2714. if limit <= 0 {
  2715. limit = 10
  2716. }
  2717. if patientID <= 0 {
  2718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2719. return
  2720. }
  2721. timeLayout := "2006-01-02"
  2722. loc, _ := time.LoadLocation("Local")
  2723. var theStartTIme int64
  2724. if len(startTime) > 0 {
  2725. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2726. if err != nil {
  2727. theStartTIme = 0
  2728. }
  2729. theStartTIme = theTime.Unix()
  2730. }
  2731. var theEndtTIme int64
  2732. if len(endTime) > 0 {
  2733. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2734. if err != nil {
  2735. theEndtTIme = 0
  2736. }
  2737. theEndtTIme = theTime.Unix()
  2738. }
  2739. adminUserInfo := c.GetMobileAdminUserInfo()
  2740. records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2741. c.ServeSuccessJSON(map[string]interface{}{
  2742. "total": total,
  2743. "records": records,
  2744. })
  2745. return
  2746. }
  2747. func (c *PatientApiController) GetPatientMonitor() {
  2748. partition, _ := c.GetInt64("partition")
  2749. monitorDate := c.GetString("date")
  2750. patient_id, _ := c.GetInt64("patient_id")
  2751. timeLayout := "2006-01-02"
  2752. loc, _ := time.LoadLocation("Local")
  2753. var theStartTime int64
  2754. if len(monitorDate) > 0 {
  2755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  2756. if err != nil {
  2757. theStartTime = 0
  2758. }
  2759. theStartTime = theTime.Unix()
  2760. }
  2761. adminInfo := c.GetMobileAdminUserInfo()
  2762. orgID := adminInfo.Org.Id
  2763. monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
  2764. if err != nil {
  2765. c.ErrorLog("获取排班信息失败:%v", err)
  2766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2767. } else {
  2768. if len(monitor) > 0 {
  2769. //获取所有床位
  2770. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  2771. //获取所有分区
  2772. zoneList, _ := service.GetAllZoneByList(orgID)
  2773. //获取透析处方
  2774. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  2775. //获取透前评估
  2776. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  2777. //获取上机
  2778. dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
  2779. //获取透后
  2780. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  2781. //获取透后监测
  2782. monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
  2783. //获取所有的患者
  2784. patients, _ := service.GetAllPatientListByListOne(orgID)
  2785. //获取所有透析模式
  2786. treatments, _ := service.GetAllTreatModeByList(orgID)
  2787. for key, item := range monitor {
  2788. // 获取床位信息
  2789. for _, it := range numberList {
  2790. if item.BedId == it.ID {
  2791. monitor[key].DeviceNumber = it
  2792. break
  2793. }
  2794. }
  2795. //获取分区信息
  2796. for _, it := range zoneList {
  2797. if item.PartitionId == it.ID {
  2798. monitor[key].DeviceZone = it
  2799. }
  2800. }
  2801. for _, prescription := range prescriptions {
  2802. if item.PatientId == prescription.PatientId {
  2803. monitor[key].Prescription = prescription
  2804. break
  2805. }
  2806. }
  2807. // 透前评估
  2808. for _, assessmentBefore := range assessmentBefores {
  2809. if item.PatientId == assessmentBefore.PatientId {
  2810. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  2811. break
  2812. }
  2813. }
  2814. // 透析上下机
  2815. for _, dialysisOrder := range dialysisOrders {
  2816. if item.PatientId == dialysisOrder.PatientId {
  2817. monitor[key].DialysisOrder = dialysisOrder
  2818. break
  2819. }
  2820. }
  2821. // 治疗小节
  2822. for _, afterDislysis := range AssessmentAfterDislysis {
  2823. if item.PatientId == afterDislysis.PatientId {
  2824. monitor[key].AssessmentAfterDislysis = afterDislysis
  2825. break
  2826. }
  2827. }
  2828. for _, it := range monitorlist {
  2829. if item.PatientId == it.PatientId {
  2830. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  2831. }
  2832. }
  2833. for _, patient := range patients {
  2834. if item.PatientId == patient.ID {
  2835. monitor[key].MonitorPatients = patient
  2836. break
  2837. }
  2838. }
  2839. for _, treatment := range treatments {
  2840. if item.ModeId == treatment.ID {
  2841. monitor[key].TreatmentMode = treatment
  2842. break
  2843. }
  2844. }
  2845. }
  2846. }
  2847. }
  2848. //获取患者的透析次数
  2849. count, err := service.GetDialysisCount(orgID, partition)
  2850. patients, err := service.GetAllpatientThirty(orgID)
  2851. if err == nil {
  2852. c.ServeSuccessJSON(map[string]interface{}{
  2853. "monitor": monitor,
  2854. "patientCount": count,
  2855. "patients": patients,
  2856. })
  2857. } else {
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2859. }
  2860. }
  2861. // /m/api/monitor/patient [get] 搜索病人的测量记录
  2862. // @param keyword:string 病人姓名或透析号
  2863. // @param page:int
  2864. func (this *PatientApiController) SearchMonitorPatient() {
  2865. keyword := this.GetString("keyword")
  2866. page, _ := this.GetInt("page")
  2867. if page <= 0 {
  2868. page = 1
  2869. }
  2870. if len(keyword) == 0 {
  2871. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2872. return
  2873. }
  2874. adminUserInfo := this.GetMobileAdminUserInfo()
  2875. monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
  2876. if getMonitorErr != nil {
  2877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2878. return
  2879. } else {
  2880. this.ServeSuccessJSON(map[string]interface{}{
  2881. "monitor": monitors,
  2882. })
  2883. }
  2884. }
  2885. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  2886. id, _ := c.GetInt64("id", 0)
  2887. page, _ := c.GetInt64("page", 0)
  2888. limit, _ := c.GetInt64("limit", 0)
  2889. if id <= 0 {
  2890. c.ServeSuccessJSON(map[string]interface{}{
  2891. "solutions": nil,
  2892. })
  2893. return
  2894. }
  2895. if page <= 0 {
  2896. page = 1
  2897. }
  2898. if limit <= 0 {
  2899. limit = 10
  2900. }
  2901. adminInfo := c.GetMobileAdminUserInfo()
  2902. solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
  2903. c.ServeSuccessJSON(map[string]interface{}{
  2904. "solutions": solutions,
  2905. "total": total,
  2906. })
  2907. return
  2908. }
  2909. // GetDoctorAdvices 医嘱列表
  2910. func (c *PatientApiController) GetDoctorAdvices() {
  2911. id, _ := c.GetInt64("id", 0)
  2912. adviceType, _ := c.GetInt64("advice_type", 0)
  2913. stopType, _ := c.GetInt64("stop_state", 0)
  2914. startTime := c.GetString("start_time", "")
  2915. endTime := c.GetString("end_time", "")
  2916. keywords := c.GetString("keywords", "")
  2917. need, _ := c.GetInt64("need_doctor", 0)
  2918. adminUserInfo := c.GetMobileAdminUserInfo()
  2919. timeLayout := "2006-01-02"
  2920. loc, _ := time.LoadLocation("Local")
  2921. var theStartTIme int64
  2922. if len(startTime) > 0 {
  2923. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2924. if err != nil {
  2925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2926. return
  2927. }
  2928. theStartTIme = theTime.Unix()
  2929. }
  2930. var theEndtTIme int64
  2931. if len(endTime) > 0 {
  2932. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2933. if err != nil {
  2934. utils.ErrorLog(err.Error())
  2935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2936. return
  2937. }
  2938. theEndtTIme = theTime.Unix()
  2939. }
  2940. advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
  2941. if need == 1 {
  2942. users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2943. c.ServeSuccessJSON(map[string]interface{}{
  2944. "advices": advices,
  2945. "total": total,
  2946. "users": users,
  2947. })
  2948. } else {
  2949. c.ServeSuccessJSON(map[string]interface{}{
  2950. "advices": advices,
  2951. "total": total,
  2952. "users": []string{},
  2953. })
  2954. }
  2955. return
  2956. }
  2957. func (c *PatientApiController) GetPrintDialysisOrder() {
  2958. xtno := c.GetString("xtno")
  2959. xtdate := c.GetString("xtdate")
  2960. timeLayout := "2006-01-02"
  2961. loc, _ := time.LoadLocation("Local")
  2962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  2963. if err != nil {
  2964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2965. return
  2966. }
  2967. xttime := theTime.Unix()
  2968. //获取当前日期月份的第一天
  2969. firstmonth := service.GetFirstDateOfMonth(theTime)
  2970. firstMonthDate := firstmonth.Unix()
  2971. operatorIDs := make([]int64, 0)
  2972. adminUserInfo := c.GetMobileAdminUserInfo()
  2973. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
  2974. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
  2975. //透析单
  2976. dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2977. if dialysisOrder != nil {
  2978. if dialysisOrder.FinishNurse > 0 {
  2979. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  2980. }
  2981. if dialysisOrder.StartNurse > 0 {
  2982. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  2983. }
  2984. }
  2985. last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2986. //透前评估
  2987. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2988. //透后评估
  2989. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2990. if AssessmentAfterDislysis.Modifier > 0 {
  2991. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  2992. }
  2993. //透析处方
  2994. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2995. if dialysisPrescription.PrescriptionDoctor > 0 {
  2996. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  2997. }
  2998. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  2999. patientInfo.TotalDialysis = dialysis_count
  3000. //临时医嘱
  3001. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3002. fmt.Println("DoctorAdvice3223323323232323223323323223332232332wode", DoctorAdvice)
  3003. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3004. config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
  3005. project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
  3006. projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3007. if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3008. for _, item := range projects {
  3009. cnt, _ := strconv.ParseFloat(item.Count, 64)
  3010. var advice models.HisDoctorAdviceInfo
  3011. advice.ID = item.ID
  3012. advice.Checker = item.Checker
  3013. advice.CheckTime = item.CheckTime
  3014. advice.CheckState = item.CheckState
  3015. advice.ExecutionState = item.ExecutionState
  3016. advice.ExecutionStaff = item.ExecutionStaff
  3017. //advice.PrescribingNumber = float64(item.Count)
  3018. advice.PrescribingNumber = cnt
  3019. advice.PrescribingNumberUnit = item.Unit
  3020. advice.AdviceDoctor = item.Doctor
  3021. if item.Type == 3 {
  3022. advice.AdviceName = item.GoodInfo.GoodName
  3023. advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
  3024. } else if item.Type == 2 {
  3025. advice.AdviceName = item.HisProject.ProjectName
  3026. }
  3027. advice.StartTime = item.StartTime
  3028. hisAdvice = append(hisAdvice, &advice)
  3029. }
  3030. }
  3031. if len(DoctorAdvice) > 0 {
  3032. for _, item := range DoctorAdvice {
  3033. if item.AdviceDoctor > 0 {
  3034. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3035. }
  3036. if item.ExecutionStaff > 0 {
  3037. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3038. }
  3039. if item.Checker > 0 {
  3040. operatorIDs = append(operatorIDs, item.Checker)
  3041. }
  3042. }
  3043. }
  3044. //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3045. //透析监测
  3046. Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3047. //透析小结
  3048. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3049. //接诊评估
  3050. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3051. //相关操作对应的操作人
  3052. //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
  3053. operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
  3054. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3055. check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3056. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
  3057. lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3058. if config.IsOpen == 1 {
  3059. c.ServeSuccessJSON(map[string]interface{}{
  3060. "users": adminUser,
  3061. "patientInfo": patientInfo,
  3062. "PredialysisEvaluation": PredialysisEvaluation,
  3063. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3064. "dialysisPrescription": dialysisPrescription,
  3065. "advices": hisAdvice,
  3066. "monitors": Record,
  3067. "summary": TreatmentSummary,
  3068. "receiverTreatmentAccess": receiverTreatmentAccess,
  3069. "dialysisOrder": dialysisOrder,
  3070. "operators": operators,
  3071. "org_template_info": templateInfo,
  3072. "check": check,
  3073. "dialysiscount": dialysiscount,
  3074. "last_order": last_order,
  3075. "projects": projects,
  3076. "project_config": project_config,
  3077. "lastWeight": lastWeight,
  3078. })
  3079. }
  3080. if config.IsOpen == 0 || config.IsOpen == 2 {
  3081. c.ServeSuccessJSON(map[string]interface{}{
  3082. "users": adminUser,
  3083. "patientInfo": patientInfo,
  3084. "PredialysisEvaluation": PredialysisEvaluation,
  3085. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3086. "dialysisPrescription": dialysisPrescription,
  3087. "advices": DoctorAdvice,
  3088. "monitors": Record,
  3089. "summary": TreatmentSummary,
  3090. "receiverTreatmentAccess": receiverTreatmentAccess,
  3091. "dialysisOrder": dialysisOrder,
  3092. "operators": operators,
  3093. "org_template_info": templateInfo,
  3094. "check": check,
  3095. "dialysiscount": dialysiscount,
  3096. "last_order": last_order,
  3097. "projects": projects,
  3098. "project_config": project_config,
  3099. "lastWeight": lastWeight,
  3100. })
  3101. }
  3102. }
  3103. func (c *PatientApiController) CreateGroupAdvice() {
  3104. is_child, _ := c.GetInt64("is_child", 0)
  3105. if is_child == 1 {
  3106. patient, _ := c.GetInt64("id", 0)
  3107. if patient <= 0 {
  3108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3109. return
  3110. }
  3111. adminUserInfo := c.GetMobileAdminUserInfo()
  3112. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3113. if patientInfo.ID == 0 {
  3114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3115. return
  3116. }
  3117. group_no, _ := c.GetInt64("group_no")
  3118. if group_no <= 0 {
  3119. group_no = 0
  3120. }
  3121. dataBody := make(map[string]interface{}, 0)
  3122. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3123. if err != nil {
  3124. utils.ErrorLog(err.Error())
  3125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3126. return
  3127. }
  3128. timeLayout := "2006-01-02"
  3129. loc, _ := time.LoadLocation("Local")
  3130. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3131. utils.ErrorLog("advice_type")
  3132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3133. return
  3134. }
  3135. adviceType := int64(dataBody["advice_type"].(float64))
  3136. if adviceType != 1 && adviceType != 2 {
  3137. utils.ErrorLog("advice_type != 1&&2")
  3138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3139. return
  3140. }
  3141. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3142. utils.ErrorLog("start_time")
  3143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3144. return
  3145. }
  3146. startTime2, _ := dataBody["start_time"].(string)
  3147. time_arr := strings.Split(startTime2, " ")
  3148. if len(time_arr) > 0 {
  3149. startTime2 = time_arr[0]
  3150. }
  3151. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3152. utils.ErrorLog("advice_date")
  3153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3154. return
  3155. }
  3156. adviceDate := startTime2
  3157. if len(adviceDate) == 0 {
  3158. utils.ErrorLog("len(adviceDate) == 0")
  3159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3160. return
  3161. }
  3162. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3163. if err != nil {
  3164. utils.ErrorLog(err.Error())
  3165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3166. return
  3167. }
  3168. AdviceDate := theTime.Unix()
  3169. RecordDate := theTime.Unix()
  3170. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3171. utils.ErrorLog("start_time")
  3172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3173. return
  3174. }
  3175. startTime, _ := dataBody["start_time"].(string)
  3176. if len(startTime) == 0 {
  3177. utils.ErrorLog("len(start_time) == 0")
  3178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3179. return
  3180. }
  3181. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  3182. if err != nil {
  3183. utils.ErrorLog(err.Error())
  3184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3185. return
  3186. }
  3187. StartTime := theTime.Unix()
  3188. Remark := ""
  3189. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3190. remark, _ := dataBody["remark"].(string)
  3191. Remark = remark
  3192. }
  3193. var advices []*models.GroupAdvice
  3194. // utils.TraceLog("%+v", dataBody["adviceNames"])
  3195. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  3196. utils.ErrorLog("adviceNames")
  3197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3198. return
  3199. }
  3200. adviceNames := dataBody["adviceNames"].([]interface{})
  3201. for _, adviceNameMap := range adviceNames {
  3202. adviceNameM := adviceNameMap.(map[string]interface{})
  3203. var advice models.GroupAdvice
  3204. advice.Remark = Remark
  3205. advice.AdviceType = adviceType
  3206. advice.StartTime = StartTime
  3207. advice.AdviceDate = AdviceDate
  3208. advice.RecordDate = RecordDate
  3209. advice.Status = 1
  3210. advice.CreatedTime = time.Now().Unix()
  3211. advice.UpdatedTime = time.Now().Unix()
  3212. advice.StopState = 2
  3213. advice.ExecutionState = 2
  3214. advice.UserOrgId = adminUserInfo.Org.Id
  3215. advice.PatientId = patientInfo.ID
  3216. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3217. advice.IsSettle = 2
  3218. //入口
  3219. errcode := c.setAdviceWithJSON(&advice, adviceNameM)
  3220. if errcode > 0 {
  3221. c.ServeFailJSONWithSGJErrorCode(errcode)
  3222. return
  3223. }
  3224. if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
  3225. subdrugs := adviceNameM["subdrugs"].([]interface{})
  3226. if len(subdrugs) > 0 {
  3227. for _, subdrug := range subdrugs {
  3228. var s models.GroupAdvice
  3229. s.Remark = Remark
  3230. s.AdviceType = adviceType
  3231. s.StartTime = StartTime
  3232. s.AdviceDate = AdviceDate
  3233. s.RecordDate = RecordDate
  3234. s.Status = 1
  3235. s.CreatedTime = time.Now().Unix()
  3236. s.UpdatedTime = time.Now().Unix()
  3237. s.StopState = 2
  3238. s.ExecutionState = 2
  3239. s.UserOrgId = adminUserInfo.Org.Id
  3240. s.PatientId = patientInfo.ID
  3241. s.AdviceDoctor = adminUserInfo.AdminUser.Id
  3242. s.IsSettle = 2
  3243. errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
  3244. if errcode > 0 {
  3245. c.ServeFailJSONWithSGJErrorCode(errcode)
  3246. return
  3247. }
  3248. advice.Children = append(advice.Children, &s)
  3249. }
  3250. }
  3251. }
  3252. //长沙南雅
  3253. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3254. //查询该患者今日有没有双人核对
  3255. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, RecordDate)
  3256. if check.ID > 0 {
  3257. advice.Checker = check.Modifier
  3258. advice.CheckState = 1
  3259. advice.CheckTime = time.Now().Unix()
  3260. }
  3261. }
  3262. advices = append(advices, &advice)
  3263. }
  3264. newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
  3265. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3266. redis := service.RedisClient()
  3267. //清空key 值
  3268. redis.Set(key, "", time.Second)
  3269. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3270. redis.Set(keyOne, "", time.Second)
  3271. defer redis.Close()
  3272. if createErr != nil {
  3273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3274. return
  3275. }
  3276. c.ServeSuccessJSON(map[string]interface{}{
  3277. "msg": "ok",
  3278. "advices": newAdvices,
  3279. })
  3280. return
  3281. } else if is_child == 2 {
  3282. patient, _ := c.GetInt64("id", 0)
  3283. if patient <= 0 {
  3284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3285. return
  3286. }
  3287. adminUserInfo := c.GetMobileAdminUserInfo()
  3288. patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
  3289. if patientInfo.ID == 0 {
  3290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3291. return
  3292. }
  3293. var advice models.DoctorAdvice
  3294. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  3295. if code > 0 {
  3296. c.ServeFailJSONWithSGJErrorCode(code)
  3297. return
  3298. }
  3299. if advice.ParentId > 0 {
  3300. old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
  3301. if old.ID == 0 || old.PatientId != patient {
  3302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3303. return
  3304. }
  3305. if old.StopState == 1 || old.ExecutionState == 1 {
  3306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3307. return
  3308. }
  3309. if old.ParentId > 0 {
  3310. advice.ParentId = old.ParentId
  3311. }
  3312. advice.StartTime = old.StartTime
  3313. advice.AdviceDoctor = old.AdviceDoctor
  3314. advice.DeliveryWay = old.DeliveryWay
  3315. advice.ExecutionFrequency = old.ExecutionFrequency
  3316. advice.GroupNo = old.GroupNo
  3317. }
  3318. advice.Status = 1
  3319. advice.CreatedTime = time.Now().Unix()
  3320. advice.UpdatedTime = time.Now().Unix()
  3321. advice.StopState = 2
  3322. advice.ExecutionState = 2
  3323. advice.UserOrgId = adminUserInfo.Org.Id
  3324. advice.PatientId = patient
  3325. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3326. advice.IsSettle = 2
  3327. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9671 {
  3328. if advice.PrescribingNumber == 0 {
  3329. advice.PrescribingNumber = 1
  3330. }
  3331. //查询该患者今日有没有双人核对
  3332. check, _ := service.MobileGetDoubleCheckSix(adminUserInfo.Org.Id, patientInfo.ID, advice.AdviceDate)
  3333. if check.ID > 0 {
  3334. advice.Checker = check.Modifier
  3335. advice.CheckState = 1
  3336. advice.CheckTime = time.Now().Unix()
  3337. }
  3338. }
  3339. err := service.CreateDoctorAdvice(&advice)
  3340. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  3341. redis := service.RedisClient()
  3342. //清空key 值
  3343. redis.Set(key, "", time.Second)
  3344. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  3345. redis.Set(keyOne, "", time.Second)
  3346. defer redis.Close()
  3347. if err != nil {
  3348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3349. return
  3350. }
  3351. c.ServeSuccessJSON(map[string]interface{}{
  3352. "msg": "ok",
  3353. "advice": advice,
  3354. })
  3355. return
  3356. }
  3357. }
  3358. func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
  3359. if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
  3360. utils.ErrorLog("advice_name")
  3361. return enums.ErrorCodeParamWrong
  3362. }
  3363. adviceName, _ := json["advice_name"].(string)
  3364. if len(adviceName) == 0 {
  3365. utils.ErrorLog("len(advice_name) == 0")
  3366. return enums.ErrorCodeParamWrong
  3367. }
  3368. advice.AdviceName = adviceName
  3369. adviceDesc, _ := json["advice_desc"].(string)
  3370. advice.AdviceDesc = adviceDesc
  3371. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3372. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3373. advice.DrugSpec = drugSpec
  3374. }
  3375. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3376. remark, _ := json["remark"].(string)
  3377. advice.Remark = remark
  3378. }
  3379. //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
  3380. // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
  3381. // advice.Way = src_type
  3382. //}
  3383. if json["way"] == nil {
  3384. advice.Way = 0
  3385. } else {
  3386. if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
  3387. way := int64(json["way"].(float64))
  3388. advice.Way = way
  3389. }
  3390. }
  3391. if json["drug_id"] == nil {
  3392. advice.DrugId = 0
  3393. } else {
  3394. if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
  3395. drug_id := int64(json["drug_id"].(float64))
  3396. advice.DrugId = drug_id
  3397. }
  3398. }
  3399. if json["drug_name_id"] == nil {
  3400. advice.DrugNameId = 0
  3401. } else {
  3402. if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
  3403. drug_name_id := int64(json["drug_name_id"].(float64))
  3404. advice.DrugNameId = drug_name_id
  3405. }
  3406. }
  3407. if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
  3408. drugSpecUnit, _ := json["drug_spec_unit"].(string)
  3409. advice.DrugSpecUnit = drugSpecUnit
  3410. }
  3411. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3412. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3413. advice.SingleDose = singleDose
  3414. }
  3415. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3416. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3417. advice.SingleDoseUnit = singleDoseUnit
  3418. }
  3419. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3420. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3421. advice.PrescribingNumber = prescribingNumber
  3422. }
  3423. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3424. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3425. advice.PrescribingNumberUnit = prescribingNumberUnit
  3426. }
  3427. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3428. deliveryWay, _ := json["delivery_way"].(string)
  3429. advice.DeliveryWay = deliveryWay
  3430. }
  3431. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3432. executionFrequency, _ := json["execution_frequency"].(string)
  3433. advice.ExecutionFrequency = executionFrequency
  3434. }
  3435. return 0
  3436. }
  3437. func (c *PatientApiController) DelDoctorAdvice() {
  3438. groupno, _ := c.GetInt64("groupno", -1)
  3439. is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
  3440. patient_id, _ := c.GetInt64("patient_id")
  3441. doc_advice_date, _ := c.GetInt64("advice_date")
  3442. redis := service.RedisClient()
  3443. if is_sub == 1 { //是
  3444. advice_id, _ := c.GetInt64("advice_id")
  3445. adminUserInfo := c.GetMobileAdminUserInfo()
  3446. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3447. if advice.ID == 0 {
  3448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3449. return
  3450. }
  3451. advice.Status = 0
  3452. advice.UpdatedTime = time.Now().Unix()
  3453. advice.Modifier = adminUserInfo.AdminUser.Id
  3454. err := service.DeleteDoctorAdvice(&advice)
  3455. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3456. redis.Set(key, "", time.Second)
  3457. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3458. redis.Set(keyTwo, "", time.Second)
  3459. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3460. redis.Set(keyThree, "", time.Second)
  3461. redis.Close()
  3462. if err != nil {
  3463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3464. return
  3465. }
  3466. c.ServeSuccessJSON(map[string]interface{}{
  3467. "msg": "ok",
  3468. })
  3469. return
  3470. } else { //
  3471. var ids []string
  3472. if groupno == 0 {
  3473. advice_id := c.GetString("advice_id")
  3474. ids = strings.Split(advice_id, ",")
  3475. if len(ids) <= 0 {
  3476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3477. return
  3478. }
  3479. }
  3480. if groupno < 0 {
  3481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3482. return
  3483. }
  3484. adminUserInfo := c.GetMobileAdminUserInfo()
  3485. var advice models.DoctorAdvice
  3486. if groupno > 0 {
  3487. advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
  3488. if advice.ID == 0 {
  3489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3490. return
  3491. }
  3492. } else {
  3493. advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
  3494. for _, item := range advices {
  3495. if item.ID == 0 {
  3496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3497. return
  3498. }
  3499. }
  3500. }
  3501. advice.UpdatedTime = time.Now().Unix()
  3502. advice.Status = 0
  3503. advice.GroupNo = groupno
  3504. advice.Modifier = adminUserInfo.AdminUser.Id
  3505. var err error
  3506. if groupno > 0 {
  3507. err = service.DeleteDoctorAdviceByGroupNo(&advice)
  3508. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3509. redis.Set(key, "", time.Second)
  3510. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3511. redis.Set(keyTwo, "", time.Second)
  3512. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3513. redis.Set(keyThree, "", time.Second)
  3514. } else {
  3515. err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
  3516. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
  3517. redis.Set(key, "", time.Second)
  3518. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
  3519. redis.Set(keyTwo, "", time.Second)
  3520. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
  3521. redis.Set(keyThree, "", time.Second)
  3522. redis.Close()
  3523. }
  3524. if err != nil {
  3525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3526. return
  3527. }
  3528. c.ServeSuccessJSON(map[string]interface{}{
  3529. "msg": "ok",
  3530. })
  3531. return
  3532. }
  3533. }
  3534. // /m/api/advice/group/modify_starttime [post]
  3535. // @param group_no:int
  3536. // @param start_time:string yyyy-MM-dd hh:mm:ss
  3537. func (this *PatientApiController) ModifyAdviceGroupStartTime() {
  3538. group_no, _ := this.GetInt64("group_no")
  3539. start_time_str := this.GetString("start_time")
  3540. if group_no <= 0 || len(start_time_str) == 0 {
  3541. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3542. return
  3543. }
  3544. startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
  3545. if parseTimeErr != nil {
  3546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
  3547. return
  3548. }
  3549. adminUserInfo := this.GetMobileAdminUserInfo()
  3550. updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
  3551. if updateStartTimeErr != nil {
  3552. utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
  3553. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3554. return
  3555. }
  3556. this.ServeSuccessJSON(map[string]interface{}{
  3557. "start_time": startTime.Unix(),
  3558. })
  3559. }
  3560. func (this *PatientApiController) DelSubDoctorAdvice() {
  3561. advice_id, _ := this.GetInt64("advice_id")
  3562. adminUserInfo := this.GetMobileAdminUserInfo()
  3563. advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
  3564. if advice.ID == 0 {
  3565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3566. return
  3567. }
  3568. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  3569. // this.ServeFailJSONWithSGJErrorCode(enums. bh)
  3570. // return
  3571. //}
  3572. advice.Status = 0
  3573. advice.UpdatedTime = time.Now().Unix()
  3574. advice.Modifier = adminUserInfo.AdminUser.Id
  3575. err := service.DeleteDoctorAdvice(&advice)
  3576. if err != nil {
  3577. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  3578. return
  3579. }
  3580. this.ServeSuccessJSON(map[string]interface{}{
  3581. "msg": "ok",
  3582. })
  3583. return
  3584. }
  3585. func (this *PatientApiController) GetAdviceUnReadMessage() {
  3586. //adminUserInfo := this.GetMobileAdminUserInfo()
  3587. //service.FindUnReadDoctorAdviceMessage()
  3588. }
  3589. func (this *PatientApiController) GetPatientsByKeyWord() {
  3590. keyWord := this.GetString("keyword")
  3591. adminUserInfo := this.GetMobileAdminUserInfo()
  3592. today := utils.ZeroHourTimeOfDay(time.Now())
  3593. patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
  3594. if err != nil {
  3595. utils.ErrorLog(err.Error())
  3596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3597. return
  3598. }
  3599. this.ServeSuccessJSON(map[string]interface{}{
  3600. "patient": patient,
  3601. })
  3602. }
  3603. func (this *PatientApiController) GetSearchPatient() {
  3604. keyWord := this.GetString("keyword")
  3605. adminUserInfo := this.GetMobileAdminUserInfo()
  3606. patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
  3607. if err != nil {
  3608. utils.ErrorLog(err.Error())
  3609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3610. return
  3611. }
  3612. this.ServeSuccessJSON(map[string]interface{}{
  3613. "patient": patient,
  3614. })
  3615. }
  3616. func (c *PatientApiController) ExecProject() {
  3617. execution_time := c.GetString("execution_time")
  3618. project_id, _ := c.GetInt64("project_id")
  3619. team_id, _ := c.GetInt64("team_id")
  3620. is_check_team, _ := c.GetInt64("is_check_team")
  3621. if len(execution_time) <= 0 {
  3622. utils.ErrorLog("execution_time")
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3624. return
  3625. }
  3626. timeLayout2 := "2006-01-02 15:04:05"
  3627. loc, _ := time.LoadLocation("Local")
  3628. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3629. if errs != nil {
  3630. utils.ErrorLog(errs.Error())
  3631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3632. return
  3633. }
  3634. adminInfo := c.GetMobileAdminUserInfo()
  3635. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3636. if project.Type == 3 {
  3637. good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
  3638. if good.IsUser != 1 {
  3639. //查询开关是否开启
  3640. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  3641. //开关已经开启
  3642. if stockSetting.IsType == 1 {
  3643. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  3644. scheduleDateStart := theTime.Format("2006-01-02")
  3645. timeLayout3 := "2006-01-02"
  3646. loc, _ := time.LoadLocation("Local")
  3647. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  3648. //查询该耗材是否已经出库
  3649. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  3650. if auto.ID == 0 {
  3651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  3652. return
  3653. }
  3654. }
  3655. }
  3656. if good.IsUser == 1 && good.IsWarehouse == 1 {
  3657. //查询开关是否开启
  3658. stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
  3659. //开关已经开启
  3660. if stockSetting.IsType == 1 {
  3661. theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
  3662. scheduleDateStart := theTime.Format("2006-01-02")
  3663. timeLayout3 := "2006-01-02"
  3664. loc, _ := time.LoadLocation("Local")
  3665. execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
  3666. //查询该耗材是否已经出库
  3667. auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
  3668. if auto.ID == 0 {
  3669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
  3670. return
  3671. }
  3672. }
  3673. }
  3674. }
  3675. if project.ExecutionState == 1 {
  3676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  3677. return
  3678. }
  3679. if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
  3680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3681. return
  3682. }
  3683. project.ExecutionState = 1
  3684. project.ExecutionStaff = adminInfo.AdminUser.Id
  3685. project.ExecutionTime = theTime.Unix()
  3686. if team_id == 0 {
  3687. err := service.SaveHisProject(&project)
  3688. if err == nil {
  3689. c.ServeSuccessJSON(map[string]interface{}{
  3690. "project": project,
  3691. })
  3692. } else {
  3693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3694. return
  3695. }
  3696. } else {
  3697. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3698. err := service.SaveHisProject(&project)
  3699. if err == nil {
  3700. c.ServeSuccessJSON(map[string]interface{}{
  3701. "project": project,
  3702. })
  3703. } else {
  3704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3705. return
  3706. }
  3707. } else {
  3708. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3709. var ids []int64
  3710. for _, items := range ps {
  3711. ids = append(ids, items.ID)
  3712. }
  3713. err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
  3714. if err == nil {
  3715. c.ServeSuccessJSON(map[string]interface{}{
  3716. "project": project,
  3717. })
  3718. } else {
  3719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3720. return
  3721. }
  3722. }
  3723. }
  3724. }
  3725. func (c *PatientApiController) CheckProject() {
  3726. adminInfo := c.GetMobileAdminUserInfo()
  3727. project_id, _ := c.GetInt64("project_id")
  3728. team_id, _ := c.GetInt64("team_id")
  3729. is_check_team, _ := c.GetInt64("is_check_team")
  3730. project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
  3731. if project.CheckState == 1 {
  3732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  3733. return
  3734. }
  3735. if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
  3736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  3737. return
  3738. }
  3739. project.Checker = adminInfo.AdminUser.Id
  3740. project.CheckTime = time.Now().Unix()
  3741. project.CheckState = 1
  3742. if team_id == 0 {
  3743. err := service.SaveHisProject(&project)
  3744. if err == nil {
  3745. c.ServeSuccessJSON(map[string]interface{}{
  3746. "msg": "ok",
  3747. "project": project,
  3748. })
  3749. } else {
  3750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3751. return
  3752. }
  3753. } else {
  3754. if is_check_team == 2 { //虽然是组套数据,但不是检验项目
  3755. err := service.SaveHisProject(&project)
  3756. if err == nil {
  3757. c.ServeSuccessJSON(map[string]interface{}{
  3758. "msg": "ok",
  3759. "project": project,
  3760. })
  3761. } else {
  3762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3763. return
  3764. }
  3765. } else {
  3766. ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
  3767. var ids []int64
  3768. for _, items := range ps {
  3769. ids = append(ids, items.ID)
  3770. }
  3771. err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
  3772. if err == nil {
  3773. c.ServeSuccessJSON(map[string]interface{}{
  3774. "project": project,
  3775. })
  3776. } else {
  3777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3778. return
  3779. }
  3780. }
  3781. }
  3782. }