1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342 |
- package mobile_api_controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "math"
- "strings"
-
- // "fmt"
- "reflect"
- "strconv"
- "time"
- )
-
- type PatientApiController struct {
- MobileBaseAPIAuthController
- }
-
- func (c *PatientApiController) GetPatientInfoWithDiseases() {
- id, _ := c.GetInt64("patient", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- Registrars, err := service.GetAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, patient.RegistrarsId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- if Registrars != nil {
- patient.Registrars = Registrars.Name
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- return
-
- }
-
- func (c *PatientApiController) CreateDialysisSolution() {
- id, _ := c.GetInt64("patient", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- //根据路由来做权限
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
-
- //if template.TemplateId == 2 || template.TemplateId == 6 {
- // if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- // }
- //}
-
- var solution models.DialysisSolution
-
- code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.RegistrarsId = adminUserInfo.AdminUser.Id
- solution.Doctor = adminUserInfo.AdminUser.Id
- solution.Status = 1
- solution.PatientId = id
- solution.CreatedTime = time.Now().Unix()
- solution.UserOrgId = adminUserInfo.Org.Id
- solution.UpdatedTime = time.Now().Unix()
- solution.SubName = ""
- solution.ParentId = 0
-
- err := service.CreatePatientDialysisSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) EditDialysisSolution() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.Org.Id, id)
- if solution.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- //if solution.Doctor != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "update")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- // solution.RegistrarsId = adminUserInfo.AdminUser.Id
- solution.Doctor = adminUserInfo.AdminUser.Id
- solution.Status = 1
- // solution.PatientId = id
- // solution.CreatedTime = time.Now().Unix()
- // solution.UserOrgId = adminUserInfo.Org.Id
- solution.UpdatedTime = time.Now().Unix()
- // solution.SubName = ""
- // solution.ParentId = 0
-
- err := service.UpdatePatientDialysisSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) CreateDoctorAdvice() {
-
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
-
- //if appRole.UserType == 3{
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdvicePermissionDeniedModify)
- // return
- //}
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- var advice models.DoctorAdvice
- code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- if advice.ParentId > 0 {
- old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
- if old.ID == 0 || old.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
- return
- }
-
- if old.StopState == 1 || old.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- if old.ParentId > 0 {
- advice.ParentId = old.ParentId
- }
- advice.StartTime = old.StartTime
- advice.AdviceDoctor = old.AdviceDoctor
- advice.DeliveryWay = old.DeliveryWay
- advice.ExecutionFrequency = old.ExecutionFrequency
- advice.GroupNo = old.GroupNo
-
- }
-
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.Org.Id
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- err := service.CreateDoctorAdvice(&advice)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) EditDoctorAdvice() {
- id, _ := c.GetInt64("id", 0)
- patient_id, _ := c.GetInt64("patient_id")
- doc_advice_date, _ := c.GetInt64("advice_date")
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- redis := service.RedisClient()
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- advice.Status = 1
- advice.UpdatedTime = time.Now().Unix()
- advice.UserOrgId = adminUserInfo.Org.Id
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- //处理修改医嘱开始时间逻辑(不包括子医嘱)
- //1.一组医嘱内只有一条医嘱(不包括子医嘱)的情况下,只需要直接修改医嘱开始时间,不需要重新分配组号
- //2.一组医嘱内有多条医嘱(不包括子医嘱)的情况下,需要为修改的那条医嘱重新分配组号,并修改医嘱开始时间
- var err error
- var isChangeGroup bool
- if advice.ParentId == 0 {
- adviceSlice, _ := service.FindAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
- sourceAdvice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice.ID)
- if len(adviceSlice) == 1 {
- //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要修改子医嘱的开始时间,如果相同直接修改,不需要修改子医嘱的开始时间
- if advice.StartTime == sourceAdvice.StartTime {
- err = service.UpdateDoctorAdvice(&advice)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
-
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- isChangeGroup = false
- } else {
- err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
- isChangeGroup = false
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
-
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- }
- } else if len(adviceSlice) > 1 {
-
- //判断前端上传上来的开始时间和数据库中想要修改的那条医嘱的开始时间是否相同,如果不同,需要重新分配组,如果相同直接修改,不需要分配组
- if advice.StartTime == sourceAdvice.StartTime {
- err = service.UpdateDoctorAdvice(&advice)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
-
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- isChangeGroup = false
-
- } else {
- gruopNo := service.GetMaxAdviceGroupID(adminUserInfo.Org.Id)
- gruopNo = gruopNo + 1
- advice.GroupNo = gruopNo
- err = service.UpdateDoctorAdviceAndSubAdvice(&advice)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
-
- defer redis.Close()
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- isChangeGroup = true
-
- }
- }
- } else {
- isChangeGroup = false
- err = service.UpdateDoctorAdvice(&advice)
- redis := service.RedisClient()
- defer redis.Close()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
- redis.Set(keyOne, "", time.Second)
-
- }
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- if !isChangeGroup {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- "isChange": isChangeGroup, //方便前端处理数据
- })
-
- } else {
- newGroupAdvice, err := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, advice.GroupNo)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": newGroupAdvice,
- "isChange": isChangeGroup, //方便前端处理数据
- })
-
- }
- return
- }
-
- func (c *PatientApiController) StopDoctorAdvice() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- //}
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- if advice.StopState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
- utils.ErrorLog("stop_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stopTime, _ := dataBody["stop_time"].(string)
- if len(stopTime) == 0 {
- utils.ErrorLog("len(stop_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.StopTime = theTime.Unix()
-
- if dataBody["stop_reason"] == nil || reflect.TypeOf(dataBody["stop_reason"]).String() != "string" {
- utils.ErrorLog("stop_reason")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- stopReason, _ := dataBody["stop_reason"].(string)
- if len(stopReason) == 0 {
- utils.ErrorLog("len(stop_reason) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.StopReason = stopReason
-
- advice.Status = 1
- advice.UpdatedTime = time.Now().Unix()
- advice.StopDoctor = adminUserInfo.AdminUser.Id
- advice.StopState = 1
- advice.StopTime = time.Now().Unix()
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- err = service.StopDoctorAdvice(&advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) DeleteDoctorAdvice() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- //}
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- advice.UpdatedTime = time.Now().Unix()
- advice.Status = 0
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- err := service.DeleteDoctorAdvice(&advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) ExecDoctorAdvice() {
- execution_time := c.GetString("execution_time")
-
- origin, _ := c.GetInt64("origin", 0)
- groupno, _ := c.GetInt64("groupno", -1)
-
- if origin != 2 {
- adminUserInfo := c.GetMobileAdminUserInfo()
- execution_staff := adminUserInfo.AdminUser.Id
- var ids []string
- advice_ids := c.GetString("advice_id")
- if groupno == 0 {
- ids = strings.Split(advice_ids, ",")
- }
- if groupno < 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(execution_time) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout2 := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- var advice models.DoctorAdvice
-
- if groupno > 0 {
- advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
- for _, item := range advices {
- if item.ExecutionState == 2 {
- advice = item
- }
- }
- } else {
- advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
- for _, item := range advices {
- if item.ExecutionState == 2 {
- advice = item
- }
- }
- }
-
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- if advice.Checker >= 0 && advice.Checker == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
-
- advices := models.DoctorAdvice{
- ExecutionStaff: execution_staff,
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- if groupno > 0 {
- err = service.ExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
-
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
- theTime := toTime.Format("2006-01-02")
-
- fmt.Println("theTIME", theTime)
- keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- } else {
-
- err = service.BatchExceOldDoctorAdvice(&advices, ids)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
-
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", execution_time)
- theTime := toTime.Format("2006-01-02")
- fmt.Println("theTIME", theTime)
- keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyFour, "", time.Second)
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keySix, "", time.Second)
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
-
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.ExecutionStaff = execution_staff
- advice.ExecutionTime = theTime.Unix()
- advice.ExecutionState = 1
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- //处理出库相关逻辑
-
- //1.判断是否启用药品管理和自备药出库功能
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
-
- //自备药信息
- privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
-
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
- fmt.Println("drugStockConfig.IsOpen32232323232", drugStockConfig.IsOpen)
- if drugStockConfig.IsOpen == 1 {
- if groupno > 0 {
- advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
-
- isHasWay := false //用来判断是否包含来自药品库的医嘱
- for _, item := range advices {
- if item.Way == 1 {
- isHasWay = true
- }
-
- }
-
- if isHasWay {
- var total int64
- var prescribing_number_total int64
- fmt.Println("advicesssssssssssssssss", len(advices))
- for _, item := range advices {
- if item.Way == 1 {
- houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询该药品的剩余库存
- list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //判断单位是否相等
- if medical.MaxUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count * medical.MinNumber
- prescribing_number_total = count * medical.MinNumber
- }
- if medical.MinUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count
- }
-
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- return
- }
-
- if medical.IsUse != 1 {
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- if prescribing_number_total > total {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- }
-
- if prescribing_number_total <= total {
-
- //查询是否出库按钮开启
- adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
- if adviceSetting.IsAdviceOpen == 1 {
- //查询是否出库按钮开启
- prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if prescriptionConfig.IsOpen == 1 {
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
- }
- } else {
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
-
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
- }
- }
- }
- }
-
- }
- } else {
-
- advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
- isHasWay := false //用来判断是否包含来自药品库的医嘱
-
- for _, item := range advices {
- if item.Way == 1 {
- isHasWay = true
- }
- }
-
- if isHasWay {
- var total int64
- var prescribing_number_total int64
- for _, item := range advices {
-
- if item.Way == 1 {
- houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
- //查询该药品的剩余库存
- list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
-
- //判断单位是否相等
- if medical.MaxUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
-
- prescribing_number_total = count * medical.MinNumber
- }
-
- if medical.MinUnit == item.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count
- }
-
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- if medical.IsUse != 1 {
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- if prescribing_number_total > total {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- }
-
- if prescribing_number_total <= total {
- pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
- if medical.IsUse == 2 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
- if its.MaxUnit == baseDrug.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
- if medical.IsUse == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- return
- }
-
- }
- }
- }
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- return
- }
-
- if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
- if groupno > 0 {
- advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
- for _, item := range advices {
-
- if item.ExecutionState == 1 && item.Way == 2 {
- prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
- //插入自备药出库单
- outStock := models.XtSelfOutStock{
- DrugName: item.AdviceName,
- DrugNameId: item.DrugNameId,
- DrugSpec: item.AdviceDesc,
- OutstoreNumber: count,
- AdminUserId: adminUserInfo.AdminUser.Id,
- StorckTime: item.AdviceDate,
- UserOrgId: adminUserInfo.Org.Id,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- PatientId: item.PatientId,
- ExitMode: 2,
- MedicId: item.DrugId,
- StockOutNumber: warehousing_out_order,
- }
- //查询 该患者是否已出库
- out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
-
- if errcode == gorm.ErrRecordNotFound {
- service.CreateOutStock(&outStock)
- } else if errcode == nil {
- err := service.UpdatedSelfOutSatock(out.ID, &outStock)
- fmt.Println("err", err)
- }
- }
- }
- } else {
-
- advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
- for _, item := range advices {
-
- if item.ExecutionState == 1 && item.Way == 2 {
-
- prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
-
- timeStr := time.Now().Format("2006-01-02")
- timeArr := strings.Split(timeStr, "-")
- total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
- number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
- number = number + total
- warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
-
- //插入自备药出库单
- outStock := models.XtSelfOutStock{
- DrugName: item.AdviceName,
- DrugNameId: item.DrugNameId,
- DrugSpec: item.AdviceDesc,
- OutstoreNumber: count,
- AdminUserId: adminUserInfo.AdminUser.Id,
- StorckTime: item.AdviceDate,
- UserOrgId: adminUserInfo.Org.Id,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- PatientId: item.PatientId,
- ExitMode: 2,
- MedicId: item.DrugId,
- StockOutNumber: warehousing_out_order,
- }
-
- //查询 该患者是否已出库
- out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
-
- if errcode == gorm.ErrRecordNotFound {
- service.CreateOutStock(&outStock)
- } else if errcode == nil {
- err := service.UpdatedSelfOutSatock(out.ID, &outStock)
- fmt.Println("err", err)
- }
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- return
- } else if origin == 2 {
- adminInfo := c.GetMobileAdminUserInfo()
- creater := c.GetMobileAdminUserInfo().AdminUser.Id
- var ids []string
- advice_ids := c.GetString("advice_id")
- ids = strings.Split(advice_ids, ",")
- if len(execution_time) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout2 := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
-
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
- var err error
- for _, item := range advices {
- if item.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- if item.Checker >= 0 && item.Checker == adminInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- if item.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
-
- item.ExecutionState = 1
- item.ExecutionStaff = adminInfo.AdminUser.Id
- item.ExecutionTime = theTime.Unix()
- err = service.SaveHisDoctorAdvice(item)
- key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
-
- defer redis.Close()
- }
-
- if err == nil {
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
- storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
- if drugStockConfig.IsOpen == 1 {
- for _, item := range advices {
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(item.DrugId)
- //查询这个患者这个患者这个药已经出库的所有数量
- advicelist, _ := service.GetAllHisDoctorAdviceById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
- drugoutlist, _ := service.GetAllDrugFlowById(item.DrugId, item.PatientId, item.AdviceDate, item.UserOrgId)
- var total_count int64
- var drug_count int64
- for _, it := range advicelist {
- if it.PrescribingNumberUnit == medical.MaxUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
- prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total_count += prenumber * medical.MinNumber
- }
- if it.PrescribingNumberUnit == medical.MinUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(it.PrescribingNumber), 'f', 0, 64)
- prenumber, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total_count += prenumber
- }
-
- }
-
- for _, its := range drugoutlist {
- if its.CountUnit == medical.MaxUnit {
- drug_count += its.Count * medical.MinNumber
- }
- if its.CountUnit == medical.MinUnit {
- drug_count += its.Count
- }
- }
- if total_count == drug_count {
- advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- return
- }
-
- advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
-
- var total int64
- var prescribing_number_total int64
-
- config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
- if config.IsOpen != 1 {
- //查询该药品是否有库存
- houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
- list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId, houseConfig.DrugStorehouseOut)
-
- //判断单位是否相等
- if medical.MaxUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //转化为最小单位
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count * medical.MinNumber
- }
- //fmt.Println("医嘱开的数量", total)
- if medical.MinUnit == advice.PrescribingNumberUnit {
- prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count
- }
-
- if medical.IsUse == 1 {
-
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- }
- if medical.IsUse != 1 {
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- if prescribing_number_total > total {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- "ids": ids,
- })
- return
- }
- }
-
- if prescribing_number_total <= total {
- pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
- if medical.IsUse == 2 {
-
- if config.IsOpen != 1 {
- if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
- service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
- }
- if pharmacyConfig.IsOpen != 1 {
- service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
- }
-
- //更新字典里面的库存
- stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- var sum_count int64
- for _, its := range stockInfo {
- if its.MaxUnit == medical.MaxUnit {
- its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- }
- sum_count += its.StockMaxNumber + its.StockMinNumber
- }
- service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- //剩余库存
- service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- }
-
- }
- }
- }
- //
- //if config.IsOpen == 1 && item.UserOrgId == 10088 {
- //
- // service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
- // //更新字典里面的库存
- // stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
- // var sum_count int64
- // for _, its := range stockInfo {
- // if its.MaxUnit == medical.MaxUnit {
- // its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
- // }
- // sum_count += its.StockMaxNumber + its.StockMinNumber
- // }
- // service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
- // //剩余库存
- // service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
- //}
-
- }
- }
- for _, item := range advices {
- advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, item.ID)
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- "ids": ids,
- })
- }
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
-
- }
- }
-
- func (c *PatientApiController) ModifyExecDoctorAdvice() {
- execution_time := c.GetString("execution_time")
- fmt.Println("execution_time", execution_time)
- groupno, _ := c.GetInt64("groupno", -1)
-
- var ids []string
- if groupno == 0 {
- advice_ids := c.GetString("advice_id")
- ids = strings.Split(advice_ids, ",")
- }
- if groupno < 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(execution_time) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout2 := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- var advice models.DoctorAdvice
-
- if groupno > 0 {
- advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
- for _, item := range advices {
- if item.ExecutionState == 1 {
- advice = item
-
- }
- }
- } else {
- advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
- for _, item := range advices {
- if item.ExecutionState == 1 {
- advice = item
- }
- }
- }
-
- //if advice.ExecutionStaff != adminUserInfo.AdminUser.Id {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
-
- advices := models.DoctorAdvice{
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- if groupno > 0 {
-
- err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- fmt.Println("keyThh322323232323232323223", key)
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- defer redis.Close()
-
- } else {
- err = service.BatchModifyExceOldDoctorAdvice(&advices, ids)
- err = service.ModifyExceDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- fmt.Println("keyTwohh322323232323232323223", key)
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- defer redis.Close()
- }
-
- //判断是否开启his
- errs, config := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
- //如果开启去修改执行时间
- if config.IsOpen == 1 {
- advicesinfo := models.HisDoctorAdviceInfo{
- ExecutionTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- fmt.Println("ids2323232232323", ids)
- var advicehis models.HisDoctorAdviceInfo
- service.ModifyExceDoctorAdviceById(&advicesinfo, ids)
- his_advices, _ := service.FindHisDoctorAdviceByIdOne(adminUserInfo.Org.Id, ids)
- for _, item := range his_advices {
- if item.ExecutionState == 1 {
- advicehis = item
- }
- }
- redis := service.RedisClient()
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.PatientId, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicehis.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- project := models.HisPrescriptionProject{
- ExecutionTime: theTime.Unix(),
- Mtime: time.Now().Unix(),
- }
- service.ModifyHisPrescriptionProject(&project, ids)
-
- keyEnd := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.PatientId, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyEnd, "", time.Second)
- keyFours := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyFours, "", time.Second)
- keyFives := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advicesinfo.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFives, "", time.Second)
- defer redis.Close()
- }
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
- advice.ExecutionTime = theTime.Unix()
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- "ids": ids,
- })
- return
-
- }
-
- func (c *PatientApiController) CheckDoctorAdvice() {
- origin, _ := c.GetInt64("origin", 0)
-
- if origin != 2 {
- groupno, _ := c.GetInt64("groupno", -1)
- var ids []string
- if groupno == 0 {
- advice_ids := c.GetString("advice_id")
- if advice_ids == "" {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- } else {
- ids = strings.Split(advice_ids, ",")
- if len(ids) <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- }
- }
- if groupno < 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- var advice models.DoctorAdvice
-
- if groupno > 0 {
- advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
- for _, item := range advices {
- if item.CheckState == 0 {
- advice = item
- }
- }
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- } else {
- advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
- for _, item := range advices {
- if item.CheckState == 0 {
- advice = item
-
- }
- }
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
- }
-
- checker := adminUserInfo.AdminUser.Id
- theTime := time.Now()
-
- advices := models.DoctorAdvice{
- CheckTime: theTime.Unix(),
- Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- if groupno > 0 {
- err = service.CheckDoctorAdviceByGroupNo(&advices, groupno, adminUserInfo.Org.Id)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- } else {
-
- if len(ids[0]) <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- } else {
- //t := time.Now().Format("2006-01-02")/**/
- //timeLayout2 := "2006-01-02"
- //loc, _ := time.LoadLocation("Local")
- //theTime, _ := time.ParseInLocation(timeLayout2, t, loc)
- err = service.BatchCheckOldDoctorAdvice(&advices, ids, adminUserInfo.Org.Id, advice.AdviceDate)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- }
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
- advice.CheckState = 1
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- } else if origin == 2 {
- adminInfo := c.GetMobileAdminUserInfo()
- var ids []string
- advice_ids := c.GetString("advice_id")
- ids = strings.Split(advice_ids, ",")
- advices, _ := service.FindHisDoctorAdviceByIds(adminInfo.Org.Id, ids)
- var err error
- for _, item := range advices {
- if item.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
- if item.ExecutionStaff >= 0 && item.ExecutionStaff == adminInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
- item.Checker = adminInfo.AdminUser.Id
- item.CheckTime = time.Now().Unix()
- item.CheckState = 1
- err = service.SaveHisDoctorAdvice(item)
- redis := service.RedisClient()
- key := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
- //清空key 值
- redis.Set(key, "", time.Second)
- keyTwo := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- theTime := time.Now()
-
- recordDate := theTime.Format("2006-01-02")
- keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminInfo.Org.Id, 10)
-
- redis.Set(keyFour, "", time.Second)
- keyFive := strconv.FormatInt(adminInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
- redis.Set(keyFive, "", time.Second)
- defer redis.Close()
- }
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advices,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
- return
- }
-
- func (c *PatientApiController) EditAssessmentBeforeDislysis() {
- id, _ := c.GetInt64("patient", 0)
- assessmentDate := c.GetString("assessment_date", "")
- if id <= 0 || len(assessmentDate) != 10 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", assessmentDate+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theAssessmentDateTime := theTime.Unix()
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationSeven(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- if getPEErr != nil {
- c.ErrorLog("获取透前评估失败:%v", getPEErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- //templateInfo,_ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
- var evaluation models.PredialysisEvaluation
- if theEvaluation != nil {
- evaluation = *theEvaluation
- }
-
- code := predialysisEvaluationFormData(&evaluation, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- if theEvaluation == nil {
- evaluation.CreatedTime = time.Now().Unix()
- evaluation.Status = 1
- evaluation.AssessmentDate = theAssessmentDateTime
- evaluation.PatientId = id
- evaluation.UserOrgId = adminUserInfo.Org.Id
- if appRole.UserType == 2 || appRole.UserType == 1 {
- evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
- evaluation.AssessmentTime = time.Now().Unix()
- } else {
- evaluation.Creater = adminUserInfo.AdminUser.Id
- }
- } else {
- evaluation.UpdatedTime = time.Now().Unix()
- evaluation.Evaluator = adminUserInfo.AdminUser.Id
- if appRole.UserType == 2 || appRole.UserType == 1 {
- evaluation.AssessmentDoctor = adminUserInfo.AdminUser.Id
- evaluation.AssessmentTime = time.Now().Unix()
- } else {
- evaluation.Modifier = adminUserInfo.AdminUser.Id
- if evaluation.Creater == 0 {
- evaluation.Creater = adminUserInfo.AdminUser.Id
- }
- }
- }
-
- //新增逻辑
-
- var dewater_amount float64
- dewater_amount = 0
- if evaluation.DryWeight > 0 {
- dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
-
- if template.TemplateId == 17 || template.TemplateId == 22 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 34 || template.TemplateId == 32 {
- dewater_amount = dewater_amount * 1000
-
- }
-
- if dewater_amount <= 0 {
- dewater_amount = 0
- }
- } else {
- dewater_amount = 0
- }
- // 计算透析处方的相关超滤量
- schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.Org.Id, patient.ID, theAssessmentDateTime)
- lastDialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient.ID, adminUserInfo.Org.Id)
- var lastDialysisPrescribe *models.DialysisPrescription
- var dialysisSolution *models.DialysisSolution
- var dialysisPrescribe *models.DialysisPrescription
- var system_dialysisPrescribe *models.SystemPrescription
-
- var mode_id int64
-
- dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
- lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
- if schedual != nil {
- // 获取透析模版
- dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
- system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
-
- mode_id = schedual.ModeId
- } else {
- // 获取透析模版
- dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
-
- if dialysisPrescribe == nil && dialysisSolution != nil {
- mode_id = dialysisSolution.ModeId
- }
-
- if dialysisPrescribe == nil && dialysisSolution == nil {
- mode_id = 0
- }
- }
-
- // 插入透析处方
- if dialysisPrescribe == nil && dialysisSolution != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = dialysisSolution.UserOrgId
- newprescribe.PatientId = dialysisSolution.PatientId
- newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
- newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
- newprescribe.ModeId = dialysisSolution.ModeId
- newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
- newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
- newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
- newprescribe.BloodFilter = dialysisSolution.BloodFilter
- newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
- newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
- newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
- newprescribe.Glucose = dialysisSolution.Glucose
- newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
- newprescribe.Kalium = dialysisSolution.Kalium
- newprescribe.Sodium = dialysisSolution.Sodium
- newprescribe.Calcium = dialysisSolution.Calcium
- newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
- newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
- newprescribe.Conductivity = dialysisSolution.Conductivity
- newprescribe.BodyFluid = dialysisSolution.BodyFluid
- newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
- newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
- newprescribe.BloodAccess = dialysisSolution.BloodAccess
- newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
- newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
- newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
- newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
- newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
- newprescribe.Dialyzer = dialysisSolution.Dialyzer
- newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
- newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
- newprescribe.TargetKtv = dialysisSolution.TargetKtv
-
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = theAssessmentDateTime
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
- newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
- newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
- newprescribe.Remark = lastDialysisPrescription.Remark
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
- newprescribe.ID = dialysisPrescription.ID
-
- if dialysisPrescription.ID == 0 {
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- }
- err := service.AddSigleRecord(&newprescribe)
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- } else {
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- }
- err := service.UpDateDialysisPrescription(&newprescribe)
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
-
- }
-
- if dialysisPrescribe == nil && dialysisSolution == nil {
- if lastDialysisPrescribe != nil {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
- newprescribe.PatientId = lastDialysisPrescribe.PatientId
- newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
- newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
- newprescribe.ModeId = lastDialysisPrescribe.ModeId
- newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
- newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
- newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
- newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
- newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
- newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
- newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
- newprescribe.Glucose = lastDialysisPrescribe.Glucose
- newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
- newprescribe.Kalium = lastDialysisPrescribe.Kalium
- newprescribe.Sodium = lastDialysisPrescribe.Sodium
- newprescribe.Calcium = lastDialysisPrescribe.Calcium
- newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
- newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
- newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
- newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
- newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
- newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
- newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
- newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
- newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
- newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
- newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
- newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
- newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
- newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
- newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = theAssessmentDateTime
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
- newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
- newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
- newprescribe.Remark = lastDialysisPrescription.Remark
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
- newprescribe.ID = dialysisPrescription.ID
- if dialysisPrescription.ID == 0 {
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- }
- err := service.AddSigleRecord(&newprescribe)
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- } else {
- err := service.UpDateDialysisPrescription(&newprescribe)
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- } else if system_dialysisPrescribe != nil {
-
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
- newprescribe.PatientId = id
- newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
- newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
- newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
- newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
- newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
- newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
- newprescribe.ModeId = system_dialysisPrescribe.ModeId
- newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
- newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
- newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
- newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
- newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
- newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
- newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
- newprescribe.Glucose = system_dialysisPrescribe.Glucose
- newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
- newprescribe.Kalium = system_dialysisPrescribe.Kalium
- newprescribe.Sodium = system_dialysisPrescribe.Sodium
- newprescribe.Calcium = system_dialysisPrescribe.Calcium
- newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
- newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
- newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
- newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
- newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
- newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
- newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
- newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
- newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
- newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
- newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
- newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
- newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
- newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
- newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
- newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
- newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
- newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = theAssessmentDateTime
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
- newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
- newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
- newprescribe.Remark = lastDialysisPrescription.Remark
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
- newprescribe.ID = dialysisPrescription.ID
- if dialysisPrescription.ID == 0 {
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- }
- err := service.AddSigleRecord(&newprescribe)
-
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- } else {
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- }
- err := service.UpDateDialysisPrescription(&newprescribe)
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
-
- } else {
- var newprescribe models.DialysisPrescription
- newprescribe.UserOrgId = adminUserInfo.Org.Id
- newprescribe.PatientId = id
- newprescribe.ModeId = mode_id
- newprescribe.CreatedTime = time.Now().Unix()
- newprescribe.UpdatedTime = time.Now().Unix()
- newprescribe.RecordDate = theAssessmentDateTime
- newprescribe.DewaterAmount = dewater_amount
- newprescribe.TargetUltrafiltration = dewater_amount
- newprescribe.Status = 1
-
- _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, theAssessmentDateTime, adminUserInfo.Org.Id)
- newprescribe.ID = dialysisPrescription.ID
- if dialysisPrescription.ID == 0 {
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- }
- err := service.AddSigleRecord(&newprescribe)
-
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- } else {
- if adminUserInfo.Org.Id == 10340 {
- newprescribe.Sodium = 138
- newprescribe.Bicarbonate = 31.1
- newprescribe.DialysateFlow = 500
- }
- err := service.UpDateDialysisPrescription(&newprescribe)
- //获取key,清空redis
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
- redis := service.RedisClient()
-
- //清空key 值
- redis.Set(key, "", time.Second)
-
- keyOne := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- //清空key 值
- redis.Set(keyOne, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
- //清空key 值
- redis.Set(keyTwo, "", time.Second)
-
- keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
- redis.Set(keySix, "", time.Second)
-
- keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":dialysis_prescribe_by_mode"
- redis.Set(keySeven, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- }
- }
- }
-
- // 手动修改透前评估的时候,如果透析处方已经存在,则不修改对应的透析处方
- // if dialysisPrescribe != nil {
- // dialysisPrescribe.UpdatedTime = time.Now().Unix()
- // dialysisPrescribe.RecordDate = theAssessmentDateTime
- // dialysisPrescribe.DewaterAmount = dewater_amount
- // dialysisPrescribe.TargetUltrafiltration = dewater_amount
- // dialysisPrescribe.Status = 1
- // updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
- // if updateErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
- // }
- // }
-
- err = service.UpadatePredialysisEvaluation(&evaluation)
-
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
- redis := service.RedisClient()
- defer redis.Close()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
- redis.Set(keyOne, "", time.Second)
- keyTwo := "scheduals_" + assessmentDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
- redis.Set(keyTwo, "", time.Second)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "evaluation": evaluation,
- })
- return
- }
-
- func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- // if method == "create" {
- if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
- utils.ErrorLog("mode")
- code = enums.ErrorCodeParamWrong
- return
- }
- mode := int64(dataBody["mode"].(float64))
- if mode <= 0 {
- utils.ErrorLog("mode <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ModeId = mode
-
- if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
- utils.ErrorLog("mode_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- modeName, _ := dataBody["mode_name"].(string)
- if len(modeName) == 0 {
- utils.ErrorLog("len(mode_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ModeName = modeName
- solution.Name = modeName
-
- // }
-
- if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
- dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
- solution.DialysisDuration = dialysisDuration
- }
- if dataBody["dialysis_duration"] != nil {
- if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
- dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
- solution.DialysisDuration = dialysisDuration
- } else if reflect.TypeOf(dataBody["dialysis_duration"]).String() == "float64" {
- dialysisDuration := dataBody["dialysis_duration"].(float64)
- solution.DialysisDuration = dialysisDuration
- }
- }
-
- if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
- dialyzer := int64(dataBody["dialyzer"].(float64))
- solution.Dialyzer = dialyzer
- }
-
- if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
- perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
- solution.PerfusionApparatus = perfusionApparatus
- }
-
- if dataBody["blood_flow_volume"] != nil {
- if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
- bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
- solution.BloodFlowVolume = bloodFlowVolume
- } else if reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "float64" {
- bloodFlowVolume := dataBody["blood_flow_volume"].(float64)
- solution.BloodFlowVolume = bloodFlowVolume
- }
- }
-
- if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
- hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
- solution.HemodialysisMachine = hemodialysisMachine
- }
-
- if dataBody["dewater"] != nil {
- if reflect.TypeOf(dataBody["dewater"]).String() == "string" {
- dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
- solution.Dewater = dewater
- } else if reflect.TypeOf(dataBody["dewater"]).String() == "float64" {
- dewater := dataBody["dewater"].(float64)
- solution.Dewater = dewater
- }
- }
-
- if dataBody["replacement_total"] != nil {
- if reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
- replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
- solution.ReplacementTotal = replacementTotal
- } else if reflect.TypeOf(dataBody["replacement_total"]).String() == "float64" {
- replacementTotal := dataBody["replacement_total"].(float64)
- solution.ReplacementTotal = replacementTotal
- }
- }
-
- if dataBody["displace_liqui"] != nil {
- if reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
- displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
- solution.DisplaceLiqui = displaceLiqui
- } else if reflect.TypeOf(dataBody["displace_liqui"]).String() == "float64" {
- displaceLiqui := dataBody["displace_liqui"].(float64)
- solution.DisplaceLiqui = displaceLiqui
- }
- }
-
- if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
- replacementWay := int64(dataBody["replacement_way"].(float64))
- solution.ReplacementWay = replacementWay
- }
-
- if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
- anticoagulant := int64(dataBody["anticoagulant"].(float64))
- solution.Anticoagulant = anticoagulant
- }
-
- if dataBody["anticoagulant_shouji"] != nil {
- if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
- anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
- solution.AnticoagulantShouji = anticoagulantShouji
- } else if reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "float64" {
- anticoagulantShouji := dataBody["anticoagulant_shouji"].(float64)
- solution.AnticoagulantShouji = anticoagulantShouji
- }
- }
-
- if dataBody["anticoagulant_weichi"] != nil {
- if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
- anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- } else if reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "float64" {
- anticoagulantWeichi := dataBody["anticoagulant_weichi"].(float64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- }
- }
-
- if dataBody["anticoagulant_zongliang"] != nil {
- if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
- anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
- solution.AnticoagulantZongliang = anticoagulantZongliang
- } else if reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "float64" {
- anticoagulantZongliang := dataBody["anticoagulant_zongliang"].(float64)
- solution.AnticoagulantZongliang = anticoagulantZongliang
- }
- }
-
- if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
- anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
- solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
- }
-
- if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
- anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
- solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
- }
-
- if dataBody["kalium"] != nil {
- if reflect.TypeOf(dataBody["kalium"]).String() == "string" {
- kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
- solution.Kalium = kalium
- } else if reflect.TypeOf(dataBody["kalium"]).String() == "float64" {
- kalium := dataBody["kalium"].(float64)
- solution.Kalium = kalium
- }
- }
-
- if dataBody["sodium"] != nil {
- if reflect.TypeOf(dataBody["sodium"]).String() == "string" {
- sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
- solution.Sodium = sodium
- } else if reflect.TypeOf(dataBody["sodium"]).String() == "float64" {
- sodium := dataBody["sodium"].(float64)
- solution.Sodium = sodium
- }
- }
-
- if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- if reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
- solution.Calcium = calcium
- } else if reflect.TypeOf(dataBody["calcium"]).String() == "float64" {
- calcium := dataBody["calcium"].(float64)
- solution.Calcium = calcium
- }
- }
-
- if dataBody["bicarbonate"] != nil {
- if reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
- bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
- solution.Bicarbonate = bicarbonate
- } else if reflect.TypeOf(dataBody["bicarbonate"]).String() == "float64" {
- bicarbonate := dataBody["bicarbonate"].(float64)
- solution.Bicarbonate = bicarbonate
- }
- }
-
- if dataBody["glucose"] != nil {
- if reflect.TypeOf(dataBody["glucose"]).String() == "string" {
- glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
- solution.Glucose = glucose
- } else if reflect.TypeOf(dataBody["glucose"]).String() == "float64" {
- glucose := dataBody["glucose"].(float64)
- solution.Glucose = glucose
- }
- }
-
- // if dataBody["dry_weight"] != nil {
- // if reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
- // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
- // solution.DryWeight = dryWeight
- // } else if reflect.TypeOf(dataBody["dry_weight"]).String() == "float64" {
- // dryWeight := dataBody["dry_weight"].(float64)
- // solution.DryWeight = dryWeight
- // }
- // }
-
- if dataBody["dialysate_flow"] != nil {
- if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
- dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
- solution.DialysateFlow = dialysateFlow
- } else if reflect.TypeOf(dataBody["dialysate_flow"]).String() == "float64" {
- dialysateFlow := dataBody["dialysate_flow"].(float64)
- solution.DialysateFlow = dialysateFlow
- }
- }
-
- if dataBody["dialysate_temperature"] != nil {
- if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
- dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
- solution.DialysateTemperature = dialysateTemperature
- } else if reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "float64" {
- dialysateTemperature := dataBody["dialysate_temperature"].(float64)
- solution.DialysateTemperature = dialysateTemperature
- }
- }
-
- if dataBody["conductivity"] != nil {
- if reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
- conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
- solution.Conductivity = conductivity
- } else if reflect.TypeOf(dataBody["conductivity"]).String() == "float64" {
- conductivity := dataBody["conductivity"].(float64)
- solution.Conductivity = conductivity
- }
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark := dataBody["remark"].(string)
- solution.Remark = remark
- }
-
- if dataBody["dialysis_duration_hour"] != nil {
- if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
- dialysisDurationHour, _ := strconv.ParseInt(dataBody["dialysis_duration_hour"].(string), 10, 64)
- solution.DialysisDurationHour = dialysisDurationHour
- } else if reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "float64" {
- dialysisDurationHour := dataBody["dialysis_duration_hour"].(float64)
- solution.DialysisDurationHour = int64(dialysisDurationHour)
- }
- }
-
- if dataBody["dialysis_duration_minute"] != nil {
- if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
- dialysisDurationMinute, _ := strconv.ParseInt(dataBody["dialysis_duration_minute"].(string), 10, 64)
- solution.DialysisDurationMinute = dialysisDurationMinute
- } else if reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "float64" {
- dialysisDurationMinute := dataBody["dialysis_duration_minute"].(float64)
- solution.DialysisDurationMinute = int64(dialysisDurationMinute)
- }
- }
- if dataBody["target_ultrafiltration"] != nil {
- if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
- targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
- solution.TargetUltrafiltration = targetUltrafiltration
- } else if reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "float64" {
- targetUltrafiltration := dataBody["target_ultrafiltration"].(float64)
- solution.TargetUltrafiltration = targetUltrafiltration
- }
- }
-
- if dataBody["dialysate_formulation"] != nil {
- if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "string" {
- dialysateFormulation, _ := strconv.ParseInt(dataBody["dialysate_formulation"].(string), 10, 64)
- solution.DialysateFormulation = dialysateFormulation
- } else if reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
- dialysateFormulation := dataBody["dialysate_formulation"].(float64)
- solution.DialysateFormulation = int64(dialysateFormulation)
- }
- }
-
- return
- }
-
- func predialysisEvaluationFormData(evaluation *models.PredialysisEvaluation, data []byte) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- utils.InfoLog(string(data))
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if dataBody["weight_before"] != nil && reflect.TypeOf(dataBody["weight_before"]).String() == "string" {
- weightVefore, _ := strconv.ParseFloat(dataBody["weight_before"].(string), 64)
- evaluation.WeightBefore = weightVefore
- }
- // fmt.Println(dataBody["dry_weight"])
- // fmt.Println(reflect.TypeOf(dataBody["dry_weight"]).String())
-
- if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
- additionalWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
- fmt.Println(additionalWeight)
- evaluation.DryWeight = additionalWeight
- }
-
- if dataBody["additional_weight"] != nil && reflect.TypeOf(dataBody["additional_weight"]).String() == "string" {
- additionalWeight, _ := strconv.ParseFloat(dataBody["additional_weight"].(string), 64)
- fmt.Println(additionalWeight)
- evaluation.AdditionalWeight = additionalWeight
- }
-
- if dataBody["temperature"] != nil && reflect.TypeOf(dataBody["temperature"]).String() == "string" {
- Temperature, _ := strconv.ParseFloat(dataBody["temperature"].(string), 64)
- evaluation.Temperature = Temperature
- }
-
- if dataBody["systolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["systolic_blood_pressure"]).String() == "string" {
- systolicBloodPressure, _ := strconv.ParseFloat(dataBody["systolic_blood_pressure"].(string), 64)
- evaluation.SystolicBloodPressure = systolicBloodPressure
- }
-
- if dataBody["diastolic_blood_pressure"] != nil && reflect.TypeOf(dataBody["diastolic_blood_pressure"]).String() == "string" {
- diastolicBloodPressure, _ := strconv.ParseFloat(dataBody["diastolic_blood_pressure"].(string), 64)
- evaluation.DiastolicBloodPressure = diastolicBloodPressure
- }
-
- if dataBody["pulse_frequency"] != nil && reflect.TypeOf(dataBody["pulse_frequency"]).String() == "string" {
- pulseFrequency, _ := strconv.ParseFloat(dataBody["pulse_frequency"].(string), 64)
- evaluation.PulseFrequency = pulseFrequency
- }
-
- if dataBody["breathing_rate"] != nil && reflect.TypeOf(dataBody["breathing_rate"]).String() == "string" {
- breathingRate := dataBody["breathing_rate"].(string)
- evaluation.BreathingRate = breathingRate
- }
-
- if dataBody["last_post_dialysis"] != nil && reflect.TypeOf(dataBody["last_post_dialysis"]).String() == "string" {
- lastPostDialysis, _ := dataBody["last_post_dialysis"].(string)
- evaluation.LastPostDialysis = lastPostDialysis
- }
-
- if dataBody["dialysis_interphase"] != nil && reflect.TypeOf(dataBody["dialysis_interphase"]).String() == "string" {
- dialysisInterphase, _ := dataBody["dialysis_interphase"].(string)
- evaluation.DialysisInterphase = dialysisInterphase
- }
-
- if dataBody["symptom_before_dialysis"] != nil && reflect.TypeOf(dataBody["symptom_before_dialysis"]).String() == "string" {
- symptomBeforeDialysis, _ := dataBody["symptom_before_dialysis"].(string)
- evaluation.SymptomBeforeDialysis = symptomBeforeDialysis
- }
-
- if dataBody["catheter"] != nil && reflect.TypeOf(dataBody["catheter"]).String() == "string" {
- catheter, _ := dataBody["catheter"].(string)
- evaluation.Catheter = catheter
- }
-
- if dataBody["catheter_bend"] != nil && reflect.TypeOf(dataBody["catheter_bend"]).String() == "float64" {
- catheter_bend := int(dataBody["catheter_bend"].(float64))
- evaluation.CatheterBend = catheter_bend
- }
-
- if dataBody["complication"] != nil && reflect.TypeOf(dataBody["complication"]).String() == "string" {
- Complication, _ := dataBody["complication"].(string)
- evaluation.Complication = Complication
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark := dataBody["remark"].(string)
- evaluation.Remark = remark
- }
-
- if dataBody["machine_type"] != nil && reflect.TypeOf(dataBody["machine_type"]).String() == "string" {
- machine_type := dataBody["machine_type"].(string)
- evaluation.MachineType = machine_type
- }
-
- if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "string" {
- blood_access_part_id := dataBody["blood_access_part_id"].(string)
- evaluation.BloodAccessPartId = blood_access_part_id
- }
- //if dataBody["blood_access_part_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_id"]).String() == "float64" {
- // blood_access_part_id := int64(dataBody["blood_access_part_id"].(float64))
- // evaluation.BloodAccessPartId = blood_access_part_id
- //}
- if dataBody["blood_access_part_opera_id"] != nil && reflect.TypeOf(dataBody["blood_access_part_opera_id"]).String() == "float64" {
- blood_access_part_opera_id := int64(dataBody["blood_access_part_opera_id"].(float64))
- evaluation.BloodAccessPartOperaId = blood_access_part_opera_id
- }
-
- if dataBody["internal_fistula"] != nil && reflect.TypeOf(dataBody["internal_fistula"]).String() == "string" {
- internal_fistula, _ := dataBody["internal_fistula"].(string)
- evaluation.InternalFistula = internal_fistula
- }
- if dataBody["internal_fistula_skin"] != nil && reflect.TypeOf(dataBody["internal_fistula_skin"]).String() == "string" {
- internal_fistula_skin := dataBody["internal_fistula_skin"].(string)
- evaluation.InternalFistulaSkin = internal_fistula_skin
- }
- if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "string" {
- ishemorrhage, _ := dataBody["is_hemorrhage"].(string)
- is_hemorrhage, _ := strconv.ParseInt(ishemorrhage, 10, 64)
- evaluation.IsHemorrhage = is_hemorrhage
-
- //if dataBody["is_hemorrhage"] != nil && reflect.TypeOf(dataBody["is_hemorrhage"]).String() == "float64" {
- // is_hemorrhage := int64(dataBody["is_hemorrhage"].(float64))
- // fmt.Println("is_hemorrhage2222222222222222",is_hemorrhage)
- if is_hemorrhage != 1 && is_hemorrhage != 2 {
- is_hemorrhage = 0
- }
- evaluation.IsHemorrhage = is_hemorrhage
- if is_hemorrhage == 1 {
- if dataBody["hemorrhage"] != nil && reflect.TypeOf(dataBody["hemorrhage"]).String() == "string" {
- hemorrhage, _ := dataBody["hemorrhage"].(string)
- evaluation.Hemorrhage = hemorrhage
- }
- if dataBody["hemorrhage_other"] != nil && reflect.TypeOf(dataBody["hemorrhage_other"]).String() == "string" {
- hemorrhage_other, _ := dataBody["hemorrhage_other"].(string)
- evaluation.HemorrhageOther = hemorrhage_other
- }
- }
- } else {
- evaluation.IsHemorrhage = 0
- }
-
- if dataBody["blood_access_internal_fistula"] != nil && reflect.TypeOf(dataBody["blood_access_internal_fistula"]).String() == "string" {
- blood_access_internal_fistula, _ := dataBody["blood_access_internal_fistula"].(string)
- evaluation.BloodAccessInternalFistula = blood_access_internal_fistula
- }
-
- if dataBody["internal_fistula_other"] != nil && reflect.TypeOf(dataBody["internal_fistula_other"]).String() == "string" {
- internal_fistula_other, _ := dataBody["internal_fistula_other"].(string)
- evaluation.InternalFistulaOther = internal_fistula_other
- }
-
- if dataBody["blood_access_noise"] != nil && reflect.TypeOf(dataBody["blood_access_noise"]).String() == "float64" {
- blood_access_noise := int64(dataBody["blood_access_noise"].(float64))
- evaluation.BloodAccessNoise = blood_access_noise
- }
-
- if dataBody["puncture_way"] != nil && reflect.TypeOf(dataBody["puncture_way"]).String() == "string" {
- //puncture_way := int64(dataBody["puncture_way"].(float64))
- puncture_way := dataBody["puncture_way"].(string)
- evaluation.PunctureWay = puncture_way
- }
-
- if dataBody["venous_catheterization"] != nil && reflect.TypeOf(dataBody["venous_catheterization"]).String() == "float64" {
- venous_catheterization := int64(dataBody["venous_catheterization"].(float64))
- evaluation.VenousCatheterization = venous_catheterization
- }
-
- if dataBody["venous_catheterization_part"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part"]).String() == "float64" {
- venous_catheterization_part := int64(dataBody["venous_catheterization_part"].(float64))
- evaluation.VenousCatheterizationPart = venous_catheterization_part
- }
-
- if dataBody["venous_catheterization_part_other"] != nil && reflect.TypeOf(dataBody["venous_catheterization_part_other"]).String() == "string" {
- venous_catheterization_part_other, _ := dataBody["venous_catheterization_part_other"].(string)
- evaluation.VenousCatheterizationPartOther = venous_catheterization_part_other
- }
-
- if dataBody["ductus_arantii"] != nil && reflect.TypeOf(dataBody["ductus_arantii"]).String() == "string" {
- ductus_arantii, _ := dataBody["ductus_arantii"].(string)
- evaluation.DuctusArantii = ductus_arantii
- }
-
- if dataBody["emergency_treatment"] != nil && reflect.TypeOf(dataBody["emergency_treatment"]).String() == "float64" {
- emergency_treatment := int64(dataBody["emergency_treatment"].(float64))
- evaluation.EmergencyTreatment = emergency_treatment
- }
- if dataBody["emergency_treatment_other"] != nil && reflect.TypeOf(dataBody["emergency_treatment_other"]).String() == "string" {
- emergency_treatment_other, _ := dataBody["emergency_treatment_other"].(string)
- evaluation.EmergencyTreatmentOther = emergency_treatment_other
- }
-
- if dataBody["dialysis_count"] != nil && reflect.TypeOf(dataBody["dialysis_count"]).String() == "string" {
- dialysis_count, _ := dataBody["dialysis_count"].(string)
- //count, _ := strconv.ParseInt(dialysis_count, 10, 64)
- evaluation.DialysisCount = dialysis_count
- }
-
- if dataBody["is_infect"] != nil && reflect.TypeOf(dataBody["is_infect"]).String() == "string" {
- is_infect, _ := dataBody["is_infect"].(string)
- infect, _ := strconv.ParseInt(is_infect, 10, 64)
- evaluation.IsInfect = infect
- }
-
- if dataBody["exposed"] != nil && reflect.TypeOf(dataBody["exposed"]).String() == "string" {
- exposed, _ := strconv.ParseFloat(dataBody["exposed"].(string), 64)
- evaluation.Exposed = exposed
- }
-
- if dataBody["skin"] != nil && reflect.TypeOf(dataBody["skin"]).String() == "string" {
- skin, _ := dataBody["skin"].(string)
- //skins, _ := strconv.ParseInt(skin, 10, 64)
- evaluation.Skin = skin
- }
-
- if dataBody["skin_other"] != nil && reflect.TypeOf(dataBody["skin_other"]).String() == "string" {
- skin_other, _ := dataBody["skin_other"].(string)
- evaluation.SkinOther = skin_other
- }
-
- if dataBody["infect_other"] != nil && reflect.TypeOf(dataBody["infect_other"]).String() == "string" {
- infect_other, _ := dataBody["infect_other"].(string)
- evaluation.InfectOther = infect_other
- }
-
- if dataBody["ductus_arantii_other"] != nil && reflect.TypeOf(dataBody["ductus_arantii_other"]).String() == "string" {
- ductus_arantii_other, _ := dataBody["ductus_arantii_other"].(string)
- evaluation.DuctusArantiiOther = ductus_arantii_other
- }
-
- if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
- punctureNeedle, _ := dataBody["puncture_needle"].(string)
- evaluation.PunctureNeedle = punctureNeedle
- }
-
- if dataBody["humor_excessive_symptom"] != nil && reflect.TypeOf(dataBody["humor_excessive_symptom"]).String() == "string" {
-
- humor_excessive_symptom, _ := dataBody["humor_excessive_symptom"].(string)
-
- evaluation.HumorExcessiveSymptom = humor_excessive_symptom
- }
-
- if dataBody["pinholing"] != nil && reflect.TypeOf(dataBody["pinholing"]).String() == "string" {
- pinholing := dataBody["pinholing"].(string)
- evaluation.Phinholing = pinholing
- }
-
- if dataBody["catheter_suture"] != nil && reflect.TypeOf(dataBody["catheter_suture"]).String() == "string" {
- catheter_suture := dataBody["catheter_suture"].(string)
- evaluation.CatheterSuture = catheter_suture
- }
-
- if dataBody["catheter_suture_other"] != nil && reflect.TypeOf(dataBody["catheter_suture_other"]).String() == "string" {
- catheter_suture_other := dataBody["catheter_suture_other"].(string)
- evaluation.CatheterSutureOther = catheter_suture_other
- }
-
- if dataBody["urine_volume"] != nil && reflect.TypeOf(dataBody["urine_volume"]).String() == "string" {
- urine_volume, _ := strconv.ParseFloat(dataBody["urine_volume"].(string), 64)
- evaluation.UrineVolume = urine_volume
- }
-
- if dataBody["edema"] != nil && reflect.TypeOf(dataBody["edema"]).String() == "string" {
- edema := dataBody["edema"].(string)
- evaluation.Edema = edema
- }
-
- if dataBody["special_treatment"] != nil && reflect.TypeOf(dataBody["special_treatment"]).String() == "string" {
- specialTreatment := dataBody["special_treatment"].(string)
- evaluation.SpecialTreatment = specialTreatment
- }
-
- if dataBody["catheter_maintenance"] != nil && reflect.TypeOf(dataBody["catheter_maintenance"]).String() == "string" {
- catheter_maintenance := dataBody["catheter_maintenance"].(string)
- evaluation.CatheterMaintenance = catheter_maintenance
- }
-
- if dataBody["thromubus_type"] != nil && reflect.TypeOf(dataBody["thromubus_type"]).String() == "float64" {
-
- thromubusType := int64(dataBody["thromubus_type"].(float64))
-
- evaluation.ThromubusType = thromubusType
- }
-
- if dataBody["thrombus_av"] != nil && reflect.TypeOf(dataBody["thrombus_av"]).String() == "string" {
- thrombus_av := dataBody["thrombus_av"].(string)
- evaluation.ThrombusAv = thrombus_av
- }
-
- if dataBody["thromubus_a"] != nil && reflect.TypeOf(dataBody["thromubus_a"]).String() == "string" {
- thromubus_a := dataBody["thromubus_a"].(string)
- evaluation.ThromubusA = thromubus_a
- }
-
- if dataBody["thromubus_v"] != nil && reflect.TypeOf(dataBody["thromubus_v"]).String() == "string" {
- thromubus_v := dataBody["thromubus_v"].(string)
- evaluation.ThromubusV = thromubus_v
- }
-
- if dataBody["dehydration"] != nil && reflect.TypeOf(dataBody["dehydration"]).String() == "string" {
- dehydration := dataBody["dehydration"].(string)
- evaluation.Dehydration = dehydration
- }
-
- if dataBody["period"] != nil && reflect.TypeOf(dataBody["period"]).String() == "float64" {
- period := int64(dataBody["period"].(float64))
- evaluation.Period = period
- }
-
- if dataBody["estimated_food_intake"] != nil && reflect.TypeOf(dataBody["estimated_food_intake"]).String() == "string" {
- estimated_food_intake := dataBody["estimated_food_intake"].(string)
- evaluation.EstimatedFoodIntake = estimated_food_intake
- }
-
- if dataBody["blood_pressure_during_dialysis"] != nil && reflect.TypeOf(dataBody["blood_pressure_during_dialysis"]).String() == "string" {
- blood_pressure_during_dialysis := dataBody["blood_pressure_during_dialysis"].(string)
- evaluation.BloodPressureDuringDialysis = blood_pressure_during_dialysis
- }
-
- if dataBody["pre_dialysis_drugs"] != nil && reflect.TypeOf(dataBody["pre_dialysis_drugs"]).String() == "string" {
- pre_dialysis_drugs := dataBody["pre_dialysis_drugs"].(string)
- evaluation.PreDialysisDrugs = pre_dialysis_drugs
- }
-
- if dataBody["urea_befor"] != nil && reflect.TypeOf(dataBody["urea_befor"]).String() == "string" {
- urea_befor := dataBody["urea_befor"].(string)
- evaluation.UreaBefor = urea_befor
- }
-
- if dataBody["suction"] != nil && reflect.TypeOf(dataBody["suction"]).String() == "string" {
- suction := dataBody["suction"].(string)
-
- evaluation.Suction = suction
- }
- if dataBody["weight_befor_remake"] != nil && reflect.TypeOf(dataBody["weight_befor_remake"]).String() == "string" {
- weight_befor_remake := dataBody["weight_befor_remake"].(string)
-
- evaluation.WeightBeforRemake = weight_befor_remake
- }
-
- if dataBody["height"] != nil && reflect.TypeOf(dataBody["height"]).String() == "string" {
- height := dataBody["height"].(string)
-
- evaluation.Height = height
- }
-
- if dataBody["age"] != nil && reflect.TypeOf(dataBody["age"]).String() == "string" {
- age := dataBody["age"].(string)
-
- evaluation.Age = age
- }
-
- if dataBody["his_department"] != nil && reflect.TypeOf(dataBody["his_department"]).String() == "string" {
- his_department := dataBody["his_department"].(string)
-
- evaluation.HisDepartment = his_department
- }
-
- if dataBody["his_bed"] != nil && reflect.TypeOf(dataBody["his_bed"]).String() == "string" {
- his_bed := dataBody["his_bed"].(string)
-
- evaluation.HisBed = his_bed
- }
- return
- }
-
- func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- isChild := false
-
- if action == "create" {
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceType := int64(dataBody["advice_type"].(float64))
- if adviceType != 1 && adviceType != 2 {
- utils.ErrorLog("advice_type != 1&&2")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceType = adviceType
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceDate, _ := dataBody["advice_date"].(string)
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceDate = theTime.Unix()
- advice.RecordDate = theTime.Unix()
-
- if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
- parentId := int64(dataBody["parent_id"].(float64))
- advice.ParentId = parentId
- if parentId > 0 {
- isChild = true
- }
- }
-
- } else {
- isChild = advice.ParentId > 0
- }
-
- if !isChild {
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- code = enums.ErrorCodeParamWrong
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.StartTime = theTime.Unix()
-
- if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
- deliveryWay, _ := dataBody["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
- executionFrequency, _ := dataBody["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
- }
-
- if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
- deliveryWay, _ := dataBody["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
- executionFrequency, _ := dataBody["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- adviceName, _ := dataBody["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.AdviceName = adviceName
-
- if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
- adviceDsc, _ := dataBody["advice_desc"].(string)
- advice.AdviceDesc = adviceDsc
- }
-
- if dataBody["way"] == nil {
- advice.Way = 0
-
- } else {
- if dataBody["way"] != nil || reflect.TypeOf(dataBody["way"]).String() == "float64" {
- way := int64(dataBody["way"].(float64))
- advice.Way = way
- }
-
- }
-
- if dataBody["drug_id"] == nil {
- advice.DrugId = 0
- } else {
- if dataBody["drug_id"] != nil || reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
- drug_id := int64(dataBody["drug_id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if dataBody["drug_name_id"] == nil {
- advice.DrugNameId = 0
- } else {
- if dataBody["drug_name_id"] != nil || reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(dataBody["drug_name_id"].(float64))
- advice.DrugNameId = drug_name_id
-
- }
- }
-
- if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
-
- if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- advice.Remark = remark
- }
-
- return
- }
-
- func (c *PatientApiController) GetPatientEducation() {
- patientID, _ := c.GetInt64("patient_id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- edus, total, _ := service.GetPatientTreatmentSummaryList(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme)
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "edus": edus,
- })
- return
-
- }
-
- func (c *PatientApiController) GetPatientSchedulesList() {
- patientID, _ := c.GetInt64("patient_id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
- todayTime := time.Now().Format("2006-01-02")
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
- theStartTime = theTime.Unix()
-
- schedules, _ := service.GetPatientScheduleList(adminUserInfo.Org.Id, patientID, page, limit, theStartTime)
- if len(schedules) > 0 {
- for index, item := range schedules {
- _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
- schedules[index].Week = int64(week)
- }
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "schedules": schedules,
- })
- return
- }
-
- func (c *PatientApiController) GetRecords() {
-
- patientID, _ := c.GetInt64("patient_id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- mode_id, _ := c.GetInt64("mode_id", 0)
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- if patientID <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- theStartTIme = 0
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- theEndtTIme = 0
- }
- theEndtTIme = theTime.Unix()
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- records, total, _ := service.GetPatientDialysisRecord(adminUserInfo.Org.Id, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "records": records,
- })
- return
- }
-
- func (c *PatientApiController) GetPatientMonitor() {
- partition, _ := c.GetInt64("partition")
- monitorDate := c.GetString("date")
- patient_id, _ := c.GetInt64("patient_id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTime int64
- if len(monitorDate) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
- if err != nil {
- theStartTime = 0
- }
- theStartTime = theTime.Unix()
- }
- adminInfo := c.GetMobileAdminUserInfo()
- orgID := adminInfo.Org.Id
- monitor, err := service.GetMonitorRecord(orgID, theStartTime, partition, patient_id)
-
- if err != nil {
- c.ErrorLog("获取排班信息失败:%v", err)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- } else {
- if len(monitor) > 0 {
- //获取所有床位
- numberList, _ := service.GetAllDeviceNumberByList(orgID)
- //获取所有分区
- zoneList, _ := service.GetAllZoneByList(orgID)
- //获取透析处方
- prescriptions, _ := service.GetAllPrescriptionByList(orgID, theStartTime)
- //获取透前评估
- assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
- //获取上机
- dialysisOrders, _ := service.GetAllDialysisOrdersByListSix(orgID, theStartTime)
- //获取透后
- AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListOne(orgID, theStartTime)
-
- //获取透后监测
- monitorlist, _ := service.GetAllMonitorList(orgID, theStartTime)
-
- //获取所有的患者
- patients, _ := service.GetAllPatientListByListOne(orgID)
-
- //获取所有透析模式
- treatments, _ := service.GetAllTreatModeByList(orgID)
-
- for key, item := range monitor {
- // 获取床位信息
- for _, it := range numberList {
- if item.BedId == it.ID {
- monitor[key].DeviceNumber = it
- break
- }
- }
-
- //获取分区信息
- for _, it := range zoneList {
- if item.PartitionId == it.ID {
- monitor[key].DeviceZone = it
- }
- }
-
- for _, prescription := range prescriptions {
- if item.PatientId == prescription.PatientId {
- monitor[key].Prescription = prescription
- break
- }
- }
-
- // 透前评估
- for _, assessmentBefore := range assessmentBefores {
- if item.PatientId == assessmentBefore.PatientId {
- monitor[key].AssessmentBeforeDislysis = assessmentBefore
- break
- }
- }
-
- // 透析上下机
- for _, dialysisOrder := range dialysisOrders {
- if item.PatientId == dialysisOrder.PatientId {
- monitor[key].DialysisOrder = dialysisOrder
- break
- }
- }
-
- // 治疗小节
- for _, afterDislysis := range AssessmentAfterDislysis {
- if item.PatientId == afterDislysis.PatientId {
- monitor[key].AssessmentAfterDislysis = afterDislysis
- break
- }
- }
-
- for _, it := range monitorlist {
- if item.PatientId == it.PatientId {
- monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
- }
- }
-
- for _, patient := range patients {
- if item.PatientId == patient.ID {
- monitor[key].MonitorPatients = patient
- break
- }
- }
-
- for _, treatment := range treatments {
- if item.ModeId == treatment.ID {
- monitor[key].TreatmentMode = treatment
- break
- }
- }
- }
- }
-
- }
-
- //获取患者的透析次数
- count, err := service.GetDialysisCount(orgID, partition)
-
- patients, err := service.GetAllpatientThirty(orgID)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "monitor": monitor,
- "patientCount": count,
- "patients": patients,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- }
- }
-
- // /m/api/monitor/patient [get] 搜索病人的测量记录
- // @param keyword:string 病人姓名或透析号
- // @param page:int
- func (this *PatientApiController) SearchMonitorPatient() {
- keyword := this.GetString("keyword")
- page, _ := this.GetInt("page")
- if page <= 0 {
- page = 1
- }
- if len(keyword) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- monitors, getMonitorErr := service.MobileGetMonitorsWithPatient(adminUserInfo.Org.Id, keyword, page)
- if getMonitorErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "monitor": monitors,
- })
- }
- }
-
- func (c *PatientApiController) GetPatientDialysisSolutionList() {
- id, _ := c.GetInt64("id", 0)
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if id <= 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": nil,
- })
- return
- }
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
-
- adminInfo := c.GetMobileAdminUserInfo()
-
- solutions, total, _ := service.GetPatientDialysisSolutionList(adminInfo.Org.Id, id, page, limit)
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": solutions,
- "total": total,
- })
- return
- }
-
- //GetDoctorAdvices 医嘱列表
- func (c *PatientApiController) GetDoctorAdvices() {
- id, _ := c.GetInt64("id", 0)
- adviceType, _ := c.GetInt64("advice_type", 0)
- stopType, _ := c.GetInt64("stop_state", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- keywords := c.GetString("keywords", "")
-
- need, _ := c.GetInt64("need_doctor", 0)
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var theStartTIme int64
- if len(startTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theStartTIme = theTime.Unix()
- }
- var theEndtTIme int64
- if len(endTime) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theEndtTIme = theTime.Unix()
- }
-
- advices, total, _ := service.GetDoctorAdviceList(adminUserInfo.Org.Id, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords)
-
- if need == 1 {
- users, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
- c.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "total": total,
- "users": users,
- })
- } else {
- c.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "total": total,
- "users": []string{},
- })
- }
- return
-
- }
-
- func (c *PatientApiController) GetPrintDialysisOrder() {
- xtno := c.GetString("xtno")
- xtdate := c.GetString("xtdate")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- xttime := theTime.Unix()
- //获取当前日期月份的第一天
- firstmonth := service.GetFirstDateOfMonth(theTime)
- firstMonthDate := firstmonth.Unix()
- operatorIDs := make([]int64, 0)
-
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- adminUser, _ := service.GetAllAdminUsers(adminUserInfo.Org.Id, adminUserInfo.App.Id)
-
- patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.Org.Id, xtno, xttime)
-
- //透析单
- dialysisOrder, _ := service.MobileGetSchedualDialysisRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- if dialysisOrder != nil {
- if dialysisOrder.FinishNurse > 0 {
- operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
- }
- if dialysisOrder.StartNurse > 0 {
- operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
- }
- }
-
- last_order, _ := service.GetLastTimeOrder(adminUserInfo.Org.Id, patientInfo.ID, xttime)
-
- //透前评估
- PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
-
- //透后评估
- AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- if AssessmentAfterDislysis.Modifier > 0 {
- operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
- }
- //透析处方
- dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- if dialysisPrescription.PrescriptionDoctor > 0 {
- operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
- }
-
- dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- patientInfo.TotalDialysis = dialysis_count
-
- //临时医嘱
- DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- fmt.Println("DoctorAdvice3223323323232323223323323223332232332wode", DoctorAdvice)
- hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- config, err := service.GetHisDoctorConfig(adminUserInfo.Org.Id)
-
- project_config, _ := service.GetHisProjectConfig(adminUserInfo.Org.Id)
- projects, _ := service.FindAllHisProjectById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
- for _, item := range projects {
- cnt, _ := strconv.ParseFloat(item.Count, 64)
- var advice models.HisDoctorAdviceInfo
- advice.ID = item.ID
- advice.Checker = item.Checker
- advice.CheckTime = item.CheckTime
- advice.CheckState = item.CheckState
- advice.ExecutionState = item.ExecutionState
- advice.ExecutionStaff = item.ExecutionStaff
- //advice.PrescribingNumber = float64(item.Count)
- advice.PrescribingNumber = cnt
- advice.PrescribingNumberUnit = item.Unit
- advice.AdviceDoctor = item.Doctor
- if item.Type == 3 {
- advice.AdviceName = item.GoodInfo.GoodName
- advice.PrescribingNumberUnit = item.GoodInfo.PackingUnit
- } else if item.Type == 2 {
- advice.AdviceName = item.HisProject.ProjectName
- }
- advice.StartTime = item.StartTime
- hisAdvice = append(hisAdvice, &advice)
- }
-
- }
-
- if len(DoctorAdvice) > 0 {
- for _, item := range DoctorAdvice {
- if item.AdviceDoctor > 0 {
- operatorIDs = append(operatorIDs, item.AdviceDoctor)
- }
- if item.ExecutionStaff > 0 {
- operatorIDs = append(operatorIDs, item.ExecutionStaff)
- }
- if item.Checker > 0 {
- operatorIDs = append(operatorIDs, item.Checker)
- }
- }
- }
-
- //DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
-
- //透析监测
- Record, _ := service.FindAllMonitorRecord(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- //透析小结
- TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
-
- //接诊评估
- receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
-
- //相关操作对应的操作人
- //operators, _ := service.GetAdminUserES(adminUserInfo.Org.Id, adminUserInfo.App.Id, operatorIDs)
- operators, err := service.GetAllStarfEs(adminUserInfo.Org.Id)
- templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
- check, _ := service.FindDoubleCheckById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
-
- dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.Org.Id)
- lastWeight, _ := service.MobileGetLast(adminUserInfo.Org.Id, patientInfo.ID, xttime)
- if config.IsOpen == 1 {
- c.ServeSuccessJSON(map[string]interface{}{
- "users": adminUser,
- "patientInfo": patientInfo,
- "PredialysisEvaluation": PredialysisEvaluation,
- "AssessmentAfterDislysis": AssessmentAfterDislysis,
- "dialysisPrescription": dialysisPrescription,
- "advices": hisAdvice,
- "monitors": Record,
- "summary": TreatmentSummary,
- "receiverTreatmentAccess": receiverTreatmentAccess,
- "dialysisOrder": dialysisOrder,
- "operators": operators,
- "org_template_info": templateInfo,
- "check": check,
- "dialysiscount": dialysiscount,
- "last_order": last_order,
- "projects": projects,
- "project_config": project_config,
- "lastWeight": lastWeight,
- })
- }
-
- if config.IsOpen == 0 || config.IsOpen == 2 {
- c.ServeSuccessJSON(map[string]interface{}{
- "users": adminUser,
- "patientInfo": patientInfo,
- "PredialysisEvaluation": PredialysisEvaluation,
- "AssessmentAfterDislysis": AssessmentAfterDislysis,
- "dialysisPrescription": dialysisPrescription,
- "advices": DoctorAdvice,
- "monitors": Record,
- "summary": TreatmentSummary,
- "receiverTreatmentAccess": receiverTreatmentAccess,
- "dialysisOrder": dialysisOrder,
- "operators": operators,
- "org_template_info": templateInfo,
- "check": check,
- "dialysiscount": dialysiscount,
- "last_order": last_order,
- "projects": projects,
- "project_config": project_config,
- "lastWeight": lastWeight,
- })
- }
-
- }
-
- func (c *PatientApiController) CreateGroupAdvice() {
- is_child, _ := c.GetInt64("is_child", 0)
- if is_child == 1 {
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetMobileAdminUserInfo()
-
- patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- group_no, _ := c.GetInt64("group_no")
- if group_no <= 0 {
- group_no = 0
- }
-
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
- utils.ErrorLog("advice_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceType := int64(dataBody["advice_type"].(float64))
- if adviceType != 1 && adviceType != 2 {
- utils.ErrorLog("advice_type != 1&&2")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime2, _ := dataBody["start_time"].(string)
- time_arr := strings.Split(startTime2, " ")
- if len(time_arr) > 0 {
- startTime2 = time_arr[0]
- }
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceDate := startTime2
- if len(adviceDate) == 0 {
- utils.ErrorLog("len(adviceDate) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- AdviceDate := theTime.Unix()
- RecordDate := theTime.Unix()
-
- if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
- utils.ErrorLog("start_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime, _ := dataBody["start_time"].(string)
- if len(startTime) == 0 {
- utils.ErrorLog("len(start_time) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- StartTime := theTime.Unix()
-
- Remark := ""
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- Remark = remark
- }
-
- var advices []*models.GroupAdvice
- // utils.TraceLog("%+v", dataBody["adviceNames"])
- if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
- utils.ErrorLog("adviceNames")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceNames := dataBody["adviceNames"].([]interface{})
- for _, adviceNameMap := range adviceNames {
- adviceNameM := adviceNameMap.(map[string]interface{})
- var advice models.GroupAdvice
- advice.Remark = Remark
- advice.AdviceType = adviceType
- advice.StartTime = StartTime
- advice.AdviceDate = AdviceDate
- advice.RecordDate = RecordDate
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.Org.Id
- advice.PatientId = patientInfo.ID
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
- advice.IsSettle = 2
- //入口
- errcode := c.setAdviceWithJSON(&advice, adviceNameM)
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- if adviceNameM["subdrugs"] != nil && reflect.TypeOf(adviceNameM["subdrugs"]).String() == "[]interface {}" {
- subdrugs := adviceNameM["subdrugs"].([]interface{})
- if len(subdrugs) > 0 {
- for _, subdrug := range subdrugs {
- var s models.GroupAdvice
- s.Remark = Remark
- s.AdviceType = adviceType
- s.StartTime = StartTime
- s.AdviceDate = AdviceDate
- s.RecordDate = RecordDate
- s.Status = 1
- s.CreatedTime = time.Now().Unix()
- s.UpdatedTime = time.Now().Unix()
- s.StopState = 2
- s.ExecutionState = 2
- s.UserOrgId = adminUserInfo.Org.Id
- s.PatientId = patientInfo.ID
- s.AdviceDoctor = adminUserInfo.AdminUser.Id
- s.IsSettle = 2
- errcode := c.setAdviceWithJSON(&s, subdrug.(map[string]interface{}))
- if errcode > 0 {
- c.ServeFailJSONWithSGJErrorCode(errcode)
- return
- }
-
- advice.Children = append(advice.Children, &s)
- }
- }
- }
-
- advices = append(advices, &advice)
- }
-
- newAdvices, createErr := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, group_no)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
-
- defer redis.Close()
- if createErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": newAdvices,
- })
- return
-
- } else if is_child == 2 {
-
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.Org.Id, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- var advice models.DoctorAdvice
- code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- if advice.ParentId > 0 {
- old, _ := service.FindDoctorAdvice(adminUserInfo.Org.Id, advice.ParentId)
- if old.ID == 0 || old.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
- return
- }
-
- if old.StopState == 1 || old.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- if old.ParentId > 0 {
- advice.ParentId = old.ParentId
- }
- advice.StartTime = old.StartTime
- advice.AdviceDoctor = old.AdviceDoctor
- advice.DeliveryWay = old.DeliveryWay
- advice.ExecutionFrequency = old.ExecutionFrequency
- advice.GroupNo = old.GroupNo
-
- }
-
- advice.Status = 1
- advice.CreatedTime = time.Now().Unix()
- advice.UpdatedTime = time.Now().Unix()
- advice.StopState = 2
- advice.ExecutionState = 2
- advice.UserOrgId = adminUserInfo.Org.Id
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
- advice.IsSettle = 2
- err := service.CreateDoctorAdvice(&advice)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
- redis := service.RedisClient()
- //清空key 值
- redis.Set(key, "", time.Second)
- keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
- redis.Set(keyOne, "", time.Second)
- defer redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
-
- }
-
- }
-
- func (c *PatientApiController) setAdviceWithJSON(advice *models.GroupAdvice, json map[string]interface{}) int {
-
- if json["advice_name"] == nil || reflect.TypeOf(json["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- return enums.ErrorCodeParamWrong
- }
- adviceName, _ := json["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- return enums.ErrorCodeParamWrong
- }
- advice.AdviceName = adviceName
-
- adviceDesc, _ := json["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
-
- if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
- remark, _ := json["remark"].(string)
- advice.Remark = remark
- }
-
- //if json["src_type"] != nil || reflect.TypeOf(json["src_type"]).String() == "float64" {
- // src_type, _ := strconv.ParseInt(json["src_type"].(string),10)
- // advice.Way = src_type
- //}
- if json["way"] == nil {
- advice.Way = 0
-
- } else {
- if json["way"] != nil || reflect.TypeOf(json["way"]).String() == "float64" {
- way := int64(json["way"].(float64))
- advice.Way = way
- }
-
- }
-
- if json["drug_id"] == nil {
- advice.DrugId = 0
- } else {
- if json["drug_id"] != nil || reflect.TypeOf(json["drug_id"]).String() == "float64" {
- drug_id := int64(json["drug_id"].(float64))
- advice.DrugId = drug_id
- }
- }
-
- if json["drug_name_id"] == nil {
- advice.DrugNameId = 0
- } else {
- if json["drug_name_id"] != nil || reflect.TypeOf(json["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(json["drug_name_id"].(float64))
- advice.DrugNameId = drug_name_id
- }
- }
-
- if json["drug_spec_unit"] != nil && reflect.TypeOf(json["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := json["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
-
- if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := json["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
- deliveryWay, _ := json["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
- executionFrequency, _ := json["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
- return 0
- }
-
- func (c *PatientApiController) DelDoctorAdvice() {
- groupno, _ := c.GetInt64("groupno", -1)
- is_sub, _ := c.GetInt64("is_sub", -1) //是否子药
- patient_id, _ := c.GetInt64("patient_id")
- doc_advice_date, _ := c.GetInt64("advice_date")
- redis := service.RedisClient()
- if is_sub == 1 { //是
-
- advice_id, _ := c.GetInt64("advice_id")
- adminUserInfo := c.GetMobileAdminUserInfo()
- advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- advice.Status = 0
- advice.UpdatedTime = time.Now().Unix()
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- err := service.DeleteDoctorAdvice(&advice)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
-
- redis.Set(key, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- redis.Close()
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
-
- return
-
- } else { //
-
- var ids []string
- if groupno == 0 {
- advice_id := c.GetString("advice_id")
- ids = strings.Split(advice_id, ",")
- if len(ids) <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- }
- if groupno < 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetMobileAdminUserInfo()
- var advice models.DoctorAdvice
- if groupno > 0 {
- advice, _ = service.FindDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- } else {
- advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
- for _, item := range advices {
- if item.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- }
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.Status = 0
- advice.GroupNo = groupno
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- var err error
- if groupno > 0 {
-
- err = service.DeleteDoctorAdviceByGroupNo(&advice)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
-
- redis.Set(key, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
-
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- } else {
-
- err = service.BatchDeleteDoctorAdvice(ids, adminUserInfo.AdminUser.Id)
- key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":doctor_advices"
-
- redis.Set(key, "", time.Second)
-
- keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":advice_list_all"
-
- redis.Set(keyTwo, "", time.Second)
- keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(doc_advice_date, 10) + ":his_doctor_advice"
- redis.Set(keyThree, "", time.Second)
- redis.Close()
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
-
- }
-
- }
-
- // /m/api/advice/group/modify_starttime [post]
- // @param group_no:int
- // @param start_time:string yyyy-MM-dd hh:mm:ss
- func (this *PatientApiController) ModifyAdviceGroupStartTime() {
- group_no, _ := this.GetInt64("group_no")
- start_time_str := this.GetString("start_time")
- if group_no <= 0 || len(start_time_str) == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- startTime, parseTimeErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time_str)
- if parseTimeErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamFormatWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
- updateStartTimeErr := service.UpdateAdviceGroupStartTime(adminUserInfo.Org.Id, group_no, startTime.Unix(), adminUserInfo.AdminUser.Id)
- if updateStartTimeErr != nil {
- utils.ErrorLog("修改医嘱分组的开始时间失败:%v", updateStartTimeErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "start_time": startTime.Unix(),
- })
- }
-
- func (this *PatientApiController) DelSubDoctorAdvice() {
- advice_id, _ := this.GetInt64("advice_id")
- adminUserInfo := this.GetMobileAdminUserInfo()
- advice, _ := service.FindOldDoctorAdvice(adminUserInfo.Org.Id, advice_id)
- if advice.ID == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
- // this.ServeFailJSONWithSGJErrorCode(enums. bh)
- // return
- //}
-
- advice.Status = 0
- advice.UpdatedTime = time.Now().Unix()
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- err := service.DeleteDoctorAdvice(&advice)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (this *PatientApiController) GetAdviceUnReadMessage() {
- //adminUserInfo := this.GetMobileAdminUserInfo()
- //service.FindUnReadDoctorAdviceMessage()
-
- }
-
- func (this *PatientApiController) GetPatientsByKeyWord() {
- keyWord := this.GetString("keyword")
- adminUserInfo := this.GetMobileAdminUserInfo()
- today := utils.ZeroHourTimeOfDay(time.Now())
- patient, err := service.GetSchedualPatientByKeyWord(adminUserInfo.Org.Id, keyWord, today.Unix())
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (this *PatientApiController) GetSearchPatient() {
-
- keyWord := this.GetString("keyword")
- adminUserInfo := this.GetMobileAdminUserInfo()
- patient, err := service.GetPatientsByKey(adminUserInfo.Org.Id, keyWord)
- if err != nil {
- utils.ErrorLog(err.Error())
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (c *PatientApiController) ExecProject() {
- execution_time := c.GetString("execution_time")
- project_id, _ := c.GetInt64("project_id")
- team_id, _ := c.GetInt64("team_id")
- is_check_team, _ := c.GetInt64("is_check_team")
-
- if len(execution_time) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- timeLayout2 := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
- theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
- if errs != nil {
- utils.ErrorLog(errs.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminInfo := c.GetMobileAdminUserInfo()
-
- project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
-
- if project.Type == 3 {
- good, _ := service.GetGoodInformationByGoodId(project.ProjectId)
- if good.IsUser != 1 {
-
- //查询开关是否开启
- stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
-
- //开关已经开启
- if stockSetting.IsType == 1 {
- theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
- scheduleDateStart := theTime.Format("2006-01-02")
- timeLayout3 := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
- //查询该耗材是否已经出库
- auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
- if auto.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
- return
- }
- }
- }
-
- if good.IsUser == 1 && good.IsWarehouse == 1 {
-
- //查询开关是否开启
- stockSetting, _ := service.FindStockSettingById(adminInfo.Org.Id)
-
- //开关已经开启
- if stockSetting.IsType == 1 {
- theTime, _ := time.ParseInLocation(timeLayout2, execution_time, loc)
- scheduleDateStart := theTime.Format("2006-01-02")
- timeLayout3 := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- execuTime, _ := time.ParseInLocation(timeLayout3, scheduleDateStart, loc)
- //查询该耗材是否已经出库
- auto, _ := service.GetAutoWarehouseOutList(project.ProjectId, execuTime.Unix(), adminInfo.Org.Id, project.PatientId)
- if auto.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStockExced)
- return
- }
- }
- }
- }
-
- if project.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
- if project.Checker >= 0 && project.Checker == adminInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
- project.ExecutionState = 1
- project.ExecutionStaff = adminInfo.AdminUser.Id
- project.ExecutionTime = theTime.Unix()
- if team_id == 0 {
-
- err := service.SaveHisProject(&project)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "project": project,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
- } else {
- if is_check_team == 2 { //虽然是组套数据,但不是检验项目
-
- err := service.SaveHisProject(&project)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "project": project,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
- } else {
- ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
- var ids []int64
- for _, items := range ps {
- ids = append(ids, items.ID)
- }
- err := service.UpdateTeamProjectExceStatus(ids, adminInfo.AdminUser.Id, theTime.Unix())
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "project": project,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
- }
-
- }
- }
-
- func (c *PatientApiController) CheckProject() {
-
- adminInfo := c.GetMobileAdminUserInfo()
- project_id, _ := c.GetInt64("project_id")
- team_id, _ := c.GetInt64("team_id")
- is_check_team, _ := c.GetInt64("is_check_team")
-
- project, _ := service.FindHisProjectById(adminInfo.Org.Id, project_id)
- if project.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
- if project.ExecutionStaff >= 0 && project.ExecutionStaff == adminInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- project.Checker = adminInfo.AdminUser.Id
- project.CheckTime = time.Now().Unix()
- project.CheckState = 1
- if team_id == 0 {
- err := service.SaveHisProject(&project)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "project": project,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- } else {
- if is_check_team == 2 { //虽然是组套数据,但不是检验项目
- err := service.SaveHisProject(&project)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "project": project,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
-
- } else {
- ps, _ := service.GetCheckTeamProject(team_id, project.PatientId, project.RecordDate, project.UserOrgId)
- var ids []int64
- for _, items := range ps {
- ids = append(ids, items.ID)
- }
- err := service.UpdateTeamProjectCheckStatus(ids, project.PatientId, project.RecordDate, project.UserOrgId, adminInfo.AdminUser.Id, time.Now().Unix())
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "project": project,
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
-
- }
- }
-
- }
-
- }
|