patient_api_controller.go 156KB

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