patient_api_controller.go 134KB

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