patient_api_controller.go 151KB

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