patient_api_controller.go 154KB

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