patient_api_controller.go 152KB

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