patient_api_controller.go 153KB

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