patient_api_controller.go 154KB

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