patient_api_controller.go 156KB

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