his_api_controller.go 278KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  540. } else { //门诊
  541. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  542. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  543. }
  544. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  545. if sch.ID > 0 {
  546. var week string
  547. t := time.Now()
  548. switch t.Weekday().String() {
  549. case "Monday":
  550. week = "周一"
  551. break
  552. case "Tuesday":
  553. week = "周二"
  554. break
  555. case "Wednesday":
  556. week = "周三"
  557. break
  558. case "Thursday":
  559. week = "周四"
  560. break
  561. case "Friday":
  562. week = "周五"
  563. break
  564. case "Saturday":
  565. week = "周六"
  566. break
  567. case "Sunday":
  568. week = "周日"
  569. break
  570. }
  571. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  572. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  573. //根据推送频率组装新的数组
  574. for _, item := range temp_sch_prescriptions {
  575. var cus CustomTemplate
  576. cus.ID = item.ID
  577. cus.UserOrgId = item.UserOrgId
  578. cus.PatientId = item.PatientId
  579. cus.MedType = item.MedType
  580. cus.RecordDate = item.RecordDate
  581. cus.Type = item.Type
  582. cus.PType = item.PType
  583. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  584. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  585. if subItem.FrequencyType == 1 { //每次必推
  586. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  587. }
  588. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  589. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  590. }
  591. if subItem.FrequencyType == 2 { //按照天数频率
  592. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  593. now := p.Unix()
  594. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  595. dayStr2 := "-" + dayStr
  596. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  597. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  598. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  599. if len(advices) == 0 {
  600. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  601. }
  602. }
  603. }
  604. }
  605. for _, subItem := range item.HisPrescriptionProjectTemplate {
  606. if subItem.Type == 2 {
  607. if subItem.XtHisProject.MedicalStatus != 1 {
  608. if subItem.FrequencyType == 1 {
  609. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  610. }
  611. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  612. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  613. }
  614. if subItem.FrequencyType == 2 {
  615. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  616. now := p.Unix()
  617. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  618. dayStr2 := "-" + dayStr
  619. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  620. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  621. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  622. if len(projects) == 0 {
  623. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  624. }
  625. }
  626. }
  627. } else if subItem.Type == 3 {
  628. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  629. if subItem.FrequencyType == 1 {
  630. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  631. }
  632. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  633. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  634. }
  635. if subItem.FrequencyType == 2 {
  636. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  637. now := p.Unix()
  638. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  639. dayStr2 := "-" + dayStr
  640. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  641. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  642. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  643. if len(projects) == 0 {
  644. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  645. }
  646. }
  647. }
  648. }
  649. }
  650. sch_prescriptions = append(sch_prescriptions, cus)
  651. }
  652. for _, item := range sch_prescriptions {
  653. if len(item.HisPrescriptionProjectTemplate) == 0 {
  654. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  655. }
  656. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  657. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  658. }
  659. }
  660. }
  661. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  662. if config.ID > 0 && config.IsOpen == 1 {
  663. for _, item := range sch_prescriptions {
  664. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  665. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  666. if info.RetailPrice > 0 {
  667. subItem.Drug.MinPrice = info.RetailPrice
  668. }
  669. }
  670. }
  671. }
  672. if config.ID > 0 && config.IsOpen == 1 {
  673. for _, item := range sch_prescriptions {
  674. for _, subItem := range item.HisPrescriptionProjectTemplate {
  675. if subItem.Type == 3 {
  676. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  677. if info.Price > 0 {
  678. subItem.GoodInfo.PackingPrice = info.Price
  679. }
  680. }
  681. }
  682. }
  683. }
  684. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  685. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  686. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  687. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  688. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  689. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  690. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  691. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  692. //获取所有科室信息
  693. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "his_info": his_patient_info,
  696. "xt_info": xt_patient_info,
  697. "prescription": prescriptions,
  698. "case_history": case_history,
  699. "info": patientPrescriptionInfo,
  700. //"month_prescriptions": monthPrescriptions,
  701. "order": order,
  702. "doctors": doctors,
  703. "department": department,
  704. "sch_prescriptions": sch_prescriptions,
  705. "last_prescriptions": last_prescriptions,
  706. "schedule": sch,
  707. "count": count,
  708. "drugStockConfig": drugStockConfig,
  709. "last_info": lastPatientPrescriptionInfo,
  710. })
  711. return
  712. }
  713. func (c *HisApiController) GetHisPrescriptionConfig() {
  714. adminInfo := c.GetAdminUserInfo()
  715. //获取医嘱模版
  716. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  717. //获取所有基础药
  718. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  719. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  720. if config.ID > 0 && config.IsOpen == 1 {
  721. for _, item := range drugs {
  722. var index = 0
  723. for _, subItem := range item.OtherDrugWarehouseInfo {
  724. if index == 0 {
  725. index = index + 1
  726. if subItem.RetailPrice > 0 {
  727. item.MinPrice = subItem.RetailPrice
  728. }
  729. }
  730. }
  731. }
  732. }
  733. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  734. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  735. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  736. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  737. //获取所有科室信息
  738. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  739. //获取诊断信息
  740. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  741. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  742. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  743. c.ServeSuccessJSON(map[string]interface{}{
  744. "drugs": drugs,
  745. "advices_template": advices,
  746. "drugways": drugways,
  747. "efs": efs,
  748. "doctors": doctors,
  749. "department": department,
  750. "sick": sick,
  751. "additions": additions,
  752. "diagnose": diagnose,
  753. "manufacturers": manufacturers,
  754. })
  755. }
  756. func (c *HisApiController) CreateHisPrescription() {
  757. record_date := c.GetString("record_date")
  758. patient_id, _ := c.GetInt64("patient_id")
  759. reg_type, _ := c.GetInt64("reg_type")
  760. diagnose := c.GetString("diagnose")
  761. sick_type, _ := c.GetInt64("sick_type")
  762. sick_history := c.GetString("sick_history")
  763. doctor_id, _ := c.GetInt64("doctor", 0)
  764. department, _ := c.GetInt64("department", 0)
  765. his_patient_id, _ := c.GetInt64("his_patient_id")
  766. p_type, _ := c.GetInt64("p_type")
  767. dataBody := make(map[string]interface{}, 0)
  768. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  769. if err != nil {
  770. utils.ErrorLog(err.Error())
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. timeLayout := "2006-01-02"
  775. loc, _ := time.LoadLocation("Local")
  776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  777. if err != nil {
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. adminInfo := c.GetAdminUserInfo()
  782. recordDateTime := theTime.Unix()
  783. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  784. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  785. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  786. if len(lists) == 1 {
  787. his_patient_id = lists[0].ID
  788. }
  789. }
  790. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  791. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  792. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  793. if drugStockConfig.IsOpen == 1 {
  794. //校验库存总量
  795. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  796. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  797. if len(prescriptions) > 0 {
  798. for _, item := range prescriptions {
  799. items := item.(map[string]interface{})
  800. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  801. advices := items["advices"].([]interface{})
  802. if len(advices) > 0 {
  803. for _, advice := range advices {
  804. var drug_id int64
  805. //var prescribing_number float64
  806. var prescribingNumberUnit string
  807. var prescribingNumber string
  808. var prescribing_number_one int64
  809. var adviceId int64
  810. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  811. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  812. }
  813. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  814. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  815. //prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  816. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  817. prescribing_number_one, _ = strconv.ParseInt(prescribing_number_str, 10, 64)
  818. }
  819. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  820. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  821. }
  822. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  823. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  824. }
  825. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  826. if drug.ID == 0 {
  827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  828. return
  829. }
  830. //查询药品的所有库存
  831. //list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
  832. //var total_count int64
  833. //for _, it := range list {
  834. // total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  835. //}
  836. //totals := strconv.FormatInt(total_count, 10)
  837. //查询该药品是否存在开药记录
  838. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  839. //新增处方
  840. if advicelist.ID == 0 {
  841. // all_count, _ := strconv.ParseFloat(totals, 64)
  842. if prescribingNumberUnit == drug.MinUnit {
  843. if prescribing_number_one > drug.SumCount {
  844. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  845. return
  846. }
  847. } else {
  848. if prescribingNumberUnit == drug.MaxUnit {
  849. num := prescribing_number_one * drug.MinNumber
  850. if num > drug.SumCount {
  851. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  852. return
  853. }
  854. }
  855. }
  856. }
  857. //修改处方
  858. if advicelist.ID > 0 {
  859. var device_number int64
  860. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  861. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  862. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  863. device_number = prescribingNumberInt * drug.MinNumber
  864. }
  865. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  866. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  867. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  868. device_number = prescribingNumberInt
  869. }
  870. var number_count int64
  871. if prescribingNumberUnit == drug.MaxUnit {
  872. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  873. number_count = prescribingNumberInt * drug.MinNumber
  874. }
  875. if prescribingNumberUnit == drug.MinUnit {
  876. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  877. number_count = prescribingNumberInt
  878. }
  879. //如果修改的数量大于之前修改的数量
  880. if (number_count - device_number) > 0 {
  881. //如果修改的差数量 大于库存数量
  882. if (number_count - device_number) > drug.SumCount {
  883. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  884. return
  885. }
  886. }
  887. if device_number != number_count {
  888. // 查询该药品最后一次出库记录
  889. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  890. //回退库存
  891. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  892. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  893. //查询默认仓库
  894. houseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
  895. //查询默认仓库剩余多少库存
  896. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  897. var sum_count int64
  898. var sum_in_count int64
  899. for _, it := range list {
  900. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  901. if it.MaxUnit == baseDrug.MaxUnit {
  902. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  903. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  904. }
  905. sum_count += it.StockMaxNumber + it.StockMinNumber
  906. sum_in_count += it.WarehousingCount
  907. }
  908. service.UpdateMedicalSumCount(drug_id, sum_count, sum_in_count, druginfo.OrgId)
  909. }
  910. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  911. var stock_max_number int64
  912. var stock_min_number int64
  913. if number_count >= drug.MinNumber {
  914. stock_max_number = device_number / drug.MinNumber
  915. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  916. stock_min_number = device_number % drug.MinNumber
  917. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  918. //查询默认仓库
  919. houseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
  920. //查询默认仓库剩余多少库存
  921. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  922. var sum_count int64
  923. var sum_in_count int64
  924. for _, it := range list {
  925. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  926. if it.MaxUnit == baseDrug.MaxUnit {
  927. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  928. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  929. }
  930. sum_count += it.StockMaxNumber + it.StockMinNumber
  931. sum_in_count += it.WarehousingCount
  932. }
  933. service.UpdateMedicalSumCount(drug_id, sum_count, sum_in_count, druginfo.OrgId)
  934. } else {
  935. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  936. //查询默认仓库
  937. houseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
  938. //查询默认仓库剩余多少库存
  939. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  940. var sum_count int64
  941. var sum_in_count int64
  942. for _, it := range list {
  943. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  944. if it.MaxUnit == baseDrug.MaxUnit {
  945. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  946. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  947. }
  948. sum_count += it.StockMaxNumber + it.StockMinNumber
  949. sum_in_count += it.WarehousingCount
  950. }
  951. service.UpdateMedicalSumCount(drug_id, sum_count, sum_in_count, druginfo.OrgId)
  952. }
  953. }
  954. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  955. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  956. //查询默认仓库
  957. houseConfig, _ := service.GetAllStoreHouseConfig(druginfo.OrgId)
  958. //查询默认仓库剩余多少库存
  959. list, _ := service.GetDrugSumCountByStorehouseId(houseConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  960. var sum_count int64
  961. var sum_in_count int64
  962. for _, it := range list {
  963. baseDrug, _ := service.GetBaseDrugMedical(it.DrugId)
  964. if it.MaxUnit == baseDrug.MaxUnit {
  965. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  966. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  967. }
  968. sum_count += it.StockMaxNumber + it.StockMinNumber
  969. sum_in_count += it.WarehousingCount
  970. }
  971. service.UpdateMedicalSumCount(drug_id, sum_count, sum_in_count, druginfo.OrgId)
  972. }
  973. //删除记录
  974. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  975. }
  976. }
  977. }
  978. }
  979. }
  980. }
  981. }
  982. }
  983. }
  984. if stockConfig.IsOpen == 1 {
  985. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  986. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  987. if len(prescriptions) > 0 {
  988. for _, item := range prescriptions {
  989. items := item.(map[string]interface{})
  990. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  991. projects := items["project"].([]interface{})
  992. if len(projects) > 0 {
  993. for _, project := range projects {
  994. var project_id int64
  995. var project_type int64
  996. //var totals float64
  997. var project_name string
  998. var parsetotal int64
  999. var id int64
  1000. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1001. id = int64(project.(map[string]interface{})["id"].(float64))
  1002. }
  1003. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1004. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1005. }
  1006. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1007. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1008. }
  1009. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1010. total, _ := project.(map[string]interface{})["total"].(string)
  1011. // totals, _ = strconv.ParseFloat(total, 64)
  1012. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1013. }
  1014. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1015. project_name = project.(map[string]interface{})["project_name"].(string)
  1016. }
  1017. if project_type == 3 {
  1018. //查找该耗材的出库记录
  1019. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1020. //var total_count int64
  1021. //for _, it := range goodWarehouseInfo {
  1022. // total_count += it.Count
  1023. //}
  1024. if len(goodWarehouseInfo) == 0 {
  1025. //查询耗材库存
  1026. //list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1027. //var stock_count int64
  1028. //for _, it := range list {
  1029. // stock_count += it.StockCount
  1030. //}
  1031. //stock_counts := strconv.FormatInt(stock_count, 10)
  1032. //stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1033. //if totals > stock_total_count {
  1034. // c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1035. // return
  1036. //}
  1037. good, _ := service.GetGoodInformationByGoodId(project_id)
  1038. if parsetotal > good.SumCount {
  1039. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1040. return
  1041. }
  1042. //查找今日该患者已经出库的所有耗材
  1043. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1044. for _, item := range goodList {
  1045. //回退库存
  1046. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  1047. //查询默认仓库
  1048. houseConfig, _ := service.GetAllStoreHouseConfig(item.GoodId)
  1049. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.OrgId)
  1050. var sum_count int64
  1051. var sum_in_count int64
  1052. for _, it := range goodList {
  1053. sum_count += it.StockCount
  1054. sum_in_count += it.WarehousingCount
  1055. }
  1056. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  1057. }
  1058. //删除记录
  1059. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1060. }
  1061. if len(goodWarehouseInfo) > 0 {
  1062. //查询该患者耗材的历史数据
  1063. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1064. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1065. //数量发生改变
  1066. if parsetotal != count {
  1067. //查找今日该患者已经出库的所有耗材
  1068. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1069. for _, item := range goodList {
  1070. //回退库存
  1071. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  1072. //查询默认仓库
  1073. houseConfig, _ := service.GetAllStoreHouseConfig(item.GoodId)
  1074. goodList, _ := service.GetGoodSumCountByStoreId(houseConfig.StorehouseOutInfo, item.ProjectId, item.OrgId)
  1075. var sum_count int64
  1076. var sum_in_count int64
  1077. for _, it := range goodList {
  1078. sum_count += it.StockCount
  1079. sum_in_count += it.WarehousingCount
  1080. }
  1081. service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
  1082. }
  1083. //删除记录
  1084. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1085. }
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. }
  1094. }
  1095. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1096. var hpInfo models.HisPrescriptionInfo
  1097. if info.ID == 0 {
  1098. var randNum int
  1099. randNum = rand.Intn(10000) + 1000
  1100. timestamp := time.Now().Unix()
  1101. tempTime := time.Unix(timestamp, 0)
  1102. timeFormat := tempTime.Format("20060102150405")
  1103. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1104. hpInfo = models.HisPrescriptionInfo{
  1105. HisPatientId: his_patient_id,
  1106. UserOrgId: adminInfo.CurrentOrgId,
  1107. RecordDate: theTime.Unix(),
  1108. PatientId: patient_id,
  1109. Status: 1,
  1110. Ctime: time.Now().Unix(),
  1111. Mtime: time.Now().Unix(),
  1112. Creator: adminInfo.AdminUser.Id,
  1113. Modifier: adminInfo.AdminUser.Id,
  1114. Diagnosis: diagnose,
  1115. SickHistory: sick_history,
  1116. Departments: department,
  1117. RegisterType: reg_type,
  1118. PrescriptionNumber: p_number,
  1119. PrescriptionStatus: 1,
  1120. Doctor: role.UserName,
  1121. DoctorId: doctor_id,
  1122. SickType: sick_type,
  1123. PType: p_type,
  1124. }
  1125. service.SavePatientPrescriptionInfo(hpInfo)
  1126. redis := service.RedisClient()
  1127. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1128. redis.Set(key, "", time.Second)
  1129. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1130. redis.Set(keyOne, "", time.Second)
  1131. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1132. redis.Set(keySeven, "", time.Second)
  1133. defer redis.Close()
  1134. } else {
  1135. hpInfo = models.HisPrescriptionInfo{
  1136. ID: info.ID,
  1137. UserOrgId: adminInfo.CurrentOrgId,
  1138. RecordDate: info.RecordDate,
  1139. PatientId: info.PatientId,
  1140. Status: 1,
  1141. Ctime: info.Ctime,
  1142. Mtime: time.Now().Unix(),
  1143. Creator: info.Creator,
  1144. Modifier: adminInfo.AdminUser.Id,
  1145. Diagnosis: diagnose,
  1146. SickHistory: sick_history,
  1147. Departments: department,
  1148. RegisterType: reg_type,
  1149. PrescriptionNumber: info.PrescriptionNumber,
  1150. Doctor: role.UserName,
  1151. PrescriptionStatus: info.PrescriptionStatus,
  1152. DoctorId: doctor_id,
  1153. SickType: sick_type,
  1154. PType: info.PType,
  1155. HisPatientId: info.HisPatientId,
  1156. }
  1157. service.SavePatientPrescriptionInfo(hpInfo)
  1158. redis := service.RedisClient()
  1159. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1160. redis.Set(key, "", time.Second)
  1161. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1162. redis.Set(keyOne, "", time.Second)
  1163. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1164. redis.Set(keySeven, "", time.Second)
  1165. defer redis.Close()
  1166. }
  1167. //定义切片
  1168. var adviceList []models.HisDoctorAdviceInfo
  1169. var projectList []models.HisPrescriptionProject
  1170. //var hisLis []models.HisList
  1171. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1172. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1173. var tempPrescription *models.HisPrescription
  1174. if len(prescriptions) > 0 {
  1175. for _, item := range prescriptions {
  1176. items := item.(map[string]interface{})
  1177. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1178. utils.ErrorLog("id")
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. id := int64(items["id"].(float64))
  1183. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1184. tempPrescription = &new_prescription
  1185. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1186. utils.ErrorLog("type")
  1187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1188. return
  1189. }
  1190. types := int64(items["type"].(float64))
  1191. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1192. utils.ErrorLog("med_type")
  1193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1194. return
  1195. }
  1196. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1197. if med_type == "0" {
  1198. med_type = "14"
  1199. }
  1200. //if order_status == 0 {
  1201. // order_status = 1
  1202. //}
  1203. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1204. utils.ErrorLog("pre_time")
  1205. }
  1206. preTime, _ := items["pre_time"].(string)
  1207. timeLayout := "2006-01-02"
  1208. loc, _ := time.LoadLocation("Local")
  1209. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1210. if err != nil {
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1212. return
  1213. }
  1214. pTime := theTime2.Unix()
  1215. ctime := time.Now().Unix()
  1216. if tempPrescription.ID == 0 {
  1217. prescription := &models.HisPrescription{
  1218. ID: 0,
  1219. PatientId: patient_id,
  1220. UserOrgId: adminInfo.CurrentOrgId,
  1221. RecordDate: recordDateTime,
  1222. Ctime: ctime,
  1223. Mtime: ctime,
  1224. Type: types,
  1225. Modifier: adminInfo.AdminUser.Id,
  1226. Creator: adminInfo.AdminUser.Id,
  1227. Status: 1,
  1228. Doctor: role.UserName,
  1229. HisPatientId: his_patient_id,
  1230. OrderStatus: 1,
  1231. BatchNumber: "",
  1232. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1233. PreTime: pTime,
  1234. PType: p_type,
  1235. MedType: med_type,
  1236. }
  1237. tempPrescription = prescription
  1238. service.SaveHisPrescription(tempPrescription)
  1239. redis := service.RedisClient()
  1240. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1241. redis.Set(key, "", time.Second)
  1242. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1243. redis.Set(keyOne, "", time.Second)
  1244. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1245. redis.Set(keySeven, "", time.Second)
  1246. defer redis.Close()
  1247. } else {
  1248. tempPrescription.ID = id
  1249. tempPrescription.Type = types
  1250. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1251. tempPrescription.Mtime = time.Now().Unix()
  1252. tempPrescription.Doctor = role.UserName
  1253. //tempPrescription.OrderStatus = order_status
  1254. tempPrescription.PreTime = pTime
  1255. tempPrescription.MedType = med_type
  1256. service.SaveHisPrescription(tempPrescription)
  1257. redis := service.RedisClient()
  1258. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1259. redis.Set(key, "", time.Second)
  1260. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1261. redis.Set(keyOne, "", time.Second)
  1262. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1263. redis.Set(keySeven, "", time.Second)
  1264. defer redis.Close()
  1265. }
  1266. //service.SaveHisPrescription(prescription)
  1267. //更改患者挂号状态
  1268. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1269. fmt.Println("更改失败", err2)
  1270. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1271. advices := items["advices"].([]interface{})
  1272. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1273. groupNo := int64(0)
  1274. ctime := time.Now().Unix()
  1275. mtime := ctime
  1276. if len(advices) > 0 {
  1277. for _, advice := range advices {
  1278. var s models.HisDoctorAdviceInfo
  1279. s.PrescriptionId = tempPrescription.ID
  1280. s.AdviceType = 2
  1281. s.AdviceDoctor = doctor_id
  1282. s.StopState = 2
  1283. s.ExecutionState = 2
  1284. s.AdviceDate = recordDateTime
  1285. s.Status = 1
  1286. s.UserOrgId = adminInfo.CurrentOrgId
  1287. s.RecordDate = recordDateTime
  1288. s.StartTime = tempPrescription.PreTime
  1289. s.Groupno = groupNo
  1290. s.CreatedTime = ctime
  1291. s.UpdatedTime = mtime
  1292. s.PatientId = patient_id
  1293. s.HisPatientId = his_patient_id
  1294. s.StartTime = pTime
  1295. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1296. if errcode > 0 {
  1297. c.ServeFailJSONWithSGJErrorCode(errcode)
  1298. return
  1299. }
  1300. s.StartTime = pTime
  1301. service.CreateHisDoctorAdvice(&s)
  1302. //存储切片中
  1303. adviceList = append(adviceList, s)
  1304. redis := service.RedisClient()
  1305. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1306. redis.Set(key, "", time.Second)
  1307. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1308. redis.Set(keyOne, "", time.Second)
  1309. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1310. redis.Set(keySeven, "", time.Second)
  1311. var randNum int
  1312. randNum = rand.Intn(10000) + 1000
  1313. timestamp := time.Now().Unix()
  1314. tempTime := time.Unix(timestamp, 0)
  1315. timeFormat := tempTime.Format("20060102150405")
  1316. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1317. service.CreateHisDoctorAdvice(&s)
  1318. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1319. redis.Set(keySix, "", time.Second)
  1320. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1321. redis.Set(keyFive, "", time.Second)
  1322. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1323. redis.Set(keyEight, "", time.Second)
  1324. defer redis.Close()
  1325. }
  1326. }
  1327. }
  1328. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1329. projects := items["project"].([]interface{})
  1330. if len(projects) > 0 {
  1331. for _, project := range projects {
  1332. var p models.HisPrescriptionProject
  1333. p.PrescriptionId = tempPrescription.ID
  1334. p.Ctime = time.Now().Unix()
  1335. p.Mtime = time.Now().Unix()
  1336. p.PatientId = patient_id
  1337. p.RecordDate = recordDateTime
  1338. p.Doctor = doctor_id
  1339. p.UserOrgId = adminInfo.CurrentOrgId
  1340. p.HisPatientId = his_patient_id
  1341. p.Status = 1
  1342. p.StartTime = pTime
  1343. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1344. if errcode > 0 {
  1345. c.ServeFailJSONWithSGJErrorCode(errcode)
  1346. return
  1347. }
  1348. service.CreateHisProjectTwo(&p)
  1349. projectList = append(projectList, p)
  1350. var randNum int
  1351. randNum = rand.Intn(10000) + 1000
  1352. timestamp := time.Now().Unix()
  1353. tempTime := time.Unix(timestamp, 0)
  1354. timeFormat := tempTime.Format("20060102150405")
  1355. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1356. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1357. //新增或者编辑项目,修改对应的标签数据
  1358. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1359. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1360. var label models.HisLabelPrintInfo
  1361. project, _ := service.GetProjectDetail(p.ProjectId)
  1362. if project.CostClassify == 3 { //类别为检验检查
  1363. if p.TeamId > 0 { //检验检查组套
  1364. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1365. if tempLabel.ID == 0 {
  1366. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1367. label.Number = tempPrescription.PrescriptionNumber
  1368. label.ProjectId = project.ID
  1369. label.Status = 1
  1370. label.IsPrint = 2
  1371. label.DoctorId = info.DoctorId
  1372. label.UserOrgId = p.UserOrgId
  1373. label.PatientId = patient_id
  1374. label.RecordDate = recordDateTime
  1375. label.Ctime = time.Now().Unix()
  1376. label.Mtime = time.Now().Unix()
  1377. label.ItemId = p.TeamId
  1378. label.FeedetlSn = p.FeedetlSn
  1379. label.PProjectId = p.ID
  1380. label.ProjectName = team.ProjectTeam
  1381. label.PatientName = patient.Name
  1382. service.CreateHisLabelRecord(&label)
  1383. }
  1384. } else { //单条检验检查项目
  1385. label.Number = tempPrescription.PrescriptionNumber
  1386. label.ProjectId = project.ID
  1387. label.Status = 1
  1388. label.DoctorId = info.DoctorId
  1389. label.UserOrgId = p.UserOrgId
  1390. label.PatientId = patient_id
  1391. label.RecordDate = recordDateTime
  1392. label.IsPrint = 2
  1393. label.Ctime = time.Now().Unix()
  1394. label.Mtime = time.Now().Unix()
  1395. label.FeedetlSn = p.FeedetlSn
  1396. label.PProjectId = p.ID
  1397. label.ItemId = p.TeamId
  1398. label.ProjectName = project.ProjectName
  1399. label.PatientName = patient.Name
  1400. service.CreateHisLabelRecord(&label)
  1401. }
  1402. }
  1403. }
  1404. }
  1405. service.SaveHisProjectTwo(&p)
  1406. //if p.Type == 3 { //处理透前准备耗材数量数据
  1407. // consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  1408. // if consumables.ID > 0 {
  1409. // cnt, _ := strconv.ParseInt(p.Count, 10, 64)
  1410. // consumables.Count = cnt
  1411. // service.UpdateConsumables(&consumables)
  1412. // }
  1413. //}
  1414. }
  1415. }
  1416. }
  1417. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1418. // addition := items["addition"].([]interface{})
  1419. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1420. // ctime := time.Now().Unix()
  1421. // mtime := ctime
  1422. // if len(addition) > 0 {
  1423. // for _, item := range addition {
  1424. // var s models.HisAdditionalCharge
  1425. // s.PrescriptionId = tempPrescription.ID
  1426. // s.Status = 1
  1427. // s.UserOrgId = adminInfo.CurrentOrgId
  1428. // s.RecordDate = recordDateTime
  1429. // s.CreatedTime = ctime
  1430. // s.UpdatedTime = mtime
  1431. // s.PatientId = patient_id
  1432. // s.HisPatientId = his_patient_id
  1433. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1434. // if errcode > 0 {
  1435. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1436. // return
  1437. // }
  1438. // service.CreateAdditionalCharge(&s)
  1439. // var randNum int
  1440. // randNum = rand.Intn(10000) + 1000
  1441. // timestamp := time.Now().Unix()
  1442. // tempTime := time.Unix(timestamp, 0)
  1443. // timeFormat := tempTime.Format("20060102150405")
  1444. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1445. // service.CreateAdditionalCharge(&s)
  1446. //
  1447. // }
  1448. // }
  1449. //}
  1450. }
  1451. }
  1452. }
  1453. //redisClient := service.RedisClient()
  1454. //defer redisClient.Close()
  1455. //
  1456. //list := models.HisList{
  1457. // Patient_id: patient_id,
  1458. // Advice_id:0,
  1459. // Record_date: 0,
  1460. // Advice: adviceList,
  1461. // Project: nil,
  1462. //}
  1463. //hisLis = append(hisLis, list)
  1464. //
  1465. //advice_json, _ := json.Marshal(&hisLis)
  1466. //redisClient.RPush("111", advice_json).Result()
  1467. //result, _ := redisClient.RPop("111").Result()
  1468. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1469. //
  1470. //var dat []map[string]interface{}
  1471. //json.Unmarshal([]byte(result), &dat)
  1472. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1473. //
  1474. //for k,v:=range dat{
  1475. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1476. //}
  1477. //project_json, _ := json.Marshal(&projectList)
  1478. //redisClient.LPush("222", project_json).Result()
  1479. if err == nil {
  1480. c.ServeSuccessJSON(map[string]interface{}{
  1481. "msg": "保存成功",
  1482. })
  1483. return
  1484. } else {
  1485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1486. return
  1487. }
  1488. }
  1489. func (c *HisApiController) EditHisPrescription() {
  1490. record_date := c.GetString("record_date")
  1491. patient_id, _ := c.GetInt64("patient_id")
  1492. reg_type, _ := c.GetInt64("reg_type")
  1493. //diagnose, _ := c.GetInt64("diagnose", 0)
  1494. diagnose := c.GetString("diagnose")
  1495. sick_type, _ := c.GetInt64("sick_type")
  1496. sick_history := c.GetString("sick_history")
  1497. doctor_id, _ := c.GetInt64("doctor", 0)
  1498. department, _ := c.GetInt64("department", 0)
  1499. his_patient_id, _ := c.GetInt64("his_patient_id")
  1500. p_type, _ := c.GetInt64("p_type")
  1501. dataBody := make(map[string]interface{}, 0)
  1502. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1503. if err != nil {
  1504. utils.ErrorLog(err.Error())
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1506. return
  1507. }
  1508. timeLayout := "2006-01-02"
  1509. loc, _ := time.LoadLocation("Local")
  1510. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1511. if err != nil {
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1513. return
  1514. }
  1515. adminInfo := c.GetAdminUserInfo()
  1516. recordDateTime := theTime.Unix()
  1517. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1518. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1519. var hpInfo models.HisPrescriptionInfo
  1520. if info.ID == 0 {
  1521. var randNum int
  1522. randNum = rand.Intn(10000) + 1000
  1523. timestamp := time.Now().Unix()
  1524. tempTime := time.Unix(timestamp, 0)
  1525. timeFormat := tempTime.Format("20060102150405")
  1526. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1527. hpInfo = models.HisPrescriptionInfo{
  1528. UserOrgId: adminInfo.CurrentOrgId,
  1529. RecordDate: theTime.Unix(),
  1530. PatientId: patient_id,
  1531. Status: 1,
  1532. Ctime: time.Now().Unix(),
  1533. Mtime: time.Now().Unix(),
  1534. Creator: adminInfo.AdminUser.Id,
  1535. Modifier: adminInfo.AdminUser.Id,
  1536. Diagnosis: diagnose,
  1537. SickHistory: sick_history,
  1538. Departments: department,
  1539. RegisterType: reg_type,
  1540. PrescriptionNumber: p_number,
  1541. PrescriptionStatus: 1,
  1542. Doctor: role.UserName,
  1543. DoctorId: doctor_id,
  1544. SickType: sick_type,
  1545. PType: p_type,
  1546. }
  1547. service.SavePatientPrescriptionInfo(hpInfo)
  1548. } else {
  1549. hpInfo = models.HisPrescriptionInfo{
  1550. ID: info.ID,
  1551. UserOrgId: adminInfo.CurrentOrgId,
  1552. RecordDate: info.RecordDate,
  1553. PatientId: info.PatientId,
  1554. Status: 1,
  1555. Ctime: info.Ctime,
  1556. Mtime: time.Now().Unix(),
  1557. Creator: info.Creator,
  1558. Modifier: adminInfo.AdminUser.Id,
  1559. Diagnosis: diagnose,
  1560. SickHistory: sick_history,
  1561. Departments: department,
  1562. RegisterType: reg_type,
  1563. PrescriptionNumber: info.PrescriptionNumber,
  1564. Doctor: role.UserName,
  1565. PrescriptionStatus: info.PrescriptionStatus,
  1566. DoctorId: doctor_id,
  1567. SickType: sick_type,
  1568. PType: info.PType,
  1569. }
  1570. service.SavePatientPrescriptionInfo(hpInfo)
  1571. }
  1572. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1573. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1574. if len(prescriptions) > 0 {
  1575. for _, item := range prescriptions {
  1576. items := item.(map[string]interface{})
  1577. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1578. utils.ErrorLog("id")
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. id := int64(items["id"].(float64))
  1583. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1584. utils.ErrorLog("type")
  1585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1586. return
  1587. }
  1588. types := int64(items["type"].(float64))
  1589. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1590. utils.ErrorLog("med_type")
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1595. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1596. ctime := time.Now().Unix()
  1597. prescription := &models.HisPrescription{
  1598. ID: id,
  1599. PatientId: patient_id,
  1600. UserOrgId: adminInfo.CurrentOrgId,
  1601. RecordDate: recordDateTime,
  1602. Ctime: ctime,
  1603. Mtime: ctime,
  1604. Type: types,
  1605. Modifier: adminInfo.AdminUser.Id,
  1606. Creator: adminInfo.AdminUser.Id,
  1607. Status: 1,
  1608. Doctor: role.UserName,
  1609. HisPatientId: his_patient_id,
  1610. OrderStatus: 1,
  1611. BatchNumber: "",
  1612. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1613. PType: hpInfo.PType,
  1614. MedType: med_type,
  1615. }
  1616. if historyPrescription.ID > 0 {
  1617. prescription.PreTime = historyPrescription.PreTime
  1618. }
  1619. service.SaveHisPrescription(prescription)
  1620. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1621. advices := items["advices"].([]interface{})
  1622. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1623. groupNo := int64(0)
  1624. ctime := time.Now().Unix()
  1625. mtime := ctime
  1626. if len(advices) > 0 {
  1627. for _, advice := range advices {
  1628. var s models.HisDoctorAdviceInfo
  1629. s.PrescriptionId = prescription.ID
  1630. s.AdviceType = 2
  1631. s.AdviceDoctor = adminInfo.AdminUser.Id
  1632. s.StopState = 2
  1633. s.ExecutionState = 2
  1634. s.AdviceDate = recordDateTime
  1635. s.Status = 1
  1636. s.UserOrgId = adminInfo.CurrentOrgId
  1637. s.RecordDate = recordDateTime
  1638. s.StartTime = prescription.PreTime
  1639. s.Groupno = groupNo
  1640. s.CreatedTime = ctime
  1641. s.UpdatedTime = mtime
  1642. s.PatientId = patient_id
  1643. s.HisPatientId = his_patient_id
  1644. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1645. if errcode > 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(errcode)
  1647. return
  1648. }
  1649. service.CreateHisDoctorAdvice(&s)
  1650. redis := service.RedisClient()
  1651. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1652. redis.Set(key, "", time.Second)
  1653. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1654. fmt.Println("keyOne", keyOne)
  1655. redis.Set(keyOne, "", time.Second)
  1656. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1657. redis.Set(keySeven, "", time.Second)
  1658. redis.Close()
  1659. }
  1660. }
  1661. }
  1662. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1663. projects := items["project"].([]interface{})
  1664. if len(projects) > 0 {
  1665. for _, project := range projects {
  1666. var p models.HisPrescriptionProject
  1667. p.PrescriptionId = prescription.ID
  1668. p.Ctime = time.Now().Unix()
  1669. p.Mtime = time.Now().Unix()
  1670. p.PatientId = patient_id
  1671. p.RecordDate = recordDateTime
  1672. p.UserOrgId = adminInfo.CurrentOrgId
  1673. p.HisPatientId = his_patient_id
  1674. p.Status = 1
  1675. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1676. if errcode > 0 {
  1677. c.ServeFailJSONWithSGJErrorCode(errcode)
  1678. return
  1679. }
  1680. service.CreateHisProjectTwo(&p)
  1681. }
  1682. }
  1683. }
  1684. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1685. addition := items["addition"].([]interface{})
  1686. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1687. ctime := time.Now().Unix()
  1688. mtime := ctime
  1689. if len(addition) > 0 {
  1690. for _, item := range addition {
  1691. var s models.HisAdditionalCharge
  1692. s.PrescriptionId = prescription.ID
  1693. s.Status = 1
  1694. s.UserOrgId = adminInfo.CurrentOrgId
  1695. s.RecordDate = recordDateTime
  1696. s.CreatedTime = ctime
  1697. s.UpdatedTime = mtime
  1698. s.PatientId = patient_id
  1699. s.HisPatientId = his_patient_id
  1700. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1701. if errcode > 0 {
  1702. c.ServeFailJSONWithSGJErrorCode(errcode)
  1703. return
  1704. }
  1705. service.CreateAdditionalCharge(&s)
  1706. }
  1707. }
  1708. }
  1709. }
  1710. }
  1711. }
  1712. if err == nil {
  1713. c.ServeSuccessJSON(map[string]interface{}{
  1714. "msg": "保存成功",
  1715. })
  1716. return
  1717. } else {
  1718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1719. return
  1720. }
  1721. }
  1722. func (c *HisApiController) DeletePrescription() {
  1723. prescription_id, _ := c.GetInt64("id")
  1724. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1725. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1726. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1727. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1728. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1729. if len(projects) > 0 {
  1730. for _, item := range projects {
  1731. service.DeletePrintInfo(item.ID) //删除打印信息
  1732. if stockConfig.IsOpen == 1 {
  1733. if item.Type == 3 {
  1734. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1735. f_count, _ := strconv.ParseFloat(item.Count, 64)
  1736. good.Total = good.Total + f_count
  1737. service.UpdateGoodInfo(&good)
  1738. operation_time := time.Now().Unix()
  1739. creater := c.GetAdminUserInfo().AdminUser.Id
  1740. //创建退库单
  1741. timeStr := time.Now().Format("2006-01-02")
  1742. timeArr := strings.Split(timeStr, "-")
  1743. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1744. total = total + 1
  1745. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1746. cancelStock := models.CancelStock{
  1747. OrderNumber: orderNumber,
  1748. OperaTime: operation_time,
  1749. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1750. Creater: creater,
  1751. Ctime: time.Now().Unix(),
  1752. Status: 1,
  1753. ReturnTime: item.RecordDate,
  1754. Type: 1,
  1755. StorehouseId: houseConfig.StorehouseOutInfo,
  1756. }
  1757. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1758. if msgerrkonde == gorm.ErrRecordNotFound {
  1759. service.AddSigleCancelStock(&cancelStock)
  1760. }
  1761. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1762. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1763. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1764. //查询该耗材是否出库
  1765. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1766. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1767. deaerler, _ := service.GetDealerById(info.Dealer)
  1768. if info.ID > 0 {
  1769. cancelStockInfo := models.CancelStockInfo{
  1770. GoodId: item.ProjectId,
  1771. CancelStockId: cancel.ID,
  1772. GoodTypeId: good.GoodTypeId,
  1773. Count: prescribingNumber,
  1774. Price: info.Price,
  1775. Total: 0,
  1776. ProductDate: info.ProductDate,
  1777. ExpiryDate: info.ExpiryDate,
  1778. Ctime: time.Now().Unix(),
  1779. Status: 1,
  1780. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1781. OrderNumber: cancel.OrderNumber,
  1782. Type: 0,
  1783. Dealer: deaerler.DealerName,
  1784. Manufacturer: manufacturer.ManufacturerName,
  1785. Number: info.Number,
  1786. RegisterAccount: "",
  1787. Remark: "",
  1788. WarehouseInfoId: info.WarehouseInfotId,
  1789. PatientId: info.PatientId,
  1790. RecordDate: info.SysRecordTime,
  1791. StorehouseId: houseConfig.StorehouseOutInfo,
  1792. }
  1793. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1794. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1795. flow := models.VmStockFlow{
  1796. WarehousingId: 0,
  1797. GoodId: item.ProjectId,
  1798. Number: info.Number,
  1799. LicenseNumber: info.LicenseNumber,
  1800. Count: prescribingNumber,
  1801. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1802. PatientId: item.PatientId,
  1803. SystemTime: info.SysRecordTime,
  1804. ConsumableType: 7,
  1805. IsSys: 0,
  1806. WarehousingOrder: "",
  1807. WarehouseOutId: 0,
  1808. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1809. IsEdit: 0,
  1810. CancelStockId: cancel.ID,
  1811. CancelOrderNumber: cancel.OrderNumber,
  1812. Manufacturer: manufacturer.ID,
  1813. Dealer: 0,
  1814. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1815. UpdateCreator: 0,
  1816. Status: 1,
  1817. Ctime: time.Now().Unix(),
  1818. Mtime: 0,
  1819. Price: info.Price,
  1820. WarehousingDetailId: info.WarehouseInfotId,
  1821. WarehouseOutDetailId: 0,
  1822. CancelOutDetailId: cancelInfo.ID,
  1823. ProductDate: info.ProductDate,
  1824. ExpireDate: info.ExpiryDate,
  1825. StorehouseId: houseConfig.StorehouseOutInfo,
  1826. }
  1827. service.CreateStockFlowOne(flow)
  1828. //删除出库表
  1829. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1830. //查询今日该患者开了多少耗材
  1831. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1832. var total_count int64
  1833. var cha_count int64
  1834. for _, item := range projectList {
  1835. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1836. total_count += count
  1837. }
  1838. //回退库存
  1839. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1840. service.ModifyGoodAddInformation(info.GoodId, total_count, info.OrgId)
  1841. //查询今日该耗材退库数量
  1842. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1843. var cancel_Count int64
  1844. for _, items := range cancelInfoOne {
  1845. cancel_Count += items.Count
  1846. }
  1847. cha_count = total_count - cancel_Count
  1848. if total_count > cancel_Count {
  1849. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1850. if err == gorm.ErrRecordNotFound {
  1851. //没有记录,则创建出库单
  1852. timeStr := time.Now().Format("2006-01-02")
  1853. timeArr := strings.Split(timeStr, "-")
  1854. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1855. total = total + 1
  1856. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1857. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1858. number = number + total
  1859. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1860. warehouseOut := models.WarehouseOut{
  1861. WarehouseOutOrderNumber: warehousing_out_order,
  1862. OperationTime: time.Now().Unix(),
  1863. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1864. Creater: creater,
  1865. Ctime: time.Now().Unix(),
  1866. Status: 1,
  1867. WarehouseOutTime: info.SysRecordTime,
  1868. Dealer: 0,
  1869. Manufacturer: 0,
  1870. Type: 1,
  1871. IsSys: 1,
  1872. StorehouseId: houseConfig.StorehouseOutInfo,
  1873. }
  1874. err := service.AddSigleWarehouseOut(&warehouseOut)
  1875. if err != nil {
  1876. utils.TraceLog("创建出库单失败 err = %v", err)
  1877. return
  1878. }
  1879. prepare := &models.DialysisBeforePrepare{
  1880. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1881. PatientId: info.PatientId,
  1882. RecordDate: info.SysRecordTime,
  1883. GoodId: item.ProjectId,
  1884. GoodTypeId: info.GoodTypeId,
  1885. Count: cha_count,
  1886. StorehouseId: houseConfig.StorehouseOutInfo,
  1887. }
  1888. //出库
  1889. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1890. } else if err == nil {
  1891. prepare := &models.DialysisBeforePrepare{
  1892. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1893. PatientId: info.PatientId,
  1894. RecordDate: info.SysRecordTime,
  1895. GoodId: item.ProjectId,
  1896. GoodTypeId: info.GoodTypeId,
  1897. Count: cha_count,
  1898. StorehouseId: houseConfig.StorehouseOutInfo,
  1899. }
  1900. //出库
  1901. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1902. }
  1903. }
  1904. }
  1905. }
  1906. }
  1907. }
  1908. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1909. fmt.Println(err)
  1910. }
  1911. if drugStockConfig.IsOpen == 1 {
  1912. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1913. fmt.Println(err)
  1914. if len(advices) > 0 {
  1915. for _, item := range advices {
  1916. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1917. redis := service.RedisClient()
  1918. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1919. redis.Set(keyFive, "", time.Second)
  1920. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1921. redis.Set(keyOne, "", time.Second)
  1922. redis.Close()
  1923. //查询该药品是否存在出库记录
  1924. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1925. if errcode == gorm.ErrRecordNotFound {
  1926. } else if errcode == nil {
  1927. if item.PrescribingNumberUnit == drug.MinUnit {
  1928. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1929. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1930. //退库
  1931. warehouseInfo := models.DrugWarehouseInfo{
  1932. StockMinNumber: prescribingNumber,
  1933. }
  1934. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1935. service.ModifyDrugAddInformation(info.DrugId, warehouseInfo.StockMinNumber, warehouseInfo.OrgId)
  1936. adminUserInfo := c.GetAdminUserInfo()
  1937. operation_time := time.Now().Unix()
  1938. creater := adminUserInfo.AdminUser.Id
  1939. ctime := time.Now().Unix()
  1940. timeStr := time.Now().Format("2006-01-02")
  1941. timeArr := strings.Split(timeStr, "-")
  1942. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1943. total = total + 1
  1944. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1945. cancelStock := models.DrugCancelStock{
  1946. OrderNumber: orderNumber,
  1947. OperaTime: operation_time,
  1948. OrgId: adminUserInfo.CurrentOrgId,
  1949. Creater: creater,
  1950. Ctime: ctime,
  1951. Status: 1,
  1952. ReturnTime: item.AdviceDate,
  1953. Dealer: info.Dealer,
  1954. Manufacturer: info.Manufacturer,
  1955. Type: 1,
  1956. StorehouseId: houseConfig.DrugStorehouseOut,
  1957. }
  1958. service.AddSigleDrugCancelStock(&cancelStock)
  1959. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1960. dealer, _ := service.GetDealerById(info.Dealer)
  1961. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1962. cancelStockInfo := models.DrugCancelStockInfo{
  1963. OrderNumber: cancelInfo.OrderNumber,
  1964. CancelStockId: cancelInfo.ID,
  1965. DrugId: info.DrugId,
  1966. Count: prescribingNumber,
  1967. Status: 1,
  1968. Ctime: ctime,
  1969. OrgId: adminUserInfo.CurrentOrgId,
  1970. Type: 1,
  1971. Manufacturer: manufactureName.ManufacturerName,
  1972. Dealer: dealer.DealerName,
  1973. Total: 0,
  1974. RetailPrice: info.RetailPrice,
  1975. RetailTotalPrice: info.RetailTotalPrice,
  1976. Price: info.Price,
  1977. RegisterAccount: "",
  1978. Remark: info.Remark,
  1979. BatchNumber: info.BatchNumber,
  1980. MaxUnit: info.CountUnit,
  1981. ProductDate: info.ProductDate,
  1982. ExpiryDate: info.ExpiryDate,
  1983. BatchNumberId: info.WarehouseInfoId,
  1984. StorehouseId: houseConfig.DrugStorehouseOut,
  1985. }
  1986. flow := models.DrugFlow{
  1987. WarehousingId: 0,
  1988. DrugId: info.DrugId,
  1989. Number: "",
  1990. BatchNumber: info.BatchNumber,
  1991. Count: prescribingNumber,
  1992. UserOrgId: adminUserInfo.CurrentOrgId,
  1993. PatientId: 0,
  1994. SystemTime: info.SysRecordTime,
  1995. ConsumableType: 7,
  1996. IsSys: 0,
  1997. WarehousingOrder: "",
  1998. WarehouseOutId: 0,
  1999. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2000. IsEdit: 0,
  2001. CancelStockId: cancelStock.ID,
  2002. CancelOrderNumber: cancelStock.OrderNumber,
  2003. Manufacturer: info.Manufacturer,
  2004. Dealer: info.Dealer,
  2005. Creator: adminUserInfo.AdminUser.Id,
  2006. UpdateCreator: 0,
  2007. Status: 1,
  2008. Ctime: time.Now().Unix(),
  2009. Mtime: 0,
  2010. Price: info.Price,
  2011. WarehousingDetailId: 0,
  2012. WarehouseOutDetailId: 0,
  2013. CancelOutDetailId: 0,
  2014. ExpireDate: info.ExpiryDate,
  2015. ProductDate: info.ProductDate,
  2016. MaxUnit: info.CountUnit,
  2017. MinUnit: "",
  2018. AdviceId: info.AdviceId,
  2019. StorehouseId: houseConfig.DrugStorehouseOut,
  2020. }
  2021. service.CreatedCancelStock(cancelStockInfo)
  2022. service.CreateDrugFlowOne(flow)
  2023. //删除出库记录
  2024. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2025. //删除流水
  2026. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2027. } else {
  2028. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  2029. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2030. if item.PrescribingNumberUnit == drug.MaxUnit {
  2031. warehouseInfo := models.DrugWarehouseInfo{
  2032. StockMaxNumber: prescribingNumber,
  2033. StorehouseId: houseConfig.DrugStorehouseOut,
  2034. }
  2035. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2036. var sum_count int64
  2037. sum_count = prescribingNumber * drug.MinNumber
  2038. service.ModifyDrugAddInformation(info.DrugId, sum_count, info.OrgId)
  2039. }
  2040. adminUserInfo := c.GetAdminUserInfo()
  2041. operation_time := time.Now().Unix()
  2042. creater := adminUserInfo.AdminUser.Id
  2043. ctime := time.Now().Unix()
  2044. timeStr := time.Now().Format("2006-01-02")
  2045. timeArr := strings.Split(timeStr, "-")
  2046. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2047. total = total + 1
  2048. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2049. cancelStock := models.DrugCancelStock{
  2050. OrderNumber: orderNumber,
  2051. OperaTime: operation_time,
  2052. OrgId: adminUserInfo.CurrentOrgId,
  2053. Creater: creater,
  2054. Ctime: ctime,
  2055. Status: 1,
  2056. ReturnTime: item.AdviceDate,
  2057. Dealer: info.Dealer,
  2058. Manufacturer: info.Manufacturer,
  2059. Type: 1,
  2060. StorehouseId: houseConfig.DrugStorehouseOut,
  2061. }
  2062. service.AddSigleDrugCancelStock(&cancelStock)
  2063. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2064. dealer, _ := service.GetDealerById(info.Dealer)
  2065. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2066. cancelStockInfo := models.DrugCancelStockInfo{
  2067. OrderNumber: cancelInfo.OrderNumber,
  2068. CancelStockId: cancelInfo.ID,
  2069. DrugId: info.DrugId,
  2070. // Count: info.Count,
  2071. Count: prescribingNumber,
  2072. Status: 1,
  2073. Ctime: ctime,
  2074. OrgId: adminUserInfo.CurrentOrgId,
  2075. Type: 1,
  2076. Manufacturer: manufactureName.ManufacturerName,
  2077. Dealer: dealer.DealerName,
  2078. Total: 0,
  2079. RetailPrice: info.RetailPrice,
  2080. RetailTotalPrice: info.RetailTotalPrice,
  2081. Price: info.Price,
  2082. RegisterAccount: "",
  2083. Remark: info.Remark,
  2084. BatchNumber: info.BatchNumber,
  2085. MaxUnit: info.CountUnit,
  2086. ProductDate: info.ProductDate,
  2087. ExpiryDate: info.ExpiryDate,
  2088. BatchNumberId: info.WarehouseInfoId,
  2089. StorehouseId: houseConfig.DrugStorehouseOut,
  2090. }
  2091. flow := models.DrugFlow{
  2092. WarehousingId: 0,
  2093. DrugId: info.DrugId,
  2094. Number: "",
  2095. BatchNumber: info.BatchNumber,
  2096. //Count: info.Count,
  2097. Count: prescribingNumber,
  2098. UserOrgId: adminUserInfo.CurrentOrgId,
  2099. PatientId: 0,
  2100. SystemTime: info.SysRecordTime,
  2101. ConsumableType: 7,
  2102. IsSys: 0,
  2103. WarehousingOrder: "",
  2104. WarehouseOutId: 0,
  2105. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2106. IsEdit: 0,
  2107. CancelStockId: cancelStock.ID,
  2108. CancelOrderNumber: cancelStock.OrderNumber,
  2109. Manufacturer: info.Manufacturer,
  2110. Dealer: info.Dealer,
  2111. Creator: adminUserInfo.AdminUser.Id,
  2112. UpdateCreator: 0,
  2113. Status: 1,
  2114. Ctime: time.Now().Unix(),
  2115. Mtime: 0,
  2116. Price: info.Price,
  2117. WarehousingDetailId: 0,
  2118. WarehouseOutDetailId: 0,
  2119. CancelOutDetailId: 0,
  2120. ExpireDate: info.ExpiryDate,
  2121. ProductDate: info.ProductDate,
  2122. MaxUnit: info.CountUnit,
  2123. MinUnit: "",
  2124. AdviceId: info.AdviceId,
  2125. StorehouseId: houseConfig.DrugStorehouseOut,
  2126. }
  2127. service.CreatedCancelStock(cancelStockInfo)
  2128. service.CreateDrugFlowOne(flow)
  2129. //删除出库记录
  2130. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2131. //删除流水
  2132. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2133. }
  2134. }
  2135. if item.PrescribingNumberUnit == drug.MinUnit {
  2136. drug.Total = drug.Total + item.PrescribingNumber
  2137. service.UpdateBaseDrugLib(&drug)
  2138. } else {
  2139. if item.PrescribingNumberUnit == drug.MaxUnit {
  2140. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  2141. drug.Total = drug.Total + item.PrescribingNumber
  2142. service.UpdateBaseDrugLib(&drug)
  2143. }
  2144. }
  2145. }
  2146. }
  2147. }
  2148. c.ServeSuccessJSON(map[string]interface{}{
  2149. "msg": "删除成功",
  2150. })
  2151. return
  2152. }
  2153. func (c *HisApiController) DeleteDoctorAdvice() {
  2154. id, _ := c.GetInt64("id")
  2155. advice, _ := service.GetHisDoctorAdvicesById(id)
  2156. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2157. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2158. redis := service.RedisClient()
  2159. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2160. redis.Set(keyFive, "", time.Second)
  2161. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2162. redis.Set(keyOne, "", time.Second)
  2163. defer redis.Close()
  2164. if err == nil {
  2165. if drugStockConfig.IsOpen == 1 {
  2166. //判断该医嘱是否执行了
  2167. if advice.ExecutionState == 1 {
  2168. houseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  2169. //查询该病人该药品是否有库存记录
  2170. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  2171. if errcode == gorm.ErrRecordNotFound {
  2172. } else {
  2173. //退库
  2174. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  2175. if advice.PrescribingNumberUnit == drug.MinUnit {
  2176. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2177. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2178. //退库
  2179. warehouseInfo := models.DrugWarehouseInfo{
  2180. StockMinNumber: prescribingNumber,
  2181. }
  2182. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  2183. service.ModifyDrugAddInformation(info.DrugId, warehouseInfo.StockMinNumber, info.OrgId)
  2184. adminUserInfo := c.GetAdminUserInfo()
  2185. operation_time := time.Now().Unix()
  2186. creater := adminUserInfo.AdminUser.Id
  2187. ctime := time.Now().Unix()
  2188. timeStr := time.Now().Format("2006-01-02")
  2189. timeArr := strings.Split(timeStr, "-")
  2190. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2191. total = total + 1
  2192. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2193. cancelStock := models.DrugCancelStock{
  2194. OrderNumber: orderNumber,
  2195. OperaTime: operation_time,
  2196. OrgId: adminUserInfo.CurrentOrgId,
  2197. Creater: creater,
  2198. Ctime: ctime,
  2199. Status: 1,
  2200. ReturnTime: advice.AdviceDate,
  2201. Dealer: info.Dealer,
  2202. Manufacturer: info.Manufacturer,
  2203. Type: 1,
  2204. StorehouseId: houseConfig.DrugStorehouseOut,
  2205. }
  2206. service.AddSigleDrugCancelStock(&cancelStock)
  2207. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2208. dealer, _ := service.GetDealerById(info.Dealer)
  2209. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2210. cancelStockInfo := models.DrugCancelStockInfo{
  2211. OrderNumber: cancelInfo.OrderNumber,
  2212. CancelStockId: cancelInfo.ID,
  2213. DrugId: info.DrugId,
  2214. Count: info.Count,
  2215. Status: 1,
  2216. Ctime: ctime,
  2217. OrgId: adminUserInfo.CurrentOrgId,
  2218. Type: 1,
  2219. Manufacturer: manufactureName.ManufacturerName,
  2220. Dealer: dealer.DealerName,
  2221. Total: 0,
  2222. RetailPrice: info.RetailPrice,
  2223. RetailTotalPrice: info.RetailTotalPrice,
  2224. Price: info.Price,
  2225. RegisterAccount: "",
  2226. Remark: info.Remark,
  2227. BatchNumber: info.BatchNumber,
  2228. MaxUnit: info.CountUnit,
  2229. ProductDate: info.ProductDate,
  2230. ExpiryDate: info.ExpiryDate,
  2231. BatchNumberId: info.WarehouseInfoId,
  2232. StorehouseId: houseConfig.DrugStorehouseOut,
  2233. }
  2234. flow := models.DrugFlow{
  2235. WarehousingId: 0,
  2236. DrugId: info.DrugId,
  2237. Number: "",
  2238. BatchNumber: info.BatchNumber,
  2239. Count: info.Count,
  2240. UserOrgId: adminUserInfo.CurrentOrgId,
  2241. PatientId: 0,
  2242. SystemTime: info.SysRecordTime,
  2243. ConsumableType: 7,
  2244. IsSys: 0,
  2245. WarehousingOrder: "",
  2246. WarehouseOutId: 0,
  2247. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2248. IsEdit: 0,
  2249. CancelStockId: cancelStock.ID,
  2250. CancelOrderNumber: cancelStock.OrderNumber,
  2251. Manufacturer: info.Manufacturer,
  2252. Dealer: info.Dealer,
  2253. Creator: adminUserInfo.AdminUser.Id,
  2254. UpdateCreator: 0,
  2255. Status: 1,
  2256. Ctime: time.Now().Unix(),
  2257. Mtime: 0,
  2258. Price: info.Price,
  2259. WarehousingDetailId: 0,
  2260. WarehouseOutDetailId: 0,
  2261. CancelOutDetailId: 0,
  2262. ExpireDate: info.ExpiryDate,
  2263. ProductDate: info.ProductDate,
  2264. MaxUnit: info.CountUnit,
  2265. MinUnit: "",
  2266. AdviceId: info.AdviceId,
  2267. StorehouseId: houseConfig.DrugStorehouseOut,
  2268. }
  2269. service.CreatedCancelStock(cancelStockInfo)
  2270. service.CreateDrugFlowOne(flow)
  2271. //删除出库记录
  2272. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2273. //删除流水
  2274. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2275. } else {
  2276. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2277. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2278. if advice.PrescribingNumberUnit == drug.MaxUnit {
  2279. warehouseInfo := models.DrugWarehouseInfo{
  2280. StockMaxNumber: prescribingNumber,
  2281. }
  2282. var sum_count int64
  2283. sum_count = prescribingNumber * drug.MinNumber
  2284. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2285. service.ModifyDrugAddInformation(info.DrugId, sum_count, info.OrgId)
  2286. }
  2287. adminUserInfo := c.GetAdminUserInfo()
  2288. operation_time := time.Now().Unix()
  2289. creater := adminUserInfo.AdminUser.Id
  2290. ctime := time.Now().Unix()
  2291. timeStr := time.Now().Format("2006-01-02")
  2292. timeArr := strings.Split(timeStr, "-")
  2293. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2294. total = total + 1
  2295. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2296. cancelStock := models.DrugCancelStock{
  2297. OrderNumber: orderNumber,
  2298. OperaTime: operation_time,
  2299. OrgId: adminUserInfo.CurrentOrgId,
  2300. Creater: creater,
  2301. Ctime: ctime,
  2302. Status: 1,
  2303. ReturnTime: advice.AdviceDate,
  2304. Dealer: info.Dealer,
  2305. Manufacturer: info.Manufacturer,
  2306. Type: 1,
  2307. StorehouseId: houseConfig.DrugStorehouseOut,
  2308. }
  2309. service.AddSigleDrugCancelStock(&cancelStock)
  2310. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2311. dealer, _ := service.GetDealerById(info.Dealer)
  2312. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2313. cancelStockInfo := models.DrugCancelStockInfo{
  2314. OrderNumber: cancelInfo.OrderNumber,
  2315. CancelStockId: cancelInfo.ID,
  2316. DrugId: info.DrugId,
  2317. Count: info.Count,
  2318. Status: 1,
  2319. Ctime: ctime,
  2320. OrgId: adminUserInfo.CurrentOrgId,
  2321. Type: 1,
  2322. Manufacturer: manufactureName.ManufacturerName,
  2323. Dealer: dealer.DealerName,
  2324. Total: 0,
  2325. RetailPrice: info.RetailPrice,
  2326. RetailTotalPrice: info.RetailTotalPrice,
  2327. Price: info.Price,
  2328. RegisterAccount: "",
  2329. Remark: info.Remark,
  2330. BatchNumber: info.BatchNumber,
  2331. MaxUnit: info.CountUnit,
  2332. ProductDate: info.ProductDate,
  2333. ExpiryDate: info.ExpiryDate,
  2334. BatchNumberId: info.WarehouseInfoId,
  2335. StorehouseId: houseConfig.DrugStorehouseOut,
  2336. }
  2337. flow := models.DrugFlow{
  2338. WarehousingId: 0,
  2339. DrugId: info.DrugId,
  2340. Number: "",
  2341. BatchNumber: info.BatchNumber,
  2342. Count: info.Count,
  2343. UserOrgId: adminUserInfo.CurrentOrgId,
  2344. PatientId: 0,
  2345. SystemTime: info.SysRecordTime,
  2346. ConsumableType: 7,
  2347. IsSys: 0,
  2348. WarehousingOrder: "",
  2349. WarehouseOutId: 0,
  2350. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2351. IsEdit: 0,
  2352. CancelStockId: cancelStock.ID,
  2353. CancelOrderNumber: cancelStock.OrderNumber,
  2354. Manufacturer: info.Manufacturer,
  2355. Dealer: info.Dealer,
  2356. Creator: adminUserInfo.AdminUser.Id,
  2357. UpdateCreator: 0,
  2358. Status: 1,
  2359. Ctime: time.Now().Unix(),
  2360. Mtime: 0,
  2361. Price: info.Price,
  2362. WarehousingDetailId: 0,
  2363. WarehouseOutDetailId: 0,
  2364. CancelOutDetailId: 0,
  2365. ExpireDate: info.ExpiryDate,
  2366. ProductDate: info.ProductDate,
  2367. MaxUnit: info.CountUnit,
  2368. MinUnit: "",
  2369. AdviceId: info.AdviceId,
  2370. StorehouseId: houseConfig.DrugStorehouseOut,
  2371. }
  2372. service.CreatedCancelStock(cancelStockInfo)
  2373. service.CreateDrugFlowOne(flow)
  2374. //删除出库记录
  2375. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2376. //删除流水
  2377. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2378. }
  2379. }
  2380. }
  2381. }
  2382. c.ServeSuccessJSON(map[string]interface{}{
  2383. "msg": "删除成功",
  2384. })
  2385. return
  2386. } else {
  2387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2388. return
  2389. }
  2390. }
  2391. func (c *HisApiController) DeleteProject() {
  2392. id, _ := c.GetInt64("id")
  2393. adminInfo := c.GetAdminUserInfo()
  2394. project, _ := service.GetHisProjectByID(id)
  2395. // var consumable models.DialysisBeforePrepare
  2396. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2397. service.DeletePrintInfo(id)
  2398. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2399. label.Status = 0
  2400. service.CreateHisLabelRecord(&label)
  2401. if stockConfig.IsOpen == 1 {
  2402. if project.Type == 2 {
  2403. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2404. fmt.Println(err)
  2405. }
  2406. if project.Type == 3 {
  2407. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2408. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2409. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2410. good.Total = good.Total + f_count
  2411. service.UpdateGoodInfo(&good)
  2412. operation_time := time.Now().Unix()
  2413. creater := adminInfo.AdminUser.Id
  2414. //创建退库单
  2415. timeStr := time.Now().Format("2006-01-02")
  2416. timeArr := strings.Split(timeStr, "-")
  2417. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2418. total = total + 1
  2419. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2420. cancelStock := models.CancelStock{
  2421. OrderNumber: orderNumber,
  2422. OperaTime: operation_time,
  2423. OrgId: adminInfo.CurrentOrgId,
  2424. Creater: creater,
  2425. Ctime: time.Now().Unix(),
  2426. Status: 1,
  2427. ReturnTime: project.RecordDate,
  2428. Type: 1,
  2429. StorehouseId: houseConfig.StorehouseOutInfo,
  2430. }
  2431. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2432. if msgerrkonde == gorm.ErrRecordNotFound {
  2433. service.AddSigleCancelStock(&cancelStock)
  2434. }
  2435. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2436. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2437. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2438. //获取该耗材有库存的第一条数据
  2439. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2440. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2441. deaerler, _ := service.GetDealerById(info.Dealer)
  2442. if info.ID > 0 {
  2443. cancelStockInfo := models.CancelStockInfo{
  2444. GoodId: project.ProjectId,
  2445. CancelStockId: cancel.ID,
  2446. GoodTypeId: good.GoodTypeId,
  2447. Count: prescribingNumber,
  2448. Price: info.Price,
  2449. Total: 0,
  2450. ProductDate: info.ProductDate,
  2451. ExpiryDate: info.ExpiryDate,
  2452. Ctime: time.Now().Unix(),
  2453. Status: 1,
  2454. OrgId: adminInfo.CurrentOrgId,
  2455. OrderNumber: cancel.OrderNumber,
  2456. Type: 0,
  2457. Dealer: deaerler.DealerName,
  2458. Manufacturer: manufacturer.ManufacturerName,
  2459. Number: info.Number,
  2460. RegisterAccount: "",
  2461. Remark: "",
  2462. WarehouseInfoId: info.WarehouseInfotId,
  2463. PatientId: info.PatientId,
  2464. RecordDate: info.SysRecordTime,
  2465. StorehouseId: houseConfig.StorehouseOutInfo,
  2466. }
  2467. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2468. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2469. flow := models.VmStockFlow{
  2470. WarehousingId: 0,
  2471. GoodId: project.ProjectId,
  2472. Number: info.Number,
  2473. LicenseNumber: info.LicenseNumber,
  2474. Count: prescribingNumber,
  2475. UserOrgId: adminInfo.CurrentOrgId,
  2476. PatientId: project.PatientId,
  2477. SystemTime: time.Now().Unix(),
  2478. ConsumableType: 7,
  2479. IsSys: 0,
  2480. WarehousingOrder: "",
  2481. WarehouseOutId: 0,
  2482. WarehouseOutOrderNumber: "",
  2483. IsEdit: 0,
  2484. CancelStockId: cancel.ID,
  2485. CancelOrderNumber: cancel.OrderNumber,
  2486. Manufacturer: manufacturer.ID,
  2487. Dealer: 0,
  2488. Creator: adminInfo.AdminUser.Id,
  2489. UpdateCreator: 0,
  2490. Status: 1,
  2491. Ctime: time.Now().Unix(),
  2492. Mtime: 0,
  2493. Price: info.Price,
  2494. WarehousingDetailId: info.WarehouseInfotId,
  2495. WarehouseOutDetailId: 0,
  2496. CancelOutDetailId: cancelInfo.ID,
  2497. ProductDate: info.ProductDate,
  2498. ExpireDate: info.ExpiryDate,
  2499. StorehouseId: houseConfig.StorehouseOutInfo,
  2500. }
  2501. service.CreateStockFlowOne(flow)
  2502. //删除出库表
  2503. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2504. //查询今日该患者开了多少耗材
  2505. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2506. var total_count int64
  2507. var cha_count int64
  2508. for _, item := range projectList {
  2509. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2510. total_count += count
  2511. }
  2512. //回退库存
  2513. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2514. service.ModifyGoodAddInformation(info.GoodId, total_count, info.OrgId)
  2515. //查询今日该耗材退库数量
  2516. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2517. var cancel_count int64
  2518. for _, items := range cancelInfoOne {
  2519. cancel_count += items.Count
  2520. }
  2521. cha_count = total_count - cancel_count
  2522. if total_count > cancel_count {
  2523. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2524. if err == gorm.ErrRecordNotFound {
  2525. //没有记录,则创建出库单
  2526. timeStr := time.Now().Format("2006-01-02")
  2527. timeArr := strings.Split(timeStr, "-")
  2528. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2529. total = total + 1
  2530. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2531. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2532. number = number + total
  2533. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2534. warehouseOut := models.WarehouseOut{
  2535. WarehouseOutOrderNumber: warehousing_out_order,
  2536. OperationTime: time.Now().Unix(),
  2537. OrgId: adminInfo.CurrentOrgId,
  2538. Creater: creater,
  2539. Ctime: time.Now().Unix(),
  2540. Status: 1,
  2541. WarehouseOutTime: info.SysRecordTime,
  2542. Dealer: 0,
  2543. Manufacturer: 0,
  2544. Type: 1,
  2545. IsSys: 1,
  2546. StorehouseId: houseConfig.StorehouseOutInfo,
  2547. }
  2548. err := service.AddSigleWarehouseOut(&warehouseOut)
  2549. if err != nil {
  2550. utils.TraceLog("创建出库单失败 err = %v", err)
  2551. return
  2552. }
  2553. prepare := &models.DialysisBeforePrepare{
  2554. UserOrgId: adminInfo.CurrentOrgId,
  2555. PatientId: info.PatientId,
  2556. RecordDate: info.SysRecordTime,
  2557. GoodId: project.ProjectId,
  2558. GoodTypeId: info.GoodTypeId,
  2559. Count: cha_count,
  2560. StorehouseId: houseConfig.StorehouseOutInfo,
  2561. }
  2562. //出库
  2563. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2564. } else if err == nil {
  2565. prepare := &models.DialysisBeforePrepare{
  2566. UserOrgId: adminInfo.CurrentOrgId,
  2567. PatientId: info.PatientId,
  2568. RecordDate: info.SysRecordTime,
  2569. GoodId: project.ProjectId,
  2570. GoodTypeId: info.GoodTypeId,
  2571. Count: cha_count,
  2572. StorehouseId: houseConfig.StorehouseOutInfo,
  2573. }
  2574. //出库
  2575. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2576. }
  2577. }
  2578. }
  2579. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2580. fmt.Println(err)
  2581. }
  2582. }
  2583. c.ServeSuccessJSON(map[string]interface{}{
  2584. "msg": "删除成功",
  2585. })
  2586. return
  2587. }
  2588. func (c *HisApiController) CreateHisAdditionalCharge() {
  2589. his_patient_id, _ := c.GetInt64("his_patient_id")
  2590. patient_id, _ := c.GetInt64("patient_id")
  2591. record_date := c.GetString("record_date")
  2592. timeLayout := "2006-01-02"
  2593. loc, _ := time.LoadLocation("Local")
  2594. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2595. if err != nil {
  2596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2597. return
  2598. }
  2599. adminInfo := c.GetAdminUserInfo()
  2600. recordDateTime := theTime.Unix()
  2601. dataBody := make(map[string]interface{}, 0)
  2602. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2603. if err != nil {
  2604. utils.ErrorLog(err.Error())
  2605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2606. return
  2607. }
  2608. var additions []*models.HisAdditionalCharge
  2609. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2610. additions, _ := dataBody["addition"].([]interface{})
  2611. if len(additions) > 0 {
  2612. for _, item := range additions {
  2613. items := item.(map[string]interface{})
  2614. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2615. utils.ErrorLog("item_id")
  2616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2617. return
  2618. }
  2619. item_id := int64(items["item_id"].(float64))
  2620. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2621. utils.ErrorLog("item_name")
  2622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2623. return
  2624. }
  2625. item_name := items["item_name"].(string)
  2626. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2627. utils.ErrorLog("price")
  2628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2629. return
  2630. }
  2631. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2632. ctime := time.Now().Unix()
  2633. additional := &models.HisAdditionalCharge{
  2634. PatientId: patient_id,
  2635. HisPatientId: his_patient_id,
  2636. UserOrgId: adminInfo.CurrentOrgId,
  2637. RecordDate: recordDateTime,
  2638. CreatedTime: ctime,
  2639. UpdatedTime: ctime,
  2640. Modifier: adminInfo.AdminUser.Id,
  2641. Creator: adminInfo.AdminUser.Id,
  2642. Price: price,
  2643. ItemName: item_name,
  2644. ItemId: item_id,
  2645. Status: 1,
  2646. }
  2647. additions = append(additions, additional)
  2648. }
  2649. }
  2650. }
  2651. for _, item := range additions {
  2652. service.CreateAddtionalCharge(item)
  2653. }
  2654. c.ServeSuccessJSON(map[string]interface{}{
  2655. "msg": "创建成功",
  2656. })
  2657. }
  2658. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2659. blood_fat := c.GetString("blood_fat")
  2660. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2661. blood_sugar := c.GetString("blood_sugar")
  2662. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2663. chief_conplaint := c.GetString("chief_conplaint")
  2664. dbp := c.GetString("dbp")
  2665. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2666. delivery_way, _ := c.GetInt64("delivery_way")
  2667. diagnostic := c.GetString("diagnostic")
  2668. family_history := c.GetString("family_history")
  2669. height := c.GetString("height")
  2670. history_of_present_illness := c.GetString("history_of_present_illness")
  2671. is_infect, _ := c.GetInt64("is_infect")
  2672. past_history := c.GetString("past_history")
  2673. patient_id, _ := c.GetInt64("patient_id")
  2674. his_patient_id, _ := c.GetInt64("his_patient_id")
  2675. personal_history := c.GetString("personal_history")
  2676. pulse := c.GetString("pulse")
  2677. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2678. sbp := c.GetString("sbp")
  2679. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2680. heightfloat, _ := strconv.ParseFloat(height, 64)
  2681. sicktype := c.GetString("sick_type")
  2682. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2683. symptom := c.GetString("symptom")
  2684. sick_date := c.GetString("sick_date")
  2685. temperatures := c.GetString("temperature")
  2686. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2687. record_date := c.GetString("record_date")
  2688. breathing := c.GetString("breathing")
  2689. doctor_advice := c.GetString("doctor_advice")
  2690. remark := c.GetString("remark")
  2691. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2692. sick, _ := c.GetInt64("sick")
  2693. diagnose, _ := c.GetInt64("diagnose")
  2694. id, _ := c.GetInt64("id")
  2695. timeLayout := "2006-01-02"
  2696. loc, _ := time.LoadLocation("Local")
  2697. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2698. allergic_history := c.GetString("allergic_history")
  2699. if err != nil {
  2700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2701. return
  2702. }
  2703. recordDateTime := theTime.Unix()
  2704. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2705. if err != nil {
  2706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2707. return
  2708. }
  2709. sickTimes := sickTime.Unix()
  2710. ctime := time.Now().Unix()
  2711. caseHistory := models.HisPatientCaseHistory{
  2712. HisPatientId: his_patient_id,
  2713. PatientId: patient_id,
  2714. Temperature: temperature,
  2715. BloodSugar: bloodsugarfloat,
  2716. Pulse: pulsefloat,
  2717. Sbp: sbpfloat,
  2718. Dbp: dbpfloat,
  2719. Height: heightfloat,
  2720. BloodFat: bloodfatfloat,
  2721. SickType: sick_type,
  2722. Symptom: symptom,
  2723. SickDate: sickTimes,
  2724. IsInfect: is_infect,
  2725. HistoryOfPresentIllness: history_of_present_illness,
  2726. PastHistory: past_history,
  2727. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2728. ChiefConplaint: chief_conplaint,
  2729. PersonalHistory: personal_history,
  2730. FamilyHistory: family_history,
  2731. Diagnostic: diagnostic,
  2732. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2733. Status: 1,
  2734. Ctime: ctime,
  2735. Mtime: ctime,
  2736. RecordDate: recordDateTime,
  2737. DeliveryWay: delivery_way,
  2738. Breathing: breathingfloat,
  2739. DoctorAdvice: doctor_advice,
  2740. Remark: remark,
  2741. Sick: sick,
  2742. Diagnose: diagnose,
  2743. AllergicHistory: allergic_history,
  2744. }
  2745. //查询该患者是否有病历
  2746. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  2747. if errcodes == gorm.ErrRecordNotFound {
  2748. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2749. if err != nil {
  2750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2751. return
  2752. }
  2753. c.ServeSuccessJSON(map[string]interface{}{
  2754. "caseHistory": caseHistory,
  2755. })
  2756. return
  2757. } else if errcodes == nil {
  2758. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  2759. if err != nil {
  2760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2761. return
  2762. }
  2763. c.ServeSuccessJSON(map[string]interface{}{
  2764. "caseHistory": caseHistory,
  2765. })
  2766. }
  2767. //查询该患者是否有病历
  2768. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2769. //if errcode == gorm.ErrRecordNotFound {
  2770. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2771. // if err != nil {
  2772. // c.ServeSuccessJSON(map[string]interface{}{
  2773. // "msg": "保存成功",
  2774. // })
  2775. // }
  2776. //} else if errcode == nil {
  2777. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2778. // return
  2779. //}
  2780. }
  2781. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2782. patient_id, _ := c.GetInt64("patient_id", 0)
  2783. adminUser := c.GetAdminUserInfo()
  2784. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2785. c.ServeSuccessJSON(map[string]interface{}{
  2786. "list": caseHistorys,
  2787. })
  2788. }
  2789. func (c *HisApiController) GetHisPatientCaseHistory() {
  2790. record_date, _ := c.GetInt64("record_date", 0)
  2791. patient_id, _ := c.GetInt64("patient_id", 0)
  2792. admin := c.GetAdminUserInfo()
  2793. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2794. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2795. c.ServeSuccessJSON(map[string]interface{}{
  2796. "info": info,
  2797. "case_history": case_history,
  2798. })
  2799. }
  2800. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2801. template_name := c.GetString("template_name")
  2802. template_remark := c.GetString("template_remark")
  2803. doctor := c.GetAdminUserInfo().AdminUser.Id
  2804. diagnostic := c.GetString("diagnostic")
  2805. chief_conplaint := c.GetString("chief_conplain")
  2806. history_of_present_illness := c.GetString("history_of_present_illness")
  2807. past_history := c.GetString("past_history")
  2808. personal_history := c.GetString("personal_history")
  2809. family_history := c.GetString("family_history")
  2810. user_name := c.GetString("user_name")
  2811. doctor_advice := c.GetString("doctor_advice")
  2812. remark := c.GetString("remark")
  2813. //record_date := c.GetString("record_date")
  2814. //fmt.Println("record_date--------",record_date)
  2815. //timeLayout := "2006-01-02"
  2816. //loc, _ := time.LoadLocation("Local")
  2817. //
  2818. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2819. //if err != nil {
  2820. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2821. // return
  2822. //}
  2823. //recordDateTime := theTime.Unix()
  2824. ctime := time.Now().Unix()
  2825. template := models.HisCaseHistoryTemplate{
  2826. HistoryOfPresentIllness: history_of_present_illness,
  2827. PastHistory: past_history,
  2828. ChiefConplaint: chief_conplaint,
  2829. PersonalHistory: personal_history,
  2830. FamilyHistory: family_history,
  2831. Diagnostic: diagnostic,
  2832. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2833. Status: 1,
  2834. Ctime: ctime,
  2835. Mtime: ctime,
  2836. RecordDate: time.Now().Unix(),
  2837. TemplateName: template_name,
  2838. TemplateRemark: template_remark,
  2839. Creator: doctor,
  2840. Modifier: doctor,
  2841. UserName: user_name,
  2842. DoctorAdvice: doctor_advice,
  2843. Remark: remark,
  2844. }
  2845. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2846. if err == nil {
  2847. c.ServeSuccessJSON(map[string]interface{}{
  2848. "msg": "保存成功",
  2849. })
  2850. } else {
  2851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2852. return
  2853. }
  2854. }
  2855. func (c *HisApiController) GetCaseHistoryTemplate() {
  2856. timeLayout := "2006-01-02"
  2857. loc, _ := time.LoadLocation("Local")
  2858. keyword := c.GetString("keyword")
  2859. start_time := c.GetString("start_time")
  2860. end_time := c.GetString("end_time")
  2861. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2862. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2863. admin := c.GetAdminUserInfo()
  2864. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2865. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2866. c.ServeSuccessJSON(map[string]interface{}{
  2867. "template": template,
  2868. //"history": history,
  2869. })
  2870. }
  2871. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2872. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2873. utils.ErrorLog("drug_name")
  2874. return enums.ErrorCodeParamWrong
  2875. }
  2876. adviceName, _ := json["drug_name"].(string)
  2877. if len(adviceName) == 0 {
  2878. utils.ErrorLog("len(advice_name) == 0")
  2879. return enums.ErrorCodeParamWrong
  2880. }
  2881. advice.AdviceName = adviceName
  2882. adviceDesc, _ := json["advice_desc"].(string)
  2883. advice.AdviceDesc = adviceDesc
  2884. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2885. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2886. advice.DrugSpec = drugSpec
  2887. }
  2888. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2889. remark, _ := json["remark"].(string)
  2890. advice.Remark = remark
  2891. }
  2892. if json["id"] == nil {
  2893. advice.DrugId = 0
  2894. } else {
  2895. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2896. drug_id := int64(json["id"].(float64))
  2897. advice.DrugId = drug_id
  2898. }
  2899. }
  2900. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2901. advice_id := int64(json["advice_id"].(float64))
  2902. advice.ID = advice_id
  2903. if advice.ID > 0 {
  2904. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2905. if err == nil {
  2906. if hisAdvice.ID > 0 {
  2907. advice.ExecutionTime = hisAdvice.ExecutionTime
  2908. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2909. advice.ExecutionState = hisAdvice.ExecutionState
  2910. advice.CheckTime = hisAdvice.CheckTime
  2911. advice.Checker = hisAdvice.Checker
  2912. advice.CheckState = hisAdvice.CheckState
  2913. advice.StartTime = hisAdvice.StartTime
  2914. advice.FeedetlSn = hisAdvice.FeedetlSn
  2915. }
  2916. }
  2917. }
  2918. }
  2919. //
  2920. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2921. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2922. // advice.ExecutionTime = execution_time
  2923. //}
  2924. //
  2925. //
  2926. //
  2927. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2928. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2929. // advice.ExecutionStaff = execution_staff
  2930. //}
  2931. //
  2932. //
  2933. //
  2934. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2935. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2936. // advice.ExecutionState = execution_state
  2937. //}
  2938. //
  2939. //
  2940. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2941. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2942. // advice.CheckTime = check_time
  2943. //}
  2944. //
  2945. //
  2946. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2947. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2948. // advice.CheckState = check_state
  2949. //}
  2950. //
  2951. //
  2952. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2953. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2954. // advice.Checker = checker
  2955. //}
  2956. //
  2957. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2958. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2959. // advice.StartTime = start_time
  2960. //}
  2961. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2962. drugSpecUnit, _ := json["min_unit"].(string)
  2963. advice.DrugSpecUnit = drugSpecUnit
  2964. }
  2965. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2966. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2967. advice.SingleDose = singleDose
  2968. }
  2969. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2970. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2971. advice.SingleDoseUnit = singleDoseUnit
  2972. }
  2973. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2974. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2975. advice.PrescribingNumber = prescribingNumber
  2976. }
  2977. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2978. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2979. advice.PrescribingNumberUnit = prescribingNumberUnit
  2980. }
  2981. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2982. deliveryWay, _ := json["delivery_way"].(string)
  2983. advice.DeliveryWay = deliveryWay
  2984. }
  2985. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2986. executionFrequency, _ := json["execution_frequency"].(string)
  2987. advice.ExecutionFrequency = executionFrequency
  2988. }
  2989. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2990. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2991. advice.Price = price
  2992. }
  2993. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2994. med_list_codg, _ := json["medical_insurance_number"].(string)
  2995. advice.MedListCodg = med_list_codg
  2996. }
  2997. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2998. day := int64(json["day"].(float64))
  2999. advice.Day = day
  3000. }
  3001. return 0
  3002. }
  3003. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3004. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3005. id := int64(json["id"].(float64))
  3006. project.ID = id
  3007. historyProject, _ := service.GetHisProjectByID(id)
  3008. project.FeedetlSn = historyProject.FeedetlSn
  3009. }
  3010. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3011. project_id := int64(json["project_id"].(float64))
  3012. project.ProjectId = project_id
  3013. }
  3014. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3015. // price := int64(json["price"].(float64))
  3016. // formatInt_price := strconv.FormatInt(price, 10)
  3017. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3018. // project.Price = float_price
  3019. // }
  3020. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3021. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3022. project.Price = price
  3023. }
  3024. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3025. total, _ := json["total"].(string)
  3026. project.Count = total
  3027. }
  3028. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3029. medical_code, _ := json["medical_code"].(string)
  3030. project.MedListCodg = medical_code
  3031. }
  3032. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3033. single_dose, _ := json["single_dose"].(string)
  3034. project.SingleDose = single_dose
  3035. }
  3036. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3037. delivery_way, _ := json["delivery_way"].(string)
  3038. project.DeliveryWay = delivery_way
  3039. }
  3040. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3041. execution_frequency, _ := json["execution_frequency"].(string)
  3042. project.ExecutionFrequency = execution_frequency
  3043. }
  3044. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3045. remark, _ := json["remark"].(string)
  3046. project.Remark = remark
  3047. }
  3048. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3049. day, _ := json["number_days"].(string)
  3050. project.Day = day
  3051. }
  3052. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3053. unit, _ := json["unit"].(string)
  3054. project.Unit = unit
  3055. }
  3056. return 0
  3057. }
  3058. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3059. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3060. id := int64(json["id"].(float64))
  3061. historyAddtions, _ := service.GetHisAdditionByID(id)
  3062. additionalCharge.ID = id
  3063. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  3064. }
  3065. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3066. item_id := int64(json["item_id"].(float64))
  3067. additionalCharge.ItemId = item_id
  3068. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3069. if config.ID > 0 {
  3070. if len(config.Code) > 0 {
  3071. additionalCharge.MedListCodg = config.Code
  3072. }
  3073. }
  3074. }
  3075. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3076. // price := int64(json["price"].(float64))
  3077. // formatInt_price := strconv.FormatInt(price, 10)
  3078. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3079. // additionalCharge.Price = float_price
  3080. // }
  3081. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3082. // price := int64(json["price"].(float64))
  3083. // formatInt_price := strconv.FormatInt(price, 10)
  3084. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3085. // additionalCharge.Price = float_price
  3086. //}
  3087. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3088. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3089. additionalCharge.Price = price
  3090. }
  3091. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3092. count, _ := json["count"].(string)
  3093. counts, _ := strconv.ParseInt(count, 10, 64)
  3094. additionalCharge.Count = counts
  3095. }
  3096. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3097. item_name, _ := json["item_name"].(string)
  3098. additionalCharge.ItemName = item_name
  3099. }
  3100. return 0
  3101. }
  3102. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3103. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3104. utils.ErrorLog("drug_name")
  3105. return enums.ErrorCodeParamWrong
  3106. }
  3107. adviceName, _ := json["drug_name"].(string)
  3108. if len(adviceName) == 0 {
  3109. utils.ErrorLog("len(advice_name) == 0")
  3110. return enums.ErrorCodeParamWrong
  3111. }
  3112. advice.AdviceName = adviceName
  3113. adviceDesc, _ := json["advice_desc"].(string)
  3114. advice.AdviceDesc = adviceDesc
  3115. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3116. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3117. advice.DrugSpec = drugSpec
  3118. }
  3119. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3120. remark, _ := json["remark"].(string)
  3121. advice.Remark = remark
  3122. }
  3123. if json["id"] == nil {
  3124. advice.DrugId = 0
  3125. } else {
  3126. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3127. drug_id := int64(json["id"].(float64))
  3128. advice.DrugId = drug_id
  3129. }
  3130. }
  3131. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3132. groupno := int64(json["groupno"].(float64))
  3133. advice.Groupno = groupno
  3134. }
  3135. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3136. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3137. advice.HospApprFlag = hosp_appr_flag
  3138. }
  3139. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3140. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3141. advice.PrescribingNumber = prescribingNumber
  3142. }
  3143. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3144. // frequency_type := int64(json["frequency_type"].(float64))
  3145. // advice.FrequencyType = frequency_type
  3146. //}
  3147. //
  3148. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3149. // day_count := int64(json["day_count"].(float64))
  3150. // advice.DayCount = day_count
  3151. //}
  3152. //
  3153. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3154. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3155. // week_day, _ := json["week_day"].(string)
  3156. // advice.WeekDay = week_day
  3157. //}
  3158. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3159. drugSpecUnit, _ := json["min_unit"].(string)
  3160. advice.DrugSpecUnit = drugSpecUnit
  3161. }
  3162. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3163. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3164. advice.SingleDose = singleDose
  3165. }
  3166. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3167. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3168. advice.SingleDoseUnit = singleDoseUnit
  3169. }
  3170. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3171. deliveryWay, _ := json["delivery_way"].(string)
  3172. advice.DeliveryWay = deliveryWay
  3173. }
  3174. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3175. executionFrequency, _ := json["execution_frequency"].(string)
  3176. advice.ExecutionFrequency = executionFrequency
  3177. }
  3178. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3179. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3180. advice.Price = price
  3181. }
  3182. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3183. med_list_codg, _ := json["medical_insurance_number"].(string)
  3184. advice.MedListCodg = med_list_codg
  3185. }
  3186. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3187. day := int64(json["day"].(float64))
  3188. advice.Day = day
  3189. }
  3190. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3191. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3192. advice.PrescribingNumberUnit = prescribingNumberUnit
  3193. }
  3194. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3195. advice_id := int64(json["advice_id"].(float64))
  3196. advice.ID = advice_id
  3197. if advice.ID > 0 {
  3198. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3199. if err == nil {
  3200. if hisAdvice.ID > 0 {
  3201. advice.ExecutionTime = hisAdvice.ExecutionTime
  3202. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3203. advice.ExecutionState = hisAdvice.ExecutionState
  3204. advice.CheckTime = hisAdvice.CheckTime
  3205. advice.Checker = hisAdvice.Checker
  3206. advice.CheckState = hisAdvice.CheckState
  3207. advice.StartTime = hisAdvice.StartTime
  3208. advice.HospApprFlag = hisAdvice.HospApprFlag
  3209. if hisAdvice.UserOrgId == 10028 {
  3210. if hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  3211. advice.ExecutionTime = 0
  3212. advice.ExecutionStaff = 0
  3213. advice.ExecutionState = 2
  3214. advice.CheckTime = 0
  3215. advice.Checker = 0
  3216. advice.CheckState = 2
  3217. }
  3218. } else {
  3219. if hisAdvice.SingleDose != advice.SingleDose || hisAdvice.DeliveryWay != advice.DeliveryWay || hisAdvice.ExecutionFrequency != advice.ExecutionFrequency || hisAdvice.Day != advice.Day || hisAdvice.PrescribingNumber != advice.PrescribingNumber || hisAdvice.Price != advice.Price || hisAdvice.Remark != advice.Remark || hisAdvice.PrescribingNumberUnit != advice.PrescribingNumberUnit {
  3220. advice.ExecutionTime = 0
  3221. advice.ExecutionStaff = 0
  3222. advice.ExecutionState = 2
  3223. advice.CheckTime = 0
  3224. advice.Checker = 0
  3225. advice.CheckState = 2
  3226. }
  3227. }
  3228. //advice.Groupno = hisAdvice.Groupno
  3229. }
  3230. }
  3231. }
  3232. }
  3233. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3234. //
  3235. //if drugStockConfig.IsOpen == 1 {
  3236. //
  3237. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3238. // if advice.ID == 0 { //医嘱不存在
  3239. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3240. // drug.Total = drug.Total - advice.PrescribingNumber
  3241. // service.UpdateBaseDrugLib(&drug)
  3242. //
  3243. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3244. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3245. // drug.Total = drug.Total - num
  3246. // service.UpdateBaseDrugLib(&drug)
  3247. // }
  3248. //
  3249. // } else if advice.ID > 0 { //医嘱存在
  3250. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3251. // var num float64
  3252. //
  3253. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3254. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3255. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3256. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3257. // drug.Total = drug.Total + num
  3258. // service.UpdateBaseDrugLib(&drug)
  3259. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3260. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3261. // drug.Total = drug.Total - num
  3262. // service.UpdateBaseDrugLib(&drug)
  3263. // }
  3264. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3265. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3266. // if num2 > advice.PrescribingNumber {
  3267. // num = num2 - advice.PrescribingNumber
  3268. // drug.Total = drug.Total + num
  3269. // service.UpdateBaseDrugLib(&drug)
  3270. // } else if num2 < advice.PrescribingNumber {
  3271. // num = advice.PrescribingNumber - num2
  3272. // drug.Total = drug.Total - num
  3273. // service.UpdateBaseDrugLib(&drug)
  3274. // }
  3275. //
  3276. // }
  3277. //
  3278. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3279. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3280. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3281. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3282. // if num1 > num2 {
  3283. // num = num1 - num2
  3284. // drug.Total = drug.Total + num
  3285. // service.UpdateBaseDrugLib(&drug)
  3286. // } else if num1 < num2 {
  3287. // num = num2 - num1
  3288. // drug.Total = drug.Total - num
  3289. // service.UpdateBaseDrugLib(&drug)
  3290. // }
  3291. //
  3292. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3293. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3294. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3295. // if hisAdvice.PrescribingNumber > num2 {
  3296. // num = hisAdvice.PrescribingNumber - num2
  3297. // drug.Total = drug.Total + num
  3298. // service.UpdateBaseDrugLib(&drug)
  3299. // } else if num2 < advice.PrescribingNumber {
  3300. // num = num2 - hisAdvice.PrescribingNumber
  3301. // drug.Total = drug.Total - num
  3302. // service.UpdateBaseDrugLib(&drug)
  3303. // }
  3304. //
  3305. // }
  3306. // }
  3307. // }
  3308. //}
  3309. //
  3310. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3311. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3312. // advice.ExecutionTime = execution_time
  3313. //}
  3314. //
  3315. //
  3316. //
  3317. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3318. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3319. // advice.ExecutionStaff = execution_staff
  3320. //}
  3321. //
  3322. //
  3323. //
  3324. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3325. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3326. // advice.ExecutionState = execution_state
  3327. //}
  3328. //
  3329. //
  3330. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3331. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3332. // advice.CheckTime = check_time
  3333. //}
  3334. //
  3335. //
  3336. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3337. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3338. // advice.CheckState = check_state
  3339. //}
  3340. //
  3341. //
  3342. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3343. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3344. // advice.Checker = checker
  3345. //}
  3346. //
  3347. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3348. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3349. // advice.StartTime = start_time
  3350. //}
  3351. return 0
  3352. }
  3353. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3354. project.ExecutionStaff = 0
  3355. project.ExecutionState = 2
  3356. project.ExecutionTime = 0
  3357. project.Checker = 0
  3358. project.CheckState = 2
  3359. project.CheckTime = 0
  3360. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3361. id := int64(json["id"].(float64))
  3362. project.ID = id
  3363. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3364. project.ExecutionStaff = temp_project.ExecutionStaff
  3365. project.ExecutionState = temp_project.ExecutionState
  3366. project.ExecutionTime = temp_project.ExecutionTime
  3367. project.Checker = temp_project.Checker
  3368. project.CheckState = temp_project.CheckState
  3369. project.CheckTime = temp_project.CheckTime
  3370. project.TeamId = temp_project.TeamId
  3371. }
  3372. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3373. types := int64(json["type"].(float64))
  3374. project.Type = types
  3375. }
  3376. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3377. project_id := int64(json["project_id"].(float64))
  3378. project.ProjectId = project_id
  3379. }
  3380. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3381. team_id := int64(json["team_id"].(float64))
  3382. project.TeamId = team_id
  3383. }
  3384. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3385. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3386. project.Price = price
  3387. }
  3388. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3389. total, _ := json["total"].(string)
  3390. //totals, _ := strconv.ParseInt(total, 10, 64)
  3391. project.Count = total
  3392. }
  3393. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3394. medical_code, _ := json["medical_code"].(string)
  3395. project.MedListCodg = medical_code
  3396. }
  3397. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3398. single_dose, _ := json["single_dose"].(string)
  3399. project.SingleDose = single_dose
  3400. }
  3401. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3402. delivery_way, _ := json["delivery_way"].(string)
  3403. project.DeliveryWay = delivery_way
  3404. }
  3405. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3406. execution_frequency, _ := json["execution_frequency"].(string)
  3407. project.ExecutionFrequency = execution_frequency
  3408. }
  3409. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3410. remark, _ := json["remark"].(string)
  3411. project.Remark = remark
  3412. }
  3413. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3414. day, _ := json["number_days"].(string)
  3415. project.Day = day
  3416. }
  3417. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3418. unit, _ := json["unit"].(string)
  3419. project.Unit = unit
  3420. }
  3421. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3422. // frequency_type := int64(json["frequency_type"].(float64))
  3423. // project.FrequencyType = frequency_type
  3424. //}
  3425. //
  3426. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3427. // day_count := int64(json["day_count"].(float64))
  3428. // project.DayCount = day_count
  3429. //}
  3430. //
  3431. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3432. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3433. // week_day, _ := json["week_day"].(string)
  3434. // project.WeekDay = week_day
  3435. //}
  3436. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3437. //
  3438. //if project.ID == 0 {
  3439. // if stockConfig.IsOpen == 1 {
  3440. // if project.Type == 3 {
  3441. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3442. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3443. // good.Total = good.Total - f_count
  3444. // service.UpdateGoodInfo(&good)
  3445. // }
  3446. // }
  3447. //
  3448. //} else {
  3449. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3450. //
  3451. // if stockConfig.IsOpen == 1 {
  3452. // if project.Type == 3 {
  3453. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3454. // if project.Count < temp_project.Count {
  3455. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3456. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3457. //
  3458. // other_count := f_count_two - f_count_one
  3459. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3460. // good.Total = good.Total + other_count_two
  3461. // service.UpdateGoodInfo(&good)
  3462. // } else if project.Count > temp_project.Count {
  3463. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3464. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3465. //
  3466. // other_count := f_count_one - f_count_two
  3467. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3468. // good.Total = good.Total - other_count_two
  3469. // service.UpdateGoodInfo(&good)
  3470. // }
  3471. //
  3472. // }
  3473. // }
  3474. //
  3475. //}
  3476. return 0
  3477. }
  3478. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3479. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3480. id := int64(json["id"].(float64))
  3481. additionalCharge.ID = id
  3482. }
  3483. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3484. item_id := int64(json["item_id"].(float64))
  3485. additionalCharge.ItemId = item_id
  3486. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3487. if config.ID > 0 {
  3488. if len(config.Code) > 0 {
  3489. additionalCharge.MedListCodg = config.Code
  3490. }
  3491. }
  3492. }
  3493. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3494. // price := int64(json["price"].(float64))
  3495. // formatInt_price := strconv.FormatInt(price, 10)
  3496. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3497. // additionalCharge.Price = float_price
  3498. // }
  3499. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3500. // price := int64(json["price"].(float64))
  3501. // formatInt_price := strconv.FormatInt(price, 10)
  3502. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3503. // additionalCharge.Price = float_price
  3504. //}
  3505. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3506. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3507. additionalCharge.Price = price
  3508. }
  3509. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3510. count, _ := json["count"].(string)
  3511. counts, _ := strconv.ParseInt(count, 10, 64)
  3512. additionalCharge.Count = counts
  3513. }
  3514. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3515. item_name, _ := json["item_name"].(string)
  3516. additionalCharge.ItemName = item_name
  3517. }
  3518. return 0
  3519. }
  3520. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3521. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3522. utils.ErrorLog("drug_name")
  3523. return enums.ErrorCodeParamWrong
  3524. }
  3525. adviceName, _ := json["drug_name"].(string)
  3526. if len(adviceName) == 0 {
  3527. utils.ErrorLog("len(advice_name) == 0")
  3528. return enums.ErrorCodeParamWrong
  3529. }
  3530. advice.AdviceName = adviceName
  3531. adviceDesc, _ := json["advice_desc"].(string)
  3532. advice.AdviceDesc = adviceDesc
  3533. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3534. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3535. advice.DrugSpec = drugSpec
  3536. }
  3537. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3538. remark, _ := json["remark"].(string)
  3539. advice.Remark = remark
  3540. }
  3541. if json["id"] == nil {
  3542. advice.DrugId = 0
  3543. } else {
  3544. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3545. drug_id := int64(json["id"].(float64))
  3546. advice.DrugId = drug_id
  3547. }
  3548. }
  3549. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3550. drugSpecUnit, _ := json["min_unit"].(string)
  3551. advice.DrugSpecUnit = drugSpecUnit
  3552. }
  3553. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3554. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3555. advice.SingleDose = singleDose
  3556. }
  3557. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3558. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3559. advice.SingleDoseUnit = singleDoseUnit
  3560. }
  3561. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3562. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3563. advice.PrescribingNumber = prescribingNumber
  3564. }
  3565. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3566. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3567. advice.PrescribingNumberUnit = prescribingNumberUnit
  3568. }
  3569. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3570. deliveryWay, _ := json["delivery_way"].(string)
  3571. advice.DeliveryWay = deliveryWay
  3572. }
  3573. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3574. executionFrequency, _ := json["execution_frequency"].(string)
  3575. advice.ExecutionFrequency = executionFrequency
  3576. }
  3577. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3578. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3579. advice.Price = price
  3580. }
  3581. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3582. med_list_codg, _ := json["medical_insurance_number"].(string)
  3583. advice.MedListCodg = med_list_codg
  3584. }
  3585. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3586. day := int64(json["day"].(float64))
  3587. advice.Day = day
  3588. }
  3589. return 0
  3590. }
  3591. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3592. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3593. types := int64(json["type"].(float64))
  3594. project.Type = types
  3595. }
  3596. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3597. project_id := int64(json["project_id"].(float64))
  3598. project.ProjectId = project_id
  3599. }
  3600. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3601. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3602. project.Price = price
  3603. }
  3604. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3605. total, _ := json["total"].(string)
  3606. //totals, _ := strconv.ParseInt(total, 10, 64)
  3607. project.Count = total
  3608. }
  3609. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3610. medical_code, _ := json["medical_code"].(string)
  3611. project.MedListCodg = medical_code
  3612. }
  3613. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3614. single_dose, _ := json["single_dose"].(string)
  3615. project.SingleDose = single_dose
  3616. }
  3617. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3618. delivery_way, _ := json["delivery_way"].(string)
  3619. project.DeliveryWay = delivery_way
  3620. }
  3621. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3622. execution_frequency, _ := json["execution_frequency"].(string)
  3623. project.ExecutionFrequency = execution_frequency
  3624. }
  3625. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3626. remark, _ := json["remark"].(string)
  3627. project.Remark = remark
  3628. }
  3629. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3630. day, _ := json["number_days"].(string)
  3631. project.Day = day
  3632. }
  3633. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3634. unit, _ := json["unit"].(string)
  3635. project.Unit = unit
  3636. }
  3637. return 0
  3638. }
  3639. func (c *HisApiController) GetHisOrderList() {
  3640. page, _ := c.GetInt64("page", -1)
  3641. limit, _ := c.GetInt64("limit", -1)
  3642. start_time := c.GetString("start_time")
  3643. end_time := c.GetString("end_time")
  3644. types, _ := c.GetInt64("type", 0)
  3645. keywords := c.GetString("keywords")
  3646. p_type, _ := c.GetInt64("p_type", 0)
  3647. sort_type, _ := c.GetInt64("sort_type", 0)
  3648. timeLayout := "2006-01-02"
  3649. loc, _ := time.LoadLocation("Local")
  3650. var startTime int64
  3651. if len(start_time) > 0 {
  3652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3653. if err != nil {
  3654. fmt.Println(err)
  3655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3656. return
  3657. }
  3658. startTime = theTime.Unix()
  3659. }
  3660. var endTime int64
  3661. if len(end_time) > 0 {
  3662. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3663. if err != nil {
  3664. utils.ErrorLog(err.Error())
  3665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3666. return
  3667. }
  3668. endTime = theTime.Unix()
  3669. }
  3670. adminUser := c.GetAdminUserInfo()
  3671. org_id := adminUser.CurrentOrgId
  3672. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time)
  3673. for _, item := range order {
  3674. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3675. item.DoctorName = info.Doctor
  3676. item.DepartmentName = info.XtHisDepartment.Name
  3677. }
  3678. if err == nil {
  3679. c.ServeSuccessJSON(map[string]interface{}{
  3680. "order": order,
  3681. "total": total,
  3682. })
  3683. } else {
  3684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3685. return
  3686. }
  3687. }
  3688. func (c *HisApiController) GetHisOrder() {
  3689. patient_id, _ := c.GetInt64("patient_id", 0)
  3690. number := c.GetString("number")
  3691. adminInfo := c.GetAdminUserInfo()
  3692. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3693. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3694. if err == nil {
  3695. c.ServeSuccessJSON(map[string]interface{}{
  3696. "order": order,
  3697. "prescription": prescriptions,
  3698. })
  3699. } else {
  3700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3701. return
  3702. }
  3703. }
  3704. func (c *HisApiController) GetHisPrescriptionList() {
  3705. record_date := c.GetString("record_date")
  3706. keywords := c.GetString("keywords")
  3707. page, _ := c.GetInt64("page")
  3708. limit, _ := c.GetInt64("limit")
  3709. timeLayout := "2006-01-02"
  3710. loc, _ := time.LoadLocation("Local")
  3711. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3712. if err != nil {
  3713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3714. return
  3715. }
  3716. recordDateTime := theTime.Unix()
  3717. adminInfo := c.GetAdminUserInfo()
  3718. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3719. //adminInfo := c.GetAdminUserInfo()
  3720. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3721. //fmt.Println(prescriptionOrder)
  3722. if err == nil {
  3723. c.ServeSuccessJSON(map[string]interface{}{
  3724. "order": prescriptionOrder,
  3725. "total": total,
  3726. })
  3727. } else {
  3728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3729. return
  3730. }
  3731. }
  3732. func (c *HisApiController) GetHisPrescriptionInfo() {
  3733. id, _ := c.GetInt64("id")
  3734. adminInfo := c.GetAdminUserInfo()
  3735. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3736. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3737. if err == nil {
  3738. c.ServeSuccessJSON(map[string]interface{}{
  3739. "order": prescriptionOrder,
  3740. "prescription": prescription,
  3741. })
  3742. } else {
  3743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3744. return
  3745. }
  3746. }
  3747. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3748. adminUser := c.GetAdminUserInfo()
  3749. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3750. c.ServeSuccessJSON(map[string]interface{}{
  3751. "config": config,
  3752. })
  3753. }
  3754. type ResultTwo struct {
  3755. ErrMsg interface{} `json:"err_msg"`
  3756. InfRefmsgid string `json:"inf_refmsgid"`
  3757. Infcode int64 `json:"infcode"`
  3758. Output struct {
  3759. Baseinfo struct {
  3760. Age float64 `json:"age"`
  3761. Brdy string `json:"brdy"`
  3762. Certno string `json:"certno"`
  3763. Gend string `json:"gend"`
  3764. Naty string `json:"naty"`
  3765. PsnCertType string `json:"psn_cert_type"`
  3766. PsnName string `json:"psn_name"`
  3767. PsnNo string `json:"psn_no"`
  3768. } `json:"baseinfo"`
  3769. Idetinfo []interface{} `json:"idetinfo"`
  3770. Iinfo []struct {
  3771. Balc float64 `json:"balc"`
  3772. CvlservFlag string `json:"cvlserv_flag"`
  3773. EmpName string `json:"emp_name"`
  3774. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3775. Insutype string `json:"insutype"`
  3776. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3777. PausInsuDate interface{} `json:"paus_insu_date"`
  3778. PsnInsuDate string `json:"psn_insu_date"`
  3779. PsnInsuStas string `json:"psn_insu_stas"`
  3780. PsnType string `json:"psn_type"`
  3781. } `json:"insuinfo"`
  3782. } `json:"output"`
  3783. RefmsgTime string `json:"refmsg_time"`
  3784. RespondTime string `json:"respond_time"`
  3785. Signtype interface{} `json:"signtype"`
  3786. WarnInfo interface{} `json:"warn_info"`
  3787. }
  3788. type ResultThree struct {
  3789. Cainfo interface{} `json:"cainfo"`
  3790. ErrMsg interface{} `json:"err_msg"`
  3791. InfRefmsgid string `json:"inf_refmsgid"`
  3792. Infcode int64 `json:"infcode"`
  3793. Output struct {
  3794. Data struct {
  3795. IptOtpNo string `json:"ipt_otp_no"`
  3796. MdtrtID string `json:"mdtrt_id"`
  3797. PsnNo string `json:"psn_no"`
  3798. } `json:"data"`
  3799. } `json:"output"`
  3800. RefmsgTime string `json:"refmsg_time"`
  3801. RespondTime string `json:"respond_time"`
  3802. Signtype interface{} `json:"signtype"`
  3803. WarnMsg interface{} `json:"warn_msg"`
  3804. }
  3805. type ResultFour struct {
  3806. Cainfo string `json:"cainfo"`
  3807. ErrMsg string `json:"err_msg"`
  3808. InfRefmsgid string `json:"inf_refmsgid"`
  3809. Infcode int64 `json:"infcode"`
  3810. Output struct {
  3811. Result []struct {
  3812. BasMednFlag string `json:"bas_medn_flag"`
  3813. ChldMedcFlag string `json:"chld_medc_flag"`
  3814. ChrgitmLv string `json:"chrgitm_lv"`
  3815. Cnt float64 `json:"cnt"`
  3816. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3817. DrtReimFlag string `json:"drt_reim_flag"`
  3818. FeedetlSn string `json:"feedetl_sn"`
  3819. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3820. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3821. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3822. ListSpItemFlag string `json:"list_sp_item_flag"`
  3823. LmtUsedFlag string `json:"lmt_used_flag"`
  3824. MedChrgitmType string `json:"med_chrgitm_type"`
  3825. Memo string `json:"memo"`
  3826. OverlmtAmt float64 `json:"overlmt_amt"`
  3827. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3828. Pric float64 `json:"pric"`
  3829. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3830. SelfpayProp float64 `json:"selfpay_prop"`
  3831. } `json:"result"`
  3832. } `json:"output"`
  3833. RefmsgTime string `json:"refmsg_time"`
  3834. RespondTime string `json:"respond_time"`
  3835. Signtype string `json:"signtype"`
  3836. WarnMsg string `json:"warn_msg"`
  3837. }
  3838. type ResultFive struct {
  3839. Insutype string `json:"insutype"`
  3840. }
  3841. type ResultSix struct {
  3842. Cainfo interface{} `json:"cainfo"`
  3843. ErrMsg interface{} `json:"err_msg"`
  3844. InfRefmsgid string `json:"inf_refmsgid"`
  3845. Infcode int64 `json:"infcode"`
  3846. Output struct {
  3847. } `json:"output"`
  3848. RefmsgTime string `json:"refmsg_time"`
  3849. RespondTime string `json:"respond_time"`
  3850. Signtype interface{} `json:"signtype"`
  3851. WarnMsg interface{} `json:"warn_msg"`
  3852. }
  3853. type ResultSeven struct {
  3854. Cainfo string `json:"cainfo"`
  3855. ErrMsg string `json:"err_msg"`
  3856. InfRefmsgid string `json:"inf_refmsgid"`
  3857. Infcode int64 `json:"infcode"`
  3858. Output struct {
  3859. Setldetail []interface{} `json:"setldetail"`
  3860. Setlinfo struct {
  3861. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3862. AcctPay float64 `json:"acct_pay"`
  3863. ActPayDedc float64 `json:"act_pay_dedc"`
  3864. Age float64 `json:"age"`
  3865. Balc float64 `json:"balc"`
  3866. Brdy string `json:"brdy"`
  3867. Certno string `json:"certno"`
  3868. ClrOptins string `json:"clr_optins"`
  3869. ClrType string `json:"clr_type"`
  3870. ClrWay string `json:"clr_way"`
  3871. CvlservFlag string `json:"cvlserv_flag"`
  3872. CvlservPay float64 `json:"cvlserv_pay"`
  3873. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3874. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3875. Gend string `json:"gend"`
  3876. HifesPay float64 `json:"hifes_pay"`
  3877. HifmiPay float64 `json:"hifmi_pay"`
  3878. HifobPay float64 `json:"hifob_pay"`
  3879. HifpPay float64 `json:"hifp_pay"`
  3880. HospPartAmt float64 `json:"hosp_part_amt"`
  3881. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3882. Insutype string `json:"insutype"`
  3883. MafPay float64 `json:"maf_pay"`
  3884. MdtrtCertType string `json:"mdtrt_cert_type"`
  3885. MdtrtID string `json:"mdtrt_id"`
  3886. MedType string `json:"med_type"`
  3887. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3888. MedinsSetlID string `json:"medins_setl_id"`
  3889. Naty string `json:"naty"`
  3890. OthPay float64 `json:"oth_pay"`
  3891. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3892. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3893. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3894. PsnCashPay float64 `json:"psn_cash_pay"`
  3895. PsnCertType string `json:"psn_cert_type"`
  3896. PsnName string `json:"psn_name"`
  3897. PsnNo string `json:"psn_no"`
  3898. PsnPartAmt float64 `json:"psn_part_amt"`
  3899. PsnType string `json:"psn_type"`
  3900. SetlID string `json:"setl_id"`
  3901. SetlTime string `json:"setl_time"`
  3902. } `json:"setlinfo"`
  3903. } `json:"output"`
  3904. RefmsgTime string `json:"refmsg_time"`
  3905. RespondTime string `json:"respond_time"`
  3906. Signtype interface{} `json:"signtype"`
  3907. WarnMsg interface{} `json:"warn_msg"`
  3908. }
  3909. type ResultEight struct {
  3910. Cainfo string `json:"cainfo"`
  3911. ErrMsg string `json:"err_msg"`
  3912. InfRefmsgid string `json:"inf_refmsgid"`
  3913. Infcode int64 `json:"infcode"`
  3914. Output struct {
  3915. Stmtinfo struct {
  3916. SetlOptins string `json:"setl_optins"`
  3917. StmtRslt string `json:"stmt_rslt"`
  3918. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3919. } `json:"stmtinfo"`
  3920. } `json:"output"`
  3921. RefmsgTime string `json:"refmsg_time"`
  3922. RespondTime string `json:"respond_time"`
  3923. Signtype interface{} `json:"signtype"`
  3924. WarnMsg interface{} `json:"warn_msg"`
  3925. }
  3926. type ResultNine struct {
  3927. Cainfo string `json:"cainfo"`
  3928. ErrMsg string `json:"err_msg"`
  3929. InfRefmsgid string `json:"inf_refmsgid"`
  3930. Infcode int64 `json:"infcode"`
  3931. Output struct {
  3932. FileQuryNo string `json:"file_qury_no"`
  3933. } `json:"output"`
  3934. RefmsgTime string `json:"refmsg_time"`
  3935. RespondTime string `json:"respond_time"`
  3936. Signtype interface{} `json:"signtype"`
  3937. WarnMsg interface{} `json:"warn_msg"`
  3938. }
  3939. type ResultTen struct {
  3940. Cainfo string `json:"cainfo"`
  3941. ErrMsg string `json:"err_msg"`
  3942. InfRefmsgid string `json:"inf_refmsgid"`
  3943. Infcode int64 `json:"infcode"`
  3944. Output struct {
  3945. DldEndtime string `json:"dld_endtime"`
  3946. FileQuryNo string `json:"file_qury_no"`
  3947. Filename string `json:"filename"`
  3948. } `json:"output"`
  3949. RefmsgTime string `json:"refmsg_time"`
  3950. RespondTime string `json:"respond_time"`
  3951. Signtype interface{} `json:"signtype"`
  3952. WarnMsg interface{} `json:"warn_msg"`
  3953. }
  3954. type ResultEleven struct {
  3955. Cainfo string `json:"cainfo"`
  3956. ErrMsg string `json:"err_msg"`
  3957. InfRefmsgid string `json:"inf_refmsgid"`
  3958. Infcode int64 `json:"infcode"`
  3959. Output struct {
  3960. Setlinfo struct {
  3961. FixmedinsName string `json:"fixmedins_name"`
  3962. FixmedinsCode string `json:"fixmedins_code"`
  3963. PsnNo string `json:"psn_no"`
  3964. PsnName string `json:"psn_name"`
  3965. HifobPay float64 `json:"hifob_pay"`
  3966. Gend string `json:"gend"`
  3967. Brdy string `json:"brdy"`
  3968. PsnCertType string `json:"psn_cert_type"`
  3969. PsnType string `json:"psn_type"`
  3970. EmpName string `json:"emp_name"`
  3971. Certno string `json:"certno"`
  3972. Insutype string `json:"insutype"`
  3973. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3974. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3975. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3976. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3977. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3978. ActPayDedc float64 `json:"act_pay_dedc"`
  3979. HifpPay float64 `json:"hifp_pay"`
  3980. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3981. CvlservPay float64 `json:"cvlserv_pay"`
  3982. HifesPay float64 `json:"hifes_pay"`
  3983. HifmiPay float64 `json:"hifmi_pay"`
  3984. MafPay float64 `json:"maf_pay"`
  3985. OthPay float64 `json:"oth_pay"`
  3986. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3987. PsnPay float64 `json:"psn_pay"`
  3988. AcctPay float64 `json:"acct_pay"`
  3989. CashPayamt float64 `json:"cash_payamt"`
  3990. Balc float64 `json:"balc"`
  3991. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3992. MedinsSetlId string `json:"medins_setl_id"`
  3993. RefdSetlFlag string `json:"refd_setl_flag"`
  3994. SetlTime string `json:"setl_time"`
  3995. MedType string `json:"med_type"`
  3996. } `json:"setlinfo"`
  3997. } `json:"output"`
  3998. RefmsgTime string `json:"refmsg_time"`
  3999. RespondTime string `json:"respond_time"`
  4000. Signtype interface{} `json:"signtype"`
  4001. WarnMsg interface{} `json:"warn_msg"`
  4002. }
  4003. type Custom struct {
  4004. DetItemFeeSumamt string
  4005. Cut string
  4006. FeedetlSn string
  4007. Price string
  4008. MedListCodg string
  4009. Type int64
  4010. AdviceId int64
  4011. ProjectId int64
  4012. ItemId int64
  4013. }
  4014. //获取个人信息----挂号-----上传就诊信息
  4015. func (c *HisApiController) GetRegisterInfo() {
  4016. id, _ := c.GetInt64("id")
  4017. record_time := c.GetString("record_time")
  4018. settlementValue, _ := c.GetInt64("settlement_value")
  4019. medical_insurance_card := c.GetString("medical_insurance_card")
  4020. name := c.GetString("name")
  4021. id_card_type, _ := c.GetInt64("id_card_type")
  4022. certificates, _ := c.GetInt64("certificates")
  4023. medical_care, _ := c.GetInt64("medical_care")
  4024. birthday := c.GetString("birthday")
  4025. age, _ := c.GetInt64("age")
  4026. id_card := c.GetString("id_card")
  4027. register_type, _ := c.GetInt64("register")
  4028. doctor, _ := c.GetInt64("doctor")
  4029. department, _ := c.GetInt64("department")
  4030. gender, _ := c.GetInt64("sex")
  4031. phone := c.GetString("phone")
  4032. registration_fee, _ := c.GetFloat("registration_fee")
  4033. medical_expenses, _ := c.GetFloat("medical_expenses")
  4034. social_type, _ := c.GetInt64("social_type")
  4035. //diagnosis_id, _ := c.GetInt64("diagnosis")
  4036. diagnosis_ids := c.GetString("diagnosis")
  4037. sick_type, _ := c.GetInt64("sick_type")
  4038. reg_type := c.GetString("p_type")
  4039. timeLayout := "2006-01-02"
  4040. loc, _ := time.LoadLocation("Local")
  4041. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  4042. birthUnix := birthdays.Unix()
  4043. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4044. if err != nil {
  4045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4046. return
  4047. }
  4048. recordDateTime := theTime.Unix()
  4049. adminInfo := c.GetAdminUserInfo()
  4050. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  4051. if tempPatient.ID == 0 {
  4052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  4053. return
  4054. }
  4055. var patient service.Patients
  4056. if id == 0 {
  4057. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  4058. } else {
  4059. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  4060. }
  4061. if patient.ID == 0 {
  4062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4063. return
  4064. }
  4065. if len(patient.IdCardNo) == 0 {
  4066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4067. return
  4068. }
  4069. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4070. if len(his) >= 1 {
  4071. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  4072. if len(his) >= 1 && order.ID == 0 {
  4073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  4074. return
  4075. }
  4076. }
  4077. timeStr := time.Now().Format("2006-01-02 15:04:05")
  4078. fmt.Println(timeStr)
  4079. timeArr := strings.Split(timeStr, " ")
  4080. fmt.Println(timeArr)
  4081. timeArrTwo := strings.Split(timeArr[0], "-")
  4082. timeArrThree := strings.Split(timeArr[1], ":")
  4083. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  4084. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4085. if len(lists) == 0 {
  4086. var hisPatient models.XtHisPatient
  4087. hisPatient = models.XtHisPatient{
  4088. Name: name,
  4089. Age: age,
  4090. Gender: gender,
  4091. Birthday: birthUnix,
  4092. Phone: phone,
  4093. MedicalTreatmentType: medical_care,
  4094. IdType: certificates,
  4095. IdCardNo: id_card,
  4096. BalanceAccountsType: settlementValue,
  4097. SocialType: social_type,
  4098. MedicalInsuranceNumber: medical_insurance_card,
  4099. RegisterType: register_type,
  4100. RegisterCost: registration_fee,
  4101. TreatmentCost: medical_expenses,
  4102. AdminUserId: adminInfo.AdminUser.Id,
  4103. UserOrgId: adminInfo.CurrentOrgId,
  4104. Status: 1,
  4105. RecordDate: recordDateTime,
  4106. IsReturn: 1,
  4107. PatientId: patient.ID,
  4108. Ctime: time.Now().Unix(),
  4109. Mtime: time.Now().Unix(),
  4110. Number: str,
  4111. IdCardType: id_card_type,
  4112. Departments: department,
  4113. Doctor: doctor,
  4114. PType: reg_type,
  4115. Diagnosis: diagnosis_ids,
  4116. SickType: sick_type,
  4117. }
  4118. service.CreateHisPatient(&hisPatient)
  4119. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4120. c.ServeSuccessJSON(map[string]interface{}{
  4121. "his_info": hisPatient,
  4122. })
  4123. } else {
  4124. //chrgBchno := rand.Intn(1000000) + 10000
  4125. var hisPatient models.XtHisPatient
  4126. hisPatient = models.XtHisPatient{
  4127. Name: name,
  4128. Age: age,
  4129. Gender: gender,
  4130. Birthday: birthUnix,
  4131. Phone: phone,
  4132. MedicalTreatmentType: medical_care,
  4133. IdType: certificates,
  4134. IdCardNo: id_card,
  4135. BalanceAccountsType: settlementValue,
  4136. SocialType: social_type,
  4137. MedicalInsuranceNumber: medical_insurance_card,
  4138. RegisterType: register_type,
  4139. RegisterCost: registration_fee,
  4140. TreatmentCost: medical_expenses,
  4141. AdminUserId: adminInfo.AdminUser.Id,
  4142. UserOrgId: adminInfo.CurrentOrgId,
  4143. Status: 1,
  4144. RecordDate: recordDateTime,
  4145. IsReturn: 1,
  4146. PatientId: patient.ID,
  4147. Ctime: time.Now().Unix(),
  4148. Mtime: time.Now().Unix(),
  4149. Number: str,
  4150. IdCardType: id_card_type,
  4151. Departments: department,
  4152. Doctor: doctor,
  4153. PType: reg_type,
  4154. Diagnosis: diagnosis_ids,
  4155. SickType: sick_type,
  4156. }
  4157. service.CreateHisPatient(&hisPatient)
  4158. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4159. c.ServeSuccessJSON(map[string]interface{}{
  4160. "his_info": hisPatient,
  4161. })
  4162. }
  4163. }
  4164. //上传明细----结算
  4165. func (c *HisApiController) GetUploadInfo() {
  4166. id, _ := c.GetInt64("id")
  4167. record_time := c.GetString("record_time")
  4168. his_patient_id, _ := c.GetInt64("his_patient_id")
  4169. pay_way, _ := c.GetInt64("pay_way")
  4170. pay_price, _ := c.GetFloat("pay_price")
  4171. pay_card_no := c.GetString("pay_card_no")
  4172. discount_price, _ := c.GetFloat("discount_price")
  4173. preferential_price, _ := c.GetFloat("preferential_price")
  4174. reality_price, _ := c.GetFloat("reality_price")
  4175. found_price, _ := c.GetFloat("found_price")
  4176. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4177. private_price, _ := c.GetFloat("private_price")
  4178. timeLayout := "2006-01-02"
  4179. loc, _ := time.LoadLocation("Local")
  4180. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4181. fapiao_code := c.GetString("fapiao_code")
  4182. fapiao_number := c.GetString("fapiao_number")
  4183. diagnosis_id := c.GetString("diagnosis")
  4184. sick_type, _ := c.GetInt64("sick_type")
  4185. reg_type, _ := c.GetInt64("p_type")
  4186. order_id, _ := c.GetInt64("order_id")
  4187. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  4188. tempOrder, _ := service.GetHisOrderByID(order_id)
  4189. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4190. if err != nil {
  4191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4192. return
  4193. }
  4194. recordDateTime := theTime.Unix()
  4195. adminUser := c.GetAdminUserInfo()
  4196. var prescriptions []*models.HisPrescription
  4197. var start_time int64
  4198. var end_time int64
  4199. ids_str := c.GetString("ids")
  4200. ids_arr := strings.Split(ids_str, ",")
  4201. if tempOrder.ID == 0 {
  4202. if settle_accounts_type == 1 { //日结
  4203. fmt.Println(reg_type)
  4204. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4205. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  4206. } else {
  4207. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  4208. }
  4209. } else { //月结
  4210. start_time_str := c.GetString("start_time")
  4211. end_time_str := c.GetString("end_time")
  4212. timeLayout := "2006-01-02"
  4213. loc, _ := time.LoadLocation("Local")
  4214. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4215. if err != nil {
  4216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4217. return
  4218. }
  4219. recordStartTime := theStartTime.Unix()
  4220. start_time = recordStartTime
  4221. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4222. if err != nil {
  4223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4224. return
  4225. }
  4226. recordEndTime := theEndTime.Unix()
  4227. end_time = recordEndTime
  4228. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  4229. }
  4230. timestamp := time.Now().Unix()
  4231. tempTime := time.Unix(timestamp, 0)
  4232. timeFormat := tempTime.Format("20060102150405")
  4233. chrgBchno := rand.Intn(100000) + 10000
  4234. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4235. strconv.FormatInt(his.PatientId, 10)
  4236. var ids []int64
  4237. for _, item := range prescriptions {
  4238. ids = append(ids, item.ID)
  4239. }
  4240. var total float64
  4241. for _, item := range prescriptions {
  4242. fmt.Println(item)
  4243. if item.Type == 1 { //药品
  4244. for _, subItem := range item.HisDoctorAdviceInfo {
  4245. total = total + (subItem.Price * subItem.PrescribingNumber)
  4246. }
  4247. }
  4248. if item.Type == 2 { //项目
  4249. for _, subItem := range item.HisPrescriptionProject {
  4250. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4251. total = total + (subItem.Price * cnt)
  4252. }
  4253. }
  4254. for _, subItem := range item.HisAdditionalCharge {
  4255. total = total + (subItem.Price * float64(subItem.Count))
  4256. }
  4257. }
  4258. if reg_type == 1111 || reg_type == 1112 {
  4259. reg_type = 11
  4260. }
  4261. tm := time.Unix(time.Now().Unix(), 0)
  4262. allTotal := fmt.Sprintf("%.4f", total)
  4263. totals, _ := strconv.ParseFloat(allTotal, 64)
  4264. order := &models.HisOrder{
  4265. UserOrgId: adminUser.CurrentOrgId,
  4266. HisPatientId: his.ID,
  4267. PatientId: id,
  4268. SettleAccountsDate: recordDateTime,
  4269. Ctime: time.Now().Unix(),
  4270. Mtime: time.Now().Unix(),
  4271. Status: 1,
  4272. OrderStatus: 2,
  4273. MdtrtId: his.Number,
  4274. Number: chrg_bchno,
  4275. MedfeeSumamt: totals,
  4276. PayWay: pay_way,
  4277. PayPrice: pay_price,
  4278. MedType: strconv.Itoa(int(reg_type)),
  4279. PayCardNo: pay_card_no,
  4280. DiscountPrice: discount_price,
  4281. PreferentialPrice: preferential_price,
  4282. RealityPrice: reality_price,
  4283. FoundPrice: found_price,
  4284. MedicalInsurancePrice: medical_insurance_price,
  4285. PrivatePrice: private_price,
  4286. SettleEndTime: end_time,
  4287. SettleStartTime: start_time,
  4288. SettleType: settle_accounts_type,
  4289. FaPiaoCode: fapiao_code,
  4290. FaPiaoNumber: fapiao_number,
  4291. Diagnosis: diagnosis_id,
  4292. PType: 2,
  4293. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4294. }
  4295. err = service.CreateOrder(order)
  4296. if err != nil {
  4297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4298. return
  4299. }
  4300. var customs []*Custom
  4301. for _, item := range prescriptions {
  4302. if item.Type == 1 { //药品
  4303. for _, subItem := range item.HisDoctorAdviceInfo {
  4304. cus := &Custom{
  4305. AdviceId: subItem.ID,
  4306. ProjectId: 0,
  4307. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4308. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4309. FeedetlSn: subItem.FeedetlSn,
  4310. Price: fmt.Sprintf("%.2f", subItem.Price),
  4311. MedListCodg: subItem.MedListCodg,
  4312. Type: 1,
  4313. }
  4314. customs = append(customs, cus)
  4315. }
  4316. }
  4317. if item.Type == 2 { //项目
  4318. for _, subItem := range item.HisPrescriptionProject {
  4319. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4320. cus := &Custom{
  4321. AdviceId: 0,
  4322. ProjectId: subItem.ID,
  4323. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4324. Cut: fmt.Sprintf("%.4f", cnt),
  4325. FeedetlSn: subItem.FeedetlSn,
  4326. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4327. MedListCodg: subItem.MedListCodg,
  4328. Type: 2,
  4329. }
  4330. customs = append(customs, cus)
  4331. }
  4332. }
  4333. for _, item := range item.HisAdditionalCharge {
  4334. cus := &Custom{
  4335. ItemId: item.ID,
  4336. AdviceId: 0,
  4337. ProjectId: 0,
  4338. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4339. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4340. FeedetlSn: item.FeedetlSn,
  4341. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4342. MedListCodg: item.XtHisAddtionConfig.Code,
  4343. Type: 3,
  4344. }
  4345. customs = append(customs, cus)
  4346. }
  4347. }
  4348. for _, item := range customs {
  4349. var advice_id int64 = 0
  4350. var project_id int64 = 0
  4351. var item_id int64 = 0
  4352. var types int64 = 0
  4353. if item.Type == 1 {
  4354. advice_id = item.AdviceId
  4355. project_id = 0
  4356. item_id = 0
  4357. } else if item.Type == 2 {
  4358. advice_id = 0
  4359. item_id = 0
  4360. project_id = item.ProjectId
  4361. } else if item.Type == 3 {
  4362. advice_id = 0
  4363. item_id = item.ItemId
  4364. project_id = 0
  4365. }
  4366. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4367. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4368. pric, _ := strconv.ParseFloat(item.Price, 32)
  4369. info := &models.HisOrderInfo{
  4370. OrderNumber: order.Number,
  4371. UploadDate: time.Now().Unix(),
  4372. AdviceId: advice_id,
  4373. DetItemFeeSumamt: detItemFeeSumamt,
  4374. Cnt: cut,
  4375. Pric: pric,
  4376. PatientId: id,
  4377. Status: 1,
  4378. Mtime: time.Now().Unix(),
  4379. Ctime: time.Now().Unix(),
  4380. UserOrgId: adminUser.CurrentOrgId,
  4381. HisPatientId: his.ID,
  4382. OrderId: order.ID,
  4383. ProjectId: project_id,
  4384. Type: types,
  4385. ItemId: item_id,
  4386. }
  4387. service.CreateOrderInfo(info)
  4388. }
  4389. his.Diagnosis = diagnosis_id
  4390. his.SickType = sick_type
  4391. his.RegisterType = reg_type
  4392. his.MedicalTreatmentType = reg_type
  4393. service.UpdataHisPateint(&his)
  4394. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4395. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4396. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4397. if err == nil {
  4398. c.ServeSuccessJSON(map[string]interface{}{
  4399. "msg": "结算成功",
  4400. })
  4401. }
  4402. } else {
  4403. if tempOrder.IsPre > 0 {
  4404. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4405. totals, _ := strconv.ParseFloat(allTotal, 64)
  4406. tempOrder.OrderStatus = 2
  4407. tempOrder.PayWay = pay_way
  4408. tempOrder.PayPrice = pay_price
  4409. tempOrder.PayCardNo = pay_card_no
  4410. tempOrder.DiscountPrice = discount_price
  4411. tempOrder.PreferentialPrice = preferential_price
  4412. tempOrder.RealityPrice = reality_price
  4413. tempOrder.FoundPrice = found_price
  4414. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4415. tempOrder.PrivatePrice = private_price
  4416. tempOrder.FaPiaoCode = fapiao_code
  4417. tempOrder.FaPiaoNumber = fapiao_number
  4418. tempOrder.PType = 2
  4419. tempOrder.MedfeeSumamt = totals
  4420. tempOrder.Diagnosis = diagnosis_id
  4421. err = service.SaveHisOrder(&tempOrder)
  4422. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4423. if err != nil {
  4424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4425. return
  4426. }
  4427. if err == nil {
  4428. c.ServeSuccessJSON(map[string]interface{}{
  4429. "msg": "结算成功",
  4430. })
  4431. }
  4432. }
  4433. }
  4434. }
  4435. //退款
  4436. func (c *HisApiController) Refund() {
  4437. order_id, _ := c.GetInt64("order_id")
  4438. order, _ := service.GetHisOrderByID(order_id)
  4439. adminUser := c.GetAdminUserInfo()
  4440. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4441. if err == nil {
  4442. c.ServeSuccessJSON(map[string]interface{}{
  4443. "msg": "退费成功",
  4444. })
  4445. } else {
  4446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4447. return
  4448. }
  4449. }
  4450. func (c *HisApiController) RefundNumber() {
  4451. his_patient_id, _ := c.GetInt64("id")
  4452. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4453. info.Status = 0
  4454. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4455. if count > 0 {
  4456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4457. return
  4458. }
  4459. err := service.SaveHisPatient(info)
  4460. if err == nil {
  4461. c.ServeSuccessJSON(map[string]interface{}{
  4462. "msg": "退号成功",
  4463. })
  4464. } else {
  4465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4466. return
  4467. }
  4468. }
  4469. func (this *HisApiController) AdditionalCharge() {
  4470. dataBody := make(map[string]interface{}, 0)
  4471. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4472. fmt.Println(err)
  4473. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4474. patient_id := int64(dataBody["patient_id"].(float64))
  4475. medicineData, _ := dataBody["medicineData"].([]interface{})
  4476. adminUserInfo := this.GetAdminUserInfo()
  4477. orgId := adminUserInfo.CurrentOrgId
  4478. admin_user_id := adminUserInfo.AdminUser.Id
  4479. timeStr := time.Now().Format("2006-01-02")
  4480. timeLayout := "2006-01-02 15:04:05"
  4481. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4482. timenow := timeStringToTime.Unix()
  4483. var additionalCharges []*models.HisAdditionalCharge
  4484. for _, item := range medicineData {
  4485. var randNum int
  4486. randNum = rand.Intn(10000) + 1000
  4487. timestamp := time.Now().Unix()
  4488. tempTime := time.Unix(timestamp, 0)
  4489. timeFormat := tempTime.Format("20060102150405")
  4490. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4491. items := item.(map[string]interface{})
  4492. money := items["price"].(string)
  4493. item_id_str := items["item_id"].(string)
  4494. name := items["name"].(string)
  4495. id_str := items["id"].(string)
  4496. moneys, _ := strconv.ParseInt(money, 10, 64)
  4497. monStr := strconv.FormatInt(moneys, 10)
  4498. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4499. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4500. id, _ := strconv.ParseInt(id_str, 10, 64)
  4501. additionalCharge := &models.HisAdditionalCharge{
  4502. ID: id,
  4503. HisPatientId: his_patient_id,
  4504. UserOrgId: orgId,
  4505. PatientId: patient_id,
  4506. RecordDate: timenow,
  4507. Price: monneyStr,
  4508. Status: 1,
  4509. ItemName: name,
  4510. ItemId: item_id,
  4511. AdminUserId: admin_user_id,
  4512. CreatedTime: time.Now().Unix(),
  4513. OrderStatus: 0,
  4514. PrescriptionNumber: "",
  4515. BatchNumber: "",
  4516. FeedetlSn: p_number,
  4517. }
  4518. service.CreateAdditionalCharge(additionalCharge)
  4519. additionalCharges = append(additionalCharges, additionalCharge)
  4520. }
  4521. this.ServeSuccessJSON(map[string]interface{}{
  4522. "msg": "添加成功",
  4523. "additional_charges": additionalCharges,
  4524. })
  4525. }
  4526. func (this *HisApiController) DeleteAddition() {
  4527. id, _ := this.GetInt64("id")
  4528. //TODO 需要判断是否已经结算
  4529. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4530. if err == nil {
  4531. this.ServeSuccessJSON(map[string]interface{}{
  4532. "msg": "删除成功",
  4533. })
  4534. return
  4535. } else {
  4536. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4537. return
  4538. }
  4539. }
  4540. func (this *HisApiController) GetAdminUsers() {
  4541. adminUser := this.GetAdminUserInfo()
  4542. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4543. this.ServeSuccessJSON(map[string]interface{}{
  4544. "doctors": doctors,
  4545. })
  4546. }
  4547. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4548. change_type, _ := this.GetInt64("type", 0)
  4549. record_date := this.GetString("record_time")
  4550. patient_id, _ := this.GetInt64("patient_id", 0)
  4551. p_type, _ := this.GetInt64("p_type", 0)
  4552. timeLayout := "2006-01-02"
  4553. loc, _ := time.LoadLocation("Local")
  4554. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4555. record_time := theAdviceRecordTime.Unix()
  4556. adminUserInfo := this.GetAdminUserInfo()
  4557. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4558. if err == nil {
  4559. if len(prescriptions) == 0 {
  4560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4561. return
  4562. } else {
  4563. this.ServeSuccessJSON(map[string]interface{}{
  4564. "prescriptions": prescriptions,
  4565. })
  4566. return
  4567. }
  4568. } else {
  4569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4570. return
  4571. }
  4572. }
  4573. func (this *HisApiController) GetCallHisPrescription() {
  4574. patient_id, _ := this.GetInt64("patient_id", 0)
  4575. timeLayout := "2006-01-02"
  4576. loc, _ := time.LoadLocation("Local")
  4577. start_time := this.GetString("start_time")
  4578. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4579. end_time := this.GetString("end_time")
  4580. p_type, _ := this.GetInt64("p_type")
  4581. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4582. adminUserInfo := this.GetAdminUserInfo()
  4583. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4584. if err == nil {
  4585. this.ServeSuccessJSON(map[string]interface{}{
  4586. "prescriptions": prescriptions,
  4587. })
  4588. return
  4589. } else {
  4590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4591. return
  4592. }
  4593. }
  4594. func (this *HisApiController) GetHisDayPrescription() {
  4595. timeLayout := "2006-01-02"
  4596. loc, _ := time.LoadLocation("Local")
  4597. start_time := this.GetString("start_time")
  4598. patient_id, _ := this.GetInt64("patient_id", 0)
  4599. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4600. end_time := this.GetString("end_time")
  4601. p_type, _ := this.GetInt64("p_type")
  4602. order_status, _ := this.GetInt64("type")
  4603. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4604. adminUserInfo := this.GetAdminUserInfo()
  4605. var dayHisPrescription []*models.HisPrescription
  4606. var err error
  4607. if order_status == 1 || order_status == 0 {
  4608. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4609. } else if order_status == 2 {
  4610. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4611. }
  4612. var settle_total float64
  4613. for _, item := range dayHisPrescription {
  4614. if len(item.HisPrescriptionProject) > 0 {
  4615. for _, subItem := range item.HisPrescriptionProject {
  4616. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4617. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4618. settle_total = settle_total + total
  4619. }
  4620. }
  4621. if len(item.HisDoctorAdviceInfo) > 0 {
  4622. for _, subItem := range item.HisDoctorAdviceInfo {
  4623. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4624. settle_total = settle_total + total
  4625. }
  4626. }
  4627. }
  4628. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4629. if err == nil {
  4630. this.ServeSuccessJSON(map[string]interface{}{
  4631. "day_prescription": dayHisPrescription,
  4632. "settle_total": settle_total,
  4633. })
  4634. return
  4635. } else {
  4636. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4637. return
  4638. }
  4639. }
  4640. func (c *HisApiController) GetHisChargePatientList() {
  4641. record_date := c.GetString("record_date")
  4642. order_status, _ := c.GetInt64("type")
  4643. timeLayout := "2006-01-02"
  4644. loc, _ := time.LoadLocation("Local")
  4645. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4646. if err != nil {
  4647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4648. return
  4649. }
  4650. recordDateTime := theTime.Unix()
  4651. adminInfo := c.GetAdminUserInfo()
  4652. var tempPatients []*service.NewTempPatients
  4653. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4654. if order_status != 2 {
  4655. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4656. } else {
  4657. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4658. }
  4659. var patients []*service.NewTempPatients
  4660. var patients_two []*service.NewTempPatients
  4661. for _, item := range tempPatients {
  4662. //过滤掉没挂号的和没开处方的
  4663. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4664. patients = append(patients, item)
  4665. }
  4666. //过滤掉没挂号的
  4667. if len(item.HisPatient) > 0 {
  4668. patients_two = append(patients_two, item)
  4669. }
  4670. }
  4671. c.ServeSuccessJSON(map[string]interface{}{
  4672. "list": patients,
  4673. "list_two": patients_two,
  4674. })
  4675. }
  4676. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4677. record_date := c.GetString("record_date")
  4678. timeLayout := "2006-01-02"
  4679. loc, _ := time.LoadLocation("Local")
  4680. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4681. if err != nil {
  4682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4683. return
  4684. }
  4685. recordDateTime := theTime.Unix()
  4686. adminUser := c.GetAdminUserInfo()
  4687. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4688. var patients []*service.Patients
  4689. for _, item := range tempPatients {
  4690. if item.HisPatient.ID == 0 {
  4691. patients = append(patients, item)
  4692. }
  4693. }
  4694. c.ServeSuccessJSON(map[string]interface{}{
  4695. "list": patients,
  4696. //"list_two": patients_two,
  4697. })
  4698. }
  4699. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4700. newArr = make([]*service.Patients, 0)
  4701. for i := 0; i < len(patient); i++ {
  4702. repeat := false
  4703. for j := i + 1; j < len(patient); j++ {
  4704. if patient[i].ID == patient[j].ID {
  4705. repeat = true
  4706. break
  4707. }
  4708. }
  4709. if !repeat {
  4710. newArr = append(newArr, patient[i])
  4711. }
  4712. }
  4713. return
  4714. }
  4715. func (c *HisApiController) GetHisChargePatientInfo() {
  4716. patient_id, _ := c.GetInt64("patient_id")
  4717. his_patient_id, _ := c.GetInt64("his_patient_id")
  4718. record_date := c.GetString("record_date")
  4719. //start_time := c.GetString("start_time")
  4720. //end_time := c.GetString("end_time")
  4721. order_status, _ := c.GetInt64("type", 0)
  4722. p_type, _ := c.GetInt64("p_type", 0)
  4723. order_id, _ := c.GetInt64("order_id", 0)
  4724. timeLayout := "2006-01-02"
  4725. loc, _ := time.LoadLocation("Local")
  4726. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4727. if err != nil {
  4728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4729. return
  4730. }
  4731. recordDateTime := theTime.Unix()
  4732. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4733. //if err != nil {
  4734. //
  4735. //}
  4736. //startRecordDateTime := startTime.Unix()
  4737. //
  4738. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4739. //if err != nil {
  4740. //
  4741. //}
  4742. //endRecordDateTime := endTime.Unix()
  4743. admin := c.GetAdminUserInfo()
  4744. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4745. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4746. var prescriptions []*models.HisPrescription
  4747. //var unChargeMonthPrescriptions []*models.HisPrescription
  4748. order, _ := service.GetHisOrderByID(order_id)
  4749. if order_status == 1 || order_status == 0 {
  4750. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4751. } else if order_status == 2 {
  4752. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4753. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4754. }
  4755. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4756. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4757. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4758. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4759. //获取所有科室信息
  4760. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4761. c.ServeSuccessJSON(map[string]interface{}{
  4762. "his_info": his_patient_info,
  4763. "xt_info": xt_patient_info,
  4764. "prescription": prescriptions,
  4765. "case_history": case_history,
  4766. "info": patientPrescriptionInfo,
  4767. "last_info": lastPatientPrescriptionInfo,
  4768. "order": order,
  4769. "doctors": doctors,
  4770. "department": department,
  4771. })
  4772. return
  4773. }
  4774. func (c *HisApiController) GetAllOrderDetail() {
  4775. order_id, _ := c.GetInt64("id", 0)
  4776. order, _ := service.GetHisOrderByID(order_id)
  4777. if order.ID == 0 {
  4778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4779. return
  4780. }
  4781. org_id := c.GetAdminUserInfo().CurrentOrgId
  4782. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4783. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4784. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4785. c.ServeSuccessJSON(map[string]interface{}{
  4786. "order": order,
  4787. "order_info": order_info,
  4788. "patient": patient,
  4789. "admin_info": adminInfo,
  4790. })
  4791. return
  4792. }
  4793. func (c *HisApiController) GetAllOrderDetailCollect() {
  4794. order_id, _ := c.GetInt64("id", 0)
  4795. order, _ := service.GetHisOrderByID(order_id)
  4796. if order.ID == 0 {
  4797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4798. return
  4799. }
  4800. org_id := c.GetAdminUserInfo().CurrentOrgId
  4801. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4802. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4803. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4804. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4805. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4806. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4807. var bedCostTotal float64 = 0 //床位总费
  4808. //var bedCostSelfTotal float64 = 0 //床位自费
  4809. var operationCostTotal float64 = 0 //手术费
  4810. //var operationCostSelfTotal float64 = 0 //手术费
  4811. var otherCostTotal float64 = 0 //其他费用
  4812. //var otherCostSelfTotal float64 = 0 //其他费用
  4813. var materialCostTotal float64 = 0 //材料费
  4814. //var materialCostSelfTotal float64 = 0 //材料费
  4815. var westernMedicineCostTotal float64 = 0 //西药费
  4816. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  4817. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4818. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4819. var checkCostTotal float64 = 0 //检查费
  4820. //var checkCostSelfTotal float64 = 0 //检查费
  4821. var laboratoryCostTotal float64 = 0 //化验费
  4822. //var laboratoryCostSelfTotal float64 = 0 //化验费
  4823. var treatCostTotal float64 = 0 //治疗费用
  4824. //var treatCostSelfTotal float64 = 0 //治疗费用
  4825. var zhenChaCostTotal float64 = 0 //其他费用
  4826. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4827. decimal.DivisionPrecision = 2
  4828. if his.BalanceAccountsType != 2 {
  4829. for _, item := range order_info {
  4830. if item.MedChrgitmType == "01" { //床位费
  4831. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4832. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4833. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4834. }
  4835. if item.MedChrgitmType == "02" { //诊察费
  4836. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4837. //zhenChaCostSelfTotal = zhenChaCostTotal
  4838. }
  4839. if item.MedChrgitmType == "03" { //检查费
  4840. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4841. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4842. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4843. }
  4844. if item.MedChrgitmType == "02" { //检查费
  4845. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4846. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4847. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4848. }
  4849. if item.MedChrgitmType == "04" { //化验费
  4850. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4851. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4852. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4853. }
  4854. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4855. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4856. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4857. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4858. }
  4859. if item.MedChrgitmType == "06" { //手术费
  4860. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4861. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4862. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4863. }
  4864. if item.MedChrgitmType == "08" { //材料费
  4865. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4866. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4867. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4868. }
  4869. if item.MedChrgitmType == "09" { //西药费
  4870. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4871. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4872. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4873. }
  4874. if item.MedChrgitmType == "11" { //中成费
  4875. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4876. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4877. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4878. }
  4879. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4880. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4881. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4882. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4883. }
  4884. }
  4885. c.ServeSuccessJSON(map[string]interface{}{
  4886. "order": order,
  4887. "order_info": order_info,
  4888. "patient": patient,
  4889. "admin_info": adminInfo,
  4890. "his_hospital": record,
  4891. "bedCostTotal": bedCostTotal,
  4892. "operationCostTotal": operationCostTotal,
  4893. "otherCostTotal": otherCostTotal,
  4894. "materialCostTotal": materialCostTotal,
  4895. "westernMedicineCostTotal": westernMedicineCostTotal,
  4896. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4897. "checkCostTotal": checkCostTotal,
  4898. "zhenChaCostTotal": zhenChaCostTotal,
  4899. "laboratoryCostTotal": laboratoryCostTotal,
  4900. "treatCostTotal": treatCostTotal,
  4901. })
  4902. } else {
  4903. for _, item := range order_info {
  4904. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4905. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4906. item.MedChrgitmType = "09"
  4907. }
  4908. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4909. if item.HisPrescriptionProject.Type == 2 {
  4910. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  4911. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4912. case 0:
  4913. item.MedChrgitmType = "0"
  4914. break
  4915. case 1:
  4916. item.MedChrgitmType = "14"
  4917. break
  4918. case 2:
  4919. item.MedChrgitmType = "05"
  4920. break
  4921. case 3:
  4922. item.MedChrgitmType = "03"
  4923. break
  4924. case 4:
  4925. item.MedChrgitmType = "03"
  4926. break
  4927. case 5:
  4928. item.MedChrgitmType = "08"
  4929. break
  4930. case 6:
  4931. item.MedChrgitmType = "14"
  4932. break
  4933. case 7:
  4934. item.MedChrgitmType = "14"
  4935. break
  4936. case 8:
  4937. item.MedChrgitmType = "03"
  4938. break
  4939. case 9:
  4940. item.MedChrgitmType = "14"
  4941. break
  4942. case 10:
  4943. item.MedChrgitmType = "14"
  4944. break
  4945. case 11:
  4946. item.MedChrgitmType = "06"
  4947. break
  4948. case 12:
  4949. item.MedChrgitmType = "12"
  4950. break
  4951. case 13:
  4952. item.MedChrgitmType = "01"
  4953. break
  4954. case 14:
  4955. item.MedChrgitmType = "04"
  4956. break
  4957. case 15:
  4958. item.MedChrgitmType = "14"
  4959. break
  4960. }
  4961. } else {
  4962. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4963. case 1:
  4964. item.MedChrgitmType = "14"
  4965. break
  4966. case 2:
  4967. item.MedChrgitmType = "05"
  4968. break
  4969. case 3:
  4970. item.MedChrgitmType = "04"
  4971. break
  4972. case 4:
  4973. item.MedChrgitmType = "14"
  4974. break
  4975. case 5:
  4976. item.MedChrgitmType = "08"
  4977. break
  4978. case 6:
  4979. item.MedChrgitmType = "14"
  4980. break
  4981. case 7:
  4982. item.MedChrgitmType = "14"
  4983. break
  4984. case 8:
  4985. item.MedChrgitmType = "03"
  4986. break
  4987. case 9:
  4988. item.MedChrgitmType = "14"
  4989. break
  4990. }
  4991. }
  4992. } else if item.HisPrescriptionProject.Type == 3 {
  4993. item.MedChrgitmType = "08"
  4994. }
  4995. }
  4996. }
  4997. c.ServeSuccessJSON(map[string]interface{}{
  4998. "order": order,
  4999. "order_info": order_info,
  5000. "patient": patient,
  5001. "admin_info": adminInfo,
  5002. "his_hospital": record,
  5003. "bedCostTotal": bedCostTotal,
  5004. "operationCostTotal": operationCostTotal,
  5005. "otherCostTotal": otherCostTotal,
  5006. "materialCostTotal": materialCostTotal,
  5007. "westernMedicineCostTotal": westernMedicineCostTotal,
  5008. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5009. "checkCostTotal": checkCostTotal,
  5010. "zhenChaCostTotal": zhenChaCostTotal,
  5011. "laboratoryCostTotal": laboratoryCostTotal,
  5012. "treatCostTotal": treatCostTotal,
  5013. })
  5014. }
  5015. }
  5016. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5017. page, _ := c.GetInt64("page")
  5018. limit, _ := c.GetInt64("limit")
  5019. keywords := c.GetString("keywords")
  5020. start_time := c.GetString("start_time")
  5021. end_time := c.GetString("end_time")
  5022. //clr_type := c.GetString("clr_type")
  5023. insutype := c.GetString("insutype")
  5024. timeLayout := "2006-01-02"
  5025. loc, _ := time.LoadLocation("Local")
  5026. var theStartTIme int64
  5027. if len(start_time) > 0 {
  5028. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5029. theStartTIme = theTime.Unix()
  5030. }
  5031. var theEndtTIme int64
  5032. if len(end_time) > 0 {
  5033. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5034. theEndtTIme = theTime.Unix()
  5035. }
  5036. if page <= 0 {
  5037. page = 1
  5038. }
  5039. if limit <= 0 {
  5040. limit = 10
  5041. }
  5042. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5043. c.ServeSuccessJSON(map[string]interface{}{
  5044. "total": total,
  5045. "list": list,
  5046. })
  5047. return
  5048. }
  5049. func (c *HisApiController) GetPutOnRecordList() {
  5050. page, _ := c.GetInt64("page")
  5051. limit, _ := c.GetInt64("limit")
  5052. keywords := c.GetString("keywords")
  5053. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5054. if page <= 0 {
  5055. page = 1
  5056. }
  5057. if limit <= 0 {
  5058. limit = 10
  5059. }
  5060. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5061. c.ServeSuccessJSON(map[string]interface{}{
  5062. "total": total,
  5063. "list": list,
  5064. })
  5065. return
  5066. }
  5067. func (c *HisApiController) GetCompareData() {
  5068. start_time := c.GetString("start_time")
  5069. end_time := c.GetString("end_time")
  5070. insutype := c.GetString("insutype")
  5071. clr_type := c.GetString("clr_type")
  5072. timeLayout := "2006-01-02"
  5073. loc, _ := time.LoadLocation("Local")
  5074. var theStartTIme int64
  5075. if len(start_time) > 0 {
  5076. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5077. if err != nil {
  5078. theStartTIme = 0
  5079. }
  5080. theStartTIme = theTime.Unix()
  5081. }
  5082. var theEndtTIme int64
  5083. if len(end_time) > 0 {
  5084. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5085. if err != nil {
  5086. theEndtTIme = 0
  5087. }
  5088. theEndtTIme = theTime.Unix()
  5089. }
  5090. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5091. fmt.Println(err)
  5092. if err == nil {
  5093. c.ServeSuccessJSON(map[string]interface{}{
  5094. "list": formData,
  5095. })
  5096. } else {
  5097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5098. return
  5099. }
  5100. }
  5101. func (c *HisApiController) GetFaPiaoData() {
  5102. order_id, _ := c.GetInt64("order_id")
  5103. patient_id, _ := c.GetInt64("patient_id")
  5104. number := c.GetString("number")
  5105. adminUser := c.GetAdminUserInfo()
  5106. order, _ := service.GetHisOrderByID(order_id)
  5107. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5108. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5109. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5110. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5111. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5112. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5113. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  5114. var bedCostTotal float64 = 0 //床位总费
  5115. var bedCostSelfTotal float64 = 0 //床位自费
  5116. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5117. var operationCostTotal float64 = 0 //手术费
  5118. var operationCostSelfTotal float64 = 0 //手术费
  5119. var operationCostPartSelfTotal float64 = 0 //手术费
  5120. var otherCostTotal float64 = 0 //其他费用
  5121. var otherCostSelfTotal float64 = 0 //其他费用
  5122. var otherCostPartSelfTotal float64 = 0 //其他费用
  5123. var materialCostTotal float64 = 0 //材料费
  5124. var materialCostSelfTotal float64 = 0 //材料费
  5125. var materialCostPartSelfTotal float64 = 0 //材料费
  5126. var westernMedicineCostTotal float64 = 0 //西药费
  5127. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5128. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5129. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5130. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5131. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5132. var checkCostTotal float64 = 0 //检查费
  5133. var checkCostSelfTotal float64 = 0 //检查费
  5134. var checkCostPartSelfTotal float64 = 0 //检查费
  5135. var laboratoryCostTotal float64 = 0 //化验费
  5136. var laboratoryCostSelfTotal float64 = 0 //化验费
  5137. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5138. var treatCostTotal float64 = 0 //治疗费用
  5139. var treatCostSelfTotal float64 = 0 //治疗费用
  5140. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5141. var zhenChaCostTotal float64 = 0 //其他费用
  5142. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5143. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5144. decimal.DivisionPrecision = 2
  5145. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5146. var balanceAccountsType int64
  5147. if his.ID > 0 {
  5148. balanceAccountsType = his.BalanceAccountsType
  5149. } else {
  5150. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5151. }
  5152. if balanceAccountsType == 2 {
  5153. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5154. for _, item := range orderInfos_two {
  5155. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5156. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5157. item.MedChrgitmType = "09"
  5158. }
  5159. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5160. if item.HisPrescriptionProject.Type == 2 {
  5161. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5162. fmt.Println("CostClassify")
  5163. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  5164. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5165. case 0:
  5166. item.MedChrgitmType = "0"
  5167. break
  5168. case 1:
  5169. item.MedChrgitmType = "14"
  5170. break
  5171. case 2:
  5172. item.MedChrgitmType = "05"
  5173. break
  5174. case 3:
  5175. item.MedChrgitmType = "03"
  5176. break
  5177. case 4:
  5178. item.MedChrgitmType = "03"
  5179. break
  5180. case 5:
  5181. item.MedChrgitmType = "08"
  5182. break
  5183. case 6:
  5184. item.MedChrgitmType = "14"
  5185. break
  5186. case 7:
  5187. item.MedChrgitmType = "14"
  5188. break
  5189. case 8:
  5190. item.MedChrgitmType = "03"
  5191. break
  5192. case 9:
  5193. item.MedChrgitmType = "14"
  5194. break
  5195. case 10:
  5196. item.MedChrgitmType = "14"
  5197. break
  5198. case 11:
  5199. item.MedChrgitmType = "06"
  5200. break
  5201. case 12:
  5202. item.MedChrgitmType = "12"
  5203. break
  5204. case 13:
  5205. item.MedChrgitmType = "01"
  5206. break
  5207. case 14:
  5208. item.MedChrgitmType = "04"
  5209. break
  5210. case 15:
  5211. item.MedChrgitmType = "02"
  5212. break
  5213. }
  5214. } else {
  5215. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5216. case 1:
  5217. item.MedChrgitmType = "14"
  5218. break
  5219. case 2:
  5220. item.MedChrgitmType = "05"
  5221. break
  5222. case 3:
  5223. item.MedChrgitmType = "03"
  5224. break
  5225. case 4:
  5226. item.MedChrgitmType = "03"
  5227. break
  5228. case 5:
  5229. item.MedChrgitmType = "08"
  5230. break
  5231. case 6:
  5232. item.MedChrgitmType = "14"
  5233. break
  5234. case 7:
  5235. item.MedChrgitmType = "14"
  5236. break
  5237. case 8:
  5238. item.MedChrgitmType = "03"
  5239. break
  5240. case 9:
  5241. item.MedChrgitmType = "14"
  5242. break
  5243. }
  5244. }
  5245. } else if item.HisPrescriptionProject.Type == 3 {
  5246. item.MedChrgitmType = "08"
  5247. }
  5248. }
  5249. }
  5250. for _, item := range orderInfos_two {
  5251. fmt.Println(item.MedChrgitmType)
  5252. if item.MedChrgitmType == "01" { //床位费
  5253. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5254. bedCostSelfTotal = bedCostTotal
  5255. }
  5256. if item.MedChrgitmType == "02" { //诊察费
  5257. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5258. zhenChaCostSelfTotal = zhenChaCostTotal
  5259. }
  5260. if item.MedChrgitmType == "03" { //检查费
  5261. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5262. checkCostSelfTotal = checkCostTotal
  5263. }
  5264. if item.MedChrgitmType == "04" { //化验费
  5265. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5266. laboratoryCostSelfTotal = laboratoryCostTotal
  5267. }
  5268. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5269. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5270. treatCostSelfTotal = treatCostTotal
  5271. }
  5272. if item.MedChrgitmType == "06" { //手术费
  5273. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5274. operationCostSelfTotal = treatCostTotal
  5275. }
  5276. if item.MedChrgitmType == "08" { //材料费
  5277. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5278. materialCostSelfTotal = materialCostTotal
  5279. }
  5280. if item.MedChrgitmType == "09" { //西药费
  5281. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5282. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5283. }
  5284. if item.MedChrgitmType == "11" { //中成费
  5285. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5286. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5287. }
  5288. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5289. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5290. otherCostSelfTotal = otherCostTotal
  5291. }
  5292. }
  5293. } else {
  5294. for _, item := range orderInfos {
  5295. if item.MedChrgitmType == "01" { //床位费
  5296. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5297. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5298. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5299. }
  5300. if item.MedChrgitmType == "02" { //诊察费
  5301. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5302. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5303. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5304. }
  5305. if item.MedChrgitmType == "03" { //检查费
  5306. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5307. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5308. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5309. }
  5310. if item.MedChrgitmType == "04" { //化验费
  5311. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5312. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5313. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5314. }
  5315. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5316. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5317. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5318. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5319. }
  5320. if item.MedChrgitmType == "06" { //手术费
  5321. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5322. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5323. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5324. }
  5325. if item.MedChrgitmType == "08" { //材料费
  5326. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5327. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5328. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5329. }
  5330. if item.MedChrgitmType == "09" { //西药费
  5331. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5332. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5333. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5334. }
  5335. if item.MedChrgitmType == "11" { //中成费
  5336. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5337. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5338. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5339. }
  5340. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5341. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5342. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5343. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5344. }
  5345. }
  5346. }
  5347. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5348. c.ServeSuccessJSON(map[string]interface{}{
  5349. "order_number": order.Number, //业务流水号
  5350. "id_card_no": his.IdCardNo, //社会保障号
  5351. "department_name": department.Name, //科室
  5352. "number": his.Number, //门诊号
  5353. "date": order.SettleAccountsDate, //结算日期
  5354. "name": order.PsnName, //姓名
  5355. "gender": order.Gend, //性别
  5356. "psn_cash_money": order.PsnCashPay, //个人支付
  5357. "pay_way": "门诊", //结算方式
  5358. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5359. "admin_user_name": admin.UserName, //收款员
  5360. "order": order,
  5361. "order_info": orderInfos_two,
  5362. "his": his,
  5363. "bedCostTotal": bedCostTotal,
  5364. "bedCostSelfTotal": bedCostSelfTotal,
  5365. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5366. "operationCostTotal": operationCostTotal,
  5367. "operationCostSelfTotal": operationCostSelfTotal,
  5368. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5369. "otherCostTotal": otherCostTotal,
  5370. "otherCostSelfTotal": otherCostSelfTotal,
  5371. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5372. "materialCostTotal": materialCostTotal,
  5373. "materialCostSelfTotal": materialCostSelfTotal,
  5374. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5375. "westernMedicineCostTotal": westernMedicineCostTotal,
  5376. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5377. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5378. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5379. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5380. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5381. "checkCostTotal": checkCostTotal,
  5382. "checkCostSelfTotal": checkCostSelfTotal,
  5383. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5384. "laboratoryCostTotal": laboratoryCostTotal,
  5385. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5386. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5387. "treatCostTotal": treatCostTotal,
  5388. "treatCostSelfTotal": treatCostSelfTotal,
  5389. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5390. "zhenChaCostTotal": zhenChaCostTotal,
  5391. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5392. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5393. "his_hospital_record": his_hospital_record,
  5394. "org_name": miConfig.OrgName,
  5395. })
  5396. }
  5397. func (this *HisApiController) GetIncomeStatisticsData() {
  5398. start_time := this.GetString("start_time")
  5399. end_time := this.GetString("end_time")
  5400. key_words := this.GetString("key_words")
  5401. limit, _ := this.GetInt64("limit")
  5402. page, _ := this.GetInt64("page")
  5403. if page <= 0 {
  5404. page = 1
  5405. }
  5406. if limit <= 0 {
  5407. limit = 10
  5408. }
  5409. statistics_type, _ := this.GetInt64("statistics_type")
  5410. admin := this.GetAdminUserInfo()
  5411. timeLayout := "2006-01-02"
  5412. loc, _ := time.LoadLocation("Local")
  5413. var theStartTIme int64
  5414. if len(start_time) > 0 {
  5415. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5416. if err != nil {
  5417. theStartTIme = 0
  5418. }
  5419. theStartTIme = theTime.Unix()
  5420. }
  5421. var theEndtTIme int64
  5422. if len(end_time) > 0 {
  5423. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5424. if err != nil {
  5425. theEndtTIme = 0
  5426. }
  5427. theEndtTIme = theTime.Unix()
  5428. }
  5429. if statistics_type == 1 {
  5430. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5431. this.ServeSuccessJSON(map[string]interface{}{
  5432. "list": list,
  5433. "total": total,
  5434. })
  5435. } else {
  5436. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5437. this.ServeSuccessJSON(map[string]interface{}{
  5438. "list": list,
  5439. "total": total,
  5440. })
  5441. }
  5442. }
  5443. func (c *HisApiController) PostProjectInformation() {
  5444. adminUser := c.GetAdminUserInfo()
  5445. orgId := adminUser.CurrentOrgId
  5446. dataBody := make(map[string]interface{}, 0)
  5447. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5448. if err != nil {
  5449. utils.ErrorLog(err.Error())
  5450. return
  5451. }
  5452. utils.ErrorLog("%v", dataBody)
  5453. var projectList []*models.HisProject
  5454. var total_goods []interface{}
  5455. tempProjects := dataBody["projects"].([]interface{})
  5456. total_goods = tempProjects
  5457. for index, projectMap := range tempProjects {
  5458. projectM := projectMap.(map[string]interface{})
  5459. var project models.HisProject
  5460. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  5461. utils.ErrorLog("project_name")
  5462. return
  5463. }
  5464. project_name, _ := projectM["project_name"].(string)
  5465. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  5466. err_log := models.ExportErrLog{
  5467. LogType: 6,
  5468. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5469. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  5470. Status: 1,
  5471. CreateTime: time.Now().Unix(),
  5472. UpdateTime: time.Now().Unix(),
  5473. ExportTime: time.Now().Unix(),
  5474. }
  5475. service.CreateExportErrLog(&err_log)
  5476. continue
  5477. }
  5478. project.ProjectName = project_name
  5479. prices := projectM["price"].(string)
  5480. price, _ := strconv.ParseFloat(prices, 64)
  5481. if price <= 0 { //名字为空则生成一条导入错误日志
  5482. err_log := models.ExportErrLog{
  5483. LogType: 6,
  5484. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5485. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  5486. Status: 1,
  5487. CreateTime: time.Now().Unix(),
  5488. UpdateTime: time.Now().Unix(),
  5489. ExportTime: time.Now().Unix(),
  5490. }
  5491. service.CreateExportErrLog(&err_log)
  5492. continue
  5493. }
  5494. project.Price = price
  5495. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  5496. utils.ErrorLog("unit_id")
  5497. return
  5498. }
  5499. unit := projectM["unit"].(string)
  5500. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  5501. err_log := models.ExportErrLog{
  5502. LogType: 6,
  5503. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5504. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  5505. Status: 1,
  5506. CreateTime: time.Now().Unix(),
  5507. UpdateTime: time.Now().Unix(),
  5508. ExportTime: time.Now().Unix(),
  5509. }
  5510. service.CreateExportErrLog(&err_log)
  5511. continue
  5512. }
  5513. project.Unit = unit
  5514. cost_classify := projectM["cost_classify"].(string)
  5515. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  5516. err_log := models.ExportErrLog{
  5517. LogType: 6,
  5518. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5519. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5520. Status: 1,
  5521. CreateTime: time.Now().Unix(),
  5522. UpdateTime: time.Now().Unix(),
  5523. ExportTime: time.Now().Unix(),
  5524. }
  5525. service.CreateExportErrLog(&err_log)
  5526. continue
  5527. }
  5528. var costClassify = "费用类别"
  5529. var cost_classify_id int64
  5530. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  5531. if len(cost_classify) != 0 {
  5532. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  5533. if errcode == gorm.ErrRecordNotFound {
  5534. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  5535. dataconfig := models.DictDataconfig{
  5536. ParentId: costClassifyConfig.ID,
  5537. Module: "system",
  5538. OrgId: orgId,
  5539. Name: cost_classify,
  5540. FieldName: "",
  5541. Value: costConfig.Value + 1,
  5542. CreatedTime: "",
  5543. UpdatedTime: "",
  5544. CreateUserId: adminUser.AdminUser.Id,
  5545. Status: 1,
  5546. Remark: "",
  5547. DeleteIdSystem: 0,
  5548. Title: "",
  5549. Content: "",
  5550. Order: 0,
  5551. Code: "",
  5552. }
  5553. service.CreatedDicConfig(&dataconfig)
  5554. }
  5555. }
  5556. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5557. for _, it := range costClassList {
  5558. if cost_classify == it.Name {
  5559. cost_classify_id = int64(it.Value)
  5560. }
  5561. }
  5562. project.CostClassify = cost_classify_id
  5563. executive_section := projectM["executive_section"].(string)
  5564. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5565. err_log := models.ExportErrLog{
  5566. LogType: 6,
  5567. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5568. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5569. Status: 1,
  5570. CreateTime: time.Now().Unix(),
  5571. UpdateTime: time.Now().Unix(),
  5572. ExportTime: time.Now().Unix(),
  5573. }
  5574. service.CreateExportErrLog(&err_log)
  5575. continue
  5576. }
  5577. if len(executive_section) != 0 {
  5578. //查找科室是否有内容
  5579. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5580. if errcodedepart == gorm.ErrRecordNotFound {
  5581. department := models.XtHisDepartment{
  5582. Name: executive_section,
  5583. Status: 1,
  5584. UserOrgId: adminUser.CurrentOrgId,
  5585. CreatedTime: time.Now().Unix(),
  5586. }
  5587. service.CreateDePartment(&department)
  5588. }
  5589. }
  5590. var executive_section_id int64
  5591. departMentList, _ := service.GetAllDepartMent(orgId)
  5592. for _, it := range departMentList {
  5593. if executive_section == it.Name {
  5594. executive_section_id = it.ID
  5595. }
  5596. }
  5597. project.ExecutiveSection = executive_section_id
  5598. medical_coverage := projectM["medical_coverage"].(string)
  5599. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5600. err_log := models.ExportErrLog{
  5601. LogType: 6,
  5602. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5603. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5604. Status: 1,
  5605. CreateTime: time.Now().Unix(),
  5606. UpdateTime: time.Now().Unix(),
  5607. ExportTime: time.Now().Unix(),
  5608. }
  5609. service.CreateExportErrLog(&err_log)
  5610. continue
  5611. }
  5612. var medicalCoverage = "医保等级"
  5613. var medical_coverage_id int64
  5614. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5615. if len(medical_coverage) != 0 {
  5616. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5617. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5618. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5619. dataconfig := models.DictDataconfig{
  5620. ParentId: medicalCoverageConfig.ID,
  5621. Module: "system",
  5622. OrgId: orgId,
  5623. Name: medical_coverage,
  5624. FieldName: "",
  5625. Value: medicalCoverageConfig.Value + 1,
  5626. CreatedTime: "",
  5627. UpdatedTime: "",
  5628. CreateUserId: adminUser.AdminUser.Id,
  5629. Status: 1,
  5630. Remark: "",
  5631. DeleteIdSystem: 0,
  5632. Title: "",
  5633. Content: "",
  5634. Order: 0,
  5635. Code: "",
  5636. }
  5637. service.CreatedDicConfig(&dataconfig)
  5638. }
  5639. }
  5640. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5641. for _, it := range medicalCoverageList {
  5642. if medical_coverage == it.Name {
  5643. medical_coverage_id = int64(it.Value)
  5644. }
  5645. }
  5646. project.MedicalCoverage = medical_coverage_id
  5647. pinyin := projectM["pinyin"].(string)
  5648. project.Pinyin = pinyin
  5649. wubi := projectM["wubi"].(string)
  5650. project.Wubi = wubi
  5651. statistical_classification := projectM["statistical_classification"].(string)
  5652. var statisticalClassification = "统计分类"
  5653. var statistical_classification_id int64
  5654. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5655. if len(statistical_classification) != 0 {
  5656. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5657. if classificationerrcodes == gorm.ErrRecordNotFound {
  5658. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5659. dataconfig := models.DictDataconfig{
  5660. ParentId: classiFication.ID,
  5661. Module: "system",
  5662. OrgId: orgId,
  5663. Name: statistical_classification,
  5664. FieldName: "",
  5665. Value: classiFicationConfig.Value + 1,
  5666. CreatedTime: "",
  5667. UpdatedTime: "",
  5668. CreateUserId: adminUser.AdminUser.Id,
  5669. Status: 1,
  5670. Remark: "",
  5671. DeleteIdSystem: 0,
  5672. Title: "",
  5673. Content: "",
  5674. Order: 0,
  5675. Code: "",
  5676. }
  5677. service.CreatedDicConfig(&dataconfig)
  5678. }
  5679. }
  5680. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5681. for _, it := range classiFicationList {
  5682. if statistical_classification == it.Name {
  5683. statistical_classification_id = int64(it.Value)
  5684. }
  5685. }
  5686. project.StatisticalClassification = statistical_classification_id
  5687. disease_directory := int64(projectM["disease_directory"].(float64))
  5688. project.DiseaseDirectory = disease_directory
  5689. is_record := int64(projectM["is_record"].(float64))
  5690. project.IsRecord = is_record
  5691. medical_code := projectM["medical_code"].(string)
  5692. project.MedicalCode = medical_code
  5693. tube_color := projectM["tube_color"].(string)
  5694. var tubeColor = "试管颜色"
  5695. var tube_color_id int64
  5696. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5697. if len(tube_color) != 0 {
  5698. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5699. if errcodetube == gorm.ErrRecordNotFound {
  5700. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5701. dataconfig := models.DictDataconfig{
  5702. ParentId: tubeColorConfig.ID,
  5703. Module: "system",
  5704. OrgId: orgId,
  5705. Name: tube_color,
  5706. FieldName: "",
  5707. Value: tubeConfig.Value + 1,
  5708. CreatedTime: "",
  5709. UpdatedTime: "",
  5710. CreateUserId: adminUser.AdminUser.Id,
  5711. Status: 1,
  5712. Remark: "",
  5713. DeleteIdSystem: 0,
  5714. Title: "",
  5715. Content: "",
  5716. Order: 0,
  5717. Code: "",
  5718. }
  5719. service.CreatedDicConfig(&dataconfig)
  5720. }
  5721. }
  5722. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5723. for _, it := range tubeColorList {
  5724. if tube_color == it.Name {
  5725. tube_color_id = int64(it.Value)
  5726. }
  5727. }
  5728. project.TubeColor = tube_color_id
  5729. single_dose := projectM["single_dose"].(string)
  5730. project.SingleDose = single_dose
  5731. execution_frequency := projectM["execution_frequency"].(string)
  5732. project.ExecutionFrequency = execution_frequency
  5733. delivery_way := projectM["delivery_way"].(string)
  5734. project.DeliveryWay = delivery_way
  5735. number_days := projectM["number_days"].(string)
  5736. project.NumberDays = number_days
  5737. total := projectM["total"].(string)
  5738. project.Total = total
  5739. medical_status := int64(projectM["medical_status"].(float64))
  5740. project.MedicalStatus = medical_status
  5741. category := int64(projectM["category"].(float64))
  5742. project.Category = category
  5743. specail_project := int64(projectM["specail_project"].(float64))
  5744. project.SpecailProject = specail_project
  5745. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5746. project.SocialSecurityDirectoryCode = social_security_directory_code
  5747. remark := projectM["remark"].(string)
  5748. project.Remark = remark
  5749. record_date := projectM["record_date"].(string)
  5750. timeLayout := "2006-01-02"
  5751. loc, _ := time.LoadLocation("Local")
  5752. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5753. project.RecordDate = theTime.Unix()
  5754. projectList = append(projectList, &project)
  5755. }
  5756. export_time := time.Now().Unix()
  5757. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5758. if len(projectList) > 0 {
  5759. for _, item := range projectList {
  5760. project := models.HisProject{
  5761. ProjectName: item.ProjectName,
  5762. Price: item.Price,
  5763. Unit: item.Unit,
  5764. CostClassify: item.CostClassify,
  5765. ExecutiveSection: item.ExecutiveSection,
  5766. MedicalCoverage: item.MedicalCoverage,
  5767. UserOrgId: orgId,
  5768. Status: 1,
  5769. CreatedTime: time.Now().Unix(),
  5770. Pinyin: item.Pinyin,
  5771. Wubi: item.Wubi,
  5772. StatisticalClassification: item.StatisticalClassification,
  5773. DiseaseDirectory: item.DiseaseDirectory,
  5774. IsRecord: item.IsRecord,
  5775. MedicalCode: item.MedicalCode,
  5776. TubeColor: item.TubeColor,
  5777. SingleDose: item.SingleDose,
  5778. DeliveryWay: item.DeliveryWay,
  5779. NumberDays: item.NumberDays,
  5780. Total: item.Total,
  5781. Category: item.Category,
  5782. MedicalStatus: item.MedicalStatus,
  5783. SpecailProject: item.SpecailProject,
  5784. RecordDate: item.RecordDate,
  5785. Remark: item.Remark,
  5786. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5787. ExecutionFrequency: item.ExecutionFrequency,
  5788. }
  5789. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5790. if errcodeproject == gorm.ErrRecordNotFound {
  5791. service.CreateProjectInfomation(&project)
  5792. } else if errcodeproject == nil {
  5793. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5794. }
  5795. log := models.ExportLog{
  5796. LogType: 6,
  5797. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5798. TotalNum: int64(len(total_goods)),
  5799. FailNum: int64(len(errLogs)),
  5800. SuccessNum: int64(len(projectList)),
  5801. CreateTime: time.Now().Unix(),
  5802. UpdateTime: time.Now().Unix(),
  5803. ExportTime: export_time,
  5804. Status: 1,
  5805. }
  5806. service.CreateExportLog(&log)
  5807. c.ServeSuccessJSON(map[string]interface{}{
  5808. "msg": "导入成功",
  5809. "total_num": len(total_goods),
  5810. "success_num": len(projectList),
  5811. "fail_num": int64(len(errLogs)),
  5812. })
  5813. }
  5814. } else {
  5815. log := models.ExportLog{
  5816. LogType: 6,
  5817. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5818. TotalNum: int64(len(total_goods)),
  5819. FailNum: int64(len(errLogs)),
  5820. SuccessNum: int64(len(projectList)),
  5821. CreateTime: time.Now().Unix(),
  5822. UpdateTime: time.Now().Unix(),
  5823. ExportTime: export_time,
  5824. Status: 1,
  5825. }
  5826. service.CreateExportLog(&log)
  5827. c.ServeSuccessJSON(map[string]interface{}{
  5828. "msg": "导入成功",
  5829. "total_num": len(total_goods),
  5830. "success_num": len(projectList),
  5831. "fail_num": int64(len(errLogs)),
  5832. })
  5833. }
  5834. }
  5835. //func (this *HisApiController) EditProjectInformation(){
  5836. //
  5837. // id, _ := this.GetInt64("id")
  5838. // project_team := this.GetString("project_team")
  5839. // price := this.GetString("price")
  5840. // price_float, _ := strconv.ParseFloat(price, 64)
  5841. // pinyin := this.GetString("pinyin")
  5842. // wubi := this.GetString("wubi")
  5843. // tube_color, _ := this.GetInt64("tube_color")
  5844. // team_type, _ := this.GetInt64("team_type")
  5845. // remark := this.GetString("remark")
  5846. // ids := this.GetString("ids")
  5847. // item_id := this.GetString("item_id")
  5848. // projectTeam := models.XtHisProjectTeam{
  5849. // ProjectTeam: project_team,
  5850. // Price: price_float,
  5851. // Pinyin: pinyin,
  5852. // Wubi: wubi,
  5853. // TubeColor: tube_color,
  5854. // TeamType: team_type,
  5855. // Remark: remark,
  5856. // ProjectId: ids,
  5857. // ItemId: item_id,
  5858. // }
  5859. //
  5860. //
  5861. // dataBody := make(map[string]interface{}, 0)
  5862. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5863. // if err != nil {
  5864. // utils.ErrorLog(err.Error())
  5865. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5866. // return
  5867. // }
  5868. //
  5869. // err = service.UpdatedProjectTeam(id, &projectTeam)
  5870. //
  5871. //
  5872. // if err != nil {
  5873. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5874. // return
  5875. // }
  5876. //
  5877. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  5878. // infos, _ := dataBody["info"].([]interface{})
  5879. // if len(infos) > 0 {
  5880. // var ids []string
  5881. //
  5882. // for _, item := range infos {
  5883. // items := item.(map[string]interface{})
  5884. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5885. // utils.ErrorLog("id")
  5886. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5887. // return
  5888. // }
  5889. // id := int64(items["id"].(float64))
  5890. //
  5891. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5892. // utils.ErrorLog("type")
  5893. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5894. // return
  5895. // }
  5896. // types := int64(items["type"].(float64))
  5897. //
  5898. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5899. // utils.ErrorLog("number")
  5900. // }
  5901. //
  5902. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  5903. //
  5904. // projectList := models.XtHisProjectList{
  5905. // Number: number,
  5906. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  5907. // ProjectId: id,
  5908. // Status: 1,
  5909. // CreatedTime: time.Now().Unix(),
  5910. // UpdatedTime: time.Now().Unix(),
  5911. // TeamId: projectTeam.ID,
  5912. // Type: types,
  5913. // }
  5914. // list := projectList
  5915. //
  5916. // service.CreateProjectList(&list)
  5917. //
  5918. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  5919. //
  5920. // }
  5921. // ids_str := strings.Join(ids, ",")
  5922. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  5923. // service.SaveProjectTeam(&projectTeam)
  5924. // this.ServeSuccessJSON(map[string]interface{}{
  5925. // "projectTeam": projectTeam,
  5926. // })
  5927. // }
  5928. // }
  5929. //}
  5930. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  5931. name := c.GetString("name")
  5932. mode_id, _ := c.GetInt64("mode", 0)
  5933. types, _ := c.GetInt64("type", 0)
  5934. patient_id, _ := c.GetInt64("patient_id", 0)
  5935. types = 1
  5936. adminInfo := c.GetAdminUserInfo()
  5937. template := &models.HisPrescriptionTemplate{
  5938. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5939. PatientId: patient_id,
  5940. Type: types,
  5941. Status: 1,
  5942. Ctime: time.Now().Unix(),
  5943. Mtime: time.Now().Unix(),
  5944. Name: name,
  5945. Mode: mode_id,
  5946. }
  5947. dataBody := make(map[string]interface{}, 0)
  5948. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5949. if err != nil {
  5950. utils.ErrorLog(err.Error())
  5951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5952. return
  5953. }
  5954. err = service.CreateHisPrescriptionTemplate(template)
  5955. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5956. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5957. if len(prescriptions) > 0 {
  5958. for _, item := range prescriptions {
  5959. items := item.(map[string]interface{})
  5960. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5961. utils.ErrorLog("type")
  5962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5963. return
  5964. }
  5965. types := int64(items["type"].(float64))
  5966. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5967. utils.ErrorLog("med_type")
  5968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5969. return
  5970. }
  5971. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5972. ctime := time.Now().Unix()
  5973. prescription := &models.HisPrescriptionInfoTemplate{
  5974. PatientId: patient_id,
  5975. UserOrgId: adminInfo.CurrentOrgId,
  5976. Ctime: ctime,
  5977. Mtime: ctime,
  5978. Type: types,
  5979. Modifier: adminInfo.AdminUser.Id,
  5980. Creator: adminInfo.AdminUser.Id,
  5981. Status: 1,
  5982. PTemplateId: template.ID,
  5983. MedType: med_type,
  5984. }
  5985. service.CreateHisPrescriptionInfoTemplate(prescription)
  5986. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5987. advices := items["advices"].([]interface{})
  5988. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5989. ctime := time.Now().Unix()
  5990. mtime := ctime
  5991. if len(advices) > 0 {
  5992. for _, advice := range advices {
  5993. var s models.HisPrescriptionAdviceTemplate
  5994. s.PrescriptionId = prescription.ID
  5995. s.AdviceType = 2
  5996. s.StopState = 2
  5997. s.ExecutionState = 2
  5998. s.Status = 1
  5999. s.UserOrgId = adminInfo.CurrentOrgId
  6000. s.CreatedTime = ctime
  6001. s.UpdatedTime = mtime
  6002. s.PatientId = patient_id
  6003. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6004. if errcode > 0 {
  6005. c.ServeFailJSONWithSGJErrorCode(errcode)
  6006. return
  6007. }
  6008. service.CreateHisPrescriptionAdviceTemplate(&s)
  6009. }
  6010. }
  6011. }
  6012. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6013. projects := items["project"].([]interface{})
  6014. if len(projects) > 0 {
  6015. for _, project := range projects {
  6016. var p models.HisPrescriptionProjectTemplate
  6017. p.PrescriptionId = prescription.ID
  6018. p.Ctime = time.Now().Unix()
  6019. p.Mtime = time.Now().Unix()
  6020. p.PatientId = patient_id
  6021. p.UserOrgId = adminInfo.CurrentOrgId
  6022. p.Status = 1
  6023. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6024. if errcode > 0 {
  6025. c.ServeFailJSONWithSGJErrorCode(errcode)
  6026. return
  6027. }
  6028. service.CreateHisPrescriptionProjectTemplate(&p)
  6029. }
  6030. }
  6031. }
  6032. }
  6033. c.ServeSuccessJSON(map[string]interface{}{
  6034. "msg": "创建成功",
  6035. })
  6036. }
  6037. }
  6038. }
  6039. func (c *HisApiController) PreSettle() {
  6040. id, _ := c.GetInt64("id")
  6041. record_time := c.GetString("record_time")
  6042. his_patient_id, _ := c.GetInt64("his_patient_id")
  6043. timeLayout := "2006-01-02"
  6044. loc, _ := time.LoadLocation("Local")
  6045. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6046. diagnosis_id := c.GetString("diagnosis")
  6047. sick_type, _ := c.GetInt64("sick_type")
  6048. reg_type, _ := c.GetInt64("p_type")
  6049. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6050. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6051. if err != nil {
  6052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6053. return
  6054. }
  6055. recordDateTime := theTime.Unix()
  6056. adminUser := c.GetAdminUserInfo()
  6057. var prescriptions []*models.HisPrescription
  6058. var start_time int64
  6059. var end_time int64
  6060. ids_str := c.GetString("ids")
  6061. ids_arr := strings.Split(ids_str, ",")
  6062. fmt.Println(reg_type)
  6063. if settle_accounts_type == 1 { //日结
  6064. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6065. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6066. } else {
  6067. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6068. }
  6069. fmt.Println(prescriptions)
  6070. } else { //月结
  6071. start_time_str := c.GetString("start_time")
  6072. end_time_str := c.GetString("end_time")
  6073. timeLayout := "2006-01-02"
  6074. loc, _ := time.LoadLocation("Local")
  6075. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6076. if err != nil {
  6077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6078. return
  6079. }
  6080. recordStartTime := theStartTime.Unix()
  6081. start_time = recordStartTime
  6082. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6083. if err != nil {
  6084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6085. return
  6086. }
  6087. recordEndTime := theEndTime.Unix()
  6088. end_time = recordEndTime
  6089. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6090. }
  6091. if reg_type == 1111 || reg_type == 1112 {
  6092. reg_type = 11
  6093. }
  6094. timestamp := time.Now().Unix()
  6095. tempTime := time.Unix(timestamp, 0)
  6096. timeFormat := tempTime.Format("20060102150405")
  6097. chrgBchno := rand.Intn(100000) + 10000
  6098. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6099. strconv.FormatInt(his.PatientId, 10)
  6100. var ids []int64
  6101. for _, item := range prescriptions {
  6102. ids = append(ids, item.ID)
  6103. }
  6104. fmt.Println(ids)
  6105. var total float64
  6106. for _, item := range prescriptions {
  6107. fmt.Println(item)
  6108. if item.Type == 1 { //药品
  6109. for _, subItem := range item.HisDoctorAdviceInfo {
  6110. total = total + (subItem.Price * subItem.PrescribingNumber)
  6111. }
  6112. }
  6113. if item.Type == 2 { //项目
  6114. for _, subItem := range item.HisPrescriptionProject {
  6115. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6116. total = total + (subItem.Price * cnt)
  6117. }
  6118. }
  6119. for _, subItem := range item.HisAdditionalCharge {
  6120. total = total + (subItem.Price * float64(subItem.Count))
  6121. }
  6122. }
  6123. allTotal := fmt.Sprintf("%.2f", total)
  6124. totals, _ := strconv.ParseFloat(allTotal, 64)
  6125. order := &models.HisOrder{
  6126. UserOrgId: adminUser.CurrentOrgId,
  6127. HisPatientId: his.ID,
  6128. PatientId: id,
  6129. SettleAccountsDate: recordDateTime,
  6130. Ctime: time.Now().Unix(),
  6131. Mtime: time.Now().Unix(),
  6132. Status: 1,
  6133. OrderStatus: 1,
  6134. MdtrtId: his.Number,
  6135. Number: chrg_bchno,
  6136. MedfeeSumamt: totals,
  6137. SettleEndTime: end_time,
  6138. SettleStartTime: start_time,
  6139. SettleType: settle_accounts_type,
  6140. PType: 2,
  6141. IsPre: 1,
  6142. MedType: strconv.Itoa(int(reg_type)),
  6143. Diagnosis: diagnosis_id,
  6144. }
  6145. err = service.CreateOrder(order)
  6146. if err != nil {
  6147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6148. return
  6149. }
  6150. var customs []*Custom
  6151. for _, item := range prescriptions {
  6152. fmt.Println(item.Type)
  6153. if item.Type == 1 { //药品
  6154. for _, subItem := range item.HisDoctorAdviceInfo {
  6155. cus := &Custom{
  6156. AdviceId: subItem.ID,
  6157. ProjectId: 0,
  6158. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6159. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6160. FeedetlSn: subItem.FeedetlSn,
  6161. Price: fmt.Sprintf("%.2f", subItem.Price),
  6162. MedListCodg: subItem.MedListCodg,
  6163. Type: 1,
  6164. }
  6165. customs = append(customs, cus)
  6166. }
  6167. }
  6168. if item.Type == 2 { //项目
  6169. for _, subItem := range item.HisPrescriptionProject {
  6170. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6171. cus := &Custom{
  6172. AdviceId: 0,
  6173. ProjectId: subItem.ID,
  6174. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6175. Cut: fmt.Sprintf("%.2f", cnt),
  6176. FeedetlSn: subItem.FeedetlSn,
  6177. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6178. MedListCodg: subItem.MedListCodg,
  6179. Type: 2,
  6180. }
  6181. customs = append(customs, cus)
  6182. }
  6183. }
  6184. for _, item := range item.HisAdditionalCharge {
  6185. cus := &Custom{
  6186. ItemId: item.ID,
  6187. AdviceId: 0,
  6188. ProjectId: 0,
  6189. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6190. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6191. FeedetlSn: item.FeedetlSn,
  6192. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6193. MedListCodg: item.XtHisAddtionConfig.Code,
  6194. Type: 3,
  6195. }
  6196. customs = append(customs, cus)
  6197. }
  6198. }
  6199. fmt.Println(customs)
  6200. for _, item := range customs {
  6201. var advice_id int64 = 0
  6202. var project_id int64 = 0
  6203. var item_id int64 = 0
  6204. var types int64 = 0
  6205. if item.Type == 1 {
  6206. advice_id = item.AdviceId
  6207. project_id = 0
  6208. item_id = 0
  6209. } else if item.Type == 2 {
  6210. advice_id = 0
  6211. item_id = 0
  6212. project_id = item.ProjectId
  6213. } else if item.Type == 3 {
  6214. advice_id = 0
  6215. item_id = item.ItemId
  6216. project_id = 0
  6217. }
  6218. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6219. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6220. pric, _ := strconv.ParseFloat(item.Price, 32)
  6221. info := &models.HisOrderInfo{
  6222. OrderNumber: order.Number,
  6223. UploadDate: time.Now().Unix(),
  6224. AdviceId: advice_id,
  6225. DetItemFeeSumamt: detItemFeeSumamt,
  6226. Cnt: cut,
  6227. Pric: pric,
  6228. PatientId: id,
  6229. Status: 1,
  6230. Mtime: time.Now().Unix(),
  6231. Ctime: time.Now().Unix(),
  6232. UserOrgId: adminUser.CurrentOrgId,
  6233. HisPatientId: his.ID,
  6234. OrderId: order.ID,
  6235. ProjectId: project_id,
  6236. Type: types,
  6237. ItemId: item_id,
  6238. }
  6239. service.CreateOrderInfo(info)
  6240. }
  6241. his.SickType = sick_type
  6242. service.UpdataHisPateint(&his)
  6243. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6244. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6245. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6246. if err == nil {
  6247. c.ServeSuccessJSON(map[string]interface{}{
  6248. "msg": "结算成功",
  6249. })
  6250. }
  6251. }
  6252. type CustomOrderInfo struct {
  6253. Name string
  6254. Spec string
  6255. Unit string
  6256. Count float64
  6257. Price float64
  6258. Total float64
  6259. }
  6260. func (c *HisApiController) GetPrivateExpensesInfo() {
  6261. order_id, _ := c.GetInt64("id", 0)
  6262. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6263. order, _ := service.GetHisOrderByID(order_id)
  6264. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6265. if order.ID == 0 {
  6266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6267. return
  6268. }
  6269. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6270. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6271. org_id := c.GetAdminUserInfo().CurrentOrgId
  6272. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6273. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6274. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6275. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6276. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6277. var orderInfos_four []*models.HisOrderInfoTwo
  6278. for _, item := range orderInfos_three {
  6279. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6280. item.HisPrescriptionProject.IsCheckTeam = 1
  6281. orderInfos_four = append(orderInfos_four, item)
  6282. }
  6283. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6284. item.HisPrescriptionProject.IsCheckTeam = 2
  6285. orderInfos_two = append(orderInfos_two, item)
  6286. }
  6287. }
  6288. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6289. var cus_slice []CustomOrderInfo
  6290. for _, item := range new_order_info {
  6291. var cus CustomOrderInfo
  6292. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6293. cus.Unit = ""
  6294. cus.Spec = ""
  6295. var total float64
  6296. for _, subItem := range orderInfos_four {
  6297. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6298. total = total + subItem.DetItemFeeSumamt
  6299. fmt.Println(subItem.DetItemFeeSumamt)
  6300. }
  6301. }
  6302. cus.Count = 1
  6303. cus.Total = total
  6304. cus_slice = append(cus_slice, cus)
  6305. }
  6306. orderInfos = append(orderInfos, orderInfos_two...)
  6307. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6308. orderInfos = append(orderInfos, orderInfos_three...)
  6309. }
  6310. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6311. c.ServeSuccessJSON(map[string]interface{}{
  6312. "order": order,
  6313. "order_info": orderInfos,
  6314. "patient": patient,
  6315. "admin_info": adminInfo,
  6316. "his": his,
  6317. "current_admin": role,
  6318. "org_config": miConfig,
  6319. "new_order_info": cus_slice,
  6320. })
  6321. }
  6322. func (this *HisApiController) ChangeMedType() {
  6323. med_type := this.GetString("med_type")
  6324. old_med_type := this.GetString("old_med_type")
  6325. ids := this.GetString("ids")
  6326. settle_type, _ := this.GetInt64("settle_type")
  6327. start_time := this.GetString("start_time")
  6328. end_time := this.GetString("end_time")
  6329. ids_arr := strings.Split(ids, ",")
  6330. if settle_type == 1 { //日结
  6331. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6332. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6333. prescription.MedType = med_type
  6334. err := service.SaveHisPrescription(&prescription)
  6335. if err == nil {
  6336. this.ServeSuccessJSON(map[string]interface{}{
  6337. "msg": "修改成功",
  6338. })
  6339. } else {
  6340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6341. return
  6342. }
  6343. } else if settle_type == 2 {
  6344. timeLayout := "2006-01-02"
  6345. loc, _ := time.LoadLocation("Local")
  6346. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6347. if err != nil {
  6348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6349. return
  6350. }
  6351. recordStartTime := theStartTime.Unix()
  6352. start_time_timestamp := recordStartTime
  6353. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6354. if err != nil {
  6355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6356. return
  6357. }
  6358. recordEndTime := theEndTime.Unix()
  6359. end_time_timestamp := recordEndTime
  6360. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6361. if updateErr == nil {
  6362. this.ServeSuccessJSON(map[string]interface{}{
  6363. "msg": "修改成功",
  6364. })
  6365. } else {
  6366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6367. return
  6368. }
  6369. }
  6370. }
  6371. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6372. patient_id, _ := c.GetInt64("patient_id")
  6373. his_patient_id, _ := c.GetInt64("his_patient_id")
  6374. record_date := c.GetString("record_date")
  6375. start_time := c.GetString("start_time")
  6376. end_time := c.GetString("end_time")
  6377. order_status, _ := c.GetInt64("type", 0)
  6378. p_type, _ := c.GetInt64("p_type", 0)
  6379. order_id, _ := c.GetInt64("order_id", 0)
  6380. timeLayout := "2006-01-02"
  6381. loc, _ := time.LoadLocation("Local")
  6382. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6383. if err != nil {
  6384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6385. return
  6386. }
  6387. recordDateTime := theTime.Unix()
  6388. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6389. if err != nil {
  6390. }
  6391. startRecordDateTime := startTime.Unix()
  6392. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6393. if err != nil {
  6394. }
  6395. endRecordDateTime := endTime.Unix()
  6396. admin := c.GetAdminUserInfo()
  6397. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6398. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6399. order, _ := service.GetHisOrderByID(order_id)
  6400. var monthPrescriptions []*models.HisPrescription
  6401. if order_status == 1 || order_status == 0 {
  6402. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6403. } else if order_status == 2 {
  6404. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6405. }
  6406. var settle_total float64
  6407. for _, item := range monthPrescriptions {
  6408. if len(item.HisPrescriptionProject) > 0 {
  6409. for _, subItem := range item.HisPrescriptionProject {
  6410. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6411. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6412. settle_total = settle_total + total
  6413. }
  6414. }
  6415. if len(item.HisDoctorAdviceInfo) > 0 {
  6416. for _, subItem := range item.HisDoctorAdviceInfo {
  6417. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6418. settle_total = settle_total + total
  6419. }
  6420. }
  6421. }
  6422. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6423. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6424. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6425. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6426. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6427. //获取所有科室信息
  6428. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6429. c.ServeSuccessJSON(map[string]interface{}{
  6430. "his_info": his_patient_info,
  6431. "xt_info": xt_patient_info,
  6432. "case_history": case_history,
  6433. "info": patientPrescriptionInfo,
  6434. "last_info": lastPatientPrescriptionInfo,
  6435. "month_prescriptions": monthPrescriptions,
  6436. "order": order,
  6437. "doctors": doctors,
  6438. "department": department,
  6439. "settle_total": settle_total,
  6440. })
  6441. return
  6442. }
  6443. func (c *HisApiController) GetHisMonthPatientInfo() {
  6444. patient_id, _ := c.GetInt64("patient_id")
  6445. his_patient_id, _ := c.GetInt64("his_patient_id")
  6446. record_date := c.GetString("record_date")
  6447. number := c.GetString("number")
  6448. start_time := c.GetString("start_time")
  6449. end_time := c.GetString("end_time")
  6450. p_type, _ := c.GetInt64("p_type")
  6451. timeLayout := "2006-01-02"
  6452. loc, _ := time.LoadLocation("Local")
  6453. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6454. if err != nil {
  6455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6456. return
  6457. }
  6458. recordDateTime := theTime.Unix()
  6459. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6460. if err != nil {
  6461. }
  6462. startRecordDateTime := startTime.Unix()
  6463. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6464. if err != nil {
  6465. }
  6466. endRecordDateTime := endTime.Unix()
  6467. admin := c.GetAdminUserInfo()
  6468. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  6469. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6470. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  6471. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6472. var settle_total float64
  6473. for _, item := range monthPrescriptions {
  6474. if len(item.HisPrescriptionProject) > 0 {
  6475. for _, subItem := range item.HisPrescriptionProject {
  6476. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6477. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6478. settle_total = settle_total + total
  6479. }
  6480. }
  6481. if len(item.HisDoctorAdviceInfo) > 0 {
  6482. for _, subItem := range item.HisDoctorAdviceInfo {
  6483. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6484. settle_total = settle_total + total
  6485. }
  6486. }
  6487. }
  6488. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6489. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6490. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6491. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6492. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  6493. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6494. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  6495. //获取所有科室信息
  6496. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6497. c.ServeSuccessJSON(map[string]interface{}{
  6498. "his_info": his_patient_info,
  6499. "xt_info": xt_patient_info,
  6500. "case_history": case_history,
  6501. "info": patientPrescriptionInfo,
  6502. "month_prescriptions": monthPrescriptions,
  6503. "order": order,
  6504. "doctors": doctors,
  6505. "department": department,
  6506. "count": count,
  6507. "drugStockConfig": drugStockConfig,
  6508. "last_info": lastPatientPrescriptionInfo,
  6509. "settle_total": settle_total,
  6510. })
  6511. return
  6512. }
  6513. func (c *HisApiController) GetAllOrder() {
  6514. org_id := c.GetAdminUserInfo().CurrentOrgId
  6515. orders, _ := service.GetNewHisOrderList(org_id)
  6516. c.ServeSuccessJSON(map[string]interface{}{
  6517. "order": orders,
  6518. })
  6519. return
  6520. }
  6521. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  6522. newArr = make([]*models.HisOrderInfoTwo, 0)
  6523. for i := 0; i < len(arr); i++ {
  6524. repeat := false
  6525. for j := i + 1; j < len(arr); j++ {
  6526. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6527. repeat = true
  6528. break
  6529. }
  6530. }
  6531. if !repeat {
  6532. newArr = append(newArr, arr[i])
  6533. }
  6534. }
  6535. return
  6536. }
  6537. //修改处方退库操作 参数传修改之前的处方数据
  6538. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  6539. if advice.ExecutionState == 1 {
  6540. //查询该病人该药品是否有库存记录
  6541. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  6542. if errcode == gorm.ErrRecordNotFound {
  6543. } else {
  6544. //退库
  6545. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6546. if advice.PrescribingNumberUnit == drug.MinUnit {
  6547. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6548. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6549. //退库
  6550. warehouseInfo := models.DrugWarehouseInfo{
  6551. StockMinNumber: prescribingNumber,
  6552. }
  6553. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  6554. operation_time := time.Now().Unix()
  6555. creater := advice.AdviceDoctor
  6556. ctime := time.Now().Unix()
  6557. timeStr := time.Now().Format("2006-01-02")
  6558. timeArr := strings.Split(timeStr, "-")
  6559. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6560. total = total + 1
  6561. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6562. cancelStock := models.DrugCancelStock{
  6563. OrderNumber: orderNumber,
  6564. OperaTime: operation_time,
  6565. OrgId: advice.UserOrgId,
  6566. Creater: creater,
  6567. Ctime: ctime,
  6568. Status: 1,
  6569. ReturnTime: advice.AdviceDate,
  6570. Dealer: info.Dealer,
  6571. Manufacturer: info.Manufacturer,
  6572. Type: 1,
  6573. }
  6574. service.AddSigleDrugCancelStock(&cancelStock)
  6575. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6576. dealer, _ := service.GetDealerById(info.Dealer)
  6577. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6578. cancelStockInfo := models.DrugCancelStockInfo{
  6579. OrderNumber: cancelInfo.OrderNumber,
  6580. CancelStockId: cancelInfo.ID,
  6581. DrugId: info.DrugId,
  6582. Count: info.Count,
  6583. Status: 1,
  6584. Ctime: ctime,
  6585. OrgId: advice.UserOrgId,
  6586. Type: 1,
  6587. Manufacturer: manufactureName.ManufacturerName,
  6588. Dealer: dealer.DealerName,
  6589. Total: 0,
  6590. RetailPrice: info.RetailPrice,
  6591. RetailTotalPrice: info.RetailTotalPrice,
  6592. Price: info.Price,
  6593. RegisterAccount: "",
  6594. Remark: info.Remark,
  6595. BatchNumber: info.BatchNumber,
  6596. MaxUnit: info.CountUnit,
  6597. ProductDate: info.ProductDate,
  6598. ExpiryDate: info.ExpiryDate,
  6599. BatchNumberId: info.WarehouseInfoId,
  6600. }
  6601. flow := models.DrugFlow{
  6602. WarehousingId: 0,
  6603. DrugId: info.DrugId,
  6604. Number: "",
  6605. BatchNumber: info.BatchNumber,
  6606. Count: info.Count,
  6607. UserOrgId: advice.UserOrgId,
  6608. PatientId: 0,
  6609. SystemTime: ctime,
  6610. ConsumableType: 4,
  6611. IsSys: 0,
  6612. WarehousingOrder: "",
  6613. WarehouseOutId: 0,
  6614. WarehouseOutOrderNumber: "",
  6615. IsEdit: 0,
  6616. CancelStockId: cancelStock.ID,
  6617. CancelOrderNumber: cancelStock.OrderNumber,
  6618. Manufacturer: info.Manufacturer,
  6619. Dealer: info.Dealer,
  6620. Creator: advice.UserOrgId,
  6621. UpdateCreator: 0,
  6622. Status: 1,
  6623. Ctime: time.Now().Unix(),
  6624. Mtime: 0,
  6625. Price: info.Price,
  6626. WarehousingDetailId: 0,
  6627. WarehouseOutDetailId: 0,
  6628. CancelOutDetailId: 0,
  6629. ExpireDate: info.ExpiryDate,
  6630. ProductDate: info.ProductDate,
  6631. MaxUnit: info.CountUnit,
  6632. MinUnit: "",
  6633. }
  6634. service.CreatedCancelStock(cancelStockInfo)
  6635. service.CreateDrugFlowOne(flow)
  6636. } else {
  6637. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6638. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6639. if advice.PrescribingNumberUnit == drug.MaxUnit {
  6640. warehouseInfo := models.DrugWarehouseInfo{
  6641. StockMinNumber: prescribingNumber,
  6642. }
  6643. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  6644. }
  6645. operation_time := time.Now().Unix()
  6646. creater := advice.AdviceDoctor
  6647. ctime := time.Now().Unix()
  6648. timeStr := time.Now().Format("2006-01-02")
  6649. timeArr := strings.Split(timeStr, "-")
  6650. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6651. total = total + 1
  6652. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6653. cancelStock := models.DrugCancelStock{
  6654. OrderNumber: orderNumber,
  6655. OperaTime: operation_time,
  6656. OrgId: advice.UserOrgId,
  6657. Creater: creater,
  6658. Ctime: ctime,
  6659. Status: 1,
  6660. ReturnTime: advice.AdviceDate,
  6661. Dealer: info.Dealer,
  6662. Manufacturer: info.Manufacturer,
  6663. Type: 1,
  6664. }
  6665. service.AddSigleDrugCancelStock(&cancelStock)
  6666. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6667. dealer, _ := service.GetDealerById(info.Dealer)
  6668. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6669. cancelStockInfo := models.DrugCancelStockInfo{
  6670. OrderNumber: cancelInfo.OrderNumber,
  6671. CancelStockId: cancelInfo.ID,
  6672. DrugId: info.DrugId,
  6673. Count: info.Count,
  6674. Status: 1,
  6675. Ctime: ctime,
  6676. OrgId: advice.UserOrgId,
  6677. Type: 1,
  6678. Manufacturer: manufactureName.ManufacturerName,
  6679. Dealer: dealer.DealerName,
  6680. Total: 0,
  6681. RetailPrice: info.RetailPrice,
  6682. RetailTotalPrice: info.RetailTotalPrice,
  6683. Price: info.Price,
  6684. RegisterAccount: "",
  6685. Remark: info.Remark,
  6686. BatchNumber: info.BatchNumber,
  6687. MaxUnit: info.CountUnit,
  6688. ProductDate: info.ProductDate,
  6689. ExpiryDate: info.ExpiryDate,
  6690. BatchNumberId: info.WarehouseInfoId,
  6691. }
  6692. flow := models.DrugFlow{
  6693. WarehousingId: 0,
  6694. DrugId: info.DrugId,
  6695. Number: "",
  6696. BatchNumber: info.BatchNumber,
  6697. Count: info.Count,
  6698. UserOrgId: advice.UserOrgId,
  6699. PatientId: 0,
  6700. SystemTime: ctime,
  6701. ConsumableType: 4,
  6702. IsSys: 0,
  6703. WarehousingOrder: "",
  6704. WarehouseOutId: 0,
  6705. WarehouseOutOrderNumber: "",
  6706. IsEdit: 0,
  6707. CancelStockId: cancelStock.ID,
  6708. CancelOrderNumber: cancelStock.OrderNumber,
  6709. Manufacturer: info.Manufacturer,
  6710. Dealer: info.Dealer,
  6711. Creator: advice.AdviceDoctor,
  6712. UpdateCreator: 0,
  6713. Status: 1,
  6714. Ctime: time.Now().Unix(),
  6715. Mtime: 0,
  6716. Price: info.Price,
  6717. WarehousingDetailId: 0,
  6718. WarehouseOutDetailId: 0,
  6719. CancelOutDetailId: 0,
  6720. ExpireDate: info.ExpiryDate,
  6721. ProductDate: info.ProductDate,
  6722. MaxUnit: info.CountUnit,
  6723. MinUnit: "",
  6724. }
  6725. service.CreatedCancelStock(cancelStockInfo)
  6726. service.CreateDrugFlowOne(flow)
  6727. }
  6728. }
  6729. }
  6730. return err
  6731. }
  6732. func (this *HisApiController) DeleteNCDS() {
  6733. id, _ := this.GetInt64("id", 0)
  6734. if id > 0 {
  6735. service.DeletePsnNCDSRecordById(id)
  6736. this.ServeSuccessJSON(map[string]interface{}{
  6737. "msg": "删除成功",
  6738. })
  6739. } else {
  6740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6741. return
  6742. }
  6743. }
  6744. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6745. id, _ := c.GetInt64("id")
  6746. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6747. c.ServeSuccessJSON(map[string]interface{}{
  6748. "advice": advice,
  6749. })
  6750. return
  6751. }
  6752. func (c *HisApiController) GetHisMonthChargePatientList() {
  6753. record_date := c.GetString("record_date")
  6754. start_time := c.GetString("start_time")
  6755. end_time := c.GetString("end_time")
  6756. timeLayout := "2006-01-02"
  6757. loc, _ := time.LoadLocation("Local")
  6758. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6759. if err != nil {
  6760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6761. return
  6762. }
  6763. if err != nil {
  6764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6765. return
  6766. }
  6767. recordDateTime := theTime.Unix()
  6768. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6769. if err != nil {
  6770. }
  6771. startRecordDateTime := startTime.Unix()
  6772. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6773. if err != nil {
  6774. }
  6775. endRecordDateTime := endTime.Unix()
  6776. adminInfo := c.GetAdminUserInfo()
  6777. var tempMonthChargePatients []*service.MonthChargePatients
  6778. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  6779. for _, item := range tempPatients {
  6780. //过滤没有处方的
  6781. if len(item.HisPrescription) == 0 {
  6782. tempMonthChargePatients = append(tempMonthChargePatients, item)
  6783. }
  6784. }
  6785. c.ServeSuccessJSON(map[string]interface{}{
  6786. "list": tempMonthChargePatients,
  6787. })
  6788. }