1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516 |
- package controllers
-
- import (
- "Xcx_New/enums"
- "Xcx_New/models"
- "Xcx_New/service"
- "Xcx_New/utils"
- "encoding/json"
- //"github.com/jinzhu/gorm"
- "math"
- "math/rand"
- "reflect"
- "regexp"
- "strconv"
- "strings"
- "time"
-
- "fmt"
-
- "github.com/astaxie/beego"
- )
-
- type PatientApiController struct {
- BaseAuthAPIController
- }
-
- func PatientApiRegistRouters() {
- beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
- beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
- beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
- beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
- beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
- beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
- beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
- beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
- beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
- beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
- beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
- // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
-
- beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
- beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
-
- beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
- beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
- beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
- beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
- beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
- beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
- beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
- beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
- beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
- beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
- beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
- beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
-
- beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
- beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
- beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
- beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
-
- beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
-
- beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
-
- beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
-
- beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
- beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
-
- beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
-
- beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
-
- beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
-
- }
-
- //GetPatientsList 取患者列表
- func (c *PatientApiController) GetPatientsList() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- schedulType, _ := c.GetInt64("schedul_type", 0)
- bindingState, _ := c.GetInt64("binding_state", 0)
- lapseto, _ := c.GetInt64("lapseto", 0)
- source, _ := c.GetInt64("source", 0)
- startTime := c.GetString("start_time", "")
- endTime := c.GetString("end_time", "")
- keywords := c.GetString("keywords", "")
- contagion, _ := c.GetInt64("contagion", 0)
- reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
- isscheduling, _ := c.GetInt64("isscheduling", 0)
- isprescription, _ := c.GetInt64("isprescription", 0)
-
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- var isStartTime bool
- 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
- }
- isStartTime = true
- theStartTIme = theTime.Unix()
- }
- var isEndTime bool
- 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
- }
- isEndTime = true
- theEndtTIme = theTime.Unix()
- }
-
- patients, total, _ := service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- "total": total,
- })
- return
-
- }
-
- //GetPatientTotal
- func (c *PatientApiController) GetPatientTotal() {
- adminUserInfo := c.GetAdminUserInfo()
-
- total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- })
- return
- }
-
- func (c *PatientApiController) GetPatientsAllList() {
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patients": patients,
- "total": total,
- })
- return
- }
-
- //GenerateDialysisNo 生成透析号
- func (c *PatientApiController) GenerateDialysisNo() {
- adminUserInfo := c.GetAdminUserInfo()
-
- dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
- if dialysisNo == 0 {
- dialysisNo = 1
- } else {
- dialysisNo++
- }
- no := strconv.FormatInt(dialysisNo, 10)
-
- rep := 3 - len(no)
-
- if rep > 0 {
- no = strings.Repeat("0", rep) + no
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "no": no,
- })
- return
- }
-
- //CreatePatient 创建患者
- func (c *PatientApiController) CreatePatient() {
- record_date := c.GetString("record_date")
- is_infectious, _ := c.GetInt64("is_infectious")
- remind_cycle, _ := c.GetInt64("remind_cycle")
-
- adminUserInfo := c.GetAdminUserInfo()
- //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
-
- //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
- //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- //}
-
- var patient models.Patients
- contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
- fmt.Println(code)
- fmt.Println(patient)
-
- fmt.Println("contagions是什么", contagions)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
- return
- }
-
- thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
- return
- }
-
- thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
- if thisPatient.ID > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
- return
- }
-
- patient.RemindCycle = remind_cycle
- patient.IsInfectious = is_infectious
- patient.RegistrarsId = adminUserInfo.AdminUser.Id
- patient.Status = 1
- patient.CreatedTime = time.Now().Unix()
- patient.UserOrgId = adminUserInfo.CurrentOrgId
- patient.UpdatedTime = time.Now().Unix()
- patient.BindingState = 2
- // patient.Lapseto = 1
-
- err := service.CreatePatient(&patient, contagions, diseases)
- fmt.Println("创建病人失败err")
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
- return
- }
-
- //获取老表的最后一条数据
- patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
- patientsNew := models.XtPatientsNew{
- UserOrgId: adminUserInfo.CurrentOrgId,
- UserId: 0,
- Avatar: patients.Avatar,
- PatientType: patients.PatientType,
- DialysisNo: patients.DialysisNo,
- AdmissionNumber: patients.AdmissionNumber,
- Source: patients.Source,
- Lapseto: patients.Lapseto,
- PartitionId: patients.PartitionId,
- BedId: patients.BedId,
- Name: patients.Name,
- Alias: patients.Alias,
- Gender: patients.Gender,
- MaritalStatus: patients.MaritalStatus,
- IdCardNo: patients.IdCardNo,
- Birthday: patients.Birthday,
- ReimbursementWayId: patients.ReimbursementWayId,
- HealthCareType: patients.HealthCareType,
- HealthCareNo: patients.HealthCareNo,
- HealthCareDueDate: patients.HealthCareDueDate,
- Height: patients.Height,
- BloodType: patients.BloodType,
- Rh: patients.Rh,
- HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
- EducationLevel: patients.EducationLevel,
- Profession: patients.Profession,
- Phone: patients.Phone,
- HomeTelephone: patients.HomeTelephone,
- RelativePhone: patients.RelativePhone,
- RelativeRelations: patients.RelativeRelations,
- HomeAddress: patients.HomeAddress,
- WorkUnit: patients.WorkUnit,
- UnitAddress: patients.UnitAddress,
- Children: patients.Children,
- ReceivingDate: patients.ReceivingDate,
- IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
- FirstDialysisDate: patients.FirstDialysisDate,
- FirstDialysisHospital: patients.FirstDialysisHospital,
- PredialysisCondition: patients.PredialysisCondition,
- PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
- PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
- HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
- InductionPeriod: patients.InductionPeriod,
- InitialDialysis: patients.InitialDialysis,
- TotalDialysis: patients.TotalDialysis,
- AttendingDoctorId: patients.AttendingDoctorId,
- HeadNurseId: patients.HeadNurseId,
- Evaluate: patients.Evaluate,
- Diagnose: patients.Diagnose,
- Remark: patients.Remark,
- RegistrarsId: patients.RegistrarsId,
- Registrars: patients.Registrars,
- QrCode: patients.QrCode,
- BindingState: patients.BindingState,
- PatientComplains: patients.PatientComplains,
- PresentHistory: patients.PresentHistory,
- PastHistory: patients.PresentHistory,
- Temperature: patients.Temperature,
- Pulse: patients.Pulse,
- Respiratory: patients.Respiratory,
- Sbp: patients.SBP,
- Dbp: patients.DBP,
- Status: patients.Status,
- CreatedTime: patients.CreatedTime,
- UpdatedTime: patients.UpdatedTime,
- Nation: patients.Nation,
- NativePlace: patients.NativePlace,
- Age: patients.Age,
- InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
- IsInfectious: patients.IsInfectious,
- RemindCycle: patients.RemindCycle,
- ResponseResult: patients.ResponseResult,
- IsOpenRemind: patients.IsOpenRemind,
- FirstTreatmentDate: patients.FirstTreatmentDate,
- DialysisAge: patients.DialysisAge,
- ExpenseKind: patients.ExpenseKind,
- TellPhone: patients.TellPhone,
- ContactName: patients.ContactName,
- BloodPatients: 1,
- SlowPatients: 0,
- MemberPatients: 0,
- EcommerPatients: "",
- BloodId: patients.ID,
- SlowId: 0,
- MemberId: 0,
- MemberFistdate: 0,
- MemberPatienttype: 0,
- MemberTreatement: 0,
- EquitmentId: "",
- UserSysBeforeCount: patient.UserSysBeforeCount,
- }
-
- err = service.CreatePatientsNew(&patientsNew)
- fmt.Print("创建失败", err)
-
- if len(record_date) > 0 {
- var recordTime int64
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordTime = theTime.Unix()
- inspections := make([]models.Inspection, 0)
- for _, item := range formItems {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient.ID
- inspection.ProjectId = item.ProjectId
- inspection.ItemId = item.ItemId
- inspection.ItemName = item.ItemName
- inspection.ProjectName = item.ProjectName
- inspection.InspectType = item.RangeType
- inspection.InspectValue = item.Value
- inspection.InspectDate = recordTime
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
- }
- err = service.CreatePatientInspection(inspections)
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
-
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- break
- }
-
- errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
-
- }
-
- redis := service.RedisClient()
- defer redis.Close()
- redis.SAdd("sgj_patient:new_user_set", patient.UserId)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- //EditPatient 修改
- func (c *PatientApiController) EditPatient() {
- id, _ := c.GetInt64("id", 0)
-
- record_date := c.GetString("record_date")
- is_infectious, _ := c.GetInt64("is_infectious")
- remind_cycle, _ := c.GetInt64("remind_cycle")
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
- if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
- return
- }
-
- thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
- if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
- return
- }
-
- patient.UpdatedTime = time.Now().Unix()
- patient.IsInfectious = is_infectious
- patient.RemindCycle = remind_cycle
- err := service.UpdatePatient(&patient, contagions, diseases)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
- return
- }
- ////更新转归状态
- //lapseto := models.PatientLapseto{
- // LapsetoType: patient.Lapseto,
- // LapsetoTime: time.Now().Unix(),
- // UpdatedTime: time.Now().Unix(),
- //}
- //err = service.UpdatePatientLapseto(patient.ID, lapseto)
- //fmt.Println("更新转归失败", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
- return
- }
- patientsNew := models.XtPatientsNew{
- UserOrgId: patient.UserOrgId,
- UserId: patient.UserId,
- Avatar: patient.Avatar,
- PatientType: patient.PatientType,
- DialysisNo: patient.DialysisNo,
- AdmissionNumber: patient.AdmissionNumber,
- Source: patient.Source,
- PartitionId: patient.PartitionId,
- BedId: patient.BedId,
- Name: patient.Name,
- Alias: patient.Alias,
- Gender: patient.Gender,
- MaritalStatus: patient.MaritalStatus,
- IdCardNo: patient.IdCardNo,
- Birthday: patient.Birthday,
- ReimbursementWayId: patient.ReimbursementWayId,
- HealthCareType: patient.HealthCareType,
- HealthCareNo: patient.HealthCareNo,
- HealthCareDueDate: patient.HealthCareDueDate,
- Height: patient.Height,
- BloodType: patient.BloodType,
- Rh: patient.Rh,
- HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
- EducationLevel: patient.EducationLevel,
- Profession: patient.Profession,
- Phone: patient.Phone,
- HomeTelephone: patient.HomeTelephone,
- RelativePhone: patient.RelativePhone,
- RelativeRelations: patient.RelativeRelations,
- HomeAddress: patient.HomeAddress,
- WorkUnit: patient.WorkUnit,
- UnitAddress: patient.UnitAddress,
- Children: patient.Children,
- ReceivingDate: patient.ReceivingDate,
- IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
- FirstDialysisDate: patient.FirstDialysisDate,
- FirstDialysisHospital: patient.FirstDialysisHospital,
- PredialysisCondition: patient.PredialysisCondition,
- PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
- HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
- InductionPeriod: patient.InductionPeriod,
- InitialDialysis: patient.InitialDialysis,
- TotalDialysis: patient.TotalDialysis,
- AttendingDoctorId: patient.AttendingDoctorId,
- HeadNurseId: patient.HeadNurseId,
- Evaluate: patient.Evaluate,
- Diagnose: patient.Diagnose,
- Remark: patient.Remark,
- RegistrarsId: patient.RegistrarsId,
- Registrars: patient.Registrars,
- QrCode: patient.QrCode,
- BindingState: patient.BindingState,
- PatientComplains: patient.PatientComplains,
- PresentHistory: patient.PresentHistory,
- PastHistory: patient.PastHistory,
- Temperature: patient.Temperature,
- Pulse: patient.Pulse,
- Respiratory: patient.Respiratory,
- Sbp: patient.SBP,
- Dbp: patient.DBP,
- Nation: patient.Nation,
- NativePlace: patient.NativePlace,
- Age: patient.Age,
- InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
- IsInfectious: patient.IsInfectious,
- RemindCycle: patient.RemindCycle,
- ResponseResult: patient.ResponseResult,
- IsOpenRemind: patient.IsOpenRemind,
- FirstTreatmentDate: patient.FirstTreatmentDate,
- DialysisAge: patient.DialysisAge,
- ExpenseKind: patient.ExpenseKind,
- TellPhone: patient.TellPhone,
- ContactName: patient.ContactName,
- UpdatedTime: time.Now().Unix(),
- BloodPatients: 1,
- Lapseto: patient.Lapseto,
- }
- // //更新病人ID获取新表病人ID
- err = service.UpdatepatientTwo(&patientsNew, id)
-
- if len(record_date) > 0 {
- var recordTime int64
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- recordTime = theTime.Unix()
- inspections := make([]models.Inspection, 0)
- for _, item := range formItems {
- var inspection models.Inspection
- inspection.OrgId = adminUserInfo.CurrentOrgId
- inspection.PatientId = patient.ID
- inspection.ProjectId = item.ProjectId
- inspection.ItemId = item.ItemId
- inspection.ItemName = item.ItemName
- inspection.ProjectName = item.ProjectName
- inspection.InspectType = item.RangeType
- inspection.InspectValue = item.Value
- inspection.InspectDate = recordTime
- inspection.Status = 1
- inspection.CreatedTime = time.Now().Unix()
- inspection.UpdatedTime = time.Now().Unix()
- inspections = append(inspections, inspection)
- }
- err = service.CreatePatientInspection(inspections)
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
- var record_time int64
- switch remind_cycle {
- case 1: //1个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 1, 0).Unix()
-
- break
- case 2: //2个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 2, 0).Unix()
- break
- case 3: //3个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 3, 0).Unix()
- break
- case 4: //6个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 6, 0).Unix()
- break
- case 5: //12个月
- ts := time.Unix(infectiousRecord.InspectDate, 0)
- record_time = ts.AddDate(0, 12, 0).Unix()
- break
- }
-
- errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
- if errs != nil {
- utils.ErrorLog("更新日期出错:%v", errs)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
-
- }
-
- func (c *PatientApiController) EditLapseto() {
- id, _ := c.GetInt64("id", 0)
-
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- patientBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
- var lapseto models.PatientLapseto
- lapseto.PatientId = patient.ID
-
- if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
- utils.ErrorLog("lapseto_type")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- lapsetoType := int64(patientBody["lapseto_type"].(float64))
- if lapsetoType <= 0 || lapsetoType > 3 {
- utils.ErrorLog("lapsetoType <= 0 || lapsetoType > 3")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- lapseto.LapsetoType = lapsetoType
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
- utils.ErrorLog("lapseto_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
- return
- }
- lapsetoTime, _ := patientBody["lapseto_time"].(string)
- if len(lapsetoTime) == 0 {
- utils.ErrorLog("len(lapsetoTime) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- return
- }
-
- out_reason, _ := patientBody["out_reason"].(string)
-
- //if len(out_reason) == 0 {
- // utils.ErrorLog("len(out_reason) == 0")
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- // return
- //}
-
- lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
- if err != nil {
- utils.ErrorLog("lapsetoTimeUnix")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
- return
- }
- lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
- lapseto.UpdatedTime = time.Now().Unix()
- lapseto.CreatedTime = time.Now().Unix()
- lapseto.Status = 1
- patient.Lapseto = lapseto.LapsetoType
- patient.OutReason = out_reason
- patient.DeathTime = lapsetoTimeUnix.Unix()
- //if patient.Lapseto == 1 {
- // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
- // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
- // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
- // return
- // }
- //}
-
- err = service.EditPatientLapseto(&patient, &lapseto)
-
- if lapseto.LapsetoType == 3 {
- service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
- service.UpdateScheduleItemByPatientId(id)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) GetPatient() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
-
- infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
- diseases := service.GetPatientDiseases(patient.ID)
- contagions := service.GetPatientContagions(patient.ID)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "diseases": diseases,
- "contagions": contagions,
- "infections": infections,
- })
- return
- }
-
- func (c *PatientApiController) CreateDialysisSolution() {
-
- id, _ := c.GetInt64("patient", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
- if patient.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var solution models.DialysisSolution
-
- code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
- //if thisSolution.ID > 0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
- // 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.CurrentOrgId
- 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) UpdateDialysisSolution() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 || solution.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
-
- err := service.UpdatePatientDialysisSolution(&solution)
-
- nowTimeUinx := time.Now()
- today := nowTimeUinx.Format("2006-01-02")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- todayTime, err := time.ParseInLocation(timeLayout, today, loc)
- prescription := models.DialysisPrescription{
- Dialyzer: solution.Dialyzer,
- Anticoagulant: solution.Anticoagulant,
- AnticoagulantShouji: solution.AnticoagulantShouji,
- AnticoagulantWeichi: solution.AnticoagulantWeichi,
- AnticoagulantZongliang: solution.AnticoagulantZongliang,
- ModeId: solution.ModeId,
- DialysisDurationHour: solution.DialysisDurationHour,
- Kalium: solution.Kalium,
- Sodium: solution.Sodium,
- Calcium: solution.Calcium,
- TargetUltrafiltration: solution.TargetUltrafiltration,
- DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
- BloodAccess: solution.BloodAccess,
- DialysateFlow: solution.DialysateFlow,
- DialysateTemperature: solution.DialysateTemperature,
- DialysisIrrigation: solution.DialysisIrrigation,
- DialysisDialyszers: solution.DialysisDialyszers,
- PlasmaSeparator: solution.PlasmaSeparator,
- BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
- OxygenUptake: solution.OxygenUptake,
- OxygenFlow: solution.OxygenFlow,
- OxygenTime: solution.OxygenTime,
- MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
- }
- service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "solution": solution,
- })
- return
- }
-
- func (c *PatientApiController) UpdateDialysisSolutionDetail() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 || solution.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
- solution.AffirmState = 1
-
- 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) 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
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
- stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "solutions": solutions,
- "total": total,
- "stockType": stockType,
- })
- return
- }
- func (c *PatientApiController) DeleteDialysisSolution() {
-
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
- if solution.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
- return
- }
-
- if solution.UseState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
- return
- }
-
- solution.UpdatedTime = time.Now().Unix()
- solution.Status = 0
-
- err := service.DeleteSolution(&solution)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- //GetDryWeights 取患者干体重调整铺
- func (c *PatientApiController) GetDryWeights() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "weights": weights,
- "total": total,
- })
- return
-
- }
-
- func (c *PatientApiController) CreateDryWeights() {
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- var theWeight models.DryWeightAdjust
-
- 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
- }
-
- if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
- theWeight.Weight = weight
-
- // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- // doctor := int64(dataBody["doctor"].(float64))
- // theWeight.Doctor = doctor
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark, _ := dataBody["remark"].(string)
- theWeight.Remark = remark
- }
-
- theWeight.CreatedTime = time.Now().Unix()
- theWeight.UpdatedTime = time.Now().Unix()
- theWeight.Status = 1
- theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
- theWeight.UserOrgId = adminUserInfo.CurrentOrgId
- theWeight.PatientId = patient
- theWeight.Doctor = adminUserInfo.AdminUser.Id
-
- old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
- if old.ID > 0 {
- theWeight.AdjustedValue = theWeight.Weight - old.Weight
- }
-
- err = service.CreateDryWeightAdjust(&theWeight)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "weight": theWeight,
- })
- return
- }
-
- func (c *PatientApiController) CreateGroupAdvice() {
- patient, _ := c.GetInt64("id", 0)
- groupNo, _ := c.GetInt64("groupno", 0)
-
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- 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
- }
- utils.ErrorLog("%v", dataBody)
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- 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 && adviceType != 3 && adviceType != 4 {
- utils.ErrorLog("advice_type != 1&&2")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
- utils.ErrorLog("advice_date")
- 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", 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
- 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.CurrentOrgId
- advice.PatientId = patientInfo.ID
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
- utils.ErrorLog("advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- adviceName, _ := adviceNameM["advice_name"].(string)
- if len(adviceName) == 0 {
- utils.ErrorLog("len(advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- advice.AdviceName = adviceName
-
- if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
- drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
- advice.DrugSpec = drugSpec
- }
-
- if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
- adviceDesc, _ := adviceNameM["advice_desc"].(string)
- advice.AdviceDesc = adviceDesc
- }
-
- if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
-
- template_id, _ := adviceNameM["template_id"].(string)
- advice.TemplateId = template_id
- }
-
- if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
- drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
- advice.DrugSpecUnit = drugSpecUnit
- }
-
- if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
- singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
- advice.SingleDose = singleDose
- }
-
- if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
- singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
- advice.SingleDoseUnit = singleDoseUnit
- }
-
- if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
- prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
- advice.PrescribingNumber = prescribingNumber
- }
-
- if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
- prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
- advice.PrescribingNumberUnit = prescribingNumberUnit
- }
- if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
- deliveryWay, _ := adviceNameM["delivery_way"].(string)
- advice.DeliveryWay = deliveryWay
- }
-
- if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
- way := int64(adviceNameM["way"].(float64))
- advice.Way = way
- }
-
- if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
- drug_id := int64(adviceNameM["drug_id"].(float64))
- advice.DrugId = drug_id
- }
-
- if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
- advice.DrugNameId = drug_name_id
- }
-
- if adviceType == 1 {
-
- if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
- frequency_type := int64(adviceNameM["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
- day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
- advice.DayCount = day_count
- }
-
- if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
- week_day, _ := adviceNameM["week_days"].(string)
- advice.WeekDay = week_day
- }
- }
-
- if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
- executionFrequency, _ := adviceNameM["execution_frequency"].(string)
- advice.ExecutionFrequency = executionFrequency
- }
-
- if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
- children := adviceNameM["children"].([]interface{})
- if len(children) > 0 {
- for _, childrenMap := range children {
- childMap := childrenMap.(map[string]interface{})
- var child models.GroupAdvice
- child.Remark = Remark
- child.AdviceType = adviceType
- child.StartTime = StartTime
- child.AdviceDate = AdviceDate
- child.RecordDate = RecordDate
- child.Status = 1
- child.CreatedTime = time.Now().Unix()
- child.UpdatedTime = time.Now().Unix()
- child.StopState = 2
- child.ExecutionState = 2
- child.UserOrgId = adminUserInfo.CurrentOrgId
- child.PatientId = patientInfo.ID
- child.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
- utils.ErrorLog("child advice_name")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- childAdviceName, _ := childMap["advice_name"].(string)
- if len(childAdviceName) == 0 {
- utils.ErrorLog("len(child advice_name) == 0")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- child.AdviceName = childAdviceName
-
- if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
- childAdviceDesc, _ := childMap["advice_desc"].(string)
- child.AdviceDesc = childAdviceDesc
- }
-
- if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
- childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
- child.DrugSpec = childDrugSpec
- }
-
- if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
- childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
- child.DrugSpecUnit = childDrugSpecUnit
- }
-
- if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
- childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
- child.SingleDose = childSingleDose
- }
-
- if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
- childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
- child.SingleDoseUnit = childSingleDoseUnit
- }
-
- if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
- childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
- child.PrescribingNumber = childPrescribingNumber
- }
-
- if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
- childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
- child.PrescribingNumberUnit = childPrescribingNumberUnit
- }
-
- if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
- drug_id := int64(childMap["drug_id"].(float64))
- child.DrugId = drug_id
- }
-
- if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
- way := int64(childMap["way"].(float64))
- child.Way = way
- }
-
- if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
- drug_name_id := int64(childMap["drug_name_id"].(float64))
- child.DrugNameId = drug_name_id
- }
-
- child.DeliveryWay = advice.DeliveryWay
- child.ExecutionFrequency = advice.ExecutionFrequency
- advice.Children = append(advice.Children, &child)
- }
- }
- }
-
- advices = append(advices, &advice)
- }
-
- list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advices": list,
- })
-
- return
- }
-
- func (c *PatientApiController) CreateDoctorAdvice() {
- patient, _ := c.GetInt64("id", 0)
- if patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
- if patientInfo.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
- return
- }
-
- appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- if appRole.UserType == 3 {
- headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- if getPermissionErr != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if headNursePermission == nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
- 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.CurrentOrgId, 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.CurrentOrgId
- advice.PatientId = patient
- advice.AdviceDoctor = adminUserInfo.AdminUser.Id
-
- err := service.CreateDoctorAdvice(&advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) ExecGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- executionTime := c.GetString("execution_time")
-
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
- // checker := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
-
- exceAdvice := models.DoctorAdvice{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- // Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
- err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
- // advice.Checker = checker
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) ExecDoctorAdvice() {
-
- origin, _ := c.GetInt64("origin", 0)
-
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- executionTime := c.GetString("execution_time")
-
- if origin != 2 {
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
-
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //医嘱已执行
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
- // checker := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- exceAdvice := models.DoctorAdvice{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- // Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
- if advice.ParentId > 0 {
- err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- } else {
- err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
- // advice.Checker = checker
-
- //处理出库相关逻辑
-
- //1.判断是否启用药品管理和自备药出库功能
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
- fmt.Println("999999992322322323232", drugStockConfig.IsOpen)
- //自备药信息
- privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
- fmt.Println("drugStockConfig2323232332232332", drugStockConfig.IsOpen)
- if drugStockConfig.IsOpen == 1 {
- var total int64
- var prescribing_number_total int64
- advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
- fmt.Println("imte00000000000000", item.PrescribingNumber)
- //查询该药品是否有库存
- list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
- fmt.Println("list23232323232232323232323232", list)
- //查询改药品信息
- 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(advice.PrescribingNumber), 'f', 0, 64)
- count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- total = list.Count*medical.MinNumber + list.StockMinNumber
- prescribing_number_total = count
- }
-
- fmt.Println("数量一", prescribing_number_total)
- fmt.Println("数量二", total)
-
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total > total {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total <= total {
- service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
-
- ////查询该药品是否有库存
- //list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
- //prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- //count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- //if list.Count == 0 {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // "advice": advice,
- // })
- // return
- //}
- //if count > list.Count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "advice": advice,
- // })
- // return
- //}
- ////调用药品出库接口
- //service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
-
- }
- }
-
- advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
-
- if item.Way == 2 {
- if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
-
- //adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
-
- if item.ExecutionState == 1 {
- 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.CurrentOrgId)
-
- total = total + 1
- warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 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.DrugId,
- DrugSpec: item.AdviceDesc,
- OutstoreNumber: count,
- AdminUserId: adminUserInfo.AdminUser.Id,
- StorckTime: item.RecordDate,
- UserOrgId: adminUserInfo.CurrentOrgId,
- CreatedTime: time.Now().Unix(),
- Status: 1,
- PatientId: item.PatientId,
- ExitMode: 2,
- MedicId: item.DrugId,
- StockOutNumber: warehousing_out_order,
- }
- service.CreateOutStock(&outStock)
- }
- }
- }
-
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
-
- } else {
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if len(executionTime) <= 0 {
- utils.ErrorLog("execution_time")
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
-
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
-
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //医嘱已执行
- if advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
- return
- }
-
- executionStaff := adminUserInfo.AdminUser.Id
- // checker := adminUserInfo.AdminUser.Id
-
- timeLayout := "2006-01-02 15:04:05"
- loc, _ := time.LoadLocation("Local")
-
- theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if advice.StartTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- exceAdvice := models.HisDoctorAdviceInfo{
- ExecutionStaff: executionStaff,
- ExecutionTime: theTime.Unix(),
- // Checker: checker,
- UpdatedTime: time.Now().Unix(),
- }
- if advice.ParentId > 0 {
- err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- } else {
- err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- advice.ExecutionStaff = executionStaff
- advice.ExecutionTime = theTime.Unix()
- // advice.Checker = checker
-
- //处理出库相关逻辑
-
- //1.判断是否启用药品管理和自备药出库功能
-
- //药品管理信息
- _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
- fmt.Println("000000000000000000000000000000000000", drugStockConfig.IsOpen)
- if drugStockConfig.IsOpen == 1 {
- //查询已经执行的医嘱
- advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
- for _, item := range advices {
- var total int64
- var prescribing_number_total int64
- //查询该药品是否有库存
- list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
-
- //查询改药品信息
- medical, _ := service.GetBaseDrugMedical(advice.DrugId)
- //判断单位是否相等
- 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
- prescribing_number_total = count * medical.MinNumber
- }
- fmt.Println("单位1", medical.MinUnit)
- fmt.Println("d单位23", advice.PrescribingNumberUnit)
- fmt.Println("hhhhhhh", list.Count)
- 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
- fmt.Println("23232322323322323233223", total)
- prescribing_number_total = count
- fmt.Println("7777777777777777", prescribing_number_total)
- }
-
- fmt.Println("数量一", prescribing_number_total)
- fmt.Println("数量二", total)
-
- if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "3",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total > total {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "2",
- "advice": advice,
- })
- return
- }
- if prescribing_number_total <= total {
- service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
- break
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
- }
- }
- // //查询该药品是否有库存
- // list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
- // prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
- // count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
- // if list.Count == 0 {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "1",
- // "advice": advice,
- // })
- // return
- // }
- // if count > list.Count {
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "2",
- // "advice": advice,
- // })
- // return
- // }
- // service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
- //}
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "1",
- "advice": advice,
- })
- return
-
- }
-
- }
-
- func (c *PatientApiController) CheckGroupAdvice() {
- groupno, _ := c.GetInt64("groupno", 0)
-
- if groupno <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- 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()
-
- exceAdvice := models.DoctorAdvice{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- // advice.ExecutionStaff = executionStaff
- // advice.ExecutionTime = theTime.Unix()
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) CheckDoctorAdvice() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- origin, _ := c.GetInt64("origin", 0)
-
- if origin != 2 {
- // executionTime := c.GetString("execution_time")
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- if advice.CheckState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
- return
- }
-
- if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
- return
- }
-
- // executionStaff := adminUserInfo.AdminUser.Id
- checker := adminUserInfo.AdminUser.Id
-
- // timeLayout := "2006-01-02 15:04:05"
- // loc, _ := time.LoadLocation("Local")
-
- // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
- // if err != nil {
- // utils.ErrorLog(err.Error())
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
-
- theTime := time.Now()
-
- if advice.ExecutionTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
- exceAdvice := models.DoctorAdvice{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- if advice.ParentId > 0 {
- err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- } else {
- err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- // advice.ExecutionStaff = executionStaff
- // advice.ExecutionTime = theTime.Unix()
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
-
- } else {
-
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- 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()
-
- if advice.ExecutionTime > theTime.Unix() {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
- return
- }
- exceAdvice := models.HisDoctorAdviceInfo{
- Checker: checker,
- CheckTime: theTime.Unix(),
- UpdatedTime: time.Now().Unix(),
- }
- var err error
- if advice.ParentId > 0 {
- err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
- } else {
- err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
- }
-
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- // advice.ExecutionStaff = executionStaff
- // advice.ExecutionTime = theTime.Unix()
- advice.Checker = checker
- advice.CheckTime = theTime.Unix()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
- }
-
- func (c *PatientApiController) UpdateDoctorAdvice() {
- patient, _ := c.GetInt64("patient", 0)
- id, _ := c.GetInt64("id", 0)
- if id <= 0 || patient <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
- if advice.ID == 0 || advice.PatientId != patient {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //if advice.AdviceType == 1 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
- // return
- //}
- if advice.StopState == 1 || advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
-
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
- // return
- //}
-
- code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
- if code > 0 {
- c.ServeFailJSONWithSGJErrorCode(code)
- return
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.Modifier = adminUserInfo.AdminUser.Id
-
- err := service.UpdateDoctorAdvice(&advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- "advice": advice,
- })
- return
- }
-
- func (c *PatientApiController) StopGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- if advice.StopState == 1 || advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- 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
- }
-
- 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
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- 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" {
- stopReason, _ := dataBody["stop_reason"].(string)
- advice.StopReason = stopReason
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.StopDoctor = adminUserInfo.AdminUser.Id
- advice.StopState = 1
-
- err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- return
- }
-
- func (c *PatientApiController) StopDoctorAdvice() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 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.CurrentOrgId, id)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
- if advice.StopState == 1 || advice.ExecutionState == 1 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
- return
- }
-
- 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
- }
-
- 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
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- 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" {
- stopReason, _ := dataBody["stop_reason"].(string)
- advice.StopReason = stopReason
- }
-
- advice.UpdatedTime = time.Now().Unix()
- advice.StopDoctor = adminUserInfo.AdminUser.Id
- advice.StopState = 1
-
- 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.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, 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.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 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) DeleteGroupAdvice() {
- groupNo, _ := c.GetInt64("groupno", 0)
- if groupNo <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
-
- advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
- if advice.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
- return
- }
-
- //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
- //if appRole.UserType == 3 {
- // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
- // if getPermissionErr != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // } else if headNursePermission == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
- // return
- // }
- //}
-
- err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
- return
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "ok",
- })
- 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", "")
- page, _ := c.GetInt64("page")
- fmt.Println("page", page)
- limit, _ := c.GetInt64("limit")
- fmt.Println("limit", limit)
- adminUserInfo := c.GetAdminUserInfo()
-
- operatorIDs := make([]int64, 0)
-
- 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 {
- utils.ErrorLog(err.Error())
- 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.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
- advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
-
- if len(advices) > 0 {
- for _, item := range advices {
- 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)
- }
- if item.StopDoctor > 0 {
- operatorIDs = append(operatorIDs, item.StopDoctor)
- }
- }
- }
-
- //相关操作对应的操作人
- operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "advices": advices,
- "operators": operators,
- "total": total,
- "advicetwo": advicestwo,
- })
- return
-
- }
-
- func (c *PatientApiController) GetPatientSchedules() {
- id, _ := c.GetInt64("id", 0)
- if id <= 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := c.GetAdminUserInfo()
- 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.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, 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) GetPatientDialysisRecords() {
- 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()
- }
-
- adminInfo := c.GetAdminUserInfo()
- records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "records": records,
- })
- return
- }
-
- func (c *PatientApiController) ProEducation() {
- 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()
- }
-
- adminInfo := c.GetAdminUserInfo()
- edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "edus": edus,
- })
- 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 && adviceType != 3 && adviceType != 4 {
- 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
- }
- }
- }
-
- 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", startTime, loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
- advice.StartTime = theTime.Unix()
-
- // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
- // utils.ErrorLog("advice_doctor")
- // code = enums.ErrorCodeParamWrong
- // return
- // }
- // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
- // if adviceDoctor <= 0 {
- // utils.ErrorLog("advice_doctor <=0")
- // code = enums.ErrorCodeParamWrong
- // return
- // }
- // advice.AdviceDoctor = adviceDoctor
-
- 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 advice.AdviceType == 1 && advice.ParentId == 0 {
-
- if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
- frequency_type := int64(dataBody["frequency_type"].(float64))
- advice.FrequencyType = frequency_type
- }
-
- if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
- day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
- advice.DayCount = day_count
- }
-
- if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
- week_day, _ := dataBody["week_days"].(string)
- advice.WeekDay = week_day
- }
- }
-
- }
-
- 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["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
- dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
- advice.DialysisOrderId = int64(dialysisOrderId)
- }
-
- 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
- }
-
- if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
- drug_id, _ := dataBody["drug_id"].(float64)
- advice.DrugId = int64(drug_id)
- }
-
- if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
- drug_name_id, _ := dataBody["drug_name_id"].(float64)
- advice.DrugNameId = int64(drug_name_id)
- }
-
- if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
- way, _ := dataBody["way"].(float64)
- advice.Way = int64(way)
- }
-
- return
- }
-
- func solutionFormData(solution *models.DialysisSolution, 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["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
- dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
- solution.DialysisDuration = dialysisDuration
- }
-
- if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
- replacementWay := int64(dataBody["replacement_way"].(float64))
- solution.ReplacementWay = replacementWay
- }
-
- if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
- bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
- 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["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
- bloodFilter := int64(dataBody["blood_filter"].(float64))
- solution.BloodFilter = bloodFilter
- }
-
- if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
- perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
- solution.PerfusionApparatus = perfusionApparatus
- }
-
- if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
- dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
- solution.DialysateFlow = dialysateFlow
- }
-
- if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
- kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
- solution.Kalium = kalium
- }
-
- if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
- sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
- solution.Sodium = sodium
- }
-
- if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
- solution.Calcium = calcium
- }
-
- if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
- bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
- solution.Bicarbonate = bicarbonate
- }
-
- if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
- anticoagulant := int64(dataBody["anticoagulant"].(float64))
- solution.Anticoagulant = anticoagulant
- }
-
- if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
- anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
- solution.AnticoagulantShouji = anticoagulantShouji
- }
-
- if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
- anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- }
-
- if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
- anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
- 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
- }
-
- 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["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
- targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
- solution.TargetUltrafiltration = targetUltrafiltration
- }
-
- if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
- dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
- solution.DialysateFormulation = dialysateFormulation
- }
-
- if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
- dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
- solution.DialysisDurationHour = int64(dialysisDurationHour)
- }
-
- if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
- dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
- solution.DialysisDurationMinute = int64(dialysisDurationMinute)
- }
-
- if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
- hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
- solution.HemodialysisMachine = hemodialysisMachine
- }
- 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 && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
- bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
- solution.BloodFlowVolume = bloodFlowVolume
- }
-
- if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
- dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
- solution.Dewater = dewater
- }
-
- if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
- displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
- 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 && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
- anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
- solution.AnticoagulantShouji = anticoagulantShouji
- }
-
- if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
- anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
- solution.AnticoagulantWeichi = anticoagulantWeichi
- }
-
- if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
- anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
- 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 && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
- kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
- solution.Kalium = kalium
- }
-
- if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
- sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
- solution.Sodium = sodium
- }
-
- if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
- calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
- solution.Calcium = calcium
- }
-
- if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
- bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
- solution.Bicarbonate = bicarbonate
- }
-
- if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
- glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
- solution.Glucose = glucose
- }
-
- // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
- // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
- // solution.DryWeight = dryWeight
- // }
-
- if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
- dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
- solution.DialysateFlow = dialysateFlow
- }
-
- if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
- dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
- solution.DialysateTemperature = dialysateTemperature
- }
-
- if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
- conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
- solution.Conductivity = conductivity
- }
-
- if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
- replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
- solution.ReplacementTotal = replacementTotal
- }
-
- if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
- dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
- solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
- }
-
- if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
- body_fluid := int64(dataBody["body_fluid"].(float64))
- solution.BodyFluid = body_fluid
- }
-
- if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
- body_fluid_other := dataBody["body_fluid_other"].(string)
- solution.BodyFluidOther = body_fluid_other
- }
-
- if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
- special_medicine := int64(dataBody["special_medicine"].(float64))
- solution.SpecialMedicine = special_medicine
- }
-
- if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
- special_medicine_other := dataBody["special_medicine_other"].(string)
- solution.SpecialMedicineOther = special_medicine_other
- }
-
- if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
- displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
- solution.DisplaceLiquiPart = displace_liqui_part
- }
- if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
- displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
- solution.DisplaceLiquiValue = displace_liqui_value
- }
- if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
- blood_access := int64(dataBody["blood_access"].(float64))
- solution.BloodAccess = blood_access
- }
-
- if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
- ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
- solution.Ultrafiltration = ultrafiltration
- }
-
- if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
- target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
- solution.TargetKtv = target_ktv
- }
-
- if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
- remark := dataBody["remark"].(string)
- solution.Remark = remark
- }
-
- if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
- hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
- solution.HemodialysisPipelines = hemodialysis_pipelines
- }
-
- if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
- hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
- solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
- }
-
- if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
- puncture_needle := dataBody["puncture_needle"].(string)
- solution.PunctureNeedle = puncture_needle
- }
-
- if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
- puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
- solution.PunctureNeedleCount = puncture_needle_count
- }
-
- if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
- epo := dataBody["epo"].(string)
- solution.Epo = epo
- }
-
- if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
- epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
- solution.EpoCount = epo_count
- }
-
- if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
- created_time := int64(dataBody["created_time"].(float64))
-
- solution.CreatedTime = created_time
- }
-
- if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
- dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
- solution.DialysisDialyszers = dialysisDialyszers
- }
-
- if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
- dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
- solution.DialysisIrrigation = dialysisIrrigation
- }
-
- if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
- plasmaSeparator := dataBody["plasma_separator"].(string)
- solution.PlasmaSeparator = plasmaSeparator
- }
-
- if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
- bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
- solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
- }
-
- if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
- oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
- solution.OxygenUptake = oxygen_uptake
- }
-
- if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
- oxygen_flow := dataBody["oxygen_flow"].(string)
- solution.OxygenFlow = oxygen_flow
- }
-
- if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
- oxygen_time := dataBody["oxygen_time"].(string)
- solution.OxygenTime = oxygen_time
- }
-
- if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
- max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
- solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
- }
- return
- }
-
- func childSolutionFormData(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["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
- utils.ErrorLog("parent_id")
- code = enums.ErrorCodeParamWrong
- return
- }
- parentID := int64(dataBody["parent_id"].(float64))
- if parentID <= 0 {
- utils.ErrorLog("parentID <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.ParentId = parentID
-
- if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
- utils.ErrorLog("sub_name")
- code = enums.ErrorCodeParamWrong
- return
- }
- subName, _ := dataBody["sub_name"].(string)
- if len(subName) == 0 {
- utils.ErrorLog("len(sub_name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.SubName = subName
- }
-
- if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
- utils.ErrorLog("initiate_mode")
- code = enums.ErrorCodeParamWrong
- return
- }
- initiateMode := int64(dataBody["initiate_mode"].(float64))
- if initiateMode != 1 && initiateMode != 2 {
- utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.InitiateMode = initiateMode
-
- if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
- utils.ErrorLog("doctor")
- code = enums.ErrorCodeParamWrong
- return
- }
- doctor := int64(dataBody["doctor"].(float64))
- if doctor <= 0 {
- utils.ErrorLog("doctor <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- solution.Doctor = doctor
-
- return
- }
-
- func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
- patientBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(data, &patientBody)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- code = enums.ErrorCodeParamWrong
- return
- }
-
- if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
- formItem, _ := patientBody["formItem"].([]interface{})
-
- if len(formItem) > 0 {
- for _, item := range formItem {
- items := item.(map[string]interface{})
- project_name, _ := items["project_name"].(string)
- fmt.Println(project_name)
-
- range_type := int64(items["range_type"].(float64))
- fmt.Println(range_type)
-
- project_id := int64(items["project_id"].(float64))
- fmt.Println(project_id)
-
- item_id := int64(items["item_id"].(float64))
- fmt.Println(item_id)
-
- item, _ := items["item"].(string)
- fmt.Println(items["item"].(string))
-
- item_name, _ := items["item_name"].(string)
- fmt.Println(item_name)
-
- value, _ := items["value"].(string)
- fmt.Println(items["value"].(string))
-
- var form models.FormItem
- form.ProjectName = project_name
- form.RangeType = range_type
- form.ProjectId = project_id
- form.ItemId = item_id
- form.Item = item
- form.ItemName = item_name
- form.Value = value
- formItems = append(formItems, &form)
- }
- }
- }
- if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
- utils.ErrorLog("avatar")
- code = enums.ErrorCodeParamWrong
- return
- }
- avatar, _ := patientBody["avatar"].(string)
-
- if len(avatar) == 0 {
- utils.ErrorLog("len(avatar) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Avatar = avatar
-
- if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
- utils.ErrorLog("name")
- code = enums.ErrorCodeParamWrong
- return
- }
- name, _ := patientBody["name"].(string)
- if len(name) == 0 {
- utils.ErrorLog("len(name) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Name = name
-
- if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
- alias := patientBody["alias"].(string)
- patient.Alias = alias
- }
-
- if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
- nation := patientBody["nation"].(string)
- patient.Nation = nation
- }
- if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
- native_place := patientBody["native_place"].(string)
- patient.NativePlace = native_place
- }
-
- if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
- utils.ErrorLog("idCardNo")
- code = enums.ErrorCodeParamWrong
- return
- }
- idCardNo, _ := patientBody["idCardNo"].(string)
- if len(idCardNo) == 0 {
- utils.ErrorLog("len(idCardNo) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.IdCardNo = idCardNo
-
- patient.PatientType = 1
-
- if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
- utils.ErrorLog("dialysisNo")
- code = enums.ErrorCodeParamWrong
- return
- }
- dialysisNo, _ := patientBody["dialysisNo"].(string)
- if len(dialysisNo) == 0 {
- utils.ErrorLog("len(dialysisNo) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.DialysisNo = dialysisNo
- // }
-
- if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
- utils.ErrorLog("lapseto")
- code = enums.ErrorCodeParamWrong
- return
- }
- lapseto := int64(patientBody["lapseto"].(float64))
- if lapseto <= 0 {
- utils.ErrorLog("lapseto == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Lapseto = lapseto
-
- if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
- utils.ErrorLog("gender")
- code = enums.ErrorCodeParamWrong
- return
- }
- gender := int64(patientBody["gender"].(float64))
- if gender <= 0 {
- utils.ErrorLog("gender <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Gender = gender
-
- if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
- response_result := patientBody["response_result"].(string)
- patient.ResponseResult = response_result
- }
-
- if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
- utils.ErrorLog("age")
- code = enums.ErrorCodeParamWrong
- return
- }
- age := int64(patientBody["age"].(float64))
- patient.Age = age
-
- if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
- user_sys_before_count := patientBody["user_sys_before_count"].(string)
- count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
- patient.UserSysBeforeCount = count
- }
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
-
- if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
- utils.ErrorLog("birth")
- code = enums.ErrorCodeParamWrong
- return
- }
- birth, _ := patientBody["birth"].(string)
- if len(birth) == 0 {
- utils.ErrorLog("len(birth) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
- if err != nil {
- utils.ErrorLog("birthTime")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Birthday = birthTime.Unix()
-
- if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
- height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
- patient.Height = height
- }
-
- if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
- maritalStatus := int64(patientBody["maritalStatus"].(float64))
- patient.MaritalStatus = maritalStatus
- }
-
- if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
- children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
- patient.Children = children
- }
-
- if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
- admissionNumber, _ := patientBody["admissionNumber"].(string)
- patient.AdmissionNumber = admissionNumber
- }
-
- if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
- reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
- patient.ReimbursementWayId = reimbursementWayID
- }
-
- if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
- healthCareNo := patientBody["healthCareNo"].(string)
- patient.HealthCareNo = healthCareNo
- }
-
- if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
- utils.ErrorLog("phone")
- code = enums.ErrorCodeParamWrong
- return
- }
- phone := patientBody["phone"].(string)
- if len(phone) == 0 {
- utils.ErrorLog("len(phone) == 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- if !utils.CheckMobile(phone) {
- utils.ErrorLog("!phone")
- code = enums.ErrorCodeMobileFormat
- return
- }
- patient.Phone = phone
-
- if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
- homeTelephone := patientBody["homeTelephone"].(string)
- patient.HomeTelephone = homeTelephone
- }
-
- if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
- relativePhone := patientBody["relative_phone"].(string)
- patient.RelativePhone = relativePhone
- }
-
- if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
- relativeRelations := patientBody["relative_relations"].(string)
- patient.RelativeRelations = relativeRelations
- }
-
- if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
- homeAddress := patientBody["homeAddress"].(string)
- patient.HomeAddress = homeAddress
- }
-
- if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
- work := patientBody["work"].(string)
- patient.WorkUnit = work
- }
-
- if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
- unitAddress := patientBody["unit_address"].(string)
- patient.UnitAddress = unitAddress
- }
-
- if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
- profession := int64(patientBody["profession"].(float64))
- patient.Profession = profession
- }
-
- if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
- education := int64(patientBody["education"].(float64))
- patient.EducationLevel = education
- }
-
- if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
- utils.ErrorLog("source")
- code = enums.ErrorCodeParamWrong
- return
- }
- source := int64(patientBody["source"].(float64))
- if source <= 0 {
- utils.ErrorLog("source <= 0")
- code = enums.ErrorCodeParamWrong
- return
- }
- patient.Source = source
-
- if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
- isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
- patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
- }
-
- if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
- firstDialysisDate := patientBody["firstDialysisDate"].(string)
- firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
- if err == nil {
- patient.FirstDialysisDate = firstDialysisDateTime.Unix()
- }
- }
-
- if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
- firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
- patient.FirstDialysisHospital = firstDialysisHospital
- }
-
- if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
- thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
- if len(thePredialysisCondition) > 0 {
- conditions := make([]string, 0)
- for _, item := range thePredialysisCondition {
- if reflect.TypeOf(item).String() != "string" {
- continue
- }
- condition := item.(string)
- if len(condition) > 0 {
- conditions = append(conditions, condition)
- }
- }
- patient.PredialysisCondition = strings.Join(conditions, ",")
- }
- }
-
- if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
- preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
- patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
- }
-
- if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
- preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
- patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
- }
- if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
- hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
- hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
- if err == nil {
- patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
- }
- }
-
- if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
- partition := int64(patientBody["partition"].(float64))
- patient.PartitionId = partition
- }
- if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
- bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
- patient.BedId = bed
- }
-
- if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
- healthCareDueDate := patientBody["healthCareDueDate"].(string)
- healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
- if err == nil {
- patient.HealthCareDueDate = healthCareDueDateTime.Unix()
- }
- }
-
- if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
- blood := int64(patientBody["blood"].(float64))
- patient.BloodType = blood
- }
-
- if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
- rh := int64(patientBody["rh"].(float64))
- patient.Rh = rh
- }
-
- if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
- healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
- healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
- if err == nil {
- patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
- }
- }
-
- if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
- receivingDate := patientBody["receivingDate"].(string)
- receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
- if err == nil {
- patient.ReceivingDate = receivingDateTime.Unix()
- }
- }
-
- if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
- induction := int64(patientBody["induction"].(float64))
- patient.InductionPeriod = induction
- }
-
- if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
- initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
- patient.InitialDialysis = initial
- }
-
- if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
- dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
- patient.TotalDialysis = dialysisTotal
- }
-
- if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
- thisContagions, _ := patientBody["contagions"].([]interface{})
- if len(thisContagions) > 0 {
- for _, item := range thisContagions {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- contagion := int64(item.(float64))
- if contagion > 0 {
- contagions = append(contagions, contagion)
- }
- }
- }
- }
-
- if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
- doctor := int64(patientBody["doctor"].(float64))
- patient.AttendingDoctorId = doctor
- }
-
- if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
- nurse := int64(patientBody["nurse"].(float64))
- patient.HeadNurseId = nurse
- }
-
- if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
- assessment := patientBody["assessment"].(string)
- patient.Evaluate = assessment
- }
-
- if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
- thisDiseases, _ := patientBody["diseases"].([]interface{})
- if len(thisDiseases) > 0 {
- for _, item := range thisDiseases {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- disease := int64(item.(float64))
- if disease > 0 {
- diseases = append(diseases, disease)
- }
- }
- }
- }
-
- if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
- diagnose := patientBody["diagnose"].(string)
- patient.Diagnose = diagnose
- }
-
- if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
- remark := patientBody["remark"].(string)
- patient.Remark = remark
- }
-
- if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
- sch_remark := patientBody["sch_remark"].(string)
- patient.SchRemark = sch_remark
- }
-
- if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
- patient_complains := patientBody["patient_complains"].(string)
- patient.PatientComplains = patient_complains
- }
-
- if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
- present_history := patientBody["present_history"].(string)
- patient.PresentHistory = present_history
- }
-
- if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
- past_history := patientBody["past_history"].(string)
- patient.PastHistory = past_history
- }
-
- if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
- temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
- patient.Temperature = temperature
- }
-
- if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
- pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
- patient.Pulse = pulse
- }
-
- if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
- respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
- patient.Respiratory = respiratory
- }
-
- if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
- sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
- patient.SBP = sbp
- }
-
- if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
- dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
- patient.DBP = dbp
- }
-
- if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
- dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
- patient.DialysisAge = dialysis_age
- }
- fmt.Println(patient.DialysisAge)
-
- if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
- first_treatment_date := patientBody["first_treatment_date"].(string)
- first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
- if err == nil {
- patient.FirstTreatmentDate = first_treatment_time.Unix()
- }
- }
-
- if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
- expense_kind := int64(patientBody["expense_kind"].(float64))
- patient.ExpenseKind = expense_kind
- }
-
- fmt.Println(patient.ExpenseKind)
-
- if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
- tell_phone := patientBody["tell_phone"].(string)
- patient.TellPhone = tell_phone
- }
-
- if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
- contact_name := patientBody["contact_name"].(string)
- patient.ContactName = contact_name
- }
-
- return
-
- }
-
- func (c *PatientApiController) GetPatientsByKeyWord() {
- keyWord := c.GetString("keyword")
- adminUserInfo := c.GetAdminUserInfo()
- patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- })
- }
-
- func (c *PatientApiController) QueryPatientById() {
- id, _ := c.GetInt64("id")
- fmt.Println(id)
- patientInfo := service.QueryPatientById(id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patientInfo,
- })
- return
- }
-
- func (c *PatientApiController) GetRemindPatientList() {
- page, _ := c.GetInt64("page", 1)
- limit, _ := c.GetInt64("limit", 10)
- adminUserInfo := c.GetAdminUserInfo()
- total, patients, err := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
-
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "total": total,
- "patients": patients,
- })
-
- }
-
- func (c *PatientApiController) PostIsOpenRemind() {
- patient_id, _ := c.GetInt64("id", 1)
- is_open_remind, _ := c.GetInt64("is_open_remind", 1)
- adminUserInfo := c.GetAdminUserInfo()
-
- err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
-
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "成功",
- "is_open_remind": is_open_remind,
- })
- } else if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- }
- }
-
- func (c *PatientApiController) GetPatientScheduleOne() {
- id, _ := c.GetInt64("id")
- //查询该病人是否当天是排班
- nowDateTime := time.Now()
- nowDate := nowDateTime.Format("2006-01-02")
- nowDate += " 00:00:00"
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
- nowdate := theTime.Unix()
- fmt.Println("nowdate", nowdate)
- adminUser := c.GetAdminUserInfo()
- orgId := adminUser.CurrentOrgId
- fmt.Println("orgid", orgId)
- scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "scheduls": scheduls,
- })
- }
-
- func (c *PatientApiController) ExportPatients() {
- dataBody := make(map[string]interface{}, 0)
-
- all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
-
- //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
-
- org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
-
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
- if err != nil {
- utils.ErrorLog(err.Error())
- return
- }
- utils.ErrorLog("%v", dataBody)
- export_time := time.Now().Unix()
- var patients []*models.Patients
- var total_patients []interface{}
- if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
- tempPatients := dataBody["patients"].([]interface{})
- total_patients = tempPatients
- for index, patientMap := range tempPatients {
- patientNameM := patientMap.(map[string]interface{})
- var patient models.Patients
-
- if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
- utils.ErrorLog("name")
- return
- }
- name, _ := patientNameM["name"].(string)
- if len(name) == 0 { //名字为空则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- patient.Name = name
-
- if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
- gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
- if gender == 0 { //性别不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- patient.Gender = gender
- }
- }
-
- if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
- phone, _ := patientNameM["phone"].(string)
- if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
- if len(phone) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
-
- } else {
- //var tempPatient *models.Patients
- //for _, item := range all_patient {
- // if item.Phone == phone {
- // tempPatient = item
- // }
- //}
-
- //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
- count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
- if count >= 1 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- patient.Phone = phone
- }
- }
-
- if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
- id_card_no, _ := patientNameM["id_card_no"].(string)
-
- if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
-
- if len(id_card_no) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- }
-
- } else {
- //var tempPatient *models.Patients
- //for _, item := range all_patient {
- // if item.IdCardNo == id_card_no {
- // tempPatient = item
- // }
- //}
- count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
- if count >= 1 {
- //if tempPatient != nil && tempPatient.ID > 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- }
- //}
- patient.IdCardNo = id_card_no
- //patient.Birthday = GetBirthDay(id_card_no).Unix()
- if GetBirthDay(id_card_no) == nil {
- patient.Birthday = 0
- } else {
- patient.Birthday = GetBirthDay(id_card_no).Unix()
-
- }
- }
- }
-
- fmt.Println("111112222")
- if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
- first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
- timeLayout := "2006/01/02"
- loc, _ := time.LoadLocation("Local")
- first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
-
- if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
- if len(first_treatment_date) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- }
-
- } else {
- if len(first_treatment_date) == 0 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
-
- if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else {
- patient.FirstDialysisDate = first_dialysis_date.Unix()
- }
-
- }
-
- }
- }
-
- if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
- source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
- if source == 0 { //患者来源不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if source == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.Source = source
- }
- }
-
- if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
- lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
- if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if lapseto == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.Lapseto = lapseto
- }
- }
-
- if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
- is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
- if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
- } else if is_infectious == 3 {
- err_log := models.ExportErrLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
- Status: 1,
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- }
- service.CreateExportErrLog(&err_log)
- continue
-
- } else {
- patient.IsInfectious = is_infectious
- }
- }
-
- if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
- var contagions []int64
- thisContagions, _ := patientNameM["contagions"].([]interface{})
- if len(thisContagions) > 0 {
- for _, item := range thisContagions {
- if reflect.TypeOf(item).String() != "float64" {
- continue
- }
- contagion := int64(item.(float64))
- if contagion > 0 {
- contagions = append(contagions, contagion)
- }
- }
- }
- patient.ContagionIds = contagions
- }
-
- if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
- diagnose, _ := patientNameM["diagnose"].(string)
- patient.Diagnose = diagnose
-
- }
-
- if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
- dialysis_no, _ := patientNameM["dialysis_no"].(string)
- var tempPatient *models.Patients
- for _, item := range all_patient {
- if item.DialysisNo == dialysis_no {
- tempPatient = item
- }
- }
- if tempPatient != nil && tempPatient.ID > 0 {
- patient.DialysisNo = GenerateDialysisNoTwo(patients)
- } else {
- patient.DialysisNo = dialysis_no
- }
- }
-
- if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
- height, _ := patientNameM["height"].(string)
- heights, _ := strconv.ParseFloat(height, 64)
- patient.Height = int64(heights)
- }
-
- if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
- home_address, _ := patientNameM["home_address"].(string)
- patient.HomeAddress = home_address
- }
- if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
- dry_weight, _ := patientNameM["dry_weight"].(string)
- dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
- patient.DryWeight = dry_weights
-
- }
- patient.CreatedTime = time.Now().Unix()
- patient.UpdatedTime = time.Now().Unix()
- patient.Status = 1
- patient.Avatar = "https://images.shengws.com/201809182128111.png"
- patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
- patient.IsExcelExport = 1
- patient.PatientType = 1
- patients = append(patients, &patient)
- }
- }
- errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
-
- if len(patients) > 0 {
- for _, item := range patients {
- service.CreateExportPatient(item, item.ContagionIds, org.Creator)
- }
-
- log := models.ExportLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_patients)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(patients)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_patients),
- "success_num": len(patients),
- "fail_num": int64(len(errLogs)),
- })
- } else {
- log := models.ExportLog{
- LogType: 1,
- UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
- TotalNum: int64(len(total_patients)),
- FailNum: int64(len(errLogs)),
- SuccessNum: int64(len(patients)),
- CreateTime: time.Now().Unix(),
- UpdateTime: time.Now().Unix(),
- ExportTime: export_time,
- Status: 1,
- }
- service.CreateExportLog(&log)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "导入成功",
- "total_num": len(total_patients),
- "success_num": len(patients),
- "fail_num": int64(len(errLogs)),
- })
- }
- }
-
- func GetBirthDay(IDCardNo string) *time.Time {
- dayStr := IDCardNo[6:14]
- birthDay, err := time.Parse("20060102", dayStr)
- if err != nil {
- fmt.Println(err)
- return nil
- }
- return &birthDay
- }
-
- func IsIdCard(id string) (res bool) {
- id = strings.ToUpper(id)
- if len(id) != 15 && len(id) != 18 {
- fmt.Println("1111111")
- return false
- }
- r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
- if !r.MatchString(id) {
- fmt.Println("222222")
-
- return false
- }
- if len(id) == 15 {
- tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
- if tm2.Unix() == 0 {
- fmt.Println("44444443333")
-
- return false
- }
- return true
- } else {
- tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
- fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
- fmt.Println(tm2.Unix())
-
- if tm2.Unix() == 0 {
-
- fmt.Println("44445555555")
-
- return false
- }
- //检验18位身份证的校验码是否正确。
- //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
- arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
- arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
- sign := 0
- for k, v := range arr_int {
- int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
- sign += int_temp * v
- }
- n := sign % 11
- val_num := arr_ch[n]
- if val_num != string([]byte(id)[17:18]) {
- fmt.Println("5556666666")
-
- return false
- }
- return true
- }
- }
-
- func (c *PatientApiController) SaveEditAdvices() {
- adminInfo := c.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- startTime := c.GetString("start_time")
-
- theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
-
- groupno, _ := c.GetInt64("groupno")
- fmt.Println("组", groupno)
- date, _ := c.GetInt64("date")
- fmt.Println("date", date)
- patient_id, _ := c.GetInt64("patient_id")
- fmt.Println("paitent_id", patient_id)
- advice := models.XtDoctorAdvice{
- StartTime: theTime.Unix(),
- }
- err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "advice": advice,
- })
- }
-
- func (c *PatientApiController) GetMaxDialysisNo() {
- dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "dialysis_no": dialysisNo,
- })
-
- }
-
- func GenerateDialysisNoTwo(patients []*models.Patients) string {
- dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
- var tempPatient *models.Patients
- for _, item := range patients {
- if item.DialysisNo == dialysisNo2 {
- tempPatient = item
- }
- }
- if tempPatient == nil || tempPatient.ID == 0 {
- return dialysisNo2
- }
- return GenerateDialysisNoTwo(patients)
- }
|