patient_api_controller.go 151KB

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