patient_api_controller.go 166KB

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