patient_api_controller.go 150KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516
  1. package controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_New/service"
  6. "Xcx_New/utils"
  7. "encoding/json"
  8. //"github.com/jinzhu/gorm"
  9. "math"
  10. "math/rand"
  11. "reflect"
  12. "regexp"
  13. "strconv"
  14. "strings"
  15. "time"
  16. "fmt"
  17. "github.com/astaxie/beego"
  18. )
  19. type PatientApiController struct {
  20. BaseAuthAPIController
  21. }
  22. func PatientApiRegistRouters() {
  23. beego.Router("/api/patients", &PatientApiController{}, "get:GetPatientsList")
  24. beego.Router("/api/patients/all", &PatientApiController{}, "get:GetPatientsAllList")
  25. beego.Router("/api/patients/generatedialysisno", &PatientApiController{}, "get:GenerateDialysisNo")
  26. beego.Router("/api/patients/create", &PatientApiController{}, "Post:CreatePatient")
  27. beego.Router("/api/patients/total", &PatientApiController{}, "Get:GetPatientTotal")
  28. beego.Router("/api/patients/get", &PatientApiController{}, "Get:GetPatient")
  29. beego.Router("/api/patients/edit", &PatientApiController{}, "Put:EditPatient")
  30. beego.Router("/api/patients/dialysissolution/create", &PatientApiController{}, "Post:CreateDialysisSolution")
  31. beego.Router("/api/patients/dialysissolution/edit", &PatientApiController{}, "Put:UpdateDialysisSolution")
  32. beego.Router("/api/patients/dialysissolutions", &PatientApiController{}, "get:GetPatientDialysisSolutionList")
  33. beego.Router("/api/patients/dialysissolution/detail/edit", &PatientApiController{}, "Put:UpdateDialysisSolutionDetail")
  34. // beego.Router("/api/patients/dialysissolution/delete", &PatientApiController{}, "Delete:DeleteDialysisSolution")
  35. beego.Router("/api/patients/dryweight/get", &PatientApiController{}, "get:GetDryWeights")
  36. beego.Router("/api/patients/dryweight/create", &PatientApiController{}, "Post:CreateDryWeights")
  37. beego.Router("/api/patients/advice/create", &PatientApiController{}, "Post:CreateDoctorAdvice")
  38. beego.Router("/api/patients/advice/edit", &PatientApiController{}, "Put:UpdateDoctorAdvice")
  39. beego.Router("/api/patients/advice/exec", &PatientApiController{}, "Post:ExecDoctorAdvice")
  40. beego.Router("/api/patients/advice/check", &PatientApiController{}, "Post:CheckDoctorAdvice")
  41. beego.Router("/api/patients/advices", &PatientApiController{}, "Get:GetDoctorAdvices")
  42. beego.Router("/api/patients/advice/stop", &PatientApiController{}, "Post:StopDoctorAdvice")
  43. beego.Router("/api/patients/advice/delete", &PatientApiController{}, "Delete:DeleteDoctorAdvice")
  44. beego.Router("/api/patients/advice/creategroup", &PatientApiController{}, "Post:CreateGroupAdvice")
  45. beego.Router("/api/patients/advice/deletegroup", &PatientApiController{}, "Delete:DeleteGroupAdvice")
  46. beego.Router("/api/patients/advice/stopgroup", &PatientApiController{}, "Post:StopGroupAdvice")
  47. beego.Router("/api/patients/advice/execgroup", &PatientApiController{}, "Post:ExecGroupAdvice")
  48. beego.Router("/api/patients/advice/checkgroup", &PatientApiController{}, "Post:CheckGroupAdvice")
  49. beego.Router("/api/patients/schedules", &PatientApiController{}, "Get:GetPatientSchedules")
  50. beego.Router("/api/patients/dialysisrecords", &PatientApiController{}, "Get:GetPatientDialysisRecords")
  51. beego.Router("/api/patients/proeducation", &PatientApiController{}, "Get:ProEducation")
  52. beego.Router("/api/patients/lapseto/edit", &PatientApiController{}, "Post:EditLapseto")
  53. beego.Router("/api/patients/search", &PatientApiController{}, "Post:GetPatientsByKeyWord")
  54. beego.Router("/api/patients/querypatientbyId", &PatientApiController{}, "Get:QueryPatientById")
  55. beego.Router("/api/infectious/remind", &PatientApiController{}, "Get:GetRemindPatientList")
  56. beego.Router("/api/remind/is_open", &PatientApiController{}, "Post:PostIsOpenRemind")
  57. beego.Router("/api/patients/advices/getpatientschedules", &PatientApiController{}, "Get:GetPatientScheduleOne")
  58. beego.Router("/api/patients/export", &PatientApiController{}, "Post:ExportPatients")
  59. beego.Router("/api/patients/advices/saveditadvices", &PatientApiController{}, "Get:SaveEditAdvices")
  60. beego.Router("/api/patients/dialysis_no", &PatientApiController{}, "Get:GetMaxDialysisNo")
  61. }
  62. //GetPatientsList 取患者列表
  63. func (c *PatientApiController) GetPatientsList() {
  64. page, _ := c.GetInt64("page", 1)
  65. limit, _ := c.GetInt64("limit", 10)
  66. schedulType, _ := c.GetInt64("schedul_type", 0)
  67. bindingState, _ := c.GetInt64("binding_state", 0)
  68. lapseto, _ := c.GetInt64("lapseto", 0)
  69. source, _ := c.GetInt64("source", 0)
  70. startTime := c.GetString("start_time", "")
  71. endTime := c.GetString("end_time", "")
  72. keywords := c.GetString("keywords", "")
  73. contagion, _ := c.GetInt64("contagion", 0)
  74. reimbursement_way, _ := c.GetInt64("reimbursement_way", 0)
  75. isscheduling, _ := c.GetInt64("isscheduling", 0)
  76. isprescription, _ := c.GetInt64("isprescription", 0)
  77. if page <= 0 {
  78. page = 1
  79. }
  80. if limit <= 0 {
  81. limit = 10
  82. }
  83. adminUserInfo := c.GetAdminUserInfo()
  84. timeLayout := "2006-01-02"
  85. loc, _ := time.LoadLocation("Local")
  86. var isStartTime bool
  87. var theStartTIme int64
  88. if len(startTime) > 0 {
  89. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  90. if err != nil {
  91. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  92. return
  93. }
  94. isStartTime = true
  95. theStartTIme = theTime.Unix()
  96. }
  97. var isEndTime bool
  98. var theEndtTIme int64
  99. if len(endTime) > 0 {
  100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  101. if err != nil {
  102. utils.ErrorLog(err.Error())
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. isEndTime = true
  107. theEndtTIme = theTime.Unix()
  108. }
  109. patients, total, _ := service.GetPatientList(adminUserInfo.CurrentOrgId, keywords, page, limit, schedulType, bindingState, lapseto, source, theStartTIme, theEndtTIme, contagion, reimbursement_way, isscheduling, isprescription, isStartTime, isEndTime)
  110. c.ServeSuccessJSON(map[string]interface{}{
  111. "patients": patients,
  112. "total": total,
  113. })
  114. return
  115. }
  116. //GetPatientTotal
  117. func (c *PatientApiController) GetPatientTotal() {
  118. adminUserInfo := c.GetAdminUserInfo()
  119. total := service.GetPatientCount(adminUserInfo.CurrentOrgId)
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "total": total,
  122. })
  123. return
  124. }
  125. func (c *PatientApiController) GetPatientsAllList() {
  126. adminUserInfo := c.GetAdminUserInfo()
  127. patients, total, _ := service.GetAllPatientList(adminUserInfo.CurrentOrgId)
  128. c.ServeSuccessJSON(map[string]interface{}{
  129. "patients": patients,
  130. "total": total,
  131. })
  132. return
  133. }
  134. //GenerateDialysisNo 生成透析号
  135. func (c *PatientApiController) GenerateDialysisNo() {
  136. adminUserInfo := c.GetAdminUserInfo()
  137. dialysisNo := service.ChechLastDialysisNo(adminUserInfo.CurrentOrgId)
  138. if dialysisNo == 0 {
  139. dialysisNo = 1
  140. } else {
  141. dialysisNo++
  142. }
  143. no := strconv.FormatInt(dialysisNo, 10)
  144. rep := 3 - len(no)
  145. if rep > 0 {
  146. no = strings.Repeat("0", rep) + no
  147. }
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "no": no,
  150. })
  151. return
  152. }
  153. //CreatePatient 创建患者
  154. func (c *PatientApiController) CreatePatient() {
  155. record_date := c.GetString("record_date")
  156. is_infectious, _ := c.GetInt64("is_infectious")
  157. remind_cycle, _ := c.GetInt64("remind_cycle")
  158. adminUserInfo := c.GetAdminUserInfo()
  159. //patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  160. //subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  161. //if subscibes.State == 2 && patientTotal >= 20 { //免费试用版,不过期,限制患者数20
  162. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  163. // return
  164. //} else if subscibes.State == 1 && patientTotal >= 60 { //标准版,不过期,限制患者数60
  165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  166. // return
  167. //}
  168. var patient models.Patients
  169. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "create")
  170. fmt.Println(code)
  171. fmt.Println(patient)
  172. fmt.Println("contagions是什么", contagions)
  173. if code > 0 {
  174. c.ServeFailJSONWithSGJErrorCode(code)
  175. return
  176. }
  177. thisPatient, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  178. if thisPatient.ID > 0 {
  179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  180. return
  181. }
  182. thisPatient, _ = service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  183. if thisPatient.ID > 0 {
  184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  185. return
  186. }
  187. thisPatient, _ = service.FindPatientByMobile(adminUserInfo.CurrentOrgId, patient.Phone)
  188. if thisPatient.ID > 0 {
  189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientPhoneUsed)
  190. return
  191. }
  192. patient.RemindCycle = remind_cycle
  193. patient.IsInfectious = is_infectious
  194. patient.RegistrarsId = adminUserInfo.AdminUser.Id
  195. patient.Status = 1
  196. patient.CreatedTime = time.Now().Unix()
  197. patient.UserOrgId = adminUserInfo.CurrentOrgId
  198. patient.UpdatedTime = time.Now().Unix()
  199. patient.BindingState = 2
  200. // patient.Lapseto = 1
  201. err := service.CreatePatient(&patient, contagions, diseases)
  202. fmt.Println("创建病人失败err")
  203. if err != nil {
  204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePatient)
  205. return
  206. }
  207. //获取老表的最后一条数据
  208. patients, err := service.GetLastPatientData(adminUserInfo.CurrentOrgId)
  209. patientsNew := models.XtPatientsNew{
  210. UserOrgId: adminUserInfo.CurrentOrgId,
  211. UserId: 0,
  212. Avatar: patients.Avatar,
  213. PatientType: patients.PatientType,
  214. DialysisNo: patients.DialysisNo,
  215. AdmissionNumber: patients.AdmissionNumber,
  216. Source: patients.Source,
  217. Lapseto: patients.Lapseto,
  218. PartitionId: patients.PartitionId,
  219. BedId: patients.BedId,
  220. Name: patients.Name,
  221. Alias: patients.Alias,
  222. Gender: patients.Gender,
  223. MaritalStatus: patients.MaritalStatus,
  224. IdCardNo: patients.IdCardNo,
  225. Birthday: patients.Birthday,
  226. ReimbursementWayId: patients.ReimbursementWayId,
  227. HealthCareType: patients.HealthCareType,
  228. HealthCareNo: patients.HealthCareNo,
  229. HealthCareDueDate: patients.HealthCareDueDate,
  230. Height: patients.Height,
  231. BloodType: patients.BloodType,
  232. Rh: patients.Rh,
  233. HealthCareDueAlertDate: patients.HealthCareDueAlertDate,
  234. EducationLevel: patients.EducationLevel,
  235. Profession: patients.Profession,
  236. Phone: patients.Phone,
  237. HomeTelephone: patients.HomeTelephone,
  238. RelativePhone: patients.RelativePhone,
  239. RelativeRelations: patients.RelativeRelations,
  240. HomeAddress: patients.HomeAddress,
  241. WorkUnit: patients.WorkUnit,
  242. UnitAddress: patients.UnitAddress,
  243. Children: patients.Children,
  244. ReceivingDate: patients.ReceivingDate,
  245. IsHospitalFirstDialysis: patients.IsHospitalFirstDialysis,
  246. FirstDialysisDate: patients.FirstDialysisDate,
  247. FirstDialysisHospital: patients.FirstDialysisHospital,
  248. PredialysisCondition: patients.PredialysisCondition,
  249. PreHospitalDialysisFrequency: patients.PreHospitalDialysisFrequency,
  250. PreHospitalDialysisTimes: patients.PreHospitalDialysisTimes,
  251. HospitalFirstDialysisDate: patients.HospitalFirstDialysisDate,
  252. InductionPeriod: patients.InductionPeriod,
  253. InitialDialysis: patients.InitialDialysis,
  254. TotalDialysis: patients.TotalDialysis,
  255. AttendingDoctorId: patients.AttendingDoctorId,
  256. HeadNurseId: patients.HeadNurseId,
  257. Evaluate: patients.Evaluate,
  258. Diagnose: patients.Diagnose,
  259. Remark: patients.Remark,
  260. RegistrarsId: patients.RegistrarsId,
  261. Registrars: patients.Registrars,
  262. QrCode: patients.QrCode,
  263. BindingState: patients.BindingState,
  264. PatientComplains: patients.PatientComplains,
  265. PresentHistory: patients.PresentHistory,
  266. PastHistory: patients.PresentHistory,
  267. Temperature: patients.Temperature,
  268. Pulse: patients.Pulse,
  269. Respiratory: patients.Respiratory,
  270. Sbp: patients.SBP,
  271. Dbp: patients.DBP,
  272. Status: patients.Status,
  273. CreatedTime: patients.CreatedTime,
  274. UpdatedTime: patients.UpdatedTime,
  275. Nation: patients.Nation,
  276. NativePlace: patients.NativePlace,
  277. Age: patients.Age,
  278. InfectiousNextRecordTime: patients.InfectiousNextRecordTime,
  279. IsInfectious: patients.IsInfectious,
  280. RemindCycle: patients.RemindCycle,
  281. ResponseResult: patients.ResponseResult,
  282. IsOpenRemind: patients.IsOpenRemind,
  283. FirstTreatmentDate: patients.FirstTreatmentDate,
  284. DialysisAge: patients.DialysisAge,
  285. ExpenseKind: patients.ExpenseKind,
  286. TellPhone: patients.TellPhone,
  287. ContactName: patients.ContactName,
  288. BloodPatients: 1,
  289. SlowPatients: 0,
  290. MemberPatients: 0,
  291. EcommerPatients: "",
  292. BloodId: patients.ID,
  293. SlowId: 0,
  294. MemberId: 0,
  295. MemberFistdate: 0,
  296. MemberPatienttype: 0,
  297. MemberTreatement: 0,
  298. EquitmentId: "",
  299. UserSysBeforeCount: patient.UserSysBeforeCount,
  300. }
  301. err = service.CreatePatientsNew(&patientsNew)
  302. fmt.Print("创建失败", err)
  303. if len(record_date) > 0 {
  304. var recordTime int64
  305. timeLayout := "2006-01-02"
  306. loc, _ := time.LoadLocation("Local")
  307. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  308. if err != nil {
  309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  310. return
  311. }
  312. recordTime = theTime.Unix()
  313. inspections := make([]models.Inspection, 0)
  314. for _, item := range formItems {
  315. var inspection models.Inspection
  316. inspection.OrgId = adminUserInfo.CurrentOrgId
  317. inspection.PatientId = patient.ID
  318. inspection.ProjectId = item.ProjectId
  319. inspection.ItemId = item.ItemId
  320. inspection.ItemName = item.ItemName
  321. inspection.ProjectName = item.ProjectName
  322. inspection.InspectType = item.RangeType
  323. inspection.InspectValue = item.Value
  324. inspection.InspectDate = recordTime
  325. inspection.Status = 1
  326. inspection.CreatedTime = time.Now().Unix()
  327. inspection.UpdatedTime = time.Now().Unix()
  328. inspections = append(inspections, inspection)
  329. }
  330. err = service.CreatePatientInspection(inspections)
  331. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  332. var record_time int64
  333. switch remind_cycle {
  334. case 1: //1个月
  335. ts := time.Unix(infectiousRecord.InspectDate, 0)
  336. record_time = ts.AddDate(0, 1, 0).Unix()
  337. break
  338. case 2: //2个月
  339. ts := time.Unix(infectiousRecord.InspectDate, 0)
  340. record_time = ts.AddDate(0, 2, 0).Unix()
  341. break
  342. case 3: //3个月
  343. ts := time.Unix(infectiousRecord.InspectDate, 0)
  344. record_time = ts.AddDate(0, 3, 0).Unix()
  345. break
  346. case 4: //6个月
  347. ts := time.Unix(infectiousRecord.InspectDate, 0)
  348. record_time = ts.AddDate(0, 6, 0).Unix()
  349. break
  350. case 5: //12个月
  351. ts := time.Unix(infectiousRecord.InspectDate, 0)
  352. record_time = ts.AddDate(0, 12, 0).Unix()
  353. break
  354. }
  355. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  356. if errs != nil {
  357. utils.ErrorLog("更新日期出错:%v", errs)
  358. }
  359. }
  360. redis := service.RedisClient()
  361. defer redis.Close()
  362. redis.SAdd("sgj_patient:new_user_set", patient.UserId)
  363. c.ServeSuccessJSON(map[string]interface{}{
  364. "msg": "ok",
  365. })
  366. return
  367. }
  368. //EditPatient 修改
  369. func (c *PatientApiController) EditPatient() {
  370. id, _ := c.GetInt64("id", 0)
  371. record_date := c.GetString("record_date")
  372. is_infectious, _ := c.GetInt64("is_infectious")
  373. remind_cycle, _ := c.GetInt64("remind_cycle")
  374. if id <= 0 {
  375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  376. return
  377. }
  378. adminUserInfo := c.GetAdminUserInfo()
  379. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  380. if patient.ID == 0 {
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  382. return
  383. }
  384. contagions, diseases, code, formItems := patientFormData(&patient, c.Ctx.Input.RequestBody, "edit")
  385. if code > 0 {
  386. c.ServeFailJSONWithSGJErrorCode(code)
  387. return
  388. }
  389. thisPatientother, _ := service.FindPatientByDialysisNo(adminUserInfo.CurrentOrgId, patient.DialysisNo)
  390. if thisPatientother.ID > 0 && thisPatientother.ID != patient.ID {
  391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisNoExist)
  392. return
  393. }
  394. thisPatient, _ := service.FindPatientByIdCardNo(adminUserInfo.CurrentOrgId, patient.IdCardNo)
  395. if thisPatient.ID > 0 && thisPatient.ID != patient.ID {
  396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIdCardNoExist)
  397. return
  398. }
  399. patient.UpdatedTime = time.Now().Unix()
  400. patient.IsInfectious = is_infectious
  401. patient.RemindCycle = remind_cycle
  402. err := service.UpdatePatient(&patient, contagions, diseases)
  403. if err != nil {
  404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  405. return
  406. }
  407. ////更新转归状态
  408. //lapseto := models.PatientLapseto{
  409. // LapsetoType: patient.Lapseto,
  410. // LapsetoTime: time.Now().Unix(),
  411. // UpdatedTime: time.Now().Unix(),
  412. //}
  413. //err = service.UpdatePatientLapseto(patient.ID, lapseto)
  414. //fmt.Println("更新转归失败", err)
  415. if err != nil {
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdatePatient)
  417. return
  418. }
  419. patientsNew := models.XtPatientsNew{
  420. UserOrgId: patient.UserOrgId,
  421. UserId: patient.UserId,
  422. Avatar: patient.Avatar,
  423. PatientType: patient.PatientType,
  424. DialysisNo: patient.DialysisNo,
  425. AdmissionNumber: patient.AdmissionNumber,
  426. Source: patient.Source,
  427. PartitionId: patient.PartitionId,
  428. BedId: patient.BedId,
  429. Name: patient.Name,
  430. Alias: patient.Alias,
  431. Gender: patient.Gender,
  432. MaritalStatus: patient.MaritalStatus,
  433. IdCardNo: patient.IdCardNo,
  434. Birthday: patient.Birthday,
  435. ReimbursementWayId: patient.ReimbursementWayId,
  436. HealthCareType: patient.HealthCareType,
  437. HealthCareNo: patient.HealthCareNo,
  438. HealthCareDueDate: patient.HealthCareDueDate,
  439. Height: patient.Height,
  440. BloodType: patient.BloodType,
  441. Rh: patient.Rh,
  442. HealthCareDueAlertDate: patient.HealthCareDueAlertDate,
  443. EducationLevel: patient.EducationLevel,
  444. Profession: patient.Profession,
  445. Phone: patient.Phone,
  446. HomeTelephone: patient.HomeTelephone,
  447. RelativePhone: patient.RelativePhone,
  448. RelativeRelations: patient.RelativeRelations,
  449. HomeAddress: patient.HomeAddress,
  450. WorkUnit: patient.WorkUnit,
  451. UnitAddress: patient.UnitAddress,
  452. Children: patient.Children,
  453. ReceivingDate: patient.ReceivingDate,
  454. IsHospitalFirstDialysis: patient.IsHospitalFirstDialysis,
  455. FirstDialysisDate: patient.FirstDialysisDate,
  456. FirstDialysisHospital: patient.FirstDialysisHospital,
  457. PredialysisCondition: patient.PredialysisCondition,
  458. PreHospitalDialysisTimes: patient.PreHospitalDialysisTimes,
  459. HospitalFirstDialysisDate: patient.HospitalFirstDialysisDate,
  460. InductionPeriod: patient.InductionPeriod,
  461. InitialDialysis: patient.InitialDialysis,
  462. TotalDialysis: patient.TotalDialysis,
  463. AttendingDoctorId: patient.AttendingDoctorId,
  464. HeadNurseId: patient.HeadNurseId,
  465. Evaluate: patient.Evaluate,
  466. Diagnose: patient.Diagnose,
  467. Remark: patient.Remark,
  468. RegistrarsId: patient.RegistrarsId,
  469. Registrars: patient.Registrars,
  470. QrCode: patient.QrCode,
  471. BindingState: patient.BindingState,
  472. PatientComplains: patient.PatientComplains,
  473. PresentHistory: patient.PresentHistory,
  474. PastHistory: patient.PastHistory,
  475. Temperature: patient.Temperature,
  476. Pulse: patient.Pulse,
  477. Respiratory: patient.Respiratory,
  478. Sbp: patient.SBP,
  479. Dbp: patient.DBP,
  480. Nation: patient.Nation,
  481. NativePlace: patient.NativePlace,
  482. Age: patient.Age,
  483. InfectiousNextRecordTime: patient.InfectiousNextRecordTime,
  484. IsInfectious: patient.IsInfectious,
  485. RemindCycle: patient.RemindCycle,
  486. ResponseResult: patient.ResponseResult,
  487. IsOpenRemind: patient.IsOpenRemind,
  488. FirstTreatmentDate: patient.FirstTreatmentDate,
  489. DialysisAge: patient.DialysisAge,
  490. ExpenseKind: patient.ExpenseKind,
  491. TellPhone: patient.TellPhone,
  492. ContactName: patient.ContactName,
  493. UpdatedTime: time.Now().Unix(),
  494. BloodPatients: 1,
  495. Lapseto: patient.Lapseto,
  496. }
  497. // //更新病人ID获取新表病人ID
  498. err = service.UpdatepatientTwo(&patientsNew, id)
  499. if len(record_date) > 0 {
  500. var recordTime int64
  501. timeLayout := "2006-01-02"
  502. loc, _ := time.LoadLocation("Local")
  503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  504. if err != nil {
  505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  506. return
  507. }
  508. recordTime = theTime.Unix()
  509. inspections := make([]models.Inspection, 0)
  510. for _, item := range formItems {
  511. var inspection models.Inspection
  512. inspection.OrgId = adminUserInfo.CurrentOrgId
  513. inspection.PatientId = patient.ID
  514. inspection.ProjectId = item.ProjectId
  515. inspection.ItemId = item.ItemId
  516. inspection.ItemName = item.ItemName
  517. inspection.ProjectName = item.ProjectName
  518. inspection.InspectType = item.RangeType
  519. inspection.InspectValue = item.Value
  520. inspection.InspectDate = recordTime
  521. inspection.Status = 1
  522. inspection.CreatedTime = time.Now().Unix()
  523. inspection.UpdatedTime = time.Now().Unix()
  524. inspections = append(inspections, inspection)
  525. }
  526. err = service.CreatePatientInspection(inspections)
  527. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  528. var record_time int64
  529. switch remind_cycle {
  530. case 1: //1个月
  531. ts := time.Unix(infectiousRecord.InspectDate, 0)
  532. record_time = ts.AddDate(0, 1, 0).Unix()
  533. break
  534. case 2: //2个月
  535. ts := time.Unix(infectiousRecord.InspectDate, 0)
  536. record_time = ts.AddDate(0, 2, 0).Unix()
  537. break
  538. case 3: //3个月
  539. ts := time.Unix(infectiousRecord.InspectDate, 0)
  540. record_time = ts.AddDate(0, 3, 0).Unix()
  541. break
  542. case 4: //6个月
  543. ts := time.Unix(infectiousRecord.InspectDate, 0)
  544. record_time = ts.AddDate(0, 6, 0).Unix()
  545. break
  546. case 5: //12个月
  547. ts := time.Unix(infectiousRecord.InspectDate, 0)
  548. record_time = ts.AddDate(0, 12, 0).Unix()
  549. break
  550. }
  551. errs := service.UpDateInfectiousRecordTime(adminUserInfo.CurrentOrgId, patient.ID, record_time, remind_cycle)
  552. if errs != nil {
  553. utils.ErrorLog("更新日期出错:%v", errs)
  554. }
  555. }
  556. c.ServeSuccessJSON(map[string]interface{}{
  557. "msg": "ok",
  558. })
  559. return
  560. }
  561. func (c *PatientApiController) EditLapseto() {
  562. id, _ := c.GetInt64("id", 0)
  563. if id <= 0 {
  564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  565. return
  566. }
  567. adminUserInfo := c.GetAdminUserInfo()
  568. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  569. if patient.ID == 0 {
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  571. return
  572. }
  573. patientBody := make(map[string]interface{}, 0)
  574. err := json.Unmarshal(c.Ctx.Input.RequestBody, &patientBody)
  575. if err != nil {
  576. utils.ErrorLog(err.Error())
  577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  578. return
  579. }
  580. var lapseto models.PatientLapseto
  581. lapseto.PatientId = patient.ID
  582. if patientBody["lapseto_type"] == nil || reflect.TypeOf(patientBody["lapseto_type"]).String() != "float64" {
  583. utils.ErrorLog("lapseto_type")
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  585. return
  586. }
  587. lapsetoType := int64(patientBody["lapseto_type"].(float64))
  588. if lapsetoType <= 0 || lapsetoType > 3 {
  589. utils.ErrorLog("lapsetoType <= 0 || lapsetoType > 3")
  590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  591. return
  592. }
  593. lapseto.LapsetoType = lapsetoType
  594. timeLayout := "2006-01-02 15:04:05"
  595. loc, _ := time.LoadLocation("Local")
  596. if patientBody["lapseto_time"] == nil || reflect.TypeOf(patientBody["lapseto_time"]).String() != "string" {
  597. utils.ErrorLog("lapseto_time")
  598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoType)
  599. return
  600. }
  601. lapsetoTime, _ := patientBody["lapseto_time"].(string)
  602. if len(lapsetoTime) == 0 {
  603. utils.ErrorLog("len(lapsetoTime) == 0")
  604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  605. return
  606. }
  607. out_reason, _ := patientBody["out_reason"].(string)
  608. //if len(out_reason) == 0 {
  609. // utils.ErrorLog("len(out_reason) == 0")
  610. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  611. // return
  612. //}
  613. lapsetoTimeUnix, err := time.ParseInLocation(timeLayout, lapsetoTime, loc)
  614. if err != nil {
  615. utils.ErrorLog("lapsetoTimeUnix")
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSelectLapsetoTime)
  617. return
  618. }
  619. lapseto.LapsetoTime = lapsetoTimeUnix.Unix()
  620. lapseto.UpdatedTime = time.Now().Unix()
  621. lapseto.CreatedTime = time.Now().Unix()
  622. lapseto.Status = 1
  623. patient.Lapseto = lapseto.LapsetoType
  624. patient.OutReason = out_reason
  625. patient.DeathTime = lapsetoTimeUnix.Unix()
  626. //if patient.Lapseto == 1 {
  627. // patientTotal := service.GetLapsetoPatientCount(adminUserInfo.CurrentOrgId, 1)
  628. // subscibes := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
  629. // if subscibes.State == 2 && patientTotal >= 100 { //免费试用版,不过期,限制患者数20
  630. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  631. // return
  632. // } else if subscibes.State == 1 && patientTotal >= 200 { //标准版,不过期,限制患者数60
  633. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientReachLimit)
  634. // return
  635. // }
  636. //}
  637. err = service.EditPatientLapseto(&patient, &lapseto)
  638. if lapseto.LapsetoType == 3 {
  639. service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
  640. service.UpdateScheduleItemByPatientId(id)
  641. }
  642. if err != nil {
  643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
  644. return
  645. }
  646. c.ServeSuccessJSON(map[string]interface{}{
  647. "msg": "ok",
  648. })
  649. return
  650. }
  651. func (c *PatientApiController) GetPatient() {
  652. id, _ := c.GetInt64("id", 0)
  653. if id <= 0 {
  654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  655. return
  656. }
  657. adminUserInfo := c.GetAdminUserInfo()
  658. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  659. if patient.ID == 0 {
  660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  661. return
  662. }
  663. infectiousRecord, _ := service.FindLastRecordDate(adminUserInfo.CurrentOrgId, patient.ID, 14)
  664. infections, _ := service.GetAllInfectionRecord(infectiousRecord.InspectDate, adminUserInfo.CurrentOrgId, patient.ID, infectiousRecord.ProjectId)
  665. diseases := service.GetPatientDiseases(patient.ID)
  666. contagions := service.GetPatientContagions(patient.ID)
  667. c.ServeSuccessJSON(map[string]interface{}{
  668. "patient": patient,
  669. "diseases": diseases,
  670. "contagions": contagions,
  671. "infections": infections,
  672. })
  673. return
  674. }
  675. func (c *PatientApiController) CreateDialysisSolution() {
  676. id, _ := c.GetInt64("patient", 0)
  677. if id <= 0 {
  678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  679. return
  680. }
  681. adminUserInfo := c.GetAdminUserInfo()
  682. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  683. if patient.ID == 0 {
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  685. return
  686. }
  687. var solution models.DialysisSolution
  688. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "create")
  689. if code > 0 {
  690. c.ServeFailJSONWithSGJErrorCode(code)
  691. return
  692. }
  693. //thisSolution, _ := service.FindPatientDialysisSolutionByMode(adminUserInfo.CurrentOrgId, id, solution.ModeId)
  694. //if thisSolution.ID > 0 {
  695. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionExist)
  696. // return
  697. //}
  698. solution.RegistrarsId = adminUserInfo.AdminUser.Id
  699. solution.Doctor = adminUserInfo.AdminUser.Id
  700. solution.Status = 1
  701. solution.PatientId = id
  702. solution.CreatedTime = time.Now().Unix()
  703. solution.UserOrgId = adminUserInfo.CurrentOrgId
  704. solution.UpdatedTime = time.Now().Unix()
  705. solution.SubName = ""
  706. solution.ParentId = 0
  707. err := service.CreatePatientDialysisSolution(&solution)
  708. if err != nil {
  709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionCreate)
  710. return
  711. }
  712. c.ServeSuccessJSON(map[string]interface{}{
  713. "msg": "ok",
  714. "solution": solution,
  715. })
  716. return
  717. }
  718. func (c *PatientApiController) UpdateDialysisSolution() {
  719. patient, _ := c.GetInt64("patient", 0)
  720. id, _ := c.GetInt64("id", 0)
  721. if id <= 0 || patient <= 0 {
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. adminUserInfo := c.GetAdminUserInfo()
  726. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  727. if solution.ID == 0 || solution.PatientId != patient {
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  729. return
  730. }
  731. code := defaultSolutionFormData(&solution, c.Ctx.Input.RequestBody, "edit")
  732. if code > 0 {
  733. c.ServeFailJSONWithSGJErrorCode(code)
  734. return
  735. }
  736. solution.UpdatedTime = time.Now().Unix()
  737. err := service.UpdatePatientDialysisSolution(&solution)
  738. nowTimeUinx := time.Now()
  739. today := nowTimeUinx.Format("2006-01-02")
  740. timeLayout := "2006-01-02"
  741. loc, _ := time.LoadLocation("Local")
  742. todayTime, err := time.ParseInLocation(timeLayout, today, loc)
  743. prescription := models.DialysisPrescription{
  744. Dialyzer: solution.Dialyzer,
  745. Anticoagulant: solution.Anticoagulant,
  746. AnticoagulantShouji: solution.AnticoagulantShouji,
  747. AnticoagulantWeichi: solution.AnticoagulantWeichi,
  748. AnticoagulantZongliang: solution.AnticoagulantZongliang,
  749. ModeId: solution.ModeId,
  750. DialysisDurationHour: solution.DialysisDurationHour,
  751. Kalium: solution.Kalium,
  752. Sodium: solution.Sodium,
  753. Calcium: solution.Calcium,
  754. TargetUltrafiltration: solution.TargetUltrafiltration,
  755. DialyzerPerfusionApparatus: solution.DialyzerPerfusionApparatus,
  756. BloodAccess: solution.BloodAccess,
  757. DialysateFlow: solution.DialysateFlow,
  758. DialysateTemperature: solution.DialysateTemperature,
  759. DialysisIrrigation: solution.DialysisIrrigation,
  760. DialysisDialyszers: solution.DialysisDialyszers,
  761. PlasmaSeparator: solution.PlasmaSeparator,
  762. BilirubinAdsorptionColumn: solution.BilirubinAdsorptionColumn,
  763. OxygenUptake: solution.OxygenUptake,
  764. OxygenFlow: solution.OxygenFlow,
  765. OxygenTime: solution.OxygenTime,
  766. MaxUltrafiltrationRate: solution.MaxUltrafiltrationRate,
  767. }
  768. service.UpdatePatientDialysisSolutionOne(solution.PatientId, adminUserInfo.CurrentOrgId, &prescription, todayTime.Unix())
  769. if err != nil {
  770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  771. return
  772. }
  773. c.ServeSuccessJSON(map[string]interface{}{
  774. "msg": "ok",
  775. "solution": solution,
  776. })
  777. return
  778. }
  779. func (c *PatientApiController) UpdateDialysisSolutionDetail() {
  780. patient, _ := c.GetInt64("patient", 0)
  781. id, _ := c.GetInt64("id", 0)
  782. if id <= 0 || patient <= 0 {
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  784. return
  785. }
  786. adminUserInfo := c.GetAdminUserInfo()
  787. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  788. if solution.ID == 0 || solution.PatientId != patient {
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  790. return
  791. }
  792. code := solutionFormData(&solution, c.Ctx.Input.RequestBody)
  793. if code > 0 {
  794. c.ServeFailJSONWithSGJErrorCode(code)
  795. return
  796. }
  797. solution.UpdatedTime = time.Now().Unix()
  798. solution.AffirmState = 1
  799. err := service.UpdatePatientDialysisSolution(&solution)
  800. if err != nil {
  801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUpdate)
  802. return
  803. }
  804. c.ServeSuccessJSON(map[string]interface{}{
  805. "msg": "ok",
  806. "solution": solution,
  807. })
  808. return
  809. }
  810. func (c *PatientApiController) GetPatientDialysisSolutionList() {
  811. id, _ := c.GetInt64("id", 0)
  812. page, _ := c.GetInt64("page", 0)
  813. limit, _ := c.GetInt64("limit", 0)
  814. if id <= 0 {
  815. c.ServeSuccessJSON(map[string]interface{}{
  816. "solutions": nil,
  817. })
  818. return
  819. }
  820. if page <= 0 {
  821. page = 1
  822. }
  823. if limit <= 0 {
  824. limit = 10
  825. }
  826. adminUserInfo := c.GetAdminUserInfo()
  827. solutions, total, _ := service.GetPatientDialysisSolutionList(adminUserInfo.CurrentOrgId, id, page, limit)
  828. stockType, _ := service.GetStockType(adminUserInfo.CurrentOrgId)
  829. c.ServeSuccessJSON(map[string]interface{}{
  830. "solutions": solutions,
  831. "total": total,
  832. "stockType": stockType,
  833. })
  834. return
  835. }
  836. func (c *PatientApiController) DeleteDialysisSolution() {
  837. id, _ := c.GetInt64("id", 0)
  838. if id <= 0 {
  839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  840. return
  841. }
  842. adminUserInfo := c.GetAdminUserInfo()
  843. solution, _ := service.FindPatientDialysisSolution(adminUserInfo.CurrentOrgId, id)
  844. if solution.ID == 0 {
  845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionNotExist)
  846. return
  847. }
  848. if solution.UseState == 1 {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionUsed)
  850. return
  851. }
  852. solution.UpdatedTime = time.Now().Unix()
  853. solution.Status = 0
  854. err := service.DeleteSolution(&solution)
  855. if err != nil {
  856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisSolutionDelete)
  857. return
  858. }
  859. c.ServeSuccessJSON(map[string]interface{}{
  860. "msg": "ok",
  861. })
  862. return
  863. }
  864. //GetDryWeights 取患者干体重调整铺
  865. func (c *PatientApiController) GetDryWeights() {
  866. page, _ := c.GetInt64("page", 1)
  867. limit, _ := c.GetInt64("limit", 10)
  868. id, _ := c.GetInt64("id", 0)
  869. if id <= 0 {
  870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  871. return
  872. }
  873. adminUserInfo := c.GetAdminUserInfo()
  874. weights, total, _ := service.GetPatientDryWeightAdjustList(adminUserInfo.CurrentOrgId, id, page, limit)
  875. c.ServeSuccessJSON(map[string]interface{}{
  876. "weights": weights,
  877. "total": total,
  878. })
  879. return
  880. }
  881. func (c *PatientApiController) CreateDryWeights() {
  882. patient, _ := c.GetInt64("id", 0)
  883. if patient <= 0 {
  884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  885. return
  886. }
  887. adminUserInfo := c.GetAdminUserInfo()
  888. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  889. if patientInfo.ID == 0 {
  890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  891. return
  892. }
  893. var theWeight models.DryWeightAdjust
  894. dataBody := make(map[string]interface{}, 0)
  895. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  896. if err != nil {
  897. utils.ErrorLog(err.Error())
  898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  899. return
  900. }
  901. if dataBody["weight"] == nil || reflect.TypeOf(dataBody["weight"]).String() != "string" {
  902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  903. return
  904. }
  905. weight, _ := strconv.ParseFloat(dataBody["weight"].(string), 64)
  906. theWeight.Weight = weight
  907. // if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  908. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  909. // return
  910. // }
  911. // doctor := int64(dataBody["doctor"].(float64))
  912. // theWeight.Doctor = doctor
  913. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  914. remark, _ := dataBody["remark"].(string)
  915. theWeight.Remark = remark
  916. }
  917. theWeight.CreatedTime = time.Now().Unix()
  918. theWeight.UpdatedTime = time.Now().Unix()
  919. theWeight.Status = 1
  920. theWeight.RegistrarsId = adminUserInfo.AdminUser.Id
  921. theWeight.UserOrgId = adminUserInfo.CurrentOrgId
  922. theWeight.PatientId = patient
  923. theWeight.Doctor = adminUserInfo.AdminUser.Id
  924. old, _ := service.FindPatientLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient)
  925. if old.ID > 0 {
  926. theWeight.AdjustedValue = theWeight.Weight - old.Weight
  927. }
  928. err = service.CreateDryWeightAdjust(&theWeight)
  929. if err != nil {
  930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDryWeightFail)
  931. return
  932. }
  933. c.ServeSuccessJSON(map[string]interface{}{
  934. "msg": "ok",
  935. "weight": theWeight,
  936. })
  937. return
  938. }
  939. func (c *PatientApiController) CreateGroupAdvice() {
  940. patient, _ := c.GetInt64("id", 0)
  941. groupNo, _ := c.GetInt64("groupno", 0)
  942. if patient <= 0 {
  943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  944. return
  945. }
  946. adminUserInfo := c.GetAdminUserInfo()
  947. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  948. if patientInfo.ID == 0 {
  949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  950. return
  951. }
  952. dataBody := make(map[string]interface{}, 0)
  953. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  954. if err != nil {
  955. utils.ErrorLog(err.Error())
  956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  957. return
  958. }
  959. utils.ErrorLog("%v", dataBody)
  960. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  961. if appRole.UserType == 3 {
  962. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  963. if getPermissionErr != nil {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  965. return
  966. } else if headNursePermission == nil {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  968. return
  969. }
  970. }
  971. timeLayout := "2006-01-02"
  972. loc, _ := time.LoadLocation("Local")
  973. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  974. utils.ErrorLog("advice_type")
  975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  976. return
  977. }
  978. adviceType := int64(dataBody["advice_type"].(float64))
  979. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  980. utils.ErrorLog("advice_type != 1&&2")
  981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  982. return
  983. }
  984. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  985. utils.ErrorLog("advice_date")
  986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  987. return
  988. }
  989. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  990. utils.ErrorLog("start_time")
  991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  992. return
  993. }
  994. startTime2, _ := dataBody["start_time"].(string)
  995. time_arr := strings.Split(startTime2, " ")
  996. if len(time_arr) > 0 {
  997. startTime2 = time_arr[0]
  998. }
  999. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  1000. utils.ErrorLog("advice_date")
  1001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1002. return
  1003. }
  1004. adviceDate := startTime2
  1005. if len(adviceDate) == 0 {
  1006. utils.ErrorLog("len(adviceDate) == 0")
  1007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1008. return
  1009. }
  1010. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  1011. if err != nil {
  1012. utils.ErrorLog(err.Error())
  1013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1014. return
  1015. }
  1016. AdviceDate := theTime.Unix()
  1017. RecordDate := theTime.Unix()
  1018. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  1019. utils.ErrorLog("start_time")
  1020. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1021. return
  1022. }
  1023. startTime, _ := dataBody["start_time"].(string)
  1024. if len(startTime) == 0 {
  1025. utils.ErrorLog("len(start_time) == 0")
  1026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1027. return
  1028. }
  1029. theTime, err = time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  1030. if err != nil {
  1031. utils.ErrorLog(err.Error())
  1032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1033. return
  1034. }
  1035. StartTime := theTime.Unix()
  1036. Remark := ""
  1037. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  1038. remark, _ := dataBody["remark"].(string)
  1039. Remark = remark
  1040. }
  1041. var advices []*models.GroupAdvice
  1042. if dataBody["adviceNames"] == nil || reflect.TypeOf(dataBody["adviceNames"]).String() != "[]interface {}" {
  1043. utils.ErrorLog("adviceNames")
  1044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1045. return
  1046. }
  1047. adviceNames := dataBody["adviceNames"].([]interface{})
  1048. for _, adviceNameMap := range adviceNames {
  1049. adviceNameM := adviceNameMap.(map[string]interface{})
  1050. var advice models.GroupAdvice
  1051. advice.Remark = Remark
  1052. advice.AdviceType = adviceType
  1053. advice.StartTime = StartTime
  1054. advice.AdviceDate = AdviceDate
  1055. advice.RecordDate = RecordDate
  1056. advice.Status = 1
  1057. advice.CreatedTime = time.Now().Unix()
  1058. advice.UpdatedTime = time.Now().Unix()
  1059. advice.StopState = 2
  1060. advice.ExecutionState = 2
  1061. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1062. advice.PatientId = patientInfo.ID
  1063. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1064. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  1065. utils.ErrorLog("advice_name")
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1067. return
  1068. }
  1069. adviceName, _ := adviceNameM["advice_name"].(string)
  1070. if len(adviceName) == 0 {
  1071. utils.ErrorLog("len(advice_name) == 0")
  1072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1073. return
  1074. }
  1075. advice.AdviceName = adviceName
  1076. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  1077. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  1078. advice.DrugSpec = drugSpec
  1079. }
  1080. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  1081. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  1082. advice.AdviceDesc = adviceDesc
  1083. }
  1084. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  1085. template_id, _ := adviceNameM["template_id"].(string)
  1086. advice.TemplateId = template_id
  1087. }
  1088. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  1089. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  1090. advice.DrugSpecUnit = drugSpecUnit
  1091. }
  1092. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  1093. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  1094. advice.SingleDose = singleDose
  1095. }
  1096. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  1097. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  1098. advice.SingleDoseUnit = singleDoseUnit
  1099. }
  1100. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  1101. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  1102. advice.PrescribingNumber = prescribingNumber
  1103. }
  1104. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  1105. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  1106. advice.PrescribingNumberUnit = prescribingNumberUnit
  1107. }
  1108. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  1109. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  1110. advice.DeliveryWay = deliveryWay
  1111. }
  1112. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  1113. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1114. advice.ExecutionFrequency = executionFrequency
  1115. }
  1116. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  1117. way := int64(adviceNameM["way"].(float64))
  1118. advice.Way = way
  1119. }
  1120. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  1121. drug_id := int64(adviceNameM["drug_id"].(float64))
  1122. advice.DrugId = drug_id
  1123. }
  1124. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  1125. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  1126. advice.DrugNameId = drug_name_id
  1127. }
  1128. if adviceType == 1 {
  1129. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  1130. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  1131. advice.FrequencyType = frequency_type
  1132. }
  1133. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "string" {
  1134. day_count, _ := strconv.ParseInt(adviceNameM["day_count"].(string), 10, 64)
  1135. advice.DayCount = day_count
  1136. }
  1137. if adviceNameM["week_days"] != nil && reflect.TypeOf(adviceNameM["week_days"]).String() == "string" {
  1138. week_day, _ := adviceNameM["week_days"].(string)
  1139. advice.WeekDay = week_day
  1140. }
  1141. }
  1142. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "string" {
  1143. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  1144. advice.ExecutionFrequency = executionFrequency
  1145. }
  1146. if adviceNameM["children"] != nil && reflect.TypeOf(adviceNameM["children"]).String() == "[]interface {}" {
  1147. children := adviceNameM["children"].([]interface{})
  1148. if len(children) > 0 {
  1149. for _, childrenMap := range children {
  1150. childMap := childrenMap.(map[string]interface{})
  1151. var child models.GroupAdvice
  1152. child.Remark = Remark
  1153. child.AdviceType = adviceType
  1154. child.StartTime = StartTime
  1155. child.AdviceDate = AdviceDate
  1156. child.RecordDate = RecordDate
  1157. child.Status = 1
  1158. child.CreatedTime = time.Now().Unix()
  1159. child.UpdatedTime = time.Now().Unix()
  1160. child.StopState = 2
  1161. child.ExecutionState = 2
  1162. child.UserOrgId = adminUserInfo.CurrentOrgId
  1163. child.PatientId = patientInfo.ID
  1164. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  1165. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  1166. utils.ErrorLog("child advice_name")
  1167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1168. return
  1169. }
  1170. childAdviceName, _ := childMap["advice_name"].(string)
  1171. if len(childAdviceName) == 0 {
  1172. utils.ErrorLog("len(child advice_name) == 0")
  1173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1174. return
  1175. }
  1176. child.AdviceName = childAdviceName
  1177. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  1178. childAdviceDesc, _ := childMap["advice_desc"].(string)
  1179. child.AdviceDesc = childAdviceDesc
  1180. }
  1181. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  1182. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  1183. child.DrugSpec = childDrugSpec
  1184. }
  1185. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  1186. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  1187. child.DrugSpecUnit = childDrugSpecUnit
  1188. }
  1189. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  1190. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  1191. child.SingleDose = childSingleDose
  1192. }
  1193. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  1194. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  1195. child.SingleDoseUnit = childSingleDoseUnit
  1196. }
  1197. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  1198. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  1199. child.PrescribingNumber = childPrescribingNumber
  1200. }
  1201. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  1202. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  1203. child.PrescribingNumberUnit = childPrescribingNumberUnit
  1204. }
  1205. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  1206. drug_id := int64(childMap["drug_id"].(float64))
  1207. child.DrugId = drug_id
  1208. }
  1209. if childMap["way"] != nil && reflect.TypeOf(childMap["way"]).String() == "float64" {
  1210. way := int64(childMap["way"].(float64))
  1211. child.Way = way
  1212. }
  1213. if childMap["drug_name_id"] != nil && reflect.TypeOf(childMap["drug_name_id"]).String() == "float64" {
  1214. drug_name_id := int64(childMap["drug_name_id"].(float64))
  1215. child.DrugNameId = drug_name_id
  1216. }
  1217. child.DeliveryWay = advice.DeliveryWay
  1218. child.ExecutionFrequency = advice.ExecutionFrequency
  1219. advice.Children = append(advice.Children, &child)
  1220. }
  1221. }
  1222. }
  1223. advices = append(advices, &advice)
  1224. }
  1225. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  1226. if err != nil {
  1227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1228. return
  1229. }
  1230. c.ServeSuccessJSON(map[string]interface{}{
  1231. "msg": "ok",
  1232. "advices": list,
  1233. })
  1234. return
  1235. }
  1236. func (c *PatientApiController) CreateDoctorAdvice() {
  1237. patient, _ := c.GetInt64("id", 0)
  1238. if patient <= 0 {
  1239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1240. return
  1241. }
  1242. adminUserInfo := c.GetAdminUserInfo()
  1243. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1244. if patientInfo.ID == 0 {
  1245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1246. return
  1247. }
  1248. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1249. if appRole.UserType == 3 {
  1250. headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1251. if getPermissionErr != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1253. return
  1254. } else if headNursePermission == nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateAdvice)
  1256. return
  1257. }
  1258. }
  1259. var advice models.DoctorAdvice
  1260. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "create")
  1261. if code > 0 {
  1262. c.ServeFailJSONWithSGJErrorCode(code)
  1263. return
  1264. }
  1265. if advice.ParentId > 0 {
  1266. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  1267. if old.ID == 0 || old.PatientId != patient {
  1268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  1269. return
  1270. }
  1271. if old.StopState == 1 || old.ExecutionState == 1 {
  1272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1273. return
  1274. }
  1275. if old.ParentId > 0 {
  1276. advice.ParentId = old.ParentId
  1277. }
  1278. advice.StartTime = old.StartTime
  1279. advice.AdviceDoctor = old.AdviceDoctor
  1280. advice.DeliveryWay = old.DeliveryWay
  1281. advice.ExecutionFrequency = old.ExecutionFrequency
  1282. advice.GroupNo = old.GroupNo
  1283. }
  1284. advice.Status = 1
  1285. advice.CreatedTime = time.Now().Unix()
  1286. advice.UpdatedTime = time.Now().Unix()
  1287. advice.StopState = 2
  1288. advice.ExecutionState = 2
  1289. advice.UserOrgId = adminUserInfo.CurrentOrgId
  1290. advice.PatientId = patient
  1291. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  1292. err := service.CreateDoctorAdvice(&advice)
  1293. if err != nil {
  1294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  1295. return
  1296. }
  1297. c.ServeSuccessJSON(map[string]interface{}{
  1298. "msg": "ok",
  1299. "advice": advice,
  1300. })
  1301. return
  1302. }
  1303. func (c *PatientApiController) ExecGroupAdvice() {
  1304. groupNo, _ := c.GetInt64("groupno", 0)
  1305. executionTime := c.GetString("execution_time")
  1306. if groupNo <= 0 {
  1307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1308. return
  1309. }
  1310. if len(executionTime) <= 0 {
  1311. utils.ErrorLog("execution_time")
  1312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1313. return
  1314. }
  1315. adminUserInfo := c.GetAdminUserInfo()
  1316. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1317. if advice.ID == 0 {
  1318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1319. return
  1320. }
  1321. if advice.ExecutionState == 1 {
  1322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1323. return
  1324. }
  1325. executionStaff := adminUserInfo.AdminUser.Id
  1326. // checker := adminUserInfo.AdminUser.Id
  1327. timeLayout := "2006-01-02 15:04:05"
  1328. loc, _ := time.LoadLocation("Local")
  1329. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1330. if err != nil {
  1331. utils.ErrorLog(err.Error())
  1332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1333. return
  1334. }
  1335. if advice.StartTime > theTime.Unix() {
  1336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1337. return
  1338. }
  1339. exceAdvice := models.DoctorAdvice{
  1340. ExecutionStaff: executionStaff,
  1341. ExecutionTime: theTime.Unix(),
  1342. // Checker: checker,
  1343. UpdatedTime: time.Now().Unix(),
  1344. }
  1345. err = service.ExceDoctorAdviceByGroupNo(&exceAdvice, groupNo, adminUserInfo.CurrentOrgId)
  1346. if err != nil {
  1347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1348. return
  1349. }
  1350. advice.ExecutionStaff = executionStaff
  1351. advice.ExecutionTime = theTime.Unix()
  1352. // advice.Checker = checker
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "msg": "ok",
  1355. "advice": advice,
  1356. })
  1357. return
  1358. }
  1359. func (c *PatientApiController) ExecDoctorAdvice() {
  1360. origin, _ := c.GetInt64("origin", 0)
  1361. patient, _ := c.GetInt64("patient", 0)
  1362. id, _ := c.GetInt64("id", 0)
  1363. executionTime := c.GetString("execution_time")
  1364. if origin != 2 {
  1365. if id <= 0 || patient <= 0 {
  1366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1367. return
  1368. }
  1369. if len(executionTime) <= 0 {
  1370. utils.ErrorLog("execution_time")
  1371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1372. return
  1373. }
  1374. adminUserInfo := c.GetAdminUserInfo()
  1375. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1376. if advice.ID == 0 || advice.PatientId != patient {
  1377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1378. return
  1379. }
  1380. //医嘱已执行
  1381. if advice.ExecutionState == 1 {
  1382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1383. return
  1384. }
  1385. executionStaff := adminUserInfo.AdminUser.Id
  1386. // checker := adminUserInfo.AdminUser.Id
  1387. timeLayout := "2006-01-02 15:04:05"
  1388. loc, _ := time.LoadLocation("Local")
  1389. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1390. if err != nil {
  1391. utils.ErrorLog(err.Error())
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1393. return
  1394. }
  1395. if advice.StartTime > theTime.Unix() {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1397. return
  1398. }
  1399. exceAdvice := models.DoctorAdvice{
  1400. ExecutionStaff: executionStaff,
  1401. ExecutionTime: theTime.Unix(),
  1402. // Checker: checker,
  1403. UpdatedTime: time.Now().Unix(),
  1404. }
  1405. if advice.ParentId > 0 {
  1406. err = service.ExceDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1407. } else {
  1408. err = service.ExceDoctorAdviceById(&exceAdvice, id, patient)
  1409. }
  1410. if err != nil {
  1411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1412. return
  1413. }
  1414. advice.ExecutionStaff = executionStaff
  1415. advice.ExecutionTime = theTime.Unix()
  1416. // advice.Checker = checker
  1417. //处理出库相关逻辑
  1418. //1.判断是否启用药品管理和自备药出库功能
  1419. //药品管理信息
  1420. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1421. fmt.Println("999999992322322323232", drugStockConfig.IsOpen)
  1422. //自备药信息
  1423. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
  1424. fmt.Println("drugStockConfig2323232332232332", drugStockConfig.IsOpen)
  1425. if drugStockConfig.IsOpen == 1 {
  1426. var total int64
  1427. var prescribing_number_total int64
  1428. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1429. for _, item := range advices {
  1430. fmt.Println("imte00000000000000", item.PrescribingNumber)
  1431. //查询该药品是否有库存
  1432. list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  1433. fmt.Println("list23232323232232323232323232", list)
  1434. //查询改药品信息
  1435. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  1436. //判断单位是否相等
  1437. if medical.MaxUnit == item.PrescribingNumberUnit {
  1438. prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1439. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1440. //转化为最小单位
  1441. total = list.Count * medical.MinNumber
  1442. prescribing_number_total = count * medical.MinNumber
  1443. }
  1444. if medical.MinUnit == item.PrescribingNumberUnit {
  1445. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1446. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1447. total = list.Count*medical.MinNumber + list.StockMinNumber
  1448. prescribing_number_total = count
  1449. }
  1450. fmt.Println("数量一", prescribing_number_total)
  1451. fmt.Println("数量二", total)
  1452. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1453. c.ServeSuccessJSON(map[string]interface{}{
  1454. "msg": "3",
  1455. "advice": advice,
  1456. })
  1457. return
  1458. }
  1459. if prescribing_number_total > total {
  1460. c.ServeSuccessJSON(map[string]interface{}{
  1461. "msg": "2",
  1462. "advice": advice,
  1463. })
  1464. return
  1465. }
  1466. if prescribing_number_total <= total {
  1467. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1468. break
  1469. c.ServeSuccessJSON(map[string]interface{}{
  1470. "msg": "1",
  1471. "advice": advice,
  1472. })
  1473. return
  1474. }
  1475. ////查询该药品是否有库存
  1476. //list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  1477. //prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1478. //count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1479. //if list.Count == 0 {
  1480. // c.ServeSuccessJSON(map[string]interface{}{
  1481. // "msg": "1",
  1482. // "advice": advice,
  1483. // })
  1484. // return
  1485. //}
  1486. //if count > list.Count {
  1487. // c.ServeSuccessJSON(map[string]interface{}{
  1488. // "msg": "2",
  1489. // "advice": advice,
  1490. // })
  1491. // return
  1492. //}
  1493. ////调用药品出库接口
  1494. //service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1495. }
  1496. }
  1497. advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1498. for _, item := range advices {
  1499. if item.Way == 2 {
  1500. if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
  1501. //adviceName, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1502. if item.ExecutionState == 1 {
  1503. prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1504. count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1505. timeStr := time.Now().Format("2006-01-02")
  1506. timeArr := strings.Split(timeStr, "-")
  1507. total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
  1508. total = total + 1
  1509. warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1510. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1511. number = number + total
  1512. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1513. //插入自备药出库单
  1514. outStock := models.XtSelfOutStock{
  1515. DrugName: item.AdviceName,
  1516. DrugNameId: item.DrugId,
  1517. DrugSpec: item.AdviceDesc,
  1518. OutstoreNumber: count,
  1519. AdminUserId: adminUserInfo.AdminUser.Id,
  1520. StorckTime: item.RecordDate,
  1521. UserOrgId: adminUserInfo.CurrentOrgId,
  1522. CreatedTime: time.Now().Unix(),
  1523. Status: 1,
  1524. PatientId: item.PatientId,
  1525. ExitMode: 2,
  1526. MedicId: item.DrugId,
  1527. StockOutNumber: warehousing_out_order,
  1528. }
  1529. service.CreateOutStock(&outStock)
  1530. }
  1531. }
  1532. }
  1533. }
  1534. c.ServeSuccessJSON(map[string]interface{}{
  1535. "msg": "1",
  1536. "advice": advice,
  1537. })
  1538. return
  1539. } else {
  1540. if id <= 0 || patient <= 0 {
  1541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1542. return
  1543. }
  1544. if len(executionTime) <= 0 {
  1545. utils.ErrorLog("execution_time")
  1546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1547. return
  1548. }
  1549. adminUserInfo := c.GetAdminUserInfo()
  1550. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1551. if advice.ID == 0 || advice.PatientId != patient {
  1552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1553. return
  1554. }
  1555. //医嘱已执行
  1556. if advice.ExecutionState == 1 {
  1557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExced)
  1558. return
  1559. }
  1560. executionStaff := adminUserInfo.AdminUser.Id
  1561. // checker := adminUserInfo.AdminUser.Id
  1562. timeLayout := "2006-01-02 15:04:05"
  1563. loc, _ := time.LoadLocation("Local")
  1564. theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1565. if err != nil {
  1566. utils.ErrorLog(err.Error())
  1567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1568. return
  1569. }
  1570. if advice.StartTime > theTime.Unix() {
  1571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1572. return
  1573. }
  1574. exceAdvice := models.HisDoctorAdviceInfo{
  1575. ExecutionStaff: executionStaff,
  1576. ExecutionTime: theTime.Unix(),
  1577. // Checker: checker,
  1578. UpdatedTime: time.Now().Unix(),
  1579. }
  1580. if advice.ParentId > 0 {
  1581. err = service.ExceHidDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1582. } else {
  1583. err = service.ExceHidDoctorAdviceById(&exceAdvice, id, patient)
  1584. }
  1585. if err != nil {
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1587. return
  1588. }
  1589. advice.ExecutionStaff = executionStaff
  1590. advice.ExecutionTime = theTime.Unix()
  1591. // advice.Checker = checker
  1592. //处理出库相关逻辑
  1593. //1.判断是否启用药品管理和自备药出库功能
  1594. //药品管理信息
  1595. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
  1596. fmt.Println("000000000000000000000000000000000000", drugStockConfig.IsOpen)
  1597. if drugStockConfig.IsOpen == 1 {
  1598. //查询已经执行的医嘱
  1599. advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
  1600. for _, item := range advices {
  1601. var total int64
  1602. var prescribing_number_total int64
  1603. //查询该药品是否有库存
  1604. list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
  1605. //查询改药品信息
  1606. medical, _ := service.GetBaseDrugMedical(advice.DrugId)
  1607. //判断单位是否相等
  1608. if medical.MaxUnit == advice.PrescribingNumberUnit {
  1609. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1610. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1611. //转化为最小单位
  1612. total = list.Count * medical.MinNumber
  1613. prescribing_number_total = count * medical.MinNumber
  1614. }
  1615. fmt.Println("单位1", medical.MinUnit)
  1616. fmt.Println("d单位23", advice.PrescribingNumberUnit)
  1617. fmt.Println("hhhhhhh", list.Count)
  1618. if medical.MinUnit == advice.PrescribingNumberUnit {
  1619. prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
  1620. count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1621. total = list.Count*medical.MinNumber + list.StockMinNumber
  1622. fmt.Println("23232322323322323233223", total)
  1623. prescribing_number_total = count
  1624. fmt.Println("7777777777777777", prescribing_number_total)
  1625. }
  1626. fmt.Println("数量一", prescribing_number_total)
  1627. fmt.Println("数量二", total)
  1628. if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
  1629. c.ServeSuccessJSON(map[string]interface{}{
  1630. "msg": "3",
  1631. "advice": advice,
  1632. })
  1633. return
  1634. }
  1635. if prescribing_number_total > total {
  1636. c.ServeSuccessJSON(map[string]interface{}{
  1637. "msg": "2",
  1638. "advice": advice,
  1639. })
  1640. return
  1641. }
  1642. if prescribing_number_total <= total {
  1643. service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
  1644. break
  1645. c.ServeSuccessJSON(map[string]interface{}{
  1646. "msg": "1",
  1647. "advice": advice,
  1648. })
  1649. return
  1650. }
  1651. }
  1652. // //查询该药品是否有库存
  1653. // list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
  1654. // prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
  1655. // count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
  1656. // if list.Count == 0 {
  1657. // c.ServeSuccessJSON(map[string]interface{}{
  1658. // "msg": "1",
  1659. // "advice": advice,
  1660. // })
  1661. // return
  1662. // }
  1663. // if count > list.Count {
  1664. // c.ServeSuccessJSON(map[string]interface{}{
  1665. // "msg": "2",
  1666. // "advice": advice,
  1667. // })
  1668. // return
  1669. // }
  1670. // service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
  1671. //}
  1672. }
  1673. c.ServeSuccessJSON(map[string]interface{}{
  1674. "msg": "1",
  1675. "advice": advice,
  1676. })
  1677. return
  1678. }
  1679. }
  1680. func (c *PatientApiController) CheckGroupAdvice() {
  1681. groupno, _ := c.GetInt64("groupno", 0)
  1682. if groupno <= 0 {
  1683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1684. return
  1685. }
  1686. adminUserInfo := c.GetAdminUserInfo()
  1687. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupno)
  1688. if advice.ID == 0 {
  1689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1690. return
  1691. }
  1692. if advice.CheckState == 1 {
  1693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1694. return
  1695. }
  1696. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1698. return
  1699. }
  1700. checker := adminUserInfo.AdminUser.Id
  1701. theTime := time.Now()
  1702. exceAdvice := models.DoctorAdvice{
  1703. Checker: checker,
  1704. CheckTime: theTime.Unix(),
  1705. UpdatedTime: time.Now().Unix(),
  1706. }
  1707. var err error
  1708. err = service.CheckDoctorAdviceByGroupNo(&exceAdvice, groupno, adminUserInfo.CurrentOrgId)
  1709. if err != nil {
  1710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1711. return
  1712. }
  1713. // advice.ExecutionStaff = executionStaff
  1714. // advice.ExecutionTime = theTime.Unix()
  1715. advice.Checker = checker
  1716. advice.CheckTime = theTime.Unix()
  1717. c.ServeSuccessJSON(map[string]interface{}{
  1718. "msg": "ok",
  1719. "advice": advice,
  1720. })
  1721. return
  1722. }
  1723. func (c *PatientApiController) CheckDoctorAdvice() {
  1724. patient, _ := c.GetInt64("patient", 0)
  1725. id, _ := c.GetInt64("id", 0)
  1726. origin, _ := c.GetInt64("origin", 0)
  1727. if origin != 2 {
  1728. // executionTime := c.GetString("execution_time")
  1729. if id <= 0 || patient <= 0 {
  1730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1731. return
  1732. }
  1733. adminUserInfo := c.GetAdminUserInfo()
  1734. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1735. if advice.ID == 0 || advice.PatientId != patient {
  1736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1737. return
  1738. }
  1739. if advice.CheckState == 1 {
  1740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1741. return
  1742. }
  1743. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1745. return
  1746. }
  1747. // executionStaff := adminUserInfo.AdminUser.Id
  1748. checker := adminUserInfo.AdminUser.Id
  1749. // timeLayout := "2006-01-02 15:04:05"
  1750. // loc, _ := time.LoadLocation("Local")
  1751. // theTime, err := time.ParseInLocation(timeLayout, executionTime, loc)
  1752. // if err != nil {
  1753. // utils.ErrorLog(err.Error())
  1754. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1755. // return
  1756. // }
  1757. theTime := time.Now()
  1758. if advice.ExecutionTime > theTime.Unix() {
  1759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1760. return
  1761. }
  1762. exceAdvice := models.DoctorAdvice{
  1763. Checker: checker,
  1764. CheckTime: theTime.Unix(),
  1765. UpdatedTime: time.Now().Unix(),
  1766. }
  1767. var err error
  1768. if advice.ParentId > 0 {
  1769. err = service.CheckDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1770. } else {
  1771. err = service.CheckDoctorAdviceById(&exceAdvice, id, patient)
  1772. }
  1773. if err != nil {
  1774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1775. return
  1776. }
  1777. // advice.ExecutionStaff = executionStaff
  1778. // advice.ExecutionTime = theTime.Unix()
  1779. advice.Checker = checker
  1780. advice.CheckTime = theTime.Unix()
  1781. c.ServeSuccessJSON(map[string]interface{}{
  1782. "msg": "ok",
  1783. "advice": advice,
  1784. })
  1785. return
  1786. } else {
  1787. if id <= 0 || patient <= 0 {
  1788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1789. return
  1790. }
  1791. adminUserInfo := c.GetAdminUserInfo()
  1792. advice, _ := service.FindHisDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1793. if advice.ID == 0 || advice.PatientId != patient {
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1795. return
  1796. }
  1797. if advice.CheckState == 1 {
  1798. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceChecked)
  1799. return
  1800. }
  1801. if advice.ExecutionStaff >= 0 && advice.ExecutionStaff == adminUserInfo.AdminUser.Id {
  1802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExceAndCheckNotOneUser)
  1803. return
  1804. }
  1805. checker := adminUserInfo.AdminUser.Id
  1806. theTime := time.Now()
  1807. if advice.ExecutionTime > theTime.Unix() {
  1808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceExceBeforeStart)
  1809. return
  1810. }
  1811. exceAdvice := models.HisDoctorAdviceInfo{
  1812. Checker: checker,
  1813. CheckTime: theTime.Unix(),
  1814. UpdatedTime: time.Now().Unix(),
  1815. }
  1816. var err error
  1817. if advice.ParentId > 0 {
  1818. err = service.CheckHisDoctorAdviceById(&exceAdvice, advice.ParentId, patient)
  1819. } else {
  1820. err = service.CheckHisDoctorAdviceById(&exceAdvice, id, patient)
  1821. }
  1822. if err != nil {
  1823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1824. return
  1825. }
  1826. // advice.ExecutionStaff = executionStaff
  1827. // advice.ExecutionTime = theTime.Unix()
  1828. advice.Checker = checker
  1829. advice.CheckTime = theTime.Unix()
  1830. c.ServeSuccessJSON(map[string]interface{}{
  1831. "msg": "ok",
  1832. "advice": advice,
  1833. })
  1834. return
  1835. }
  1836. }
  1837. func (c *PatientApiController) UpdateDoctorAdvice() {
  1838. patient, _ := c.GetInt64("patient", 0)
  1839. id, _ := c.GetInt64("id", 0)
  1840. if id <= 0 || patient <= 0 {
  1841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1842. return
  1843. }
  1844. adminUserInfo := c.GetAdminUserInfo()
  1845. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1846. if advice.ID == 0 || advice.PatientId != patient {
  1847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1848. return
  1849. }
  1850. //if advice.AdviceType == 1 {
  1851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeLongTimeAdviceNotCanntEdit)
  1852. // return
  1853. //}
  1854. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1856. return
  1857. }
  1858. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1859. //if appRole.UserType == 3 {
  1860. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1861. // if getPermissionErr != nil {
  1862. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1863. // return
  1864. // } else if headNursePermission == nil {
  1865. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1866. // return
  1867. // }
  1868. //}
  1869. //if advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  1870. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCanotEditOtherAdvice)
  1871. // return
  1872. //}
  1873. code := adviceFormData(&advice, c.Ctx.Input.RequestBody, "update")
  1874. if code > 0 {
  1875. c.ServeFailJSONWithSGJErrorCode(code)
  1876. return
  1877. }
  1878. advice.UpdatedTime = time.Now().Unix()
  1879. advice.Modifier = adminUserInfo.AdminUser.Id
  1880. err := service.UpdateDoctorAdvice(&advice)
  1881. if err != nil {
  1882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  1883. return
  1884. }
  1885. c.ServeSuccessJSON(map[string]interface{}{
  1886. "msg": "ok",
  1887. "advice": advice,
  1888. })
  1889. return
  1890. }
  1891. func (c *PatientApiController) StopGroupAdvice() {
  1892. groupNo, _ := c.GetInt64("groupno", 0)
  1893. if groupNo <= 0 {
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1895. return
  1896. }
  1897. adminUserInfo := c.GetAdminUserInfo()
  1898. advice, _ := service.FindDoctorAdviceByGoroupNo(adminUserInfo.CurrentOrgId, groupNo)
  1899. if advice.ID == 0 {
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1901. return
  1902. }
  1903. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1905. return
  1906. }
  1907. dataBody := make(map[string]interface{}, 0)
  1908. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1909. if err != nil {
  1910. utils.ErrorLog(err.Error())
  1911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1912. return
  1913. }
  1914. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  1915. utils.ErrorLog("stop_time")
  1916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1917. return
  1918. }
  1919. stopTime, _ := dataBody["stop_time"].(string)
  1920. if len(stopTime) == 0 {
  1921. utils.ErrorLog("len(stop_time) == 0")
  1922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1923. return
  1924. }
  1925. timeLayout := "2006-01-02"
  1926. loc, _ := time.LoadLocation("Local")
  1927. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  1928. if err != nil {
  1929. utils.ErrorLog(err.Error())
  1930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1931. return
  1932. }
  1933. advice.StopTime = theTime.Unix()
  1934. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  1935. stopReason, _ := dataBody["stop_reason"].(string)
  1936. advice.StopReason = stopReason
  1937. }
  1938. advice.UpdatedTime = time.Now().Unix()
  1939. advice.StopDoctor = adminUserInfo.AdminUser.Id
  1940. advice.StopState = 1
  1941. err = service.StopGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, &advice)
  1942. if err != nil {
  1943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  1944. return
  1945. }
  1946. c.ServeSuccessJSON(map[string]interface{}{
  1947. "msg": "ok",
  1948. })
  1949. return
  1950. }
  1951. func (c *PatientApiController) StopDoctorAdvice() {
  1952. id, _ := c.GetInt64("id", 0)
  1953. if id <= 0 {
  1954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1955. return
  1956. }
  1957. adminUserInfo := c.GetAdminUserInfo()
  1958. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1959. //
  1960. //if appRole.UserType == 3 {
  1961. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1962. // if getPermissionErr != nil {
  1963. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1964. // return
  1965. // } else if headNursePermission == nil {
  1966. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1967. // return
  1968. // }
  1969. //}
  1970. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  1971. if advice.ID == 0 {
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  1973. return
  1974. }
  1975. if advice.StopState == 1 || advice.ExecutionState == 1 {
  1976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  1977. return
  1978. }
  1979. dataBody := make(map[string]interface{}, 0)
  1980. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1981. if err != nil {
  1982. utils.ErrorLog(err.Error())
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1984. return
  1985. }
  1986. if dataBody["stop_time"] == nil || reflect.TypeOf(dataBody["stop_time"]).String() != "string" {
  1987. utils.ErrorLog("stop_time")
  1988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1989. return
  1990. }
  1991. stopTime, _ := dataBody["stop_time"].(string)
  1992. if len(stopTime) == 0 {
  1993. utils.ErrorLog("len(stop_time) == 0")
  1994. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1995. return
  1996. }
  1997. timeLayout := "2006-01-02"
  1998. loc, _ := time.LoadLocation("Local")
  1999. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", stopTime, loc)
  2000. if err != nil {
  2001. utils.ErrorLog(err.Error())
  2002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2003. return
  2004. }
  2005. advice.StopTime = theTime.Unix()
  2006. if dataBody["stop_reason"] != nil && reflect.TypeOf(dataBody["stop_reason"]).String() == "string" {
  2007. stopReason, _ := dataBody["stop_reason"].(string)
  2008. advice.StopReason = stopReason
  2009. }
  2010. advice.UpdatedTime = time.Now().Unix()
  2011. advice.StopDoctor = adminUserInfo.AdminUser.Id
  2012. advice.StopState = 1
  2013. err = service.StopDoctorAdvice(&advice)
  2014. if err != nil {
  2015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeStopAdviceFail)
  2016. return
  2017. }
  2018. c.ServeSuccessJSON(map[string]interface{}{
  2019. "msg": "ok",
  2020. "advice": advice,
  2021. })
  2022. return
  2023. }
  2024. func (c *PatientApiController) DeleteDoctorAdvice() {
  2025. id, _ := c.GetInt64("id", 0)
  2026. if id <= 0 {
  2027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2028. return
  2029. }
  2030. adminUserInfo := c.GetAdminUserInfo()
  2031. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2032. if advice.ID == 0 {
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2034. return
  2035. }
  2036. //if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
  2037. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2038. // return
  2039. //}
  2040. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2041. //
  2042. //if appRole.UserType == 3 {
  2043. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2044. // if getPermissionErr != nil {
  2045. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2046. // return
  2047. // } else if headNursePermission == nil {
  2048. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2049. // return
  2050. // }
  2051. //}
  2052. advice.UpdatedTime = time.Now().Unix()
  2053. advice.Status = 0
  2054. advice.Modifier = adminUserInfo.AdminUser.Id
  2055. err := service.DeleteDoctorAdvice(&advice)
  2056. if err != nil {
  2057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2058. return
  2059. }
  2060. c.ServeSuccessJSON(map[string]interface{}{
  2061. "msg": "ok",
  2062. })
  2063. return
  2064. }
  2065. func (c *PatientApiController) DeleteGroupAdvice() {
  2066. groupNo, _ := c.GetInt64("groupno", 0)
  2067. if groupNo <= 0 {
  2068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2069. return
  2070. }
  2071. adminUserInfo := c.GetAdminUserInfo()
  2072. advice, _ := service.FindDoctorAdviceByGroupNo(adminUserInfo.CurrentOrgId, groupNo)
  2073. if advice.ID == 0 {
  2074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2075. return
  2076. }
  2077. //appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2078. //if appRole.UserType == 3 {
  2079. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2080. // if getPermissionErr != nil {
  2081. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2082. // return
  2083. // } else if headNursePermission == nil {
  2084. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2085. // return
  2086. // }
  2087. //}
  2088. err := service.DeleteGroupAdvice(adminUserInfo.CurrentOrgId, groupNo, adminUserInfo.AdminUser.Id)
  2089. if err != nil {
  2090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteAdviceFail)
  2091. return
  2092. }
  2093. c.ServeSuccessJSON(map[string]interface{}{
  2094. "msg": "ok",
  2095. })
  2096. return
  2097. }
  2098. //GetDoctorAdvices 医嘱列表
  2099. func (c *PatientApiController) GetDoctorAdvices() {
  2100. id, _ := c.GetInt64("id", 0)
  2101. adviceType, _ := c.GetInt64("advice_type", 0)
  2102. stopType, _ := c.GetInt64("stop_state", 0)
  2103. startTime := c.GetString("start_time", "")
  2104. endTime := c.GetString("end_time", "")
  2105. keywords := c.GetString("keywords", "")
  2106. page, _ := c.GetInt64("page")
  2107. fmt.Println("page", page)
  2108. limit, _ := c.GetInt64("limit")
  2109. fmt.Println("limit", limit)
  2110. adminUserInfo := c.GetAdminUserInfo()
  2111. operatorIDs := make([]int64, 0)
  2112. timeLayout := "2006-01-02"
  2113. loc, _ := time.LoadLocation("Local")
  2114. var theStartTIme int64
  2115. if len(startTime) > 0 {
  2116. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2117. if err != nil {
  2118. utils.ErrorLog(err.Error())
  2119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2120. return
  2121. }
  2122. theStartTIme = theTime.Unix()
  2123. }
  2124. var theEndtTIme int64
  2125. if len(endTime) > 0 {
  2126. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2127. if err != nil {
  2128. utils.ErrorLog(err.Error())
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2130. return
  2131. }
  2132. theEndtTIme = theTime.Unix()
  2133. }
  2134. advices, total, _ := service.GetDoctorAdviceListOne(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, page, limit)
  2135. advicestwo, _, _ := service.GetDoctorAdviceListTwo(adminUserInfo.CurrentOrgId, id, adviceType, stopType, theStartTIme, theEndtTIme, keywords, limit, page)
  2136. if len(advices) > 0 {
  2137. for _, item := range advices {
  2138. if item.AdviceDoctor > 0 {
  2139. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  2140. }
  2141. if item.ExecutionStaff > 0 {
  2142. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  2143. }
  2144. if item.Checker > 0 {
  2145. operatorIDs = append(operatorIDs, item.Checker)
  2146. }
  2147. if item.StopDoctor > 0 {
  2148. operatorIDs = append(operatorIDs, item.StopDoctor)
  2149. }
  2150. }
  2151. }
  2152. //相关操作对应的操作人
  2153. operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  2154. c.ServeSuccessJSON(map[string]interface{}{
  2155. "advices": advices,
  2156. "operators": operators,
  2157. "total": total,
  2158. "advicetwo": advicestwo,
  2159. })
  2160. return
  2161. }
  2162. func (c *PatientApiController) GetPatientSchedules() {
  2163. id, _ := c.GetInt64("id", 0)
  2164. if id <= 0 {
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2166. return
  2167. }
  2168. adminUserInfo := c.GetAdminUserInfo()
  2169. todayTime := time.Now().Format("2006-01-02")
  2170. timeLayout := "2006-01-02 15:04:05"
  2171. loc, _ := time.LoadLocation("Local")
  2172. var theStartTime int64
  2173. theTime, _ := time.ParseInLocation(timeLayout, todayTime+" 00:00:00", loc)
  2174. theStartTime = theTime.Unix()
  2175. schedules, _ := service.GetPatientScheduleFormToday(adminUserInfo.CurrentOrgId, id, theStartTime)
  2176. if len(schedules) > 0 {
  2177. for index, item := range schedules {
  2178. _, week := time.Unix(item.ScheduleDate, 0).ISOWeek()
  2179. schedules[index].Week = int64(week)
  2180. }
  2181. }
  2182. c.ServeSuccessJSON(map[string]interface{}{
  2183. "schedules": schedules,
  2184. })
  2185. return
  2186. }
  2187. func (c *PatientApiController) GetPatientDialysisRecords() {
  2188. patientID, _ := c.GetInt64("patient_id", 0)
  2189. page, _ := c.GetInt64("page", 0)
  2190. limit, _ := c.GetInt64("limit", 0)
  2191. startTime := c.GetString("start_time", "")
  2192. endTime := c.GetString("end_time", "")
  2193. mode_id, _ := c.GetInt64("mode_id", 0)
  2194. if page <= 0 {
  2195. page = 1
  2196. }
  2197. if limit <= 0 {
  2198. limit = 10
  2199. }
  2200. if patientID <= 0 {
  2201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2202. return
  2203. }
  2204. timeLayout := "2006-01-02"
  2205. loc, _ := time.LoadLocation("Local")
  2206. var theStartTIme int64
  2207. if len(startTime) > 0 {
  2208. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2209. if err != nil {
  2210. theStartTIme = 0
  2211. }
  2212. theStartTIme = theTime.Unix()
  2213. }
  2214. var theEndtTIme int64
  2215. if len(endTime) > 0 {
  2216. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2217. if err != nil {
  2218. theEndtTIme = 0
  2219. }
  2220. theEndtTIme = theTime.Unix()
  2221. }
  2222. adminInfo := c.GetAdminUserInfo()
  2223. records, total, _ := service.GetPatientDialysisRecord(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme, mode_id)
  2224. c.ServeSuccessJSON(map[string]interface{}{
  2225. "total": total,
  2226. "records": records,
  2227. })
  2228. return
  2229. }
  2230. func (c *PatientApiController) ProEducation() {
  2231. patientID, _ := c.GetInt64("patient_id", 0)
  2232. page, _ := c.GetInt64("page", 0)
  2233. limit, _ := c.GetInt64("limit", 0)
  2234. startTime := c.GetString("start_time", "")
  2235. endTime := c.GetString("end_time", "")
  2236. if page <= 0 {
  2237. page = 1
  2238. }
  2239. if limit <= 0 {
  2240. limit = 10
  2241. }
  2242. if patientID <= 0 {
  2243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2244. return
  2245. }
  2246. timeLayout := "2006-01-02"
  2247. loc, _ := time.LoadLocation("Local")
  2248. var theStartTIme int64
  2249. if len(startTime) > 0 {
  2250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  2251. if err != nil {
  2252. theStartTIme = 0
  2253. }
  2254. theStartTIme = theTime.Unix()
  2255. }
  2256. var theEndtTIme int64
  2257. if len(endTime) > 0 {
  2258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", endTime+" 23:59:59", loc)
  2259. if err != nil {
  2260. theEndtTIme = 0
  2261. }
  2262. theEndtTIme = theTime.Unix()
  2263. }
  2264. adminInfo := c.GetAdminUserInfo()
  2265. edus, total, _ := service.GetPatientTreatmentSummaryList(adminInfo.CurrentOrgId, patientID, page, limit, theStartTIme, theEndtTIme)
  2266. c.ServeSuccessJSON(map[string]interface{}{
  2267. "total": total,
  2268. "edus": edus,
  2269. })
  2270. return
  2271. }
  2272. func adviceFormData(advice *models.DoctorAdvice, data []byte, action string) (code int) {
  2273. dataBody := make(map[string]interface{}, 0)
  2274. err := json.Unmarshal(data, &dataBody)
  2275. if err != nil {
  2276. utils.ErrorLog(err.Error())
  2277. code = enums.ErrorCodeParamWrong
  2278. return
  2279. }
  2280. timeLayout := "2006-01-02"
  2281. loc, _ := time.LoadLocation("Local")
  2282. isChild := false
  2283. if action == "create" {
  2284. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2285. utils.ErrorLog("advice_type")
  2286. code = enums.ErrorCodeParamWrong
  2287. return
  2288. }
  2289. adviceType := int64(dataBody["advice_type"].(float64))
  2290. if adviceType != 1 && adviceType != 2 && adviceType != 3 && adviceType != 4 {
  2291. utils.ErrorLog("advice_type != 1&&2")
  2292. code = enums.ErrorCodeParamWrong
  2293. return
  2294. }
  2295. advice.AdviceType = adviceType
  2296. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2297. utils.ErrorLog("advice_date")
  2298. code = enums.ErrorCodeParamWrong
  2299. return
  2300. }
  2301. adviceDate, _ := dataBody["advice_date"].(string)
  2302. if len(adviceDate) == 0 {
  2303. utils.ErrorLog("len(adviceDate) == 0")
  2304. code = enums.ErrorCodeParamWrong
  2305. return
  2306. }
  2307. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2308. if err != nil {
  2309. utils.ErrorLog(err.Error())
  2310. code = enums.ErrorCodeParamWrong
  2311. return
  2312. }
  2313. advice.AdviceDate = theTime.Unix()
  2314. advice.RecordDate = theTime.Unix()
  2315. if dataBody["parent_id"] != nil && reflect.TypeOf(dataBody["parent_id"]).String() == "float64" {
  2316. parentId := int64(dataBody["parent_id"].(float64))
  2317. advice.ParentId = parentId
  2318. if parentId > 0 {
  2319. isChild = true
  2320. }
  2321. }
  2322. }
  2323. if !isChild {
  2324. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2325. utils.ErrorLog("start_time")
  2326. code = enums.ErrorCodeParamWrong
  2327. return
  2328. }
  2329. startTime, _ := dataBody["start_time"].(string)
  2330. if len(startTime) == 0 {
  2331. utils.ErrorLog("len(start_time) == 0")
  2332. code = enums.ErrorCodeParamWrong
  2333. return
  2334. }
  2335. theTime, err := time.ParseInLocation(timeLayout+" 15:04", startTime, loc)
  2336. if err != nil {
  2337. utils.ErrorLog(err.Error())
  2338. code = enums.ErrorCodeParamWrong
  2339. return
  2340. }
  2341. advice.StartTime = theTime.Unix()
  2342. // if dataBody["advice_doctor"] == nil || reflect.TypeOf(dataBody["advice_doctor"]).String() != "float64" {
  2343. // utils.ErrorLog("advice_doctor")
  2344. // code = enums.ErrorCodeParamWrong
  2345. // return
  2346. // }
  2347. // adviceDoctor := int64(dataBody["advice_doctor"].(float64))
  2348. // if adviceDoctor <= 0 {
  2349. // utils.ErrorLog("advice_doctor <=0")
  2350. // code = enums.ErrorCodeParamWrong
  2351. // return
  2352. // }
  2353. // advice.AdviceDoctor = adviceDoctor
  2354. if dataBody["delivery_way"] != nil && reflect.TypeOf(dataBody["delivery_way"]).String() == "string" {
  2355. deliveryWay, _ := dataBody["delivery_way"].(string)
  2356. advice.DeliveryWay = deliveryWay
  2357. }
  2358. if dataBody["execution_frequency"] != nil && reflect.TypeOf(dataBody["execution_frequency"]).String() == "string" {
  2359. executionFrequency, _ := dataBody["execution_frequency"].(string)
  2360. advice.ExecutionFrequency = executionFrequency
  2361. }
  2362. if advice.AdviceType == 1 && advice.ParentId == 0 {
  2363. if dataBody["frequency_type"] != nil || reflect.TypeOf(dataBody["frequency_type"]).String() == "float64" {
  2364. frequency_type := int64(dataBody["frequency_type"].(float64))
  2365. advice.FrequencyType = frequency_type
  2366. }
  2367. if dataBody["day_count"] != nil || reflect.TypeOf(dataBody["day_count"]).String() == "string" {
  2368. day_count, _ := strconv.ParseInt(dataBody["day_count"].(string), 10, 64)
  2369. advice.DayCount = day_count
  2370. }
  2371. if dataBody["week_days"] != nil && reflect.TypeOf(dataBody["week_days"]).String() == "string" {
  2372. week_day, _ := dataBody["week_days"].(string)
  2373. advice.WeekDay = week_day
  2374. }
  2375. }
  2376. }
  2377. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2378. utils.ErrorLog("advice_name")
  2379. code = enums.ErrorCodeParamWrong
  2380. return
  2381. }
  2382. adviceName, _ := dataBody["advice_name"].(string)
  2383. if len(adviceName) == 0 {
  2384. utils.ErrorLog("len(advice_name) == 0")
  2385. code = enums.ErrorCodeParamWrong
  2386. return
  2387. }
  2388. advice.AdviceName = adviceName
  2389. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  2390. adviceDsc, _ := dataBody["advice_desc"].(string)
  2391. advice.AdviceDesc = adviceDsc
  2392. }
  2393. if dataBody["dialysis_order_id"] != nil && reflect.TypeOf(dataBody["dialysis_order_id"]).String() == "float64" {
  2394. dialysisOrderId, _ := dataBody["dialysis_order_id"].(float64)
  2395. advice.DialysisOrderId = int64(dialysisOrderId)
  2396. }
  2397. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  2398. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  2399. advice.SingleDose = singleDose
  2400. }
  2401. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  2402. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  2403. advice.SingleDoseUnit = singleDoseUnit
  2404. }
  2405. if dataBody["drug_spec"] != nil && reflect.TypeOf(dataBody["drug_spec"]).String() == "string" {
  2406. drugSpec, _ := strconv.ParseFloat(dataBody["drug_spec"].(string), 64)
  2407. advice.DrugSpec = drugSpec
  2408. }
  2409. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  2410. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  2411. advice.DrugSpecUnit = drugSpecUnit
  2412. }
  2413. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  2414. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  2415. advice.PrescribingNumber = prescribingNumber
  2416. }
  2417. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  2418. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  2419. advice.PrescribingNumberUnit = prescribingNumberUnit
  2420. }
  2421. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2422. remark, _ := dataBody["remark"].(string)
  2423. advice.Remark = remark
  2424. }
  2425. if dataBody["drug_id"] != nil && reflect.TypeOf(dataBody["drug_id"]).String() == "float64" {
  2426. drug_id, _ := dataBody["drug_id"].(float64)
  2427. advice.DrugId = int64(drug_id)
  2428. }
  2429. if dataBody["drug_name_id"] != nil && reflect.TypeOf(dataBody["drug_name_id"]).String() == "float64" {
  2430. drug_name_id, _ := dataBody["drug_name_id"].(float64)
  2431. advice.DrugNameId = int64(drug_name_id)
  2432. }
  2433. if dataBody["way"] != nil && reflect.TypeOf(dataBody["way"]).String() == "float64" {
  2434. way, _ := dataBody["way"].(float64)
  2435. advice.Way = int64(way)
  2436. }
  2437. return
  2438. }
  2439. func solutionFormData(solution *models.DialysisSolution, data []byte) (code int) {
  2440. dataBody := make(map[string]interface{}, 0)
  2441. err := json.Unmarshal(data, &dataBody)
  2442. utils.InfoLog(string(data))
  2443. if err != nil {
  2444. utils.ErrorLog(err.Error())
  2445. code = enums.ErrorCodeParamWrong
  2446. return
  2447. }
  2448. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2449. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2450. solution.DialysisDuration = dialysisDuration
  2451. }
  2452. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2453. replacementWay := int64(dataBody["replacement_way"].(float64))
  2454. solution.ReplacementWay = replacementWay
  2455. }
  2456. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2457. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2458. solution.BloodFlowVolume = bloodFlowVolume
  2459. }
  2460. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2461. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2462. solution.HemodialysisMachine = hemodialysisMachine
  2463. }
  2464. if dataBody["blood_filter"] != nil && reflect.TypeOf(dataBody["blood_filter"]).String() == "float64" {
  2465. bloodFilter := int64(dataBody["blood_filter"].(float64))
  2466. solution.BloodFilter = bloodFilter
  2467. }
  2468. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2469. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2470. solution.PerfusionApparatus = perfusionApparatus
  2471. }
  2472. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2473. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2474. solution.DialysateFlow = dialysateFlow
  2475. }
  2476. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2477. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2478. solution.Kalium = kalium
  2479. }
  2480. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2481. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2482. solution.Sodium = sodium
  2483. }
  2484. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2485. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2486. solution.Calcium = calcium
  2487. }
  2488. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2489. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2490. solution.Bicarbonate = bicarbonate
  2491. }
  2492. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2493. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2494. solution.Anticoagulant = anticoagulant
  2495. }
  2496. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2497. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2498. solution.AnticoagulantShouji = anticoagulantShouji
  2499. }
  2500. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2501. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2502. solution.AnticoagulantWeichi = anticoagulantWeichi
  2503. }
  2504. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2505. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2506. solution.AnticoagulantZongliang = anticoagulantZongliang
  2507. }
  2508. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2509. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2510. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2511. }
  2512. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2513. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2514. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2515. }
  2516. return
  2517. }
  2518. func defaultSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2519. dataBody := make(map[string]interface{}, 0)
  2520. err := json.Unmarshal(data, &dataBody)
  2521. utils.InfoLog(string(data))
  2522. if err != nil {
  2523. utils.ErrorLog(err.Error())
  2524. code = enums.ErrorCodeParamWrong
  2525. return
  2526. }
  2527. if method == "create" {
  2528. if dataBody["mode"] == nil || reflect.TypeOf(dataBody["mode"]).String() != "float64" {
  2529. utils.ErrorLog("mode")
  2530. code = enums.ErrorCodeParamWrong
  2531. return
  2532. }
  2533. mode := int64(dataBody["mode"].(float64))
  2534. if mode <= 0 {
  2535. utils.ErrorLog("mode <= 0")
  2536. code = enums.ErrorCodeParamWrong
  2537. return
  2538. }
  2539. solution.ModeId = mode
  2540. if dataBody["mode_name"] == nil || reflect.TypeOf(dataBody["mode_name"]).String() != "string" {
  2541. utils.ErrorLog("mode_name")
  2542. code = enums.ErrorCodeParamWrong
  2543. return
  2544. }
  2545. modeName, _ := dataBody["mode_name"].(string)
  2546. if len(modeName) == 0 {
  2547. utils.ErrorLog("len(mode_name) == 0")
  2548. code = enums.ErrorCodeParamWrong
  2549. return
  2550. }
  2551. solution.ModeName = modeName
  2552. solution.Name = modeName
  2553. }
  2554. if dataBody["dialysis_duration"] != nil && reflect.TypeOf(dataBody["dialysis_duration"]).String() == "string" {
  2555. dialysisDuration, _ := strconv.ParseFloat(dataBody["dialysis_duration"].(string), 64)
  2556. solution.DialysisDuration = dialysisDuration
  2557. }
  2558. if dataBody["target_ultrafiltration"] != nil && reflect.TypeOf(dataBody["target_ultrafiltration"]).String() == "string" {
  2559. targetUltrafiltration, _ := strconv.ParseFloat(dataBody["target_ultrafiltration"].(string), 64)
  2560. solution.TargetUltrafiltration = targetUltrafiltration
  2561. }
  2562. if dataBody["dialysate_formulation"] != nil && reflect.TypeOf(dataBody["dialysate_formulation"]).String() == "float64" {
  2563. dialysateFormulation := int64(dataBody["dialysate_formulation"].(float64))
  2564. solution.DialysateFormulation = dialysateFormulation
  2565. }
  2566. if dataBody["dialysis_duration_hour"] != nil && reflect.TypeOf(dataBody["dialysis_duration_hour"]).String() == "string" {
  2567. dialysisDurationHour, _ := strconv.ParseFloat(dataBody["dialysis_duration_hour"].(string), 64)
  2568. solution.DialysisDurationHour = int64(dialysisDurationHour)
  2569. }
  2570. if dataBody["dialysis_duration_minute"] != nil && reflect.TypeOf(dataBody["dialysis_duration_minute"]).String() == "string" {
  2571. dialysisDurationMinute, _ := strconv.ParseFloat(dataBody["dialysis_duration_minute"].(string), 64)
  2572. solution.DialysisDurationMinute = int64(dialysisDurationMinute)
  2573. }
  2574. if dataBody["hemodialysis_machine"] != nil && reflect.TypeOf(dataBody["hemodialysis_machine"]).String() == "float64" {
  2575. hemodialysisMachine := int64(dataBody["hemodialysis_machine"].(float64))
  2576. solution.HemodialysisMachine = hemodialysisMachine
  2577. }
  2578. if dataBody["dialyzer"] != nil && reflect.TypeOf(dataBody["dialyzer"]).String() == "float64" {
  2579. dialyzer := int64(dataBody["dialyzer"].(float64))
  2580. solution.Dialyzer = dialyzer
  2581. }
  2582. if dataBody["perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["perfusion_apparatus"]).String() == "float64" {
  2583. perfusionApparatus := int64(dataBody["perfusion_apparatus"].(float64))
  2584. solution.PerfusionApparatus = perfusionApparatus
  2585. }
  2586. if dataBody["blood_flow_volume"] != nil && reflect.TypeOf(dataBody["blood_flow_volume"]).String() == "string" {
  2587. bloodFlowVolume, _ := strconv.ParseFloat(dataBody["blood_flow_volume"].(string), 64)
  2588. solution.BloodFlowVolume = bloodFlowVolume
  2589. }
  2590. if dataBody["dewater"] != nil && reflect.TypeOf(dataBody["dewater"]).String() == "string" {
  2591. dewater, _ := strconv.ParseFloat(dataBody["dewater"].(string), 64)
  2592. solution.Dewater = dewater
  2593. }
  2594. if dataBody["displace_liqui"] != nil && reflect.TypeOf(dataBody["displace_liqui"]).String() == "string" {
  2595. displaceLiqui, _ := strconv.ParseFloat(dataBody["displace_liqui"].(string), 64)
  2596. solution.DisplaceLiqui = displaceLiqui
  2597. }
  2598. if dataBody["replacement_way"] != nil && reflect.TypeOf(dataBody["replacement_way"]).String() == "float64" {
  2599. replacementWay := int64(dataBody["replacement_way"].(float64))
  2600. solution.ReplacementWay = replacementWay
  2601. }
  2602. if dataBody["anticoagulant"] != nil && reflect.TypeOf(dataBody["anticoagulant"]).String() == "float64" {
  2603. anticoagulant := int64(dataBody["anticoagulant"].(float64))
  2604. solution.Anticoagulant = anticoagulant
  2605. }
  2606. if dataBody["anticoagulant_shouji"] != nil && reflect.TypeOf(dataBody["anticoagulant_shouji"]).String() == "string" {
  2607. anticoagulantShouji, _ := strconv.ParseFloat(dataBody["anticoagulant_shouji"].(string), 64)
  2608. solution.AnticoagulantShouji = anticoagulantShouji
  2609. }
  2610. if dataBody["anticoagulant_weichi"] != nil && reflect.TypeOf(dataBody["anticoagulant_weichi"]).String() == "string" {
  2611. anticoagulantWeichi, _ := strconv.ParseFloat(dataBody["anticoagulant_weichi"].(string), 64)
  2612. solution.AnticoagulantWeichi = anticoagulantWeichi
  2613. }
  2614. if dataBody["anticoagulant_zongliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_zongliang"]).String() == "string" {
  2615. anticoagulantZongliang, _ := strconv.ParseFloat(dataBody["anticoagulant_zongliang"].(string), 64)
  2616. solution.AnticoagulantZongliang = anticoagulantZongliang
  2617. }
  2618. if dataBody["anticoagulant_gaimingcheng"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaimingcheng"]).String() == "string" {
  2619. anticoagulantGaimingcheng, _ := dataBody["anticoagulant_gaimingcheng"].(string)
  2620. solution.AnticoagulantGaimingcheng = anticoagulantGaimingcheng
  2621. }
  2622. if dataBody["anticoagulant_gaijiliang"] != nil && reflect.TypeOf(dataBody["anticoagulant_gaijiliang"]).String() == "string" {
  2623. anticoagulantGaijiliang, _ := dataBody["anticoagulant_gaijiliang"].(string)
  2624. solution.AnticoagulantGaijiliang = anticoagulantGaijiliang
  2625. }
  2626. if dataBody["kalium"] != nil && reflect.TypeOf(dataBody["kalium"]).String() == "string" {
  2627. kalium, _ := strconv.ParseFloat(dataBody["kalium"].(string), 64)
  2628. solution.Kalium = kalium
  2629. }
  2630. if dataBody["sodium"] != nil && reflect.TypeOf(dataBody["sodium"]).String() == "string" {
  2631. sodium, _ := strconv.ParseFloat(dataBody["sodium"].(string), 64)
  2632. solution.Sodium = sodium
  2633. }
  2634. if dataBody["calcium"] != nil && reflect.TypeOf(dataBody["calcium"]).String() == "string" {
  2635. calcium, _ := strconv.ParseFloat(dataBody["calcium"].(string), 64)
  2636. solution.Calcium = calcium
  2637. }
  2638. if dataBody["bicarbonate"] != nil && reflect.TypeOf(dataBody["bicarbonate"]).String() == "string" {
  2639. bicarbonate, _ := strconv.ParseFloat(dataBody["bicarbonate"].(string), 64)
  2640. solution.Bicarbonate = bicarbonate
  2641. }
  2642. if dataBody["glucose"] != nil && reflect.TypeOf(dataBody["glucose"]).String() == "string" {
  2643. glucose, _ := strconv.ParseFloat(dataBody["glucose"].(string), 64)
  2644. solution.Glucose = glucose
  2645. }
  2646. // if dataBody["dry_weight"] != nil && reflect.TypeOf(dataBody["dry_weight"]).String() == "string" {
  2647. // dryWeight, _ := strconv.ParseFloat(dataBody["dry_weight"].(string), 64)
  2648. // solution.DryWeight = dryWeight
  2649. // }
  2650. if dataBody["dialysate_flow"] != nil && reflect.TypeOf(dataBody["dialysate_flow"]).String() == "string" {
  2651. dialysateFlow, _ := strconv.ParseFloat(dataBody["dialysate_flow"].(string), 64)
  2652. solution.DialysateFlow = dialysateFlow
  2653. }
  2654. if dataBody["dialysate_temperature"] != nil && reflect.TypeOf(dataBody["dialysate_temperature"]).String() == "string" {
  2655. dialysateTemperature, _ := strconv.ParseFloat(dataBody["dialysate_temperature"].(string), 64)
  2656. solution.DialysateTemperature = dialysateTemperature
  2657. }
  2658. if dataBody["conductivity"] != nil && reflect.TypeOf(dataBody["conductivity"]).String() == "string" {
  2659. conductivity, _ := strconv.ParseFloat(dataBody["conductivity"].(string), 64)
  2660. solution.Conductivity = conductivity
  2661. }
  2662. if dataBody["replacement_total"] != nil && reflect.TypeOf(dataBody["replacement_total"]).String() == "string" {
  2663. replacementTotal, _ := strconv.ParseFloat(dataBody["replacement_total"].(string), 64)
  2664. solution.ReplacementTotal = replacementTotal
  2665. }
  2666. if dataBody["dialyzer_perfusion_apparatus"] != nil && reflect.TypeOf(dataBody["dialyzer_perfusion_apparatus"]).String() == "string" {
  2667. dialyzer_perfusion_apparatus := dataBody["dialyzer_perfusion_apparatus"].(string)
  2668. solution.DialyzerPerfusionApparatus = dialyzer_perfusion_apparatus
  2669. }
  2670. if dataBody["body_fluid"] != nil && reflect.TypeOf(dataBody["body_fluid"]).String() == "float64" {
  2671. body_fluid := int64(dataBody["body_fluid"].(float64))
  2672. solution.BodyFluid = body_fluid
  2673. }
  2674. if dataBody["body_fluid_other"] != nil && reflect.TypeOf(dataBody["body_fluid_other"]).String() == "string" {
  2675. body_fluid_other := dataBody["body_fluid_other"].(string)
  2676. solution.BodyFluidOther = body_fluid_other
  2677. }
  2678. if dataBody["special_medicine"] != nil && reflect.TypeOf(dataBody["special_medicine"]).String() == "float64" {
  2679. special_medicine := int64(dataBody["special_medicine"].(float64))
  2680. solution.SpecialMedicine = special_medicine
  2681. }
  2682. if dataBody["special_medicine_other"] != nil && reflect.TypeOf(dataBody["special_medicine_other"]).String() == "string" {
  2683. special_medicine_other := dataBody["special_medicine_other"].(string)
  2684. solution.SpecialMedicineOther = special_medicine_other
  2685. }
  2686. if dataBody["displace_liqui_part"] != nil && reflect.TypeOf(dataBody["displace_liqui_part"]).String() == "float64" {
  2687. displace_liqui_part := int64(dataBody["displace_liqui_part"].(float64))
  2688. solution.DisplaceLiquiPart = displace_liqui_part
  2689. }
  2690. if dataBody["displace_liqui_value"] != nil && reflect.TypeOf(dataBody["displace_liqui_value"]).String() == "string" {
  2691. displace_liqui_value, _ := strconv.ParseFloat(dataBody["displace_liqui_value"].(string), 64)
  2692. solution.DisplaceLiquiValue = displace_liqui_value
  2693. }
  2694. if dataBody["blood_access"] != nil && reflect.TypeOf(dataBody["blood_access"]).String() == "float64" {
  2695. blood_access := int64(dataBody["blood_access"].(float64))
  2696. solution.BloodAccess = blood_access
  2697. }
  2698. if dataBody["ultrafiltration"] != nil && reflect.TypeOf(dataBody["ultrafiltration"]).String() == "string" {
  2699. ultrafiltration, _ := strconv.ParseFloat(dataBody["ultrafiltration"].(string), 64)
  2700. solution.Ultrafiltration = ultrafiltration
  2701. }
  2702. if dataBody["target_ktv"] != nil && reflect.TypeOf(dataBody["target_ktv"]).String() == "string" {
  2703. target_ktv, _ := strconv.ParseFloat(dataBody["target_ktv"].(string), 64)
  2704. solution.TargetKtv = target_ktv
  2705. }
  2706. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  2707. remark := dataBody["remark"].(string)
  2708. solution.Remark = remark
  2709. }
  2710. if dataBody["hemodialysis_pipelines"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines"]).String() == "string" {
  2711. hemodialysis_pipelines := dataBody["hemodialysis_pipelines"].(string)
  2712. solution.HemodialysisPipelines = hemodialysis_pipelines
  2713. }
  2714. if dataBody["hemodialysis_pipelines_count"] != nil && reflect.TypeOf(dataBody["hemodialysis_pipelines_count"]).String() == "string" {
  2715. hemodialysis_pipelines_count, _ := strconv.ParseFloat(dataBody["hemodialysis_pipelines_count"].(string), 64)
  2716. solution.HemodialysisPipelinesCount = hemodialysis_pipelines_count
  2717. }
  2718. if dataBody["puncture_needle"] != nil && reflect.TypeOf(dataBody["puncture_needle"]).String() == "string" {
  2719. puncture_needle := dataBody["puncture_needle"].(string)
  2720. solution.PunctureNeedle = puncture_needle
  2721. }
  2722. if dataBody["puncture_needle_count"] != nil && reflect.TypeOf(dataBody["puncture_needle_count"]).String() == "string" {
  2723. puncture_needle_count, _ := strconv.ParseFloat(dataBody["puncture_needle_count"].(string), 64)
  2724. solution.PunctureNeedleCount = puncture_needle_count
  2725. }
  2726. if dataBody["epo"] != nil && reflect.TypeOf(dataBody["epo"]).String() == "string" {
  2727. epo := dataBody["epo"].(string)
  2728. solution.Epo = epo
  2729. }
  2730. if dataBody["epo_count"] != nil && reflect.TypeOf(dataBody["epo_count"]).String() == "string" {
  2731. epo_count, _ := strconv.ParseFloat(dataBody["epo_count"].(string), 64)
  2732. solution.EpoCount = epo_count
  2733. }
  2734. if dataBody["created_time"] != nil && reflect.TypeOf(dataBody["created_time"]).String() == "float64" {
  2735. created_time := int64(dataBody["created_time"].(float64))
  2736. solution.CreatedTime = created_time
  2737. }
  2738. if dataBody["dialysis_dialyszers"] != nil && reflect.TypeOf(dataBody["dialysis_dialyszers"]).String() == "string" {
  2739. dialysisDialyszers := dataBody["dialysis_dialyszers"].(string)
  2740. solution.DialysisDialyszers = dialysisDialyszers
  2741. }
  2742. if dataBody["dialysis_irrigation"] != nil && reflect.TypeOf(dataBody["dialysis_irrigation"]).String() == "string" {
  2743. dialysisIrrigation := dataBody["dialysis_irrigation"].(string)
  2744. solution.DialysisIrrigation = dialysisIrrigation
  2745. }
  2746. if dataBody["plasma_separator"] != nil && reflect.TypeOf(dataBody["plasma_separator"]).String() == "string" {
  2747. plasmaSeparator := dataBody["plasma_separator"].(string)
  2748. solution.PlasmaSeparator = plasmaSeparator
  2749. }
  2750. if dataBody["bilirubin_adsorption_column"] != nil && reflect.TypeOf(dataBody["bilirubin_adsorption_column"]).String() == "string" {
  2751. bilirubinAdsorptionColumn := dataBody["bilirubin_adsorption_column"].(string)
  2752. solution.BilirubinAdsorptionColumn = bilirubinAdsorptionColumn
  2753. }
  2754. if dataBody["oxygen_uptake"] != nil && reflect.TypeOf(dataBody["oxygen_uptake"]).String() == "float64" {
  2755. oxygen_uptake := int64(dataBody["oxygen_uptake"].(float64))
  2756. solution.OxygenUptake = oxygen_uptake
  2757. }
  2758. if dataBody["oxygen_flow"] != nil && reflect.TypeOf(dataBody["oxygen_flow"]).String() == "string" {
  2759. oxygen_flow := dataBody["oxygen_flow"].(string)
  2760. solution.OxygenFlow = oxygen_flow
  2761. }
  2762. if dataBody["oxygen_time"] != nil && reflect.TypeOf(dataBody["oxygen_time"]).String() == "string" {
  2763. oxygen_time := dataBody["oxygen_time"].(string)
  2764. solution.OxygenTime = oxygen_time
  2765. }
  2766. if dataBody["max_ultrafiltration_rate"] != nil && reflect.TypeOf(dataBody["max_ultrafiltration_rate"]).String() == "string" {
  2767. max_ultrafiltration_rate, _ := strconv.ParseFloat(dataBody["max_ultrafiltration_rate"].(string), 64)
  2768. solution.MaxUltrafiltrationRate = max_ultrafiltration_rate
  2769. }
  2770. return
  2771. }
  2772. func childSolutionFormData(solution *models.DialysisSolution, data []byte, method string) (code int) {
  2773. dataBody := make(map[string]interface{}, 0)
  2774. err := json.Unmarshal(data, &dataBody)
  2775. utils.InfoLog(string(data))
  2776. if err != nil {
  2777. utils.ErrorLog(err.Error())
  2778. code = enums.ErrorCodeParamWrong
  2779. return
  2780. }
  2781. if method == "create" {
  2782. if dataBody["parent_id"] == nil || reflect.TypeOf(dataBody["parent_id"]).String() != "float64" {
  2783. utils.ErrorLog("parent_id")
  2784. code = enums.ErrorCodeParamWrong
  2785. return
  2786. }
  2787. parentID := int64(dataBody["parent_id"].(float64))
  2788. if parentID <= 0 {
  2789. utils.ErrorLog("parentID <= 0")
  2790. code = enums.ErrorCodeParamWrong
  2791. return
  2792. }
  2793. solution.ParentId = parentID
  2794. if dataBody["sub_name"] == nil || reflect.TypeOf(dataBody["sub_name"]).String() != "string" {
  2795. utils.ErrorLog("sub_name")
  2796. code = enums.ErrorCodeParamWrong
  2797. return
  2798. }
  2799. subName, _ := dataBody["sub_name"].(string)
  2800. if len(subName) == 0 {
  2801. utils.ErrorLog("len(sub_name) == 0")
  2802. code = enums.ErrorCodeParamWrong
  2803. return
  2804. }
  2805. solution.SubName = subName
  2806. }
  2807. if dataBody["initiate_mode"] == nil || reflect.TypeOf(dataBody["initiate_mode"]).String() != "float64" {
  2808. utils.ErrorLog("initiate_mode")
  2809. code = enums.ErrorCodeParamWrong
  2810. return
  2811. }
  2812. initiateMode := int64(dataBody["initiate_mode"].(float64))
  2813. if initiateMode != 1 && initiateMode != 2 {
  2814. utils.ErrorLog("initiateMode != 1 && initiateMode != 2")
  2815. code = enums.ErrorCodeParamWrong
  2816. return
  2817. }
  2818. solution.InitiateMode = initiateMode
  2819. if dataBody["doctor"] == nil || reflect.TypeOf(dataBody["doctor"]).String() != "float64" {
  2820. utils.ErrorLog("doctor")
  2821. code = enums.ErrorCodeParamWrong
  2822. return
  2823. }
  2824. doctor := int64(dataBody["doctor"].(float64))
  2825. if doctor <= 0 {
  2826. utils.ErrorLog("doctor <= 0")
  2827. code = enums.ErrorCodeParamWrong
  2828. return
  2829. }
  2830. solution.Doctor = doctor
  2831. return
  2832. }
  2833. func patientFormData(patient *models.Patients, data []byte, method string) (contagions []int64, diseases []int64, code int, formItems []*models.FormItem) {
  2834. patientBody := make(map[string]interface{}, 0)
  2835. err := json.Unmarshal(data, &patientBody)
  2836. if err != nil {
  2837. utils.ErrorLog(err.Error())
  2838. code = enums.ErrorCodeParamWrong
  2839. return
  2840. }
  2841. if patientBody["formItem"] != nil && reflect.TypeOf(patientBody["formItem"]).String() == "[]interface {}" {
  2842. formItem, _ := patientBody["formItem"].([]interface{})
  2843. if len(formItem) > 0 {
  2844. for _, item := range formItem {
  2845. items := item.(map[string]interface{})
  2846. project_name, _ := items["project_name"].(string)
  2847. fmt.Println(project_name)
  2848. range_type := int64(items["range_type"].(float64))
  2849. fmt.Println(range_type)
  2850. project_id := int64(items["project_id"].(float64))
  2851. fmt.Println(project_id)
  2852. item_id := int64(items["item_id"].(float64))
  2853. fmt.Println(item_id)
  2854. item, _ := items["item"].(string)
  2855. fmt.Println(items["item"].(string))
  2856. item_name, _ := items["item_name"].(string)
  2857. fmt.Println(item_name)
  2858. value, _ := items["value"].(string)
  2859. fmt.Println(items["value"].(string))
  2860. var form models.FormItem
  2861. form.ProjectName = project_name
  2862. form.RangeType = range_type
  2863. form.ProjectId = project_id
  2864. form.ItemId = item_id
  2865. form.Item = item
  2866. form.ItemName = item_name
  2867. form.Value = value
  2868. formItems = append(formItems, &form)
  2869. }
  2870. }
  2871. }
  2872. if patientBody["avatar"] == nil || reflect.TypeOf(patientBody["avatar"]).String() != "string" {
  2873. utils.ErrorLog("avatar")
  2874. code = enums.ErrorCodeParamWrong
  2875. return
  2876. }
  2877. avatar, _ := patientBody["avatar"].(string)
  2878. if len(avatar) == 0 {
  2879. utils.ErrorLog("len(avatar) == 0")
  2880. code = enums.ErrorCodeParamWrong
  2881. return
  2882. }
  2883. patient.Avatar = avatar
  2884. if patientBody["name"] == nil || reflect.TypeOf(patientBody["name"]).String() != "string" {
  2885. utils.ErrorLog("name")
  2886. code = enums.ErrorCodeParamWrong
  2887. return
  2888. }
  2889. name, _ := patientBody["name"].(string)
  2890. if len(name) == 0 {
  2891. utils.ErrorLog("len(name) == 0")
  2892. code = enums.ErrorCodeParamWrong
  2893. return
  2894. }
  2895. patient.Name = name
  2896. if patientBody["alias"] != nil && reflect.TypeOf(patientBody["alias"]).String() == "string" {
  2897. alias := patientBody["alias"].(string)
  2898. patient.Alias = alias
  2899. }
  2900. if patientBody["nation"] != nil && reflect.TypeOf(patientBody["nation"]).String() == "string" {
  2901. nation := patientBody["nation"].(string)
  2902. patient.Nation = nation
  2903. }
  2904. if patientBody["native_place"] != nil && reflect.TypeOf(patientBody["native_place"]).String() == "string" {
  2905. native_place := patientBody["native_place"].(string)
  2906. patient.NativePlace = native_place
  2907. }
  2908. if patientBody["idCardNo"] == nil || reflect.TypeOf(patientBody["idCardNo"]).String() != "string" {
  2909. utils.ErrorLog("idCardNo")
  2910. code = enums.ErrorCodeParamWrong
  2911. return
  2912. }
  2913. idCardNo, _ := patientBody["idCardNo"].(string)
  2914. if len(idCardNo) == 0 {
  2915. utils.ErrorLog("len(idCardNo) == 0")
  2916. code = enums.ErrorCodeParamWrong
  2917. return
  2918. }
  2919. patient.IdCardNo = idCardNo
  2920. patient.PatientType = 1
  2921. if patientBody["dialysisNo"] == nil || reflect.TypeOf(patientBody["dialysisNo"]).String() != "string" {
  2922. utils.ErrorLog("dialysisNo")
  2923. code = enums.ErrorCodeParamWrong
  2924. return
  2925. }
  2926. dialysisNo, _ := patientBody["dialysisNo"].(string)
  2927. if len(dialysisNo) == 0 {
  2928. utils.ErrorLog("len(dialysisNo) == 0")
  2929. code = enums.ErrorCodeParamWrong
  2930. return
  2931. }
  2932. patient.DialysisNo = dialysisNo
  2933. // }
  2934. if patientBody["lapseto"] == nil || reflect.TypeOf(patientBody["lapseto"]).String() != "float64" {
  2935. utils.ErrorLog("lapseto")
  2936. code = enums.ErrorCodeParamWrong
  2937. return
  2938. }
  2939. lapseto := int64(patientBody["lapseto"].(float64))
  2940. if lapseto <= 0 {
  2941. utils.ErrorLog("lapseto == 0")
  2942. code = enums.ErrorCodeParamWrong
  2943. return
  2944. }
  2945. patient.Lapseto = lapseto
  2946. if patientBody["gender"] == nil || reflect.TypeOf(patientBody["gender"]).String() != "float64" {
  2947. utils.ErrorLog("gender")
  2948. code = enums.ErrorCodeParamWrong
  2949. return
  2950. }
  2951. gender := int64(patientBody["gender"].(float64))
  2952. if gender <= 0 {
  2953. utils.ErrorLog("gender <= 0")
  2954. code = enums.ErrorCodeParamWrong
  2955. return
  2956. }
  2957. patient.Gender = gender
  2958. if patientBody["response_result"] != nil && reflect.TypeOf(patientBody["response_result"]).String() == "string" {
  2959. response_result := patientBody["response_result"].(string)
  2960. patient.ResponseResult = response_result
  2961. }
  2962. if patientBody["age"] == nil || reflect.TypeOf(patientBody["age"]).String() != "float64" {
  2963. utils.ErrorLog("age")
  2964. code = enums.ErrorCodeParamWrong
  2965. return
  2966. }
  2967. age := int64(patientBody["age"].(float64))
  2968. patient.Age = age
  2969. if patientBody["user_sys_before_count"] != nil || reflect.TypeOf(patientBody["user_sys_before_count"]).String() == "string" {
  2970. user_sys_before_count := patientBody["user_sys_before_count"].(string)
  2971. count, _ := strconv.ParseInt(user_sys_before_count, 10, 64)
  2972. patient.UserSysBeforeCount = count
  2973. }
  2974. timeLayout := "2006-01-02"
  2975. loc, _ := time.LoadLocation("Local")
  2976. if patientBody["birth"] == nil || reflect.TypeOf(patientBody["birth"]).String() != "string" {
  2977. utils.ErrorLog("birth")
  2978. code = enums.ErrorCodeParamWrong
  2979. return
  2980. }
  2981. birth, _ := patientBody["birth"].(string)
  2982. if len(birth) == 0 {
  2983. utils.ErrorLog("len(birth) == 0")
  2984. code = enums.ErrorCodeParamWrong
  2985. return
  2986. }
  2987. birthTime, err := time.ParseInLocation(timeLayout, birth, loc)
  2988. if err != nil {
  2989. utils.ErrorLog("birthTime")
  2990. code = enums.ErrorCodeParamWrong
  2991. return
  2992. }
  2993. patient.Birthday = birthTime.Unix()
  2994. if patientBody["height"] != nil && reflect.TypeOf(patientBody["height"]).String() == "string" {
  2995. height, _ := strconv.ParseInt(patientBody["height"].(string), 10, 64)
  2996. patient.Height = height
  2997. }
  2998. if patientBody["maritalStatus"] != nil && reflect.TypeOf(patientBody["maritalStatus"]).String() == "float64" {
  2999. maritalStatus := int64(patientBody["maritalStatus"].(float64))
  3000. patient.MaritalStatus = maritalStatus
  3001. }
  3002. if patientBody["children"] != nil && reflect.TypeOf(patientBody["children"]).String() == "string" {
  3003. children, _ := strconv.ParseInt(patientBody["children"].(string), 10, 64)
  3004. patient.Children = children
  3005. }
  3006. if patientBody["admissionNumber"] != nil && reflect.TypeOf(patientBody["admissionNumber"]).String() == "string" {
  3007. admissionNumber, _ := patientBody["admissionNumber"].(string)
  3008. patient.AdmissionNumber = admissionNumber
  3009. }
  3010. if patientBody["reimbursementWayID"] != nil && reflect.TypeOf(patientBody["reimbursementWayID"]).String() == "float64" {
  3011. reimbursementWayID := int64(patientBody["reimbursementWayID"].(float64))
  3012. patient.ReimbursementWayId = reimbursementWayID
  3013. }
  3014. if patientBody["healthCareNo"] != nil && reflect.TypeOf(patientBody["healthCareNo"]).String() == "string" {
  3015. healthCareNo := patientBody["healthCareNo"].(string)
  3016. patient.HealthCareNo = healthCareNo
  3017. }
  3018. if patientBody["phone"] == nil || reflect.TypeOf(patientBody["phone"]).String() != "string" {
  3019. utils.ErrorLog("phone")
  3020. code = enums.ErrorCodeParamWrong
  3021. return
  3022. }
  3023. phone := patientBody["phone"].(string)
  3024. if len(phone) == 0 {
  3025. utils.ErrorLog("len(phone) == 0")
  3026. code = enums.ErrorCodeParamWrong
  3027. return
  3028. }
  3029. if !utils.CheckMobile(phone) {
  3030. utils.ErrorLog("!phone")
  3031. code = enums.ErrorCodeMobileFormat
  3032. return
  3033. }
  3034. patient.Phone = phone
  3035. if patientBody["homeTelephone"] != nil && reflect.TypeOf(patientBody["homeTelephone"]).String() == "string" {
  3036. homeTelephone := patientBody["homeTelephone"].(string)
  3037. patient.HomeTelephone = homeTelephone
  3038. }
  3039. if patientBody["relative_phone"] != nil && reflect.TypeOf(patientBody["relative_phone"]).String() == "string" {
  3040. relativePhone := patientBody["relative_phone"].(string)
  3041. patient.RelativePhone = relativePhone
  3042. }
  3043. if patientBody["relative_relations"] != nil && reflect.TypeOf(patientBody["relative_relations"]).String() == "string" {
  3044. relativeRelations := patientBody["relative_relations"].(string)
  3045. patient.RelativeRelations = relativeRelations
  3046. }
  3047. if patientBody["homeAddress"] != nil && reflect.TypeOf(patientBody["homeAddress"]).String() == "string" {
  3048. homeAddress := patientBody["homeAddress"].(string)
  3049. patient.HomeAddress = homeAddress
  3050. }
  3051. if patientBody["work"] != nil && reflect.TypeOf(patientBody["work"]).String() == "string" {
  3052. work := patientBody["work"].(string)
  3053. patient.WorkUnit = work
  3054. }
  3055. if patientBody["unit_address"] != nil && reflect.TypeOf(patientBody["unit_address"]).String() == "string" {
  3056. unitAddress := patientBody["unit_address"].(string)
  3057. patient.UnitAddress = unitAddress
  3058. }
  3059. if patientBody["profession"] != nil && reflect.TypeOf(patientBody["profession"]).String() == "float64" {
  3060. profession := int64(patientBody["profession"].(float64))
  3061. patient.Profession = profession
  3062. }
  3063. if patientBody["education"] != nil && reflect.TypeOf(patientBody["education"]).String() == "float64" {
  3064. education := int64(patientBody["education"].(float64))
  3065. patient.EducationLevel = education
  3066. }
  3067. if patientBody["source"] == nil || reflect.TypeOf(patientBody["source"]).String() != "float64" {
  3068. utils.ErrorLog("source")
  3069. code = enums.ErrorCodeParamWrong
  3070. return
  3071. }
  3072. source := int64(patientBody["source"].(float64))
  3073. if source <= 0 {
  3074. utils.ErrorLog("source <= 0")
  3075. code = enums.ErrorCodeParamWrong
  3076. return
  3077. }
  3078. patient.Source = source
  3079. if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
  3080. isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
  3081. patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
  3082. }
  3083. if patientBody["firstDialysisDate"] != nil && reflect.TypeOf(patientBody["firstDialysisDate"]).String() == "string" {
  3084. firstDialysisDate := patientBody["firstDialysisDate"].(string)
  3085. firstDialysisDateTime, err := time.ParseInLocation(timeLayout, firstDialysisDate, loc)
  3086. if err == nil {
  3087. patient.FirstDialysisDate = firstDialysisDateTime.Unix()
  3088. }
  3089. }
  3090. if patientBody["first_dialysis_hospital"] != nil && reflect.TypeOf(patientBody["first_dialysis_hospital"]).String() == "string" {
  3091. firstDialysisHospital := patientBody["first_dialysis_hospital"].(string)
  3092. patient.FirstDialysisHospital = firstDialysisHospital
  3093. }
  3094. if patientBody["predialysis_condition"] != nil && reflect.TypeOf(patientBody["predialysis_condition"]).String() == "[]interface {}" {
  3095. thePredialysisCondition, _ := patientBody["predialysis_condition"].([]interface{})
  3096. if len(thePredialysisCondition) > 0 {
  3097. conditions := make([]string, 0)
  3098. for _, item := range thePredialysisCondition {
  3099. if reflect.TypeOf(item).String() != "string" {
  3100. continue
  3101. }
  3102. condition := item.(string)
  3103. if len(condition) > 0 {
  3104. conditions = append(conditions, condition)
  3105. }
  3106. }
  3107. patient.PredialysisCondition = strings.Join(conditions, ",")
  3108. }
  3109. }
  3110. if patientBody["pre_hospital_dialysis_frequency"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_frequency"]).String() == "string" {
  3111. preHospitalDialysisFrequency := patientBody["pre_hospital_dialysis_frequency"].(string)
  3112. patient.PreHospitalDialysisFrequency = preHospitalDialysisFrequency
  3113. }
  3114. if patientBody["pre_hospital_dialysis_times"] != nil && reflect.TypeOf(patientBody["pre_hospital_dialysis_times"]).String() == "string" {
  3115. preHospitalDialysisTimes, _ := strconv.ParseInt(patientBody["pre_hospital_dialysis_times"].(string), 10, 64)
  3116. patient.PreHospitalDialysisTimes = preHospitalDialysisTimes
  3117. }
  3118. if patientBody["hospital_first_dialysis_date"] != nil && reflect.TypeOf(patientBody["hospital_first_dialysis_date"]).String() == "string" {
  3119. hospitalFirstDialysisDate := patientBody["hospital_first_dialysis_date"].(string)
  3120. hospitalFirstDialysisDateTime, err := time.ParseInLocation(timeLayout, hospitalFirstDialysisDate, loc)
  3121. if err == nil {
  3122. patient.HospitalFirstDialysisDate = hospitalFirstDialysisDateTime.Unix()
  3123. }
  3124. }
  3125. if patientBody["partition"] != nil && reflect.TypeOf(patientBody["partition"]).String() == "float64" {
  3126. partition := int64(patientBody["partition"].(float64))
  3127. patient.PartitionId = partition
  3128. }
  3129. if patientBody["bed"] != nil && reflect.TypeOf(patientBody["bed"]).String() == "string" {
  3130. bed, _ := strconv.ParseInt(patientBody["bed"].(string), 10, 64)
  3131. patient.BedId = bed
  3132. }
  3133. if patientBody["healthCareDueDate"] != nil && reflect.TypeOf(patientBody["healthCareDueDate"]).String() == "string" {
  3134. healthCareDueDate := patientBody["healthCareDueDate"].(string)
  3135. healthCareDueDateTime, err := time.ParseInLocation(timeLayout, healthCareDueDate, loc)
  3136. if err == nil {
  3137. patient.HealthCareDueDate = healthCareDueDateTime.Unix()
  3138. }
  3139. }
  3140. if patientBody["blood"] != nil && reflect.TypeOf(patientBody["blood"]).String() == "float64" {
  3141. blood := int64(patientBody["blood"].(float64))
  3142. patient.BloodType = blood
  3143. }
  3144. if patientBody["rh"] != nil && reflect.TypeOf(patientBody["rh"]).String() == "float64" {
  3145. rh := int64(patientBody["rh"].(float64))
  3146. patient.Rh = rh
  3147. }
  3148. if patientBody["healthCareDueAlertDate"] != nil && reflect.TypeOf(patientBody["healthCareDueAlertDate"]).String() == "string" {
  3149. healthCareDueAlertDate := patientBody["healthCareDueAlertDate"].(string)
  3150. healthCareDueAlertDateTime, err := time.ParseInLocation(timeLayout, healthCareDueAlertDate, loc)
  3151. if err == nil {
  3152. patient.HealthCareDueAlertDate = healthCareDueAlertDateTime.Unix()
  3153. }
  3154. }
  3155. if patientBody["receivingDate"] != nil && reflect.TypeOf(patientBody["receivingDate"]).String() == "string" {
  3156. receivingDate := patientBody["receivingDate"].(string)
  3157. receivingDateTime, err := time.ParseInLocation(timeLayout, receivingDate, loc)
  3158. if err == nil {
  3159. patient.ReceivingDate = receivingDateTime.Unix()
  3160. }
  3161. }
  3162. if patientBody["induction"] != nil && reflect.TypeOf(patientBody["induction"]).String() == "float64" {
  3163. induction := int64(patientBody["induction"].(float64))
  3164. patient.InductionPeriod = induction
  3165. }
  3166. if patientBody["initial"] != nil && reflect.TypeOf(patientBody["initial"]).String() == "string" {
  3167. initial, _ := strconv.ParseInt(patientBody["initial"].(string), 10, 64)
  3168. patient.InitialDialysis = initial
  3169. }
  3170. if patientBody["dialysisTotal"] != nil && reflect.TypeOf(patientBody["dialysisTotal"]).String() == "string" {
  3171. dialysisTotal, _ := strconv.ParseInt(patientBody["dialysisTotal"].(string), 10, 64)
  3172. patient.TotalDialysis = dialysisTotal
  3173. }
  3174. if patientBody["contagions"] != nil && reflect.TypeOf(patientBody["contagions"]).String() == "[]interface {}" {
  3175. thisContagions, _ := patientBody["contagions"].([]interface{})
  3176. if len(thisContagions) > 0 {
  3177. for _, item := range thisContagions {
  3178. if reflect.TypeOf(item).String() != "float64" {
  3179. continue
  3180. }
  3181. contagion := int64(item.(float64))
  3182. if contagion > 0 {
  3183. contagions = append(contagions, contagion)
  3184. }
  3185. }
  3186. }
  3187. }
  3188. if patientBody["doctor"] != nil && reflect.TypeOf(patientBody["doctor"]).String() == "float64" {
  3189. doctor := int64(patientBody["doctor"].(float64))
  3190. patient.AttendingDoctorId = doctor
  3191. }
  3192. if patientBody["nurse"] != nil && reflect.TypeOf(patientBody["nurse"]).String() == "float64" {
  3193. nurse := int64(patientBody["nurse"].(float64))
  3194. patient.HeadNurseId = nurse
  3195. }
  3196. if patientBody["assessment"] != nil && reflect.TypeOf(patientBody["assessment"]).String() == "string" {
  3197. assessment := patientBody["assessment"].(string)
  3198. patient.Evaluate = assessment
  3199. }
  3200. if patientBody["diseases"] != nil && reflect.TypeOf(patientBody["diseases"]).String() == "[]interface {}" {
  3201. thisDiseases, _ := patientBody["diseases"].([]interface{})
  3202. if len(thisDiseases) > 0 {
  3203. for _, item := range thisDiseases {
  3204. if reflect.TypeOf(item).String() != "float64" {
  3205. continue
  3206. }
  3207. disease := int64(item.(float64))
  3208. if disease > 0 {
  3209. diseases = append(diseases, disease)
  3210. }
  3211. }
  3212. }
  3213. }
  3214. if patientBody["diagnose"] != nil && reflect.TypeOf(patientBody["diagnose"]).String() == "string" {
  3215. diagnose := patientBody["diagnose"].(string)
  3216. patient.Diagnose = diagnose
  3217. }
  3218. if patientBody["remark"] != nil && reflect.TypeOf(patientBody["remark"]).String() == "string" {
  3219. remark := patientBody["remark"].(string)
  3220. patient.Remark = remark
  3221. }
  3222. if patientBody["sch_remark"] != nil && reflect.TypeOf(patientBody["sch_remark"]).String() == "string" {
  3223. sch_remark := patientBody["sch_remark"].(string)
  3224. patient.SchRemark = sch_remark
  3225. }
  3226. if patientBody["patient_complains"] != nil && reflect.TypeOf(patientBody["patient_complains"]).String() == "string" {
  3227. patient_complains := patientBody["patient_complains"].(string)
  3228. patient.PatientComplains = patient_complains
  3229. }
  3230. if patientBody["present_history"] != nil && reflect.TypeOf(patientBody["present_history"]).String() == "string" {
  3231. present_history := patientBody["present_history"].(string)
  3232. patient.PresentHistory = present_history
  3233. }
  3234. if patientBody["past_history"] != nil && reflect.TypeOf(patientBody["past_history"]).String() == "string" {
  3235. past_history := patientBody["past_history"].(string)
  3236. patient.PastHistory = past_history
  3237. }
  3238. if patientBody["temperature"] != nil && reflect.TypeOf(patientBody["temperature"]).String() == "string" {
  3239. temperature, _ := strconv.ParseFloat(patientBody["temperature"].(string), 64)
  3240. patient.Temperature = temperature
  3241. }
  3242. if patientBody["pulse"] != nil && reflect.TypeOf(patientBody["pulse"]).String() == "string" {
  3243. pulse, _ := strconv.ParseInt(patientBody["pulse"].(string), 10, 64)
  3244. patient.Pulse = pulse
  3245. }
  3246. if patientBody["respiratory"] != nil && reflect.TypeOf(patientBody["respiratory"]).String() == "string" {
  3247. respiratory, _ := strconv.ParseInt(patientBody["respiratory"].(string), 10, 64)
  3248. patient.Respiratory = respiratory
  3249. }
  3250. if patientBody["sbp"] != nil && reflect.TypeOf(patientBody["sbp"]).String() == "string" {
  3251. sbp, _ := strconv.ParseInt(patientBody["sbp"].(string), 10, 64)
  3252. patient.SBP = sbp
  3253. }
  3254. if patientBody["dbp"] != nil && reflect.TypeOf(patientBody["dbp"]).String() == "string" {
  3255. dbp, _ := strconv.ParseInt(patientBody["dbp"].(string), 10, 64)
  3256. patient.DBP = dbp
  3257. }
  3258. if patientBody["dialysis_age"] != nil && reflect.TypeOf(patientBody["dialysis_age"]).String() == "string" {
  3259. dialysis_age, _ := strconv.ParseInt(patientBody["dialysis_age"].(string), 10, 64)
  3260. patient.DialysisAge = dialysis_age
  3261. }
  3262. fmt.Println(patient.DialysisAge)
  3263. if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
  3264. first_treatment_date := patientBody["first_treatment_date"].(string)
  3265. first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3266. if err == nil {
  3267. patient.FirstTreatmentDate = first_treatment_time.Unix()
  3268. }
  3269. }
  3270. if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
  3271. expense_kind := int64(patientBody["expense_kind"].(float64))
  3272. patient.ExpenseKind = expense_kind
  3273. }
  3274. fmt.Println(patient.ExpenseKind)
  3275. if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
  3276. tell_phone := patientBody["tell_phone"].(string)
  3277. patient.TellPhone = tell_phone
  3278. }
  3279. if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
  3280. contact_name := patientBody["contact_name"].(string)
  3281. patient.ContactName = contact_name
  3282. }
  3283. return
  3284. }
  3285. func (c *PatientApiController) GetPatientsByKeyWord() {
  3286. keyWord := c.GetString("keyword")
  3287. adminUserInfo := c.GetAdminUserInfo()
  3288. patient, err := service.GetPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  3289. if err != nil {
  3290. utils.ErrorLog(err.Error())
  3291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3292. return
  3293. }
  3294. c.ServeSuccessJSON(map[string]interface{}{
  3295. "patient": patient,
  3296. })
  3297. }
  3298. func (c *PatientApiController) QueryPatientById() {
  3299. id, _ := c.GetInt64("id")
  3300. fmt.Println(id)
  3301. patientInfo := service.QueryPatientById(id)
  3302. c.ServeSuccessJSON(map[string]interface{}{
  3303. "patient": patientInfo,
  3304. })
  3305. return
  3306. }
  3307. func (c *PatientApiController) GetRemindPatientList() {
  3308. page, _ := c.GetInt64("page", 1)
  3309. limit, _ := c.GetInt64("limit", 10)
  3310. adminUserInfo := c.GetAdminUserInfo()
  3311. total, patients, err := service.GetAllWaitRemindPatient(adminUserInfo.CurrentOrgId, page, limit)
  3312. if err != nil {
  3313. utils.ErrorLog(err.Error())
  3314. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3315. return
  3316. }
  3317. c.ServeSuccessJSON(map[string]interface{}{
  3318. "total": total,
  3319. "patients": patients,
  3320. })
  3321. }
  3322. func (c *PatientApiController) PostIsOpenRemind() {
  3323. patient_id, _ := c.GetInt64("id", 1)
  3324. is_open_remind, _ := c.GetInt64("is_open_remind", 1)
  3325. adminUserInfo := c.GetAdminUserInfo()
  3326. err := service.UpdatePatientRemindStatus(patient_id, is_open_remind, adminUserInfo.CurrentOrgId)
  3327. if err == nil {
  3328. c.ServeSuccessJSON(map[string]interface{}{
  3329. "msg": "成功",
  3330. "is_open_remind": is_open_remind,
  3331. })
  3332. } else if err != nil {
  3333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3334. }
  3335. }
  3336. func (c *PatientApiController) GetPatientScheduleOne() {
  3337. id, _ := c.GetInt64("id")
  3338. //查询该病人是否当天是排班
  3339. nowDateTime := time.Now()
  3340. nowDate := nowDateTime.Format("2006-01-02")
  3341. nowDate += " 00:00:00"
  3342. timeLayout := "2006-01-02"
  3343. loc, _ := time.LoadLocation("Local")
  3344. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", nowDate, loc)
  3345. nowdate := theTime.Unix()
  3346. fmt.Println("nowdate", nowdate)
  3347. adminUser := c.GetAdminUserInfo()
  3348. orgId := adminUser.CurrentOrgId
  3349. fmt.Println("orgid", orgId)
  3350. scheduls, err := service.GetPatientScheduleOne(id, nowdate, orgId)
  3351. if err != nil {
  3352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3353. return
  3354. }
  3355. c.ServeSuccessJSON(map[string]interface{}{
  3356. "scheduls": scheduls,
  3357. })
  3358. }
  3359. func (c *PatientApiController) ExportPatients() {
  3360. dataBody := make(map[string]interface{}, 0)
  3361. all_patient, _, _ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId)
  3362. //all_patient, _,_ := service.GetAllPatientList(c.GetAdminUserInfo().CurrentOrgId )
  3363. org, _ := service.GetOrgById(c.GetAdminUserInfo().CurrentOrgId)
  3364. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3365. if err != nil {
  3366. utils.ErrorLog(err.Error())
  3367. return
  3368. }
  3369. utils.ErrorLog("%v", dataBody)
  3370. export_time := time.Now().Unix()
  3371. var patients []*models.Patients
  3372. var total_patients []interface{}
  3373. if dataBody["patients"] != nil || reflect.TypeOf(dataBody["patients"]).String() == "[]interface {}" {
  3374. tempPatients := dataBody["patients"].([]interface{})
  3375. total_patients = tempPatients
  3376. for index, patientMap := range tempPatients {
  3377. patientNameM := patientMap.(map[string]interface{})
  3378. var patient models.Patients
  3379. if patientNameM["name"] == nil || reflect.TypeOf(patientNameM["name"]).String() != "string" {
  3380. utils.ErrorLog("name")
  3381. return
  3382. }
  3383. name, _ := patientNameM["name"].(string)
  3384. if len(name) == 0 { //名字为空则生成一条导入错误日志
  3385. err_log := models.ExportErrLog{
  3386. LogType: 1,
  3387. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3388. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的姓名不能为空",
  3389. Status: 1,
  3390. CreateTime: time.Now().Unix(),
  3391. UpdateTime: time.Now().Unix(),
  3392. ExportTime: export_time,
  3393. }
  3394. service.CreateExportErrLog(&err_log)
  3395. continue
  3396. }
  3397. patient.Name = name
  3398. if patientNameM["gender"] != nil || reflect.TypeOf(patientNameM["gender"]).String() == "string" {
  3399. gender, _ := strconv.ParseInt(patientNameM["gender"].(string), 10, 64)
  3400. if gender == 0 { //性别不符合要求则生成一条导入错误日志
  3401. err_log := models.ExportErrLog{
  3402. LogType: 1,
  3403. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3404. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的性别不符合要求",
  3405. Status: 1,
  3406. CreateTime: time.Now().Unix(),
  3407. UpdateTime: time.Now().Unix(),
  3408. ExportTime: export_time,
  3409. }
  3410. service.CreateExportErrLog(&err_log)
  3411. continue
  3412. } else {
  3413. patient.Gender = gender
  3414. }
  3415. }
  3416. if patientNameM["phone"] != nil || reflect.TypeOf(patientNameM["phone"]).String() == "string" {
  3417. phone, _ := patientNameM["phone"].(string)
  3418. if utils.CellPhoneRegexp().MatchString(phone) == false { //手机号码不符合要求则生成一条导入错误日志
  3419. if len(phone) == 0 {
  3420. err_log := models.ExportErrLog{
  3421. LogType: 1,
  3422. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3423. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码不能为空",
  3424. Status: 1,
  3425. CreateTime: time.Now().Unix(),
  3426. UpdateTime: time.Now().Unix(),
  3427. ExportTime: export_time,
  3428. }
  3429. service.CreateExportErrLog(&err_log)
  3430. continue
  3431. } else {
  3432. err_log := models.ExportErrLog{
  3433. LogType: 1,
  3434. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3435. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码格式不符合要求",
  3436. Status: 1,
  3437. CreateTime: time.Now().Unix(),
  3438. UpdateTime: time.Now().Unix(),
  3439. ExportTime: export_time,
  3440. }
  3441. service.CreateExportErrLog(&err_log)
  3442. continue
  3443. }
  3444. } else {
  3445. //var tempPatient *models.Patients
  3446. //for _, item := range all_patient {
  3447. // if item.Phone == phone {
  3448. // tempPatient = item
  3449. // }
  3450. //}
  3451. //需要判断该号码是否已经在系统内存在了,存在了则生成一条导入错误日志
  3452. count := service.FindPatientPhoneIsExist(phone, c.GetAdminUserInfo().CurrentOrgId)
  3453. if count >= 1 {
  3454. err_log := models.ExportErrLog{
  3455. LogType: 1,
  3456. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3457. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的手机号码在系统中已经存在",
  3458. Status: 1,
  3459. CreateTime: time.Now().Unix(),
  3460. UpdateTime: time.Now().Unix(),
  3461. ExportTime: export_time,
  3462. }
  3463. service.CreateExportErrLog(&err_log)
  3464. continue
  3465. }
  3466. patient.Phone = phone
  3467. }
  3468. }
  3469. if patientNameM["id_card_no"] != nil || reflect.TypeOf(patientNameM["id_card_no"]).String() == "string" {
  3470. id_card_no, _ := patientNameM["id_card_no"].(string)
  3471. if IsIdCard(id_card_no) == false { //身份证号码不符合要求则生成一条导入错误日志
  3472. if len(id_card_no) == 0 {
  3473. err_log := models.ExportErrLog{
  3474. LogType: 1,
  3475. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3476. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码不能为空",
  3477. Status: 1,
  3478. CreateTime: time.Now().Unix(),
  3479. UpdateTime: time.Now().Unix(),
  3480. ExportTime: export_time,
  3481. }
  3482. service.CreateExportErrLog(&err_log)
  3483. continue
  3484. } else {
  3485. err_log := models.ExportErrLog{
  3486. LogType: 1,
  3487. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3488. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码格式不符合要求",
  3489. Status: 1,
  3490. CreateTime: time.Now().Unix(),
  3491. UpdateTime: time.Now().Unix(),
  3492. ExportTime: export_time,
  3493. }
  3494. service.CreateExportErrLog(&err_log)
  3495. continue
  3496. }
  3497. } else {
  3498. //var tempPatient *models.Patients
  3499. //for _, item := range all_patient {
  3500. // if item.IdCardNo == id_card_no {
  3501. // tempPatient = item
  3502. // }
  3503. //}
  3504. count := service.FindPatientIdCardNoIsExist(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3505. if count >= 1 {
  3506. //if tempPatient != nil && tempPatient.ID > 0 {
  3507. err_log := models.ExportErrLog{
  3508. LogType: 1,
  3509. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3510. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的身份证号码在系统中已经存在",
  3511. Status: 1,
  3512. CreateTime: time.Now().Unix(),
  3513. UpdateTime: time.Now().Unix(),
  3514. ExportTime: export_time,
  3515. }
  3516. service.CreateExportErrLog(&err_log)
  3517. continue
  3518. }
  3519. //}
  3520. patient.IdCardNo = id_card_no
  3521. //patient.Birthday = GetBirthDay(id_card_no).Unix()
  3522. if GetBirthDay(id_card_no) == nil {
  3523. patient.Birthday = 0
  3524. } else {
  3525. patient.Birthday = GetBirthDay(id_card_no).Unix()
  3526. }
  3527. }
  3528. }
  3529. fmt.Println("111112222")
  3530. if patientNameM["first_treatment_date"] != nil || reflect.TypeOf(patientNameM["first_treatment_date"]).String() == "string" {
  3531. first_treatment_date, _ := patientNameM["first_treatment_date"].(string)
  3532. timeLayout := "2006/01/02"
  3533. loc, _ := time.LoadLocation("Local")
  3534. first_dialysis_date, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
  3535. if err != nil { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3536. if len(first_treatment_date) == 0 {
  3537. err_log := models.ExportErrLog{
  3538. LogType: 1,
  3539. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3540. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3541. Status: 1,
  3542. CreateTime: time.Now().Unix(),
  3543. UpdateTime: time.Now().Unix(),
  3544. ExportTime: export_time,
  3545. }
  3546. service.CreateExportErrLog(&err_log)
  3547. continue
  3548. } else {
  3549. err_log := models.ExportErrLog{
  3550. LogType: 1,
  3551. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3552. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3553. Status: 1,
  3554. CreateTime: time.Now().Unix(),
  3555. UpdateTime: time.Now().Unix(),
  3556. ExportTime: export_time,
  3557. }
  3558. service.CreateExportErrLog(&err_log)
  3559. continue
  3560. }
  3561. } else {
  3562. if len(first_treatment_date) == 0 {
  3563. err_log := models.ExportErrLog{
  3564. LogType: 1,
  3565. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3566. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间不能为空",
  3567. Status: 1,
  3568. CreateTime: time.Now().Unix(),
  3569. UpdateTime: time.Now().Unix(),
  3570. ExportTime: export_time,
  3571. }
  3572. service.CreateExportErrLog(&err_log)
  3573. continue
  3574. } else {
  3575. if first_dialysis_date.Unix() == 0 { //首次肾脏治疗时间不符合要求则生成一条导入错误日志
  3576. err_log := models.ExportErrLog{
  3577. LogType: 1,
  3578. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3579. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的首次肾脏治疗时间格式不符合要求",
  3580. Status: 1,
  3581. CreateTime: time.Now().Unix(),
  3582. UpdateTime: time.Now().Unix(),
  3583. ExportTime: export_time,
  3584. }
  3585. service.CreateExportErrLog(&err_log)
  3586. continue
  3587. } else {
  3588. patient.FirstDialysisDate = first_dialysis_date.Unix()
  3589. }
  3590. }
  3591. }
  3592. }
  3593. if patientNameM["source"] != nil || reflect.TypeOf(patientNameM["source"]).String() == "string" {
  3594. source, _ := strconv.ParseInt(patientNameM["source"].(string), 10, 64)
  3595. if source == 0 { //患者来源不符合要求则生成一条导入错误日志
  3596. err_log := models.ExportErrLog{
  3597. LogType: 1,
  3598. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3599. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不符合要求",
  3600. Status: 1,
  3601. CreateTime: time.Now().Unix(),
  3602. UpdateTime: time.Now().Unix(),
  3603. ExportTime: export_time,
  3604. }
  3605. service.CreateExportErrLog(&err_log)
  3606. continue
  3607. } else if source == 3 {
  3608. err_log := models.ExportErrLog{
  3609. LogType: 1,
  3610. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3611. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的患者来源不能为空",
  3612. Status: 1,
  3613. CreateTime: time.Now().Unix(),
  3614. UpdateTime: time.Now().Unix(),
  3615. ExportTime: export_time,
  3616. }
  3617. service.CreateExportErrLog(&err_log)
  3618. continue
  3619. } else {
  3620. patient.Source = source
  3621. }
  3622. }
  3623. if patientNameM["lapseto"] != nil || reflect.TypeOf(patientNameM["lapseto"]).String() == "string" {
  3624. lapseto, _ := strconv.ParseInt(patientNameM["lapseto"].(string), 10, 64)
  3625. if lapseto == 0 { //治疗状态不符合要求则生成一条导入错误日志
  3626. err_log := models.ExportErrLog{
  3627. LogType: 1,
  3628. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3629. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不符合要求",
  3630. Status: 1,
  3631. CreateTime: time.Now().Unix(),
  3632. UpdateTime: time.Now().Unix(),
  3633. ExportTime: export_time,
  3634. }
  3635. service.CreateExportErrLog(&err_log)
  3636. continue
  3637. } else if lapseto == 3 {
  3638. err_log := models.ExportErrLog{
  3639. LogType: 1,
  3640. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3641. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的治疗状态不能为空",
  3642. Status: 1,
  3643. CreateTime: time.Now().Unix(),
  3644. UpdateTime: time.Now().Unix(),
  3645. ExportTime: export_time,
  3646. }
  3647. service.CreateExportErrLog(&err_log)
  3648. continue
  3649. } else {
  3650. patient.Lapseto = lapseto
  3651. }
  3652. }
  3653. if patientNameM["is_infectious"] != nil || reflect.TypeOf(patientNameM["is_infectious"]).String() == "string" {
  3654. is_infectious, _ := strconv.ParseInt(patientNameM["is_infectious"].(string), 10, 64)
  3655. if is_infectious == 0 { //传染病不符合要求则生成一条导入错误日志
  3656. err_log := models.ExportErrLog{
  3657. LogType: 1,
  3658. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3659. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不符合要求",
  3660. Status: 1,
  3661. CreateTime: time.Now().Unix(),
  3662. UpdateTime: time.Now().Unix(),
  3663. ExportTime: export_time,
  3664. }
  3665. service.CreateExportErrLog(&err_log)
  3666. continue
  3667. } else if is_infectious == 3 {
  3668. err_log := models.ExportErrLog{
  3669. LogType: 1,
  3670. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3671. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的传染病状态不能为空",
  3672. Status: 1,
  3673. CreateTime: time.Now().Unix(),
  3674. UpdateTime: time.Now().Unix(),
  3675. ExportTime: export_time,
  3676. }
  3677. service.CreateExportErrLog(&err_log)
  3678. continue
  3679. } else {
  3680. patient.IsInfectious = is_infectious
  3681. }
  3682. }
  3683. if patientNameM["contagions"] != nil && reflect.TypeOf(patientNameM["contagions"]).String() == "[]interface {}" {
  3684. var contagions []int64
  3685. thisContagions, _ := patientNameM["contagions"].([]interface{})
  3686. if len(thisContagions) > 0 {
  3687. for _, item := range thisContagions {
  3688. if reflect.TypeOf(item).String() != "float64" {
  3689. continue
  3690. }
  3691. contagion := int64(item.(float64))
  3692. if contagion > 0 {
  3693. contagions = append(contagions, contagion)
  3694. }
  3695. }
  3696. }
  3697. patient.ContagionIds = contagions
  3698. }
  3699. if patientNameM["diagnose"] != nil || reflect.TypeOf(patientNameM["diagnose"]).String() == "string" {
  3700. diagnose, _ := patientNameM["diagnose"].(string)
  3701. patient.Diagnose = diagnose
  3702. }
  3703. if patientNameM["dialysis_no"] != nil || reflect.TypeOf(patientNameM["dialysis_no"]).String() == "string" {
  3704. dialysis_no, _ := patientNameM["dialysis_no"].(string)
  3705. var tempPatient *models.Patients
  3706. for _, item := range all_patient {
  3707. if item.DialysisNo == dialysis_no {
  3708. tempPatient = item
  3709. }
  3710. }
  3711. if tempPatient != nil && tempPatient.ID > 0 {
  3712. patient.DialysisNo = GenerateDialysisNoTwo(patients)
  3713. } else {
  3714. patient.DialysisNo = dialysis_no
  3715. }
  3716. }
  3717. if patientNameM["height"] != nil || reflect.TypeOf(patientNameM["height"]).String() == "string" {
  3718. height, _ := patientNameM["height"].(string)
  3719. heights, _ := strconv.ParseFloat(height, 64)
  3720. patient.Height = int64(heights)
  3721. }
  3722. if patientNameM["home_address"] != nil || reflect.TypeOf(patientNameM["home_address"]).String() == "string" {
  3723. home_address, _ := patientNameM["home_address"].(string)
  3724. patient.HomeAddress = home_address
  3725. }
  3726. if patientNameM["dry_weight"] != nil || reflect.TypeOf(patientNameM["dry_weight"]).String() == "string" {
  3727. dry_weight, _ := patientNameM["dry_weight"].(string)
  3728. dry_weights, _ := strconv.ParseFloat(dry_weight, 64)
  3729. patient.DryWeight = dry_weights
  3730. }
  3731. patient.CreatedTime = time.Now().Unix()
  3732. patient.UpdatedTime = time.Now().Unix()
  3733. patient.Status = 1
  3734. patient.Avatar = "https://images.shengws.com/201809182128111.png"
  3735. patient.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  3736. patient.IsExcelExport = 1
  3737. patient.PatientType = 1
  3738. patients = append(patients, &patient)
  3739. }
  3740. }
  3741. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3742. if len(patients) > 0 {
  3743. for _, item := range patients {
  3744. service.CreateExportPatient(item, item.ContagionIds, org.Creator)
  3745. }
  3746. log := models.ExportLog{
  3747. LogType: 1,
  3748. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3749. TotalNum: int64(len(total_patients)),
  3750. FailNum: int64(len(errLogs)),
  3751. SuccessNum: int64(len(patients)),
  3752. CreateTime: time.Now().Unix(),
  3753. UpdateTime: time.Now().Unix(),
  3754. ExportTime: export_time,
  3755. Status: 1,
  3756. }
  3757. service.CreateExportLog(&log)
  3758. c.ServeSuccessJSON(map[string]interface{}{
  3759. "msg": "导入成功",
  3760. "total_num": len(total_patients),
  3761. "success_num": len(patients),
  3762. "fail_num": int64(len(errLogs)),
  3763. })
  3764. } else {
  3765. log := models.ExportLog{
  3766. LogType: 1,
  3767. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3768. TotalNum: int64(len(total_patients)),
  3769. FailNum: int64(len(errLogs)),
  3770. SuccessNum: int64(len(patients)),
  3771. CreateTime: time.Now().Unix(),
  3772. UpdateTime: time.Now().Unix(),
  3773. ExportTime: export_time,
  3774. Status: 1,
  3775. }
  3776. service.CreateExportLog(&log)
  3777. c.ServeSuccessJSON(map[string]interface{}{
  3778. "msg": "导入成功",
  3779. "total_num": len(total_patients),
  3780. "success_num": len(patients),
  3781. "fail_num": int64(len(errLogs)),
  3782. })
  3783. }
  3784. }
  3785. func GetBirthDay(IDCardNo string) *time.Time {
  3786. dayStr := IDCardNo[6:14]
  3787. birthDay, err := time.Parse("20060102", dayStr)
  3788. if err != nil {
  3789. fmt.Println(err)
  3790. return nil
  3791. }
  3792. return &birthDay
  3793. }
  3794. func IsIdCard(id string) (res bool) {
  3795. id = strings.ToUpper(id)
  3796. if len(id) != 15 && len(id) != 18 {
  3797. fmt.Println("1111111")
  3798. return false
  3799. }
  3800. r := regexp.MustCompile("(\\d{15})|(\\d{17}([0-9]|X))")
  3801. if !r.MatchString(id) {
  3802. fmt.Println("222222")
  3803. return false
  3804. }
  3805. if len(id) == 15 {
  3806. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[8:10])+"/"+string([]byte(id)[10:12])+"/"+"19"+string([]byte(id)[6:8]))
  3807. if tm2.Unix() == 0 {
  3808. fmt.Println("44444443333")
  3809. return false
  3810. }
  3811. return true
  3812. } else {
  3813. tm2, _ := time.Parse("01/02/2006", string([]byte(id)[10:12])+"/"+string([]byte(id)[12:14])+"/"+string([]byte(id)[6:10]))
  3814. fmt.Println(string([]byte(id)[10:12]) + "/" + string([]byte(id)[12:14]) + "/" + string([]byte(id)[6:10]))
  3815. fmt.Println(tm2.Unix())
  3816. if tm2.Unix() == 0 {
  3817. fmt.Println("44445555555")
  3818. return false
  3819. }
  3820. //检验18位身份证的校验码是否正确。
  3821. //校验位按照ISO 7064:1983.MOD 11-2的规定生成,X可以认为是数字10。
  3822. arr_int := []int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
  3823. arr_ch := []string{"1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"}
  3824. sign := 0
  3825. for k, v := range arr_int {
  3826. int_temp, _ := strconv.Atoi(string([]byte(id)[k : k+1]))
  3827. sign += int_temp * v
  3828. }
  3829. n := sign % 11
  3830. val_num := arr_ch[n]
  3831. if val_num != string([]byte(id)[17:18]) {
  3832. fmt.Println("5556666666")
  3833. return false
  3834. }
  3835. return true
  3836. }
  3837. }
  3838. func (c *PatientApiController) SaveEditAdvices() {
  3839. adminInfo := c.GetAdminUserInfo()
  3840. orgid := adminInfo.CurrentOrgId
  3841. startTime := c.GetString("start_time")
  3842. theTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", startTime)
  3843. groupno, _ := c.GetInt64("groupno")
  3844. fmt.Println("组", groupno)
  3845. date, _ := c.GetInt64("date")
  3846. fmt.Println("date", date)
  3847. patient_id, _ := c.GetInt64("patient_id")
  3848. fmt.Println("paitent_id", patient_id)
  3849. advice := models.XtDoctorAdvice{
  3850. StartTime: theTime.Unix(),
  3851. }
  3852. err := service.UpdateDoctorEditAdvice(advice, orgid, groupno, date, patient_id)
  3853. if err != nil {
  3854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3855. return
  3856. }
  3857. c.ServeSuccessJSON(map[string]interface{}{
  3858. "advice": advice,
  3859. })
  3860. }
  3861. func (c *PatientApiController) GetMaxDialysisNo() {
  3862. dialysisNo := service.ChechLastDialysisNo(c.GetAdminUserInfo().CurrentOrgId)
  3863. c.ServeSuccessJSON(map[string]interface{}{
  3864. "dialysis_no": dialysisNo,
  3865. })
  3866. }
  3867. func GenerateDialysisNoTwo(patients []*models.Patients) string {
  3868. dialysisNo2 := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
  3869. var tempPatient *models.Patients
  3870. for _, item := range patients {
  3871. if item.DialysisNo == dialysisNo2 {
  3872. tempPatient = item
  3873. }
  3874. }
  3875. if tempPatient == nil || tempPatient.ID == 0 {
  3876. return dialysisNo2
  3877. }
  3878. return GenerateDialysisNoTwo(patients)
  3879. }