his_api_controller.go 429KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033
  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. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. }
  88. func (c *HisApiController) GetFaPiaoNumber() {
  89. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  90. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  91. fmt.Println(count)
  92. var zero string
  93. number := count + 1
  94. if number >= 1000 {
  95. zero = "0000" + strconv.FormatInt(number, 10)
  96. } else if number >= 10000 {
  97. zero = "000" + strconv.FormatInt(number, 10)
  98. } else if number >= 100000 {
  99. zero = "00" + strconv.FormatInt(number, 10)
  100. } else if number >= 1000000 {
  101. zero = "0" + strconv.FormatInt(number, 10)
  102. } else {
  103. zero = strconv.FormatInt(number, 10)
  104. }
  105. c.ServeSuccessJSON(map[string]interface{}{
  106. "fapiao_number": zero,
  107. })
  108. return
  109. }
  110. func (c *HisApiController) ChangeOrderDesc() {
  111. id, _ := c.GetInt64("id")
  112. desc := c.GetString("desc")
  113. change_type := c.GetString("change_type")
  114. order, _ := service.GetHisOrderByID(id)
  115. if order.ID == 0 {
  116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  117. return
  118. }
  119. switch change_type {
  120. case "oth_desc":
  121. order.OthDesc = desc
  122. break
  123. case "cash_pay":
  124. order.CashPay = desc
  125. break
  126. case "jifen_pay":
  127. order.JifenPay = desc
  128. break
  129. case "band_card_pay":
  130. order.BandCardPay = desc
  131. break
  132. case "ali_pay":
  133. order.AliPay = desc
  134. break
  135. case "wechat_pay":
  136. order.WechatPay = desc
  137. break
  138. }
  139. err := service.SaveHisOrder(&order)
  140. if err == nil {
  141. c.ServeSuccessJSON(map[string]interface{}{
  142. "msg": "修改成功",
  143. })
  144. return
  145. } else {
  146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  147. return
  148. }
  149. }
  150. func (c *HisApiController) GetMonthHisPatient() {
  151. record_date := c.GetString("record_date")
  152. //order_status, _ := c.GetInt64("type")
  153. timeLayout := "2006-01-02"
  154. loc, _ := time.LoadLocation("Local")
  155. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  156. if err != nil {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  158. return
  159. }
  160. recordDateTime := theTime.Unix()
  161. adminInfo := c.GetAdminUserInfo()
  162. var tempPatients []service.NewTempPatients
  163. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  164. // 获取当前时间
  165. now := time.Now()
  166. // 获取本月的第一天
  167. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  168. // 获取下个月的第一天
  169. nextMonth := firstDay.AddDate(0, 1, 0)
  170. // 获取本月的最后一天
  171. lastDay := nextMonth.Add(-time.Nanosecond)
  172. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  173. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  174. var patients []service.NewTempPatients
  175. var patients_two []service.NewTempPatients
  176. for _, item := range tempPatients {
  177. //过滤掉没挂号的和没开处方的
  178. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  179. patients = append(patients, item)
  180. }
  181. ////过滤掉没挂号的
  182. //if len(item.HisPatient) > 0 {
  183. // patients_two = append(patients_two, item)
  184. //}
  185. }
  186. c.ServeSuccessJSON(map[string]interface{}{
  187. "list": patients,
  188. "list_two": patients_two,
  189. "chargePatients": chargePatients,
  190. })
  191. }
  192. func (c *HisApiController) GetBatchSettleAccounts() {
  193. order_ids := c.GetString("order_ids")
  194. admin_user_id, _ := c.GetInt64("admin_user_id")
  195. adminUser := c.GetAdminUserInfo()
  196. orders := strings.Split(order_ids, ",")
  197. var newOrders []models.Orders
  198. for _, item := range orders {
  199. order, _ := service.GetHisOrderByIDTenOne(item)
  200. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  201. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  202. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  203. orderInfos = append(orderInfos, orderInfos_two...)
  204. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  205. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  206. var diagnosis_ids []string
  207. if his.ID > 0 {
  208. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  209. } else {
  210. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  211. }
  212. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  213. var dia_config []*models.HisXtDiagnoseConfig
  214. var name string
  215. for _, item := range diagnosis_ids {
  216. id, _ := strconv.ParseInt(item, 10, 64)
  217. diagnosisConfig, _ := service.FindDiagnoseById(id)
  218. dia_config = append(dia_config, diagnosisConfig)
  219. if len(name) == 0 {
  220. name = diagnosisConfig.ClassName
  221. } else {
  222. name = name + "," + diagnosisConfig.ClassName
  223. }
  224. }
  225. var bedCostTotal float64 = 0 //床位总费
  226. var bedCostSelfTotal float64 = 0 //床位自费
  227. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  228. var bedSelfTotal float64 = 0 //床位部分项目自费
  229. var bedInscpTotal float64 = 0 //床位部分项目自费
  230. var operationCostTotal float64 = 0 //手术费
  231. var operationCostSelfTotal float64 = 0 //手术费
  232. var operationCostPartSelfTotal float64 = 0 //手术费
  233. var operationSelfTotal float64 = 0 //床位部分项目自费
  234. var operationInscpTotal float64 = 0 //床位部分项目自费
  235. var otherCostTotal float64 = 0 //其他费用
  236. var otherCostSelfTotal float64 = 0 //其他费用
  237. var otherCostPartSelfTotal float64 = 0 //其他费用
  238. var otherSelfTotal float64 = 0 //床位部分项目自费
  239. var otherInscpTotal float64 = 0 //床位部分项目自费
  240. var materialCostTotal float64 = 0 //材料费
  241. var materialCostSelfTotal float64 = 0 //材料费
  242. var materialCostPartSelfTotal float64 = 0 //材料费
  243. var materialSelfTotal float64 = 0 //床位部分项目自费
  244. var materialInscpTotal float64 = 0 //床位部分项目自费
  245. var westernMedicineCostTotal float64 = 0 //西药费
  246. var westernMedicineCostSelfTotal float64 = 0 //西药费
  247. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  248. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  249. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  250. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  251. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  252. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  253. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  254. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  255. var checkCostTotal float64 = 0 //检查费
  256. var checkCostSelfTotal float64 = 0 //检查费
  257. var checkCostPartSelfTotal float64 = 0 //检查费
  258. var checkSelfTotal float64 = 0 //床位部分项目自费
  259. var checkInscpTotal float64 = 0 //床位部分项目自费
  260. var laboratoryCostTotal float64 = 0 //化验费
  261. var laboratoryCostSelfTotal float64 = 0 //化验费
  262. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  263. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  264. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  265. var treatCostTotal float64 = 0 //治疗费用
  266. var treatCostSelfTotal float64 = 0 //治疗费用
  267. var treatCostPartSelfTotal float64 = 0 //治疗费用
  268. var treatSelfTotal float64 = 0 //床位部分项目自费
  269. var treatInscpTotal float64 = 0 //床位部分项目自费
  270. decimal.DivisionPrecision = 2
  271. for _, item := range orderInfos {
  272. if item.MedChrgitmType == "01" { //床位费
  273. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  274. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  275. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  276. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  277. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  278. }
  279. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  280. if item.MedChrgitmType == "03" { //检查费
  281. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  282. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  283. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  284. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  285. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  286. }
  287. } else {
  288. if item.MedChrgitmType == "03" { //检查费
  289. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  290. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  291. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  292. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  293. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  294. }
  295. }
  296. if item.MedChrgitmType == "04" { //化验费
  297. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  298. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  299. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  300. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  301. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  302. }
  303. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  304. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  305. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  306. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  307. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  308. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  309. }
  310. if item.MedChrgitmType == "06" { //手术费
  311. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  315. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  316. }
  317. if item.MedChrgitmType == "08" { //材料费
  318. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  319. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  320. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  321. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  322. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  323. }
  324. if item.MedChrgitmType == "09" { //西药费
  325. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  326. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  327. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  328. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  329. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  330. }
  331. if item.MedChrgitmType == "11" { //中成费
  332. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  333. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  334. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  335. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  336. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  337. }
  338. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  339. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  340. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  341. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  342. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  343. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  344. }
  345. }
  346. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  347. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  348. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  349. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  350. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  351. var doctor_name string
  352. if roles.ID == 0 {
  353. doctor_name = "管理员"
  354. } else {
  355. doctor_name = roles.UserName
  356. }
  357. yiliao_leibie := ""
  358. switch order.MedType {
  359. case "11":
  360. yiliao_leibie = "普通门诊"
  361. break
  362. case "12":
  363. yiliao_leibie = "门诊挂号"
  364. break
  365. case "13":
  366. yiliao_leibie = "急诊"
  367. break
  368. case "14":
  369. yiliao_leibie = "门诊特殊病"
  370. break
  371. case "15":
  372. yiliao_leibie = "门诊统筹"
  373. break
  374. case "16":
  375. yiliao_leibie = "门诊慢性病"
  376. break
  377. case "21":
  378. yiliao_leibie = "普通住院"
  379. break
  380. }
  381. var newOrder models.Orders
  382. newOrder.Diagnosis = name
  383. newOrder.OrderInfos = orderInfos
  384. newOrder.Number = order.MdtrtId
  385. newOrder.Date = order.SettleAccountsDate
  386. newOrder.ChargeAdmin = charge_admin
  387. newOrder.PrintorAdmin = printor_admin
  388. newOrder.Order = order
  389. newOrder.BedCostTotal = bedCostTotal
  390. newOrder.BedCostSelfTotal = bedCostSelfTotal
  391. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  392. newOrder.BedSelfTotal = bedSelfTotal
  393. newOrder.BedInscpTotal = bedInscpTotal
  394. newOrder.OperationCostTotal = operationCostTotal
  395. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  396. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  397. newOrder.OperationSelfTotal = operationSelfTotal
  398. newOrder.OperationInscpTotal = operationInscpTotal
  399. newOrder.OtherCostTotal = otherCostTotal
  400. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  401. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  402. newOrder.OtherSelfTotal = otherSelfTotal
  403. newOrder.OtherInscpTotal = otherInscpTotal
  404. newOrder.MaterialCostTotal = materialCostTotal
  405. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  406. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  407. newOrder.MaterialSelfTotal = materialSelfTotal
  408. newOrder.MaterialInscpTotal = materialInscpTotal
  409. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  410. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  411. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  412. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  413. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  414. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  415. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  416. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  417. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  418. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  419. newOrder.CheckCostTotal = checkCostTotal
  420. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  421. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  422. newOrder.CheckSelfTotal = checkSelfTotal
  423. newOrder.CheckInscpTotal = checkInscpTotal
  424. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  425. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  426. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  427. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  428. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  429. newOrder.TreatCostTotal = treatCostTotal
  430. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  431. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  432. newOrder.TreatSelfTotal = treatSelfTotal
  433. newOrder.TreatInscpTotal = treatInscpTotal
  434. newOrder.DoctorInfo = doctor_info
  435. newOrder.DoctorName = doctor_name
  436. newOrder.HealthCardNo = order.PsnNo
  437. newOrder.YiliaoLeibie = yiliao_leibie
  438. newOrder.Patient = patient
  439. newOrder.OrgName = miConfig.OrgName
  440. newOrder.OrgCode = miConfig.Code
  441. newOrder.OrderNumber = order.Number
  442. newOrder.HisPatient = his
  443. newOrder.DiaConfig = dia_config
  444. newOrders = append(newOrders, newOrder)
  445. }
  446. c.ServeSuccessJSON(map[string]interface{}{
  447. "orders": newOrders,
  448. })
  449. }
  450. func (c *HisApiController) GetTestOrder() {
  451. order_id, _ := c.GetInt64("order_id")
  452. admin_user_id, _ := c.GetInt64("admin_user_id")
  453. adminUser := c.GetAdminUserInfo()
  454. order, _ := service.GetHisOrderByID(order_id)
  455. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  456. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  457. orderInfos = append(orderInfos, orderInfos_two...)
  458. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  459. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  460. var dia_config []*models.HisXtDiagnoseConfig
  461. var name string
  462. var bedCostTotal float64 = 0 //床位总费
  463. var bedCostSelfTotal float64 = 0 //床位自费
  464. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  465. var bedSelfTotal float64 = 0 //床位部分项目自费
  466. var bedInscpTotal float64 = 0 //床位部分项目自费
  467. var operationCostTotal float64 = 0 //手术费
  468. var operationCostSelfTotal float64 = 0 //手术费
  469. var operationCostPartSelfTotal float64 = 0 //手术费
  470. var operationSelfTotal float64 = 0 //床位部分项目自费
  471. var operationInscpTotal float64 = 0 //床位部分项目自费
  472. var otherCostTotal float64 = 0 //其他费用
  473. var otherCostSelfTotal float64 = 0 //其他费用
  474. var otherCostPartSelfTotal float64 = 0 //其他费用
  475. var otherSelfTotal float64 = 0 //床位部分项目自费
  476. var otherInscpTotal float64 = 0 //床位部分项目自费
  477. var materialCostTotal float64 = 0 //材料费
  478. var materialCostSelfTotal float64 = 0 //材料费
  479. var materialCostPartSelfTotal float64 = 0 //材料费
  480. var materialSelfTotal float64 = 0 //床位部分项目自费
  481. var materialInscpTotal float64 = 0 //床位部分项目自费
  482. var westernMedicineCostTotal float64 = 0 //西药费
  483. var westernMedicineCostSelfTotal float64 = 0 //西药费
  484. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  485. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  486. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  487. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  488. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  489. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  490. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  491. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  492. var checkCostTotal float64 = 0 //检查费
  493. var checkCostSelfTotal float64 = 0 //检查费
  494. var checkCostPartSelfTotal float64 = 0 //检查费
  495. var checkSelfTotal float64 = 0 //床位部分项目自费
  496. var checkInscpTotal float64 = 0 //床位部分项目自费
  497. var laboratoryCostTotal float64 = 0 //化验费
  498. var laboratoryCostSelfTotal float64 = 0 //化验费
  499. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  500. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  501. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  502. var treatCostTotal float64 = 0 //治疗费用
  503. var treatCostSelfTotal float64 = 0 //治疗费用
  504. var treatCostPartSelfTotal float64 = 0 //治疗费用
  505. var treatSelfTotal float64 = 0 //床位部分项目自费
  506. var treatInscpTotal float64 = 0 //床位部分项目自费
  507. decimal.DivisionPrecision = 2
  508. for _, item := range orderInfos {
  509. if item.MedChrgitmType == "01" { //床位费
  510. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  511. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  512. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  513. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  514. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  515. }
  516. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  517. if item.MedChrgitmType == "03" { //检查费
  518. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  519. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  520. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  521. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  522. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  523. }
  524. } else {
  525. if item.MedChrgitmType == "03" { //检查费
  526. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  527. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  528. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  529. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  530. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  531. }
  532. }
  533. if item.MedChrgitmType == "04" { //化验费
  534. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  535. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  536. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  537. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  538. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  539. }
  540. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  541. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  542. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  543. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  544. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  545. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  546. }
  547. if item.MedChrgitmType == "06" { //手术费
  548. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  549. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  550. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  551. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  552. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  553. }
  554. if item.MedChrgitmType == "08" { //材料费
  555. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  556. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  557. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  558. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  559. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  560. }
  561. if item.MedChrgitmType == "09" { //西药费
  562. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  563. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  564. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  565. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  566. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  567. }
  568. if item.MedChrgitmType == "11" { //中成费
  569. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  570. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  571. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  572. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  573. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  574. }
  575. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  576. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  577. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  578. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  579. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  580. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  581. }
  582. }
  583. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  584. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  585. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  586. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  587. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  588. var doctor_name string
  589. if roles.ID == 0 {
  590. doctor_name = "管理员"
  591. } else {
  592. doctor_name = roles.UserName
  593. }
  594. yiliao_leibie := ""
  595. switch order.MedType {
  596. case "11":
  597. yiliao_leibie = "普通门诊"
  598. break
  599. case "12":
  600. yiliao_leibie = "门诊挂号"
  601. break
  602. case "13":
  603. yiliao_leibie = "急诊"
  604. break
  605. case "14":
  606. yiliao_leibie = "门诊特殊病"
  607. break
  608. case "15":
  609. yiliao_leibie = "门诊统筹"
  610. break
  611. case "16":
  612. yiliao_leibie = "门诊慢性病"
  613. break
  614. case "21":
  615. yiliao_leibie = "普通住院"
  616. break
  617. }
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "diagnosis": name,
  620. "order_infos": orderInfos,
  621. "number": order.MdtrtId,
  622. "date": order.SettleAccountsDate,
  623. "charge_admin": charge_admin,
  624. "printor_admin": printor_admin,
  625. "info": order,
  626. "order": order,
  627. "bedCostTotal": bedCostTotal,
  628. "bedCostSelfTotal": bedCostSelfTotal,
  629. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  630. "bedSelfTotal": bedSelfTotal,
  631. "bedInscpTotal": bedInscpTotal,
  632. "operationCostTotal": operationCostTotal,
  633. "operationCostSelfTotal": operationCostSelfTotal,
  634. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  635. "operationSelfTotal": operationSelfTotal,
  636. "operationInscpTotal": operationInscpTotal,
  637. "otherCostTotal": otherCostTotal,
  638. "otherCostSelfTotal": otherCostSelfTotal,
  639. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  640. "otherSelfTotal": otherSelfTotal,
  641. "otherInscpTotal": otherInscpTotal,
  642. "materialCostTotal": materialCostTotal,
  643. "materialCostSelfTotal": materialCostSelfTotal,
  644. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  645. "materialSelfTotal": materialSelfTotal,
  646. "materialInscpTotal": materialInscpTotal,
  647. "westernMedicineCostTotal": westernMedicineCostTotal,
  648. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  649. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  650. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  651. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  652. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  653. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  654. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  655. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  656. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  657. "checkCostTotal": checkCostTotal,
  658. "checkCostSelfTotal": checkCostSelfTotal,
  659. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  660. "checkSelfTotal": checkSelfTotal,
  661. "checkInscpTotal": checkInscpTotal,
  662. "laboratoryCostTotal": laboratoryCostTotal,
  663. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  664. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  665. "laboratorySelfTotal": laboratorySelfTotal,
  666. "laboratoryInscpTotal": laboratoryInscpTotal,
  667. "treatCostTotal": treatCostTotal,
  668. "treatCostSelfTotal": treatCostSelfTotal,
  669. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  670. "treatSelfTotal": treatSelfTotal,
  671. "treatInscpTotal": treatInscpTotal,
  672. "doctor_info": doctor_info,
  673. "doctor_name": doctor_name,
  674. "health_card_no": order.PsnNo,
  675. "yiliao_leibie": yiliao_leibie,
  676. "patient": patient,
  677. "org_name": miConfig.OrgName,
  678. "org_code": miConfig.Code,
  679. "order_number": order.Number,
  680. "his_hospital": his_hospital,
  681. "dia_config": dia_config,
  682. })
  683. }
  684. func (c *PublicApiController) GetBaiLinExportData() {
  685. data := service.GetBaiLinOrderData()
  686. fmt.Println(len(data))
  687. var new_data []*models.NewCustomHisOrder
  688. for _, item := range data {
  689. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  690. new_data = append(new_data, item)
  691. }
  692. }
  693. fmt.Println(len(new_data))
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "list": new_data,
  696. })
  697. }
  698. func (c *HisApiController) GetHisUnChargePatientList() {
  699. record_date := c.GetString("record_date")
  700. sch_type, _ := c.GetInt64("sch_type")
  701. timeLayout := "2006-01-02"
  702. loc, _ := time.LoadLocation("Local")
  703. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  704. if err != nil {
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. recordDateTime := theTime.Unix()
  709. adminInfo := c.GetAdminUserInfo()
  710. var tempPatients []*service.NewTempPatients
  711. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  712. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  713. var patients []*service.NewTempPatients
  714. var patients_two []*service.NewTempPatients
  715. for _, item := range tempPatients {
  716. //过滤掉没挂号的和没开处方的
  717. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  718. patients = append(patients, item)
  719. }
  720. //过滤掉没挂号的
  721. if len(item.HisPatient) > 0 {
  722. patients_two = append(patients_two, item)
  723. }
  724. }
  725. c.ServeSuccessJSON(map[string]interface{}{
  726. "list": patients,
  727. "list_two": patients_two,
  728. })
  729. }
  730. func (c *HisApiController) GetPrivateExpensesOrder() {
  731. //id, _ := c.GetInt64("id")
  732. //record_time := c.GetString("record_time")
  733. order_id, _ := c.GetInt64("order_id")
  734. admin_user_id, _ := c.GetInt64("admin_user_id")
  735. //timeLayout := "2006-01-02"
  736. //loc, _ := time.LoadLocation("Local")
  737. //
  738. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  739. //if err != nil {
  740. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. // return
  742. //}
  743. //recordDateTime := theTime.Unix()
  744. adminUser := c.GetAdminUserInfo()
  745. order, _ := service.GetHisOrderByID(order_id)
  746. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  747. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  748. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  749. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  750. //var config []*models.HisXtDiagnoseConfig
  751. var name string
  752. if order.PType == 1 {
  753. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  754. for _, item := range diagnosis_ids {
  755. id, _ := strconv.ParseInt(item, 10, 64)
  756. diagnosisConfig, _ := service.FindDiagnoseById(id)
  757. if len(name) == 0 {
  758. name = diagnosisConfig.ClassName
  759. } else {
  760. name = name + "," + diagnosisConfig.ClassName
  761. }
  762. }
  763. } else {
  764. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  765. for _, item := range diagnosis_ids {
  766. id, _ := strconv.ParseInt(item, 10, 64)
  767. diagnosisConfig, _ := service.FindDiagnoseById(id)
  768. if len(name) == 0 {
  769. name = diagnosisConfig.ClassName
  770. } else {
  771. name = name + "," + diagnosisConfig.ClassName
  772. }
  773. }
  774. }
  775. var bedCostTotal float64 = 0 //床位总费
  776. //var bedCostSelfTotal float64 = 0 //床位自费
  777. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  778. var operationCostTotal float64 = 0 //手术费
  779. //var operationCostSelfTotal float64 = 0 //手术费
  780. var operationCostPartSelfTotal float64 = 0 //手术费
  781. var otherCostTotal float64 = 0 //其他费用
  782. //var otherCostSelfTotal float64 = 0 //其他费用
  783. var otherCostPartSelfTotal float64 = 0 //其他费用
  784. var materialCostTotal float64 = 0 //材料费
  785. //var materialCostSelfTotal float64 = 0 //材料费
  786. var materialCostPartSelfTotal float64 = 0 //材料费
  787. var westernMedicineCostTotal float64 = 0 //西药费
  788. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  789. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  790. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  791. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  792. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  793. var checkCostTotal float64 = 0 //检查费
  794. //var checkCostSelfTotal float64 = 0 //检查费
  795. var checkCostPartSelfTotal float64 = 0 //检查费
  796. var laboratoryCostTotal float64 = 0 //化验费
  797. //var laboratoryCostSelfTotal float64 = 0 //化验费
  798. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  799. var treatCostTotal float64 = 0 //治疗费用
  800. //var treatCostSelfTotal float64 = 0 //治疗费用
  801. var treatCostPartSelfTotal float64 = 0 //治疗费用
  802. var zhenChaCostTotal float64 = 0 //其他费用
  803. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  804. decimal.DivisionPrecision = 2
  805. for _, item := range orderInfos {
  806. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  807. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  808. item.MedChrgitmType = "09"
  809. }
  810. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  811. if item.HisPrescriptionProject.Type == 2 {
  812. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  813. fmt.Println("CostClassify")
  814. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  815. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  816. case 0:
  817. item.MedChrgitmType = "0"
  818. break
  819. case 1:
  820. item.MedChrgitmType = "14"
  821. break
  822. case 2:
  823. item.MedChrgitmType = "05"
  824. break
  825. case 3:
  826. item.MedChrgitmType = "03"
  827. break
  828. case 4:
  829. item.MedChrgitmType = "03"
  830. break
  831. case 5:
  832. item.MedChrgitmType = "08"
  833. break
  834. case 6:
  835. item.MedChrgitmType = "14"
  836. break
  837. case 7:
  838. item.MedChrgitmType = "14"
  839. break
  840. case 8:
  841. item.MedChrgitmType = "03"
  842. break
  843. case 9:
  844. item.MedChrgitmType = "14"
  845. break
  846. case 10:
  847. item.MedChrgitmType = "14"
  848. break
  849. case 11:
  850. item.MedChrgitmType = "06"
  851. break
  852. case 12:
  853. item.MedChrgitmType = "12"
  854. break
  855. case 13:
  856. item.MedChrgitmType = "01"
  857. break
  858. case 14:
  859. item.MedChrgitmType = "04"
  860. break
  861. case 15:
  862. item.MedChrgitmType = "14"
  863. break
  864. }
  865. } else {
  866. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  867. case 1:
  868. item.MedChrgitmType = "14"
  869. break
  870. case 2:
  871. item.MedChrgitmType = "05"
  872. break
  873. case 3:
  874. item.MedChrgitmType = "04"
  875. break
  876. case 4:
  877. item.MedChrgitmType = "14"
  878. break
  879. case 5:
  880. item.MedChrgitmType = "08"
  881. break
  882. case 6:
  883. item.MedChrgitmType = "14"
  884. break
  885. case 7:
  886. item.MedChrgitmType = "14"
  887. break
  888. case 8:
  889. item.MedChrgitmType = "03"
  890. break
  891. case 9:
  892. item.MedChrgitmType = "14"
  893. break
  894. }
  895. }
  896. } else if item.HisPrescriptionProject.Type == 3 {
  897. item.MedChrgitmType = "08"
  898. }
  899. }
  900. }
  901. order.PsnCashPay = order.MedfeeSumamt
  902. for _, item := range orderInfos {
  903. if item.MedChrgitmType == "01" { //床位费
  904. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  905. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  906. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  907. }
  908. if item.MedChrgitmType == "02" { //诊察费
  909. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  910. //zhenChaCostSelfTotal = zhenChaCostTotal
  911. }
  912. if item.MedChrgitmType == "03" { //检查费
  913. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  914. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  915. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  916. }
  917. if item.MedChrgitmType == "02" { //检查费
  918. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  919. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  920. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  921. }
  922. if item.MedChrgitmType == "04" { //化验费
  923. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  924. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  925. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  926. }
  927. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  928. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  929. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  930. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  931. }
  932. if item.MedChrgitmType == "06" { //手术费
  933. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  934. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  935. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  936. }
  937. if item.MedChrgitmType == "08" { //材料费
  938. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  939. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  940. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  941. }
  942. if item.MedChrgitmType == "09" { //西药费
  943. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  944. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  945. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  946. }
  947. if item.MedChrgitmType == "11" { //中成费
  948. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  949. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  950. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  951. }
  952. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  953. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  954. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  955. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  956. }
  957. }
  958. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  959. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  960. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  961. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  962. c.ServeSuccessJSON(map[string]interface{}{
  963. "patient": patient,
  964. "order_infos": orderInfos,
  965. "diagnosis": name,
  966. "bedCostTotal": bedCostTotal,
  967. "bedCostSelfTotal": bedCostTotal,
  968. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  969. "operationCostTotal": operationCostTotal,
  970. "operationCostSelfTotal": operationCostTotal,
  971. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  972. "otherCostTotal": otherCostTotal,
  973. "otherCostSelfTotal": otherCostTotal,
  974. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  975. "materialCostTotal": materialCostTotal,
  976. "materialCostSelfTotal": materialCostTotal,
  977. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  978. "westernMedicineCostTotal": westernMedicineCostTotal,
  979. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  980. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  981. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  982. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  983. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  984. "checkCostTotal": checkCostTotal,
  985. "checkCostSelfTotal": checkCostTotal,
  986. "zhenChaCostTotal": zhenChaCostTotal,
  987. "zhenChaCostSelfTotal": zhenChaCostTotal,
  988. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  989. "laboratoryCostTotal": laboratoryCostTotal,
  990. "laboratoryCostSelfTotal": laboratoryCostTotal,
  991. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  992. "treatCostTotal": treatCostTotal,
  993. "treatCostSelfTotal": treatCostTotal,
  994. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  995. "charge_admin": charge_admin,
  996. "printor_admin": printor_admin,
  997. "org_name": org.OrgName,
  998. "org_code": miConfig.Code,
  999. "name": patient.Name,
  1000. "number": order.MdtrtId,
  1001. "date": order.SettleAccountsDate,
  1002. "info": order,
  1003. "his_hospital": his_hospital,
  1004. "his": his,
  1005. })
  1006. }
  1007. func (c *HisApiController) RefudDetail() {
  1008. order_id, _ := c.GetInt64("order_id")
  1009. order, _ := service.GetHisOrderByID(order_id)
  1010. adminUser := c.GetAdminUserInfo()
  1011. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1012. c.ServeSuccessJSON(map[string]interface{}{
  1013. "msg": "撤销成功",
  1014. })
  1015. }
  1016. func (c *HisApiController) Sscard() {
  1017. //r := CardInit()
  1018. //if r == 0 {
  1019. // GetBaseInfo()
  1020. //}
  1021. //c.ServeSuccessJSON(map[string]interface{}{
  1022. // "list": "11",
  1023. //})
  1024. }
  1025. func GetBaseInfo() error {
  1026. //handle := syscall.MustLoadDLL("SSCard.dll")
  1027. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1028. //
  1029. //str := make([]byte, 256)
  1030. //str1 := make([]byte, 256)
  1031. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1032. //if ferr != nil {
  1033. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1034. // return ferr
  1035. //}
  1036. //
  1037. //fmt.Println(string(str))
  1038. //
  1039. //fmt.Println(r)
  1040. return nil
  1041. }
  1042. func CardInit() int {
  1043. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1044. //add := DllTestDef.MustFindProc("Init")
  1045. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1046. //if err != nil {
  1047. // fmt.Println("SSCard的运算结果为:", ret)
  1048. //}
  1049. //result := int(ret)
  1050. return 0
  1051. }
  1052. func IntPtr(n int) uintptr {
  1053. return uintptr(n)
  1054. }
  1055. func StrPtr(s string) uintptr {
  1056. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1057. }
  1058. func (c *HisApiController) GetHisPatientList() {
  1059. //types, _ := c.GetInt64("type", 0)
  1060. record_date := c.GetString("record_date")
  1061. sch_type, _ := c.GetInt64("sch_type")
  1062. timeLayout := "2006-01-02"
  1063. loc, _ := time.LoadLocation("Local")
  1064. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1065. if err != nil {
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1067. return
  1068. }
  1069. recordDateTime := theTime.Unix()
  1070. adminInfo := c.GetAdminUserInfo()
  1071. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1072. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1073. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1074. //获取当前用户的信息
  1075. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1076. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1077. //获取所有科室信息
  1078. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1079. c.ServeSuccessJSON(map[string]interface{}{
  1080. "list": patients,
  1081. "list_two": patients_two,
  1082. "info": adminUserInfo,
  1083. "doctors": doctors,
  1084. "department": department,
  1085. })
  1086. }
  1087. type CustomTemplate struct {
  1088. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1089. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1090. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1091. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1092. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1093. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1094. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1095. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1096. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1097. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1098. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1099. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1100. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1101. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1102. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1103. }
  1104. func (c *HisApiController) GetHisPatientInfo() {
  1105. patient_id, _ := c.GetInt64("patient_id")
  1106. his_patient_id, _ := c.GetInt64("his_patient_id")
  1107. record_date := c.GetString("record_date")
  1108. number := c.GetString("number")
  1109. //start_time := c.GetString("start_time")
  1110. //end_time := c.GetString("end_time")
  1111. p_type, _ := c.GetInt64("p_type")
  1112. timeLayout := "2006-01-02"
  1113. loc, _ := time.LoadLocation("Local")
  1114. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1115. if err != nil {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. recordDateTime := theTime.Unix()
  1120. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1121. //if err != nil {
  1122. //
  1123. //}
  1124. //startRecordDateTime := startTime.Unix()
  1125. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1126. //if err != nil {
  1127. //
  1128. //}
  1129. //endRecordDateTime := endTime.Unix()
  1130. admin := c.GetAdminUserInfo()
  1131. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1132. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1133. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1134. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1135. var prescriptions []*models.HisPrescription
  1136. var last_prescriptions []*models.HisPrescription
  1137. var sch_prescriptions []CustomTemplate
  1138. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1139. if p_type == 1 { //住院
  1140. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1141. for _, item := range prescriptions {
  1142. for _, subItem := range item.HisDoctorAdviceInfo {
  1143. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1144. if info.RetailPrice > 0 {
  1145. subItem.Drug.MinPrice = info.RetailPrice
  1146. }
  1147. }
  1148. }
  1149. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1150. } else { //门诊
  1151. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1152. for _, item := range prescriptions {
  1153. for _, subItem := range item.HisDoctorAdviceInfo {
  1154. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1155. if info.RetailPrice > 0 {
  1156. subItem.Drug.MinPrice = info.RetailPrice
  1157. }
  1158. }
  1159. }
  1160. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1161. }
  1162. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1163. if sch.ID > 0 {
  1164. var week string
  1165. t := time.Now()
  1166. switch t.Weekday().String() {
  1167. case "Monday":
  1168. week = "周一"
  1169. break
  1170. case "Tuesday":
  1171. week = "周二"
  1172. break
  1173. case "Wednesday":
  1174. week = "周三"
  1175. break
  1176. case "Thursday":
  1177. week = "周四"
  1178. break
  1179. case "Friday":
  1180. week = "周五"
  1181. break
  1182. case "Saturday":
  1183. week = "周六"
  1184. break
  1185. case "Sunday":
  1186. week = "周日"
  1187. break
  1188. }
  1189. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1190. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1191. //根据推送频率组装新的数组
  1192. for _, item := range temp_sch_prescriptions {
  1193. var cus CustomTemplate
  1194. cus.ID = item.ID
  1195. cus.UserOrgId = item.UserOrgId
  1196. cus.PatientId = item.PatientId
  1197. cus.MedType = item.MedType
  1198. cus.RecordDate = item.RecordDate
  1199. cus.Type = item.Type
  1200. cus.PType = item.PType
  1201. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1202. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1203. if subItem.FrequencyType == 1 { //每次必推
  1204. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1205. }
  1206. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1207. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1208. }
  1209. if subItem.FrequencyType == 2 { //按照天数频率
  1210. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1211. now := p.Unix()
  1212. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1213. dayStr2 := "-" + dayStr
  1214. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1215. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1216. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1217. if len(advices) == 0 {
  1218. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1219. }
  1220. }
  1221. }
  1222. }
  1223. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1224. if subItem.Type == 2 {
  1225. if subItem.XtHisProject.MedicalStatus != 1 {
  1226. if subItem.FrequencyType == 1 {
  1227. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1228. }
  1229. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1230. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1231. }
  1232. if subItem.FrequencyType == 2 {
  1233. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1234. now := p.Unix()
  1235. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1236. dayStr2 := "-" + dayStr
  1237. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1238. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1239. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1240. if len(projects) == 0 {
  1241. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1242. }
  1243. }
  1244. }
  1245. } else if subItem.Type == 3 {
  1246. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1247. if subItem.FrequencyType == 1 {
  1248. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1249. }
  1250. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1251. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1252. }
  1253. if subItem.FrequencyType == 2 {
  1254. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1255. now := p.Unix()
  1256. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1257. dayStr2 := "-" + dayStr
  1258. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1259. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1260. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1261. if len(projects) == 0 {
  1262. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. sch_prescriptions = append(sch_prescriptions, cus)
  1269. }
  1270. for _, item := range sch_prescriptions {
  1271. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1272. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1273. }
  1274. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1275. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1276. }
  1277. }
  1278. }
  1279. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1280. if config.ID > 0 && config.IsOpen == 1 {
  1281. for _, item := range sch_prescriptions {
  1282. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1283. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1284. if info.RetailPrice > 0 {
  1285. subItem.Drug.MinPrice = info.RetailPrice
  1286. }
  1287. }
  1288. }
  1289. }
  1290. if config.ID > 0 && config.IsOpen == 1 {
  1291. for _, item := range sch_prescriptions {
  1292. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1293. if subItem.Type == 3 {
  1294. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1295. if info.Price > 0 {
  1296. subItem.GoodInfo.PackingPrice = info.Price
  1297. }
  1298. }
  1299. }
  1300. }
  1301. }
  1302. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1303. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1304. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1305. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1306. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1307. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1308. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1309. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1310. //获取所有科室信息
  1311. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "his_info": his_patient_info,
  1314. "xt_info": xt_patient_info,
  1315. "prescription": prescriptions,
  1316. "case_history": case_history,
  1317. "info": patientPrescriptionInfo,
  1318. //"month_prescriptions": monthPrescriptions,
  1319. "order": order,
  1320. "doctors": doctors,
  1321. "department": department,
  1322. "sch_prescriptions": sch_prescriptions,
  1323. "last_prescriptions": last_prescriptions,
  1324. "schedule": sch,
  1325. "count": count,
  1326. "drugStockConfig": drugStockConfig,
  1327. "last_info": lastPatientPrescriptionInfo,
  1328. })
  1329. return
  1330. }
  1331. func (c *HisApiController) GetHisPrescriptionConfig() {
  1332. adminInfo := c.GetAdminUserInfo()
  1333. //获取医嘱模版
  1334. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1335. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1336. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1337. //获取所有基础药
  1338. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1339. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1340. if config.ID > 0 && config.IsOpen == 1 {
  1341. for _, item := range drugs {
  1342. var index = 0
  1343. for _, subItem := range item.OtherDrugWarehouseInfo {
  1344. if index == 0 {
  1345. index = index + 1
  1346. if subItem.RetailPrice > 0 {
  1347. item.MinPrice = subItem.RetailPrice
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1354. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1355. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1356. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1357. //获取所有科室信息
  1358. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1359. //获取诊断信息
  1360. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1361. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1362. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1363. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1364. //获取是否开启保存耗材出库的开关
  1365. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1366. c.ServeSuccessJSON(map[string]interface{}{
  1367. "drugs": drugs,
  1368. "advices_template": advices,
  1369. "drugways": drugways,
  1370. "efs": efs,
  1371. "doctors": doctors,
  1372. "department": department,
  1373. "sick": sick,
  1374. "additions": additions,
  1375. "diagnose": diagnose,
  1376. "manufacturers": manufacturers,
  1377. "goodOutOpen": goodOutOpen,
  1378. "patientDiagnose": patientDiagnose,
  1379. })
  1380. }
  1381. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1382. //获取所有基础药
  1383. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1384. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1385. if config.ID > 0 && config.IsOpen == 1 {
  1386. for _, item := range drugs {
  1387. var index = 0
  1388. for _, subItem := range item.OtherDrugWarehouseInfo {
  1389. if index == 0 {
  1390. index = index + 1
  1391. if subItem.RetailPrice > 0 {
  1392. item.MinPrice = subItem.RetailPrice
  1393. }
  1394. }
  1395. }
  1396. }
  1397. }
  1398. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1399. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1400. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1401. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1402. //获取所有科室信息
  1403. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1404. //获取诊断信息
  1405. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1406. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1407. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1408. //获取是否开启保存耗材出库的开关
  1409. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1410. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1411. c.ServeSuccessJSON(map[string]interface{}{
  1412. "drugs": drugs,
  1413. "advices_template": advices,
  1414. "drugways": drugways,
  1415. "efs": efs,
  1416. "doctors": doctors,
  1417. "department": department,
  1418. "sick": sick,
  1419. "additions": additions,
  1420. "diagnose": diagnose,
  1421. "manufacturers": manufacturers,
  1422. "goodOutOpen": goodOutOpen,
  1423. "patientDiagnose": patientDiagnose,
  1424. })
  1425. }
  1426. }
  1427. func (c *HisApiController) CreateHisPrescription() {
  1428. record_date := c.GetString("record_date")
  1429. patient_id, _ := c.GetInt64("patient_id")
  1430. reg_type, _ := c.GetInt64("reg_type")
  1431. diagnose := c.GetString("diagnose")
  1432. sick_type, _ := c.GetInt64("sick_type")
  1433. sick_history := c.GetString("sick_history")
  1434. doctor_id, _ := c.GetInt64("doctor", 0)
  1435. department, _ := c.GetInt64("department", 0)
  1436. his_patient_id, _ := c.GetInt64("his_patient_id")
  1437. p_type, _ := c.GetInt64("p_type")
  1438. patient_diagnose := c.GetString("patient_diagnose")
  1439. dataBody := make(map[string]interface{}, 0)
  1440. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1441. if err != nil {
  1442. utils.ErrorLog(err.Error())
  1443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1444. return
  1445. }
  1446. timeLayout := "2006-01-02"
  1447. loc, _ := time.LoadLocation("Local")
  1448. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1449. if err != nil {
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1451. return
  1452. }
  1453. adminInfo := c.GetAdminUserInfo()
  1454. recordDateTime := theTime.Unix()
  1455. //查询默认出库仓库库存
  1456. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1457. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1458. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1459. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1460. if len(lists) == 1 {
  1461. his_patient_id = lists[0].ID
  1462. }
  1463. }
  1464. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1465. //保存处方出库
  1466. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1467. //自动出库
  1468. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1469. //耗材保存处方出库
  1470. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1471. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1472. //已发药和已收费限制逻辑
  1473. isMidicine := false
  1474. isCharge := false
  1475. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1476. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1477. if len(prescriptions) > 0 {
  1478. for _, item := range prescriptions {
  1479. items := item.(map[string]interface{})
  1480. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1481. utils.ErrorLog("id")
  1482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1483. return
  1484. }
  1485. id := int64(items["id"].(float64))
  1486. if id > 0 {
  1487. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1488. if err != nil {
  1489. if new_prescription.OrderStatus == 4 {
  1490. isCharge = true
  1491. }
  1492. }
  1493. }
  1494. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1495. advices := items["advices"].([]interface{})
  1496. if len(advices) > 0 {
  1497. for _, advice := range advices {
  1498. var adviceId int64
  1499. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1500. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1501. }
  1502. if adviceId > 0 {
  1503. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1504. if err == nil {
  1505. if his_advice_info.IsMedicine == 1 {
  1506. isMidicine = true
  1507. }
  1508. }
  1509. }
  1510. }
  1511. }
  1512. }
  1513. }
  1514. }
  1515. }
  1516. if isMidicine == true {
  1517. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1518. return
  1519. }
  1520. if isCharge == true {
  1521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1522. return
  1523. }
  1524. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1525. //药品发药出库
  1526. if pharmacyConfig.IsOpen == 1 {
  1527. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1528. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1529. if len(prescriptions) > 0 {
  1530. for _, item := range prescriptions {
  1531. items := item.(map[string]interface{})
  1532. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1533. advices := items["advices"].([]interface{})
  1534. if len(advices) > 0 {
  1535. for _, advice := range advices {
  1536. var drug_id int64
  1537. var prescribing_number float64
  1538. var prescribingNumberUnit string
  1539. var adviceId int64
  1540. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1541. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1542. }
  1543. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1544. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1545. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1546. }
  1547. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1548. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1549. }
  1550. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1551. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1552. }
  1553. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1554. if drug.ID == 0 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1556. return
  1557. }
  1558. //查询药品的所有库存
  1559. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1560. var total_count int64
  1561. for _, it := range list {
  1562. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1563. }
  1564. totals := strconv.FormatInt(total_count, 10)
  1565. //查询该药品是否存在开药记录
  1566. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1567. //新增处方
  1568. if advicelist.ID == 0 {
  1569. all_count, _ := strconv.ParseFloat(totals, 64)
  1570. if prescribingNumberUnit == drug.MinUnit {
  1571. if drug.IsUse != 1 {
  1572. if prescribing_number > all_count {
  1573. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1574. return
  1575. }
  1576. }
  1577. }
  1578. if prescribingNumberUnit == drug.MaxUnit {
  1579. num := prescribing_number * float64(drug.MinNumber)
  1580. if drug.IsUse != 1 {
  1581. if num > all_count {
  1582. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1583. return
  1584. }
  1585. }
  1586. }
  1587. }
  1588. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1589. if drugOutConfig.IsOpen != 1 {
  1590. //修改处方
  1591. for _, advice := range advices {
  1592. var drug_id int64
  1593. var prescribing_number float64
  1594. var prescribingNumberUnit string
  1595. var prescribingNumber string
  1596. var adviceId int64
  1597. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1598. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1599. }
  1600. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1601. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1602. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1603. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1604. }
  1605. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1606. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1607. }
  1608. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1609. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1610. }
  1611. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1612. if drug.ID == 0 {
  1613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1614. return
  1615. }
  1616. //查询药品的所有库存
  1617. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1618. var total_count int64
  1619. for _, it := range list {
  1620. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1621. }
  1622. totals := strconv.FormatInt(total_count, 10)
  1623. //查询该药品是否存在开药记录
  1624. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1625. //新增处方
  1626. if advicelist.ID == 0 {
  1627. all_count, _ := strconv.ParseFloat(totals, 64)
  1628. if prescribingNumberUnit == drug.MinUnit {
  1629. if drug.IsUse != 1 {
  1630. if prescribing_number > all_count {
  1631. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1632. return
  1633. }
  1634. }
  1635. } else {
  1636. if prescribingNumberUnit == drug.MaxUnit {
  1637. num := prescribing_number * float64(drug.MinNumber)
  1638. if drug.IsUse != 1 {
  1639. if num > all_count {
  1640. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1641. return
  1642. }
  1643. }
  1644. }
  1645. }
  1646. }
  1647. //修改处方
  1648. if advicelist.ID > 0 {
  1649. var device_number int64
  1650. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1651. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1652. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1653. device_number = prescribingNumberInt * drug.MinNumber
  1654. }
  1655. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1656. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1657. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1658. device_number = prescribingNumberInt
  1659. }
  1660. var number_count int64
  1661. if prescribingNumberUnit == drug.MaxUnit {
  1662. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1663. number_count = prescribingNumberInt * drug.MinNumber
  1664. }
  1665. if prescribingNumberUnit == drug.MinUnit {
  1666. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1667. number_count = prescribingNumberInt
  1668. }
  1669. //如果修改的数量大于之前修改的数量
  1670. if (number_count - device_number) > 0 {
  1671. //如果修改的差数量 大于库存数量
  1672. if drug.IsUse != 1 {
  1673. if (number_count - device_number) > total_count {
  1674. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1675. return
  1676. }
  1677. }
  1678. }
  1679. }
  1680. }
  1681. }
  1682. }
  1683. }
  1684. }
  1685. }
  1686. }
  1687. }
  1688. }
  1689. //已发药和已收费限制逻辑
  1690. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1691. //校验库存总量
  1692. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1693. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1694. if len(prescriptions) > 0 {
  1695. for _, item := range prescriptions {
  1696. items := item.(map[string]interface{})
  1697. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1698. advices := items["advices"].([]interface{})
  1699. if len(advices) > 0 {
  1700. for _, advice := range advices {
  1701. var drug_id int64
  1702. var prescribing_number float64
  1703. var prescribingNumberUnit string
  1704. var adviceId int64
  1705. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1706. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1709. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1710. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1711. }
  1712. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1713. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1714. }
  1715. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1716. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1717. }
  1718. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1719. if drug.ID == 0 {
  1720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1721. return
  1722. }
  1723. //查询药品的所有库存
  1724. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1725. var total_count int64
  1726. for _, it := range list {
  1727. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1728. }
  1729. totals := strconv.FormatInt(total_count, 10)
  1730. //查询该药品是否存在开药记录
  1731. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1732. //查询最新批次库存
  1733. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1734. var batch_number_count int64
  1735. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1736. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1737. //新增处方
  1738. if advicelist.ID == 0 {
  1739. all_count, _ := strconv.ParseFloat(totals, 64)
  1740. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1741. if prescribingNumberUnit == drug.MinUnit {
  1742. if drug.IsUse != 1 {
  1743. if prescribing_number > all_count {
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1745. return
  1746. }
  1747. if adminInfo.CurrentOrgId == 10215 {
  1748. if prescribing_number > batch_number_all_count {
  1749. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1750. return
  1751. }
  1752. }
  1753. }
  1754. }
  1755. if prescribingNumberUnit == drug.MaxUnit {
  1756. num := prescribing_number * float64(drug.MinNumber)
  1757. if drug.IsUse != 1 {
  1758. if num > all_count {
  1759. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1760. return
  1761. }
  1762. if adminInfo.CurrentOrgId == 10215 {
  1763. if num > batch_number_all_count {
  1764. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1765. return
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1772. if drugOutConfig.IsOpen != 1 {
  1773. //修改处方
  1774. for _, advice := range advices {
  1775. var drug_id int64
  1776. var prescribing_number float64
  1777. var prescribingNumberUnit string
  1778. var prescribingNumber string
  1779. var adviceId int64
  1780. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1781. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1782. }
  1783. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1784. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1785. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1786. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1787. }
  1788. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1789. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1790. }
  1791. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1792. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1793. }
  1794. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1795. if drug.ID == 0 {
  1796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1797. return
  1798. }
  1799. //查询药品的所有库存
  1800. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1801. var total_count int64
  1802. for _, it := range list {
  1803. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1804. }
  1805. totals := strconv.FormatInt(total_count, 10)
  1806. //查询该药品是否存在开药记录
  1807. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1808. //新增处方
  1809. if advicelist.ID == 0 {
  1810. //查询最新批次库存
  1811. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1812. var batch_number_count int64
  1813. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1814. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1815. all_count, _ := strconv.ParseFloat(totals, 64)
  1816. if prescribingNumberUnit == drug.MinUnit {
  1817. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1818. if drug.IsUse != 1 {
  1819. if prescribing_number > all_count {
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. if adminInfo.CurrentOrgId == 10215 {
  1824. if prescribing_number > batch_number_all_count {
  1825. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1826. return
  1827. }
  1828. }
  1829. }
  1830. } else {
  1831. if prescribingNumberUnit == drug.MaxUnit {
  1832. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1833. num := prescribing_number * float64(drug.MinNumber)
  1834. if drug.IsUse != 1 {
  1835. if num > all_count {
  1836. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1837. return
  1838. }
  1839. if adminInfo.CurrentOrgId == 10215 {
  1840. if prescribing_number > batch_number_all_count {
  1841. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1842. return
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }
  1849. //修改处方
  1850. if advicelist.ID > 0 {
  1851. //查询最新批次库存
  1852. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1853. var batch_number_count int64
  1854. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1855. var device_number int64
  1856. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1857. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1858. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1859. device_number = prescribingNumberInt * drug.MinNumber
  1860. }
  1861. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1862. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1863. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1864. device_number = prescribingNumberInt
  1865. }
  1866. var number_count int64
  1867. if prescribingNumberUnit == drug.MaxUnit {
  1868. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1869. number_count = prescribingNumberInt * drug.MinNumber
  1870. }
  1871. if prescribingNumberUnit == drug.MinUnit {
  1872. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1873. number_count = prescribingNumberInt
  1874. }
  1875. //如果修改的数量大于之前修改的数量
  1876. if (number_count - device_number) > 0 {
  1877. //如果修改的差数量 大于库存数量
  1878. if drug.IsUse != 1 {
  1879. if (number_count - device_number) > total_count {
  1880. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1881. return
  1882. }
  1883. if (number_count - device_number) > batch_number_count {
  1884. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1885. return
  1886. }
  1887. if adminInfo.CurrentOrgId == 10215 {
  1888. // 查询该药品最后一次出库记录
  1889. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1890. var out_count int64
  1891. var in_count int64
  1892. var stock_max_number int64
  1893. var stock_min_number int64
  1894. for _, it := range outInfo {
  1895. if it.CountUnit == drug.MaxUnit {
  1896. it.Count = it.Count * drug.MinNumber
  1897. }
  1898. out_count += it.Count
  1899. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1900. stock_max_number = warehouseInfoList.StockMaxNumber
  1901. stock_min_number = warehouseInfoList.StockMinNumber
  1902. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1903. }
  1904. if out_count > 0 {
  1905. if (number_count - device_number) > in_count {
  1906. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1907. return
  1908. }
  1909. }
  1910. // 未出库
  1911. if out_count == 0 {
  1912. var sum_in_count int64
  1913. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1914. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1915. fmt.Println("sum_in_count", sum_in_count)
  1916. //如果修改的数量大于有库存的第一个批次
  1917. if number_count > sum_in_count {
  1918. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1919. return
  1920. }
  1921. }
  1922. }
  1923. }
  1924. }
  1925. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1926. if pharmacyConfig.IsOpen != 1 {
  1927. if device_number != number_count {
  1928. // 查询该药品最后一次出库记录
  1929. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1930. //回退库存
  1931. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1932. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1933. }
  1934. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1935. var stock_max_number int64
  1936. var stock_min_number int64
  1937. if number_count >= drug.MinNumber {
  1938. stock_max_number = device_number / drug.MinNumber
  1939. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1940. stock_min_number = device_number % drug.MinNumber
  1941. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1942. } else {
  1943. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1944. }
  1945. }
  1946. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1947. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1948. }
  1949. //删除记录
  1950. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1951. //查询默认仓库剩余多少库存
  1952. var sum_count int64
  1953. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1954. for _, its := range stockInfo {
  1955. if its.MaxUnit == drug.MaxUnit {
  1956. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1957. }
  1958. sum_count += its.StockMaxNumber + its.StockMinNumber
  1959. }
  1960. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1961. }
  1962. }
  1963. }
  1964. }
  1965. }
  1966. //保存处方开药
  1967. if drugOutConfig.IsOpen == 1 {
  1968. //修改处方
  1969. for _, advice := range advices {
  1970. var drug_id int64
  1971. var prescribing_number float64
  1972. var prescribingNumberUnit string
  1973. var prescribingNumber string
  1974. var adviceId int64
  1975. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1976. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1977. }
  1978. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1979. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1980. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1981. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1982. }
  1983. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1984. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1985. }
  1986. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1987. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1988. }
  1989. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1990. if drug.ID == 0 {
  1991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1992. return
  1993. }
  1994. //查询药品的所有库存
  1995. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1996. var total_count int64
  1997. for _, it := range list {
  1998. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1999. }
  2000. totals := strconv.FormatInt(total_count, 10)
  2001. //查询该药品是否存在开药记录
  2002. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2003. //新增处方
  2004. if advicelist.ID == 0 {
  2005. //查询最新批次库存
  2006. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2007. var batch_number_count int64
  2008. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2009. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2010. all_count, _ := strconv.ParseFloat(totals, 64)
  2011. if prescribingNumberUnit == drug.MinUnit {
  2012. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2013. if drug.IsUse != 1 {
  2014. if prescribing_number > all_count {
  2015. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2016. return
  2017. }
  2018. if adminInfo.CurrentOrgId == 10215 {
  2019. if prescribing_number > batch_number_all_count {
  2020. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2021. return
  2022. }
  2023. }
  2024. }
  2025. } else {
  2026. if prescribingNumberUnit == drug.MaxUnit {
  2027. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2028. num := prescribing_number * float64(drug.MinNumber)
  2029. if drug.IsUse != 1 {
  2030. if num > all_count {
  2031. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2032. return
  2033. }
  2034. if adminInfo.CurrentOrgId == 10215 {
  2035. if prescribing_number > batch_number_all_count {
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2037. return
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. //修改处方
  2045. if advicelist.ID > 0 {
  2046. //查询最新批次库存
  2047. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2048. var batch_number_count int64
  2049. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2050. var device_number int64
  2051. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2052. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2053. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2054. device_number = prescribingNumberInt * drug.MinNumber
  2055. }
  2056. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2057. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2058. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2059. device_number = prescribingNumberInt
  2060. }
  2061. var number_count int64
  2062. if prescribingNumberUnit == drug.MaxUnit {
  2063. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2064. number_count = prescribingNumberInt * drug.MinNumber
  2065. }
  2066. if prescribingNumberUnit == drug.MinUnit {
  2067. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2068. number_count = prescribingNumberInt
  2069. }
  2070. //如果修改的数量大于之前修改的数量
  2071. if (number_count - device_number) > 0 {
  2072. //如果修改的差数量 大于库存数量
  2073. if drug.IsUse != 1 {
  2074. if (number_count - device_number) > total_count {
  2075. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2076. return
  2077. }
  2078. if adminInfo.CurrentOrgId == 10215 {
  2079. if (number_count - device_number) > batch_number_count {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2081. return
  2082. }
  2083. }
  2084. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2085. //查询历史出库数据总批次
  2086. // 查询该药品最后一次出库记录
  2087. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2088. var out_count int64
  2089. var in_count int64
  2090. var stock_max_number int64
  2091. var stock_min_number int64
  2092. for _, it := range outInfo {
  2093. if it.CountUnit == drug.MaxUnit {
  2094. it.Count = it.Count * drug.MinNumber
  2095. }
  2096. out_count += it.Count
  2097. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2098. stock_max_number = warehouseInfoList.StockMaxNumber
  2099. stock_min_number = warehouseInfoList.StockMinNumber
  2100. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2101. }
  2102. if out_count > 0 {
  2103. if (number_count - device_number) > in_count {
  2104. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2105. return
  2106. }
  2107. }
  2108. // 未出库
  2109. if out_count == 0 {
  2110. var sum_in_count int64
  2111. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2112. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2113. //如果修改的数量大于有库存的第一个批次
  2114. if number_count > sum_in_count {
  2115. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2116. return
  2117. }
  2118. }
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. //校验耗材库存
  2133. if goodOutConfig.IsOpen == 1 {
  2134. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2135. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2136. if len(prescriptions) > 0 {
  2137. for _, item := range prescriptions {
  2138. items := item.(map[string]interface{})
  2139. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2140. projects := items["project"].([]interface{})
  2141. if len(projects) > 0 {
  2142. for _, project := range projects {
  2143. var project_id int64
  2144. var project_type int64
  2145. var totals float64
  2146. var project_name string
  2147. var parsetotal int64
  2148. var id int64
  2149. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2150. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2151. }
  2152. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2153. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2154. }
  2155. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2156. total, _ := project.(map[string]interface{})["total"].(string)
  2157. totals, _ = strconv.ParseFloat(total, 64)
  2158. }
  2159. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2160. project_name = project.(map[string]interface{})["project_name"].(string)
  2161. }
  2162. if project_type == 3 {
  2163. //查找该耗材的出库记录
  2164. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2165. if len(goodWarehouseInfo) == 0 {
  2166. //查询耗材库存
  2167. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2168. var stock_count int64
  2169. for _, it := range list {
  2170. stock_count += it.StockCount
  2171. }
  2172. stock_counts := strconv.FormatInt(stock_count, 10)
  2173. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2174. if totals > stock_total_count {
  2175. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2176. return
  2177. }
  2178. }
  2179. if len(goodWarehouseInfo) > 0 {
  2180. //查询该患者耗材的历史数据
  2181. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2182. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2183. //数量发生改变
  2184. if parsetotal != count {
  2185. //如果现在的数量大于历史数量,就要看库存是否足够
  2186. if parsetotal > count {
  2187. //查询耗材所有库存
  2188. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2189. var stock_count int64
  2190. for _, it := range list {
  2191. stock_count += it.StockCount
  2192. }
  2193. //库存不足
  2194. if (parsetotal - count) > stock_count {
  2195. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2196. return
  2197. }
  2198. }
  2199. }
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. }
  2208. }
  2209. //不使用耗材保存处方出库
  2210. if goodOutConfig.IsOpen != 1 {
  2211. if stockConfig.IsOpen == 1 {
  2212. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2213. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2214. if len(prescriptions) > 0 {
  2215. for _, item := range prescriptions {
  2216. items := item.(map[string]interface{})
  2217. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2218. projects := items["project"].([]interface{})
  2219. if len(projects) > 0 {
  2220. for _, project := range projects {
  2221. var project_id int64
  2222. var project_type int64
  2223. var totals float64
  2224. var project_name string
  2225. var parsetotal int64
  2226. var id int64
  2227. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2228. id = int64(project.(map[string]interface{})["id"].(float64))
  2229. }
  2230. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2231. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2232. }
  2233. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2234. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2235. }
  2236. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2237. total, _ := project.(map[string]interface{})["total"].(string)
  2238. totals, _ = strconv.ParseFloat(total, 64)
  2239. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2240. }
  2241. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2242. project_name = project.(map[string]interface{})["project_name"].(string)
  2243. }
  2244. if project_type == 3 {
  2245. //查找该耗材的出库记录
  2246. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2247. //没有出库记录
  2248. if len(goodWarehouseInfo) == 0 {
  2249. //查询耗材库存
  2250. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2251. var stock_count int64
  2252. for _, it := range list {
  2253. stock_count += it.StockCount
  2254. }
  2255. stock_counts := strconv.FormatInt(stock_count, 10)
  2256. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2257. if totals > stock_total_count {
  2258. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2259. return
  2260. }
  2261. //查找今日该患者已经出库的所有耗材
  2262. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2263. for _, item := range goodList {
  2264. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2265. var flush_count int64
  2266. for _, it := range goodListSix {
  2267. flush_count += it.StockCount
  2268. }
  2269. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2270. creater := adminInfo.AdminUser.Id
  2271. if errs != nil {
  2272. goodErrcode := models.XtGoodErrcode{
  2273. UserOrgId: item.OrgId,
  2274. Errcode: "手动出库更新剩余出库失败",
  2275. GoodId: item.GoodId,
  2276. Status: 1,
  2277. Ctime: time.Now().Unix(),
  2278. Mtime: 0,
  2279. Count: 0,
  2280. StockCount: 0,
  2281. Creater: creater,
  2282. BatchNumberId: 0,
  2283. WarehouseOutId: 0,
  2284. }
  2285. service.CreateGoodErrcode(goodErrcode)
  2286. }
  2287. }
  2288. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2289. }
  2290. //有出库记录
  2291. if len(goodWarehouseInfo) > 0 {
  2292. //查询该患者耗材的历史数据
  2293. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2294. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2295. //数量发生改变
  2296. if parsetotal != count {
  2297. //查找今日该患者已经出库的所有耗材
  2298. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2299. for _, item := range goodList {
  2300. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2301. var flush_count int64
  2302. for _, it := range goodListSix {
  2303. flush_count += it.StockCount
  2304. }
  2305. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2306. //减少出库数量
  2307. creater := adminInfo.AdminUser.Id
  2308. if errs != nil {
  2309. goodErrcode := models.XtGoodErrcode{
  2310. UserOrgId: item.OrgId,
  2311. Errcode: "手动出库更新剩余出库失败",
  2312. GoodId: item.GoodId,
  2313. Status: 1,
  2314. Ctime: time.Now().Unix(),
  2315. Mtime: 0,
  2316. Count: 0,
  2317. StockCount: 0,
  2318. Creater: creater,
  2319. BatchNumberId: 0,
  2320. WarehouseOutId: 0,
  2321. }
  2322. service.CreateGoodErrcode(goodErrcode)
  2323. }
  2324. //查询默认仓库
  2325. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2326. var total_count int64
  2327. for _, it := range stockList {
  2328. total_count += it.StockCount
  2329. }
  2330. //基础库插入数据
  2331. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2332. }
  2333. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2334. }
  2335. }
  2336. }
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2346. var hpInfo models.HisPrescriptionInfo
  2347. if info.ID == 0 {
  2348. var randNum int
  2349. randNum = rand.Intn(10000) + 1000
  2350. timestamp := time.Now().Unix()
  2351. tempTime := time.Unix(timestamp, 0)
  2352. timeFormat := tempTime.Format("20060102150405")
  2353. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2354. hpInfo = models.HisPrescriptionInfo{
  2355. HisPatientId: his_patient_id,
  2356. UserOrgId: adminInfo.CurrentOrgId,
  2357. RecordDate: theTime.Unix(),
  2358. PatientId: patient_id,
  2359. Status: 1,
  2360. Ctime: time.Now().Unix(),
  2361. Mtime: time.Now().Unix(),
  2362. Creator: adminInfo.AdminUser.Id,
  2363. Modifier: adminInfo.AdminUser.Id,
  2364. Diagnosis: diagnose,
  2365. SickHistory: sick_history,
  2366. Departments: department,
  2367. RegisterType: reg_type,
  2368. PrescriptionNumber: p_number,
  2369. PrescriptionStatus: 1,
  2370. Doctor: role.UserName,
  2371. DoctorId: doctor_id,
  2372. SickType: sick_type,
  2373. PType: p_type,
  2374. PatientDiagnosis: patient_diagnose,
  2375. }
  2376. service.SavePatientPrescriptionInfo(hpInfo)
  2377. //创建步骤表
  2378. finish := models.XtDialysisFinish{
  2379. IsFinish: 1,
  2380. UserOrgId: adminInfo.CurrentOrgId,
  2381. Status: 1,
  2382. Ctime: time.Now().Unix(),
  2383. Mtime: 0,
  2384. Module: 4,
  2385. RecordDate: theTime.Unix(),
  2386. Sourse: 1,
  2387. PatientId: patient_id,
  2388. }
  2389. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2390. if dialysisFinish.ID == 0 {
  2391. service.CreateDialysisFinish(finish)
  2392. }
  2393. redis := service.RedisClient()
  2394. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2395. redis.Set(key, "", time.Second)
  2396. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2397. redis.Set(keyOne, "", time.Second)
  2398. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2399. redis.Set(keySeven, "", time.Second)
  2400. defer redis.Close()
  2401. } else {
  2402. hpInfo = models.HisPrescriptionInfo{
  2403. ID: info.ID,
  2404. UserOrgId: adminInfo.CurrentOrgId,
  2405. RecordDate: info.RecordDate,
  2406. PatientId: info.PatientId,
  2407. Status: 1,
  2408. Ctime: info.Ctime,
  2409. Mtime: time.Now().Unix(),
  2410. Creator: info.Creator,
  2411. Modifier: adminInfo.AdminUser.Id,
  2412. Diagnosis: diagnose,
  2413. SickHistory: sick_history,
  2414. Departments: department,
  2415. RegisterType: reg_type,
  2416. PrescriptionNumber: info.PrescriptionNumber,
  2417. Doctor: role.UserName,
  2418. PrescriptionStatus: info.PrescriptionStatus,
  2419. DoctorId: doctor_id,
  2420. SickType: sick_type,
  2421. PType: info.PType,
  2422. HisPatientId: info.HisPatientId,
  2423. PatientDiagnosis: patient_diagnose,
  2424. }
  2425. service.SavePatientPrescriptionInfo(hpInfo)
  2426. //创建步骤表
  2427. finish := models.XtDialysisFinish{
  2428. IsFinish: 1,
  2429. UserOrgId: adminInfo.CurrentOrgId,
  2430. Status: 1,
  2431. Ctime: time.Now().Unix(),
  2432. Mtime: 0,
  2433. Module: 4,
  2434. RecordDate: info.RecordDate,
  2435. Sourse: 1,
  2436. PatientId: info.PatientId,
  2437. }
  2438. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2439. if dialysisFinish.ID == 0 {
  2440. service.CreateDialysisFinish(finish)
  2441. }
  2442. redis := service.RedisClient()
  2443. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2444. redis.Set(key, "", time.Second)
  2445. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2446. redis.Set(keyOne, "", time.Second)
  2447. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2448. redis.Set(keySeven, "", time.Second)
  2449. defer redis.Close()
  2450. }
  2451. //定义切片
  2452. var adviceList []models.HisDoctorAdviceInfo
  2453. var projectList []models.HisPrescriptionProject
  2454. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2455. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2456. var tempPrescription *models.HisPrescription
  2457. if len(prescriptions) > 0 {
  2458. for _, item := range prescriptions {
  2459. items := item.(map[string]interface{})
  2460. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2461. utils.ErrorLog("id")
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2463. return
  2464. }
  2465. id := int64(items["id"].(float64))
  2466. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2467. tempPrescription = &new_prescription
  2468. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2469. utils.ErrorLog("type")
  2470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2471. return
  2472. }
  2473. types := int64(items["type"].(float64))
  2474. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2475. utils.ErrorLog("med_type")
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2480. if med_type == "0" {
  2481. med_type = "14"
  2482. }
  2483. //if order_status == 0 {
  2484. // order_status = 1
  2485. //}
  2486. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2487. utils.ErrorLog("pre_time")
  2488. }
  2489. preTime, _ := items["pre_time"].(string)
  2490. timeLayout := "2006-01-02"
  2491. loc, _ := time.LoadLocation("Local")
  2492. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2493. if err != nil {
  2494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2495. return
  2496. }
  2497. pTime := theTime2.Unix()
  2498. ctime := time.Now().Unix()
  2499. if tempPrescription.ID == 0 {
  2500. prescription := &models.HisPrescription{
  2501. ID: 0,
  2502. PatientId: patient_id,
  2503. UserOrgId: adminInfo.CurrentOrgId,
  2504. RecordDate: recordDateTime,
  2505. Ctime: ctime,
  2506. Mtime: ctime,
  2507. Type: types,
  2508. Modifier: adminInfo.AdminUser.Id,
  2509. Creator: adminInfo.AdminUser.Id,
  2510. Status: 1,
  2511. Doctor: role.UserName,
  2512. HisPatientId: his_patient_id,
  2513. OrderStatus: 1,
  2514. BatchNumber: "",
  2515. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2516. PreTime: pTime,
  2517. PType: p_type,
  2518. MedType: med_type,
  2519. }
  2520. tempPrescription = prescription
  2521. service.SaveHisPrescription(tempPrescription)
  2522. redis := service.RedisClient()
  2523. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2524. redis.Set(key, "", time.Second)
  2525. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2526. redis.Set(keyOne, "", time.Second)
  2527. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2528. redis.Set(keySeven, "", time.Second)
  2529. defer redis.Close()
  2530. } else {
  2531. tempPrescription.ID = id
  2532. tempPrescription.Type = types
  2533. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2534. tempPrescription.Mtime = time.Now().Unix()
  2535. tempPrescription.Doctor = role.UserName
  2536. //tempPrescription.OrderStatus = order_status
  2537. tempPrescription.PreTime = pTime
  2538. tempPrescription.MedType = med_type
  2539. service.SaveHisPrescription(tempPrescription)
  2540. redis := service.RedisClient()
  2541. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2542. redis.Set(key, "", time.Second)
  2543. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2544. redis.Set(keyOne, "", time.Second)
  2545. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2546. redis.Set(keySeven, "", time.Second)
  2547. defer redis.Close()
  2548. }
  2549. //service.SaveHisPrescription(prescription)
  2550. //更改患者挂号状态
  2551. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2552. fmt.Println("更改失败", err2)
  2553. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2554. advices := items["advices"].([]interface{})
  2555. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2556. groupNo := int64(0)
  2557. ctime := time.Now().Unix()
  2558. mtime := ctime
  2559. if len(advices) > 0 {
  2560. for _, advice := range advices {
  2561. var s models.HisDoctorAdviceInfo
  2562. s.PrescriptionId = tempPrescription.ID
  2563. s.AdviceType = 2
  2564. s.AdviceDoctor = doctor_id
  2565. s.StopState = 2
  2566. s.ExecutionState = 2
  2567. s.AdviceDate = recordDateTime
  2568. s.Status = 1
  2569. s.UserOrgId = adminInfo.CurrentOrgId
  2570. s.RecordDate = recordDateTime
  2571. s.StartTime = tempPrescription.PreTime
  2572. s.Groupno = groupNo
  2573. s.CreatedTime = ctime
  2574. s.UpdatedTime = mtime
  2575. s.PatientId = patient_id
  2576. s.HisPatientId = his_patient_id
  2577. s.StartTime = pTime
  2578. s.IsSettle = 2
  2579. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2580. if errcode > 0 {
  2581. c.ServeFailJSONWithSGJErrorCode(errcode)
  2582. return
  2583. }
  2584. s.StartTime = pTime
  2585. var total_count int64 //处方总库存
  2586. //查询改药品信息
  2587. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2588. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2589. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2590. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2591. total_count += prescribingNumberSeven * medical.MinNumber
  2592. }
  2593. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2594. total_count += prescribingNumberSeven
  2595. }
  2596. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2597. total_count += prescribingNumberSeven
  2598. }
  2599. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2600. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2601. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2602. if s.Price != lastWarehouse.RetailPrice {
  2603. s.Price = lastWarehouse.RetailPrice
  2604. }
  2605. if s.Price == 0 {
  2606. s.Price = lastWarehouse.RetailPrice
  2607. }
  2608. }
  2609. service.CreateHisDoctorAdvice(&s)
  2610. //记录日志
  2611. byterequest, _ := json.Marshal(s)
  2612. adviceLog := models.XtDoctorAdviceLog{
  2613. UserOrgId: s.UserOrgId,
  2614. PatientId: s.PatientId,
  2615. AdminUserId: adminInfo.AdminUser.Id,
  2616. Module: 1,
  2617. ErrLog: string(byterequest),
  2618. Status: 1,
  2619. Ctime: time.Now().Unix(),
  2620. Mtime: 0,
  2621. Source: "电脑端新建his医嘱",
  2622. RecordDate: s.AdviceDate,
  2623. }
  2624. service.CreateDoctorAdviceLog(adviceLog)
  2625. //存储切片中
  2626. adviceList = append(adviceList, s)
  2627. redis := service.RedisClient()
  2628. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2629. redis.Set(key, "", time.Second)
  2630. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2631. redis.Set(keyOne, "", time.Second)
  2632. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2633. redis.Set(keySeven, "", time.Second)
  2634. var randNum int
  2635. randNum = rand.Intn(10000) + 1000
  2636. timestamp := time.Now().Unix()
  2637. tempTime := time.Unix(timestamp, 0)
  2638. timeFormat := tempTime.Format("20060102150405")
  2639. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2640. service.CreateHisDoctorAdvice(&s)
  2641. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2642. redis.Set(keySix, "", time.Second)
  2643. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2644. redis.Set(keyFive, "", time.Second)
  2645. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2646. redis.Set(keyEight, "", time.Second)
  2647. defer redis.Close()
  2648. }
  2649. }
  2650. }
  2651. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2652. projects := items["project"].([]interface{})
  2653. if len(projects) > 0 {
  2654. for _, project := range projects {
  2655. var p models.HisPrescriptionProject
  2656. p.PrescriptionId = tempPrescription.ID
  2657. p.Ctime = time.Now().Unix()
  2658. p.Mtime = time.Now().Unix()
  2659. p.PatientId = patient_id
  2660. p.RecordDate = recordDateTime
  2661. p.Doctor = doctor_id
  2662. p.UserOrgId = adminInfo.CurrentOrgId
  2663. p.HisPatientId = his_patient_id
  2664. p.Status = 1
  2665. p.StartTime = pTime
  2666. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2667. if errcode > 0 {
  2668. c.ServeFailJSONWithSGJErrorCode(errcode)
  2669. return
  2670. }
  2671. if p.ID == 0 {
  2672. p.IsOut = 2
  2673. }
  2674. if p.ID > 0 {
  2675. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2676. p.IsOut = projectDetail.IsOut
  2677. }
  2678. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2679. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2680. if p.Type == 3 {
  2681. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2682. if p.Price != lastWarehouse.PackingPrice {
  2683. p.Price = lastWarehouse.PackingPrice
  2684. }
  2685. if p.Unit == "" {
  2686. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2687. p.Unit = goodInfoOne.PackingUnit
  2688. }
  2689. }
  2690. }
  2691. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2692. //
  2693. // if p.Type == 3 {
  2694. // //查询该耗材是否停用
  2695. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2696. // //表示该耗材已经停用,不能保存
  2697. // if goodInfoSeven.ID == 0 {
  2698. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2699. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2700. // return
  2701. // }
  2702. // }
  2703. //
  2704. //}
  2705. service.CreateHisProjectTwo(&p)
  2706. //记录日志
  2707. byterequest, _ := json.Marshal(p)
  2708. adviceLog := models.XtDoctorAdviceLog{
  2709. UserOrgId: p.UserOrgId,
  2710. PatientId: p.PatientId,
  2711. AdminUserId: adminInfo.AdminUser.Id,
  2712. Module: 1,
  2713. ErrLog: string(byterequest),
  2714. Status: 1,
  2715. Ctime: time.Now().Unix(),
  2716. Mtime: 0,
  2717. Source: "电脑端新建his项目",
  2718. RecordDate: p.RecordDate,
  2719. }
  2720. service.CreateDoctorAdviceLog(adviceLog)
  2721. projectList = append(projectList, p)
  2722. var randNum int
  2723. randNum = rand.Intn(10000) + 1000
  2724. timestamp := time.Now().Unix()
  2725. tempTime := time.Unix(timestamp, 0)
  2726. timeFormat := tempTime.Format("20060102150405")
  2727. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2728. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2729. //新增或者编辑项目,修改对应的标签数据
  2730. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2731. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2732. var label models.HisLabelPrintInfo
  2733. project, _ := service.GetProjectDetail(p.ProjectId)
  2734. if project.CostClassify == 3 { //类别为检验检查
  2735. if p.TeamId > 0 { //检验检查组套
  2736. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2737. if tempLabel.ID == 0 {
  2738. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2739. label.Number = tempPrescription.PrescriptionNumber
  2740. label.ProjectId = project.ID
  2741. label.Status = 1
  2742. label.IsPrint = 2
  2743. label.DoctorId = info.DoctorId
  2744. label.UserOrgId = p.UserOrgId
  2745. label.PatientId = patient_id
  2746. label.RecordDate = recordDateTime
  2747. label.Ctime = time.Now().Unix()
  2748. label.Mtime = time.Now().Unix()
  2749. label.ItemId = p.TeamId
  2750. label.FeedetlSn = p.FeedetlSn
  2751. label.PProjectId = p.ID
  2752. label.ProjectName = team.ProjectTeam
  2753. label.PatientName = patient.Name
  2754. service.CreateHisLabelRecord(&label)
  2755. }
  2756. } else { //单条检验检查项目
  2757. label.Number = tempPrescription.PrescriptionNumber
  2758. label.ProjectId = project.ID
  2759. label.Status = 1
  2760. label.DoctorId = info.DoctorId
  2761. label.UserOrgId = p.UserOrgId
  2762. label.PatientId = patient_id
  2763. label.RecordDate = recordDateTime
  2764. label.IsPrint = 2
  2765. label.Ctime = time.Now().Unix()
  2766. label.Mtime = time.Now().Unix()
  2767. label.FeedetlSn = p.FeedetlSn
  2768. label.PProjectId = p.ID
  2769. label.ItemId = p.TeamId
  2770. label.ProjectName = project.ProjectName
  2771. label.PatientName = patient.Name
  2772. service.CreateHisLabelRecord(&label)
  2773. }
  2774. }
  2775. }
  2776. }
  2777. service.SaveHisProjectTwo(&p)
  2778. }
  2779. }
  2780. }
  2781. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2782. // addition := items["addition"].([]interface{})
  2783. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2784. // ctime := time.Now().Unix()
  2785. // mtime := ctime
  2786. // if len(addition) > 0 {
  2787. // for _, item := range addition {
  2788. // var s models.HisAdditionalCharge
  2789. // s.PrescriptionId = tempPrescription.ID
  2790. // s.Status = 1
  2791. // s.UserOrgId = adminInfo.CurrentOrgId
  2792. // s.RecordDate = recordDateTime
  2793. // s.CreatedTime = ctime
  2794. // s.UpdatedTime = mtime
  2795. // s.PatientId = patient_id
  2796. // s.HisPatientId = his_patient_id
  2797. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2798. // if errcode > 0 {
  2799. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2800. // return
  2801. // }
  2802. // service.CreateAdditionalCharge(&s)
  2803. // var randNum int
  2804. // randNum = rand.Intn(10000) + 1000
  2805. // timestamp := time.Now().Unix()
  2806. // tempTime := time.Unix(timestamp, 0)
  2807. // timeFormat := tempTime.Format("20060102150405")
  2808. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2809. // service.CreateAdditionalCharge(&s)
  2810. //
  2811. // }
  2812. // }
  2813. //}
  2814. }
  2815. }
  2816. //查询今日该患者开的药品处方
  2817. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2818. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2819. //药品出库
  2820. if drugOutConfig.IsOpen == 1 {
  2821. for _, item := range hisdoctorlist {
  2822. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2823. // 查询该药品最后一次出库记录
  2824. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2825. if len(druginfo) > 0 {
  2826. //回退库存
  2827. for _, it := range druginfo {
  2828. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2829. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2830. }
  2831. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2832. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2833. }
  2834. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2835. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2836. }
  2837. }
  2838. }
  2839. //删除记录
  2840. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2841. //查询最后一次数据
  2842. if drugOutConfig.IsOpen == 1 {
  2843. //出库
  2844. if drug.IsUse == 2 {
  2845. creater := adminInfo.AdminUser.Id
  2846. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2847. }
  2848. //更新字典里面的库存
  2849. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2850. var sum_count int64
  2851. for _, its := range stockInfo {
  2852. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2853. if its.MaxUnit == baseDrug.MaxUnit {
  2854. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2855. }
  2856. sum_count += its.StockMaxNumber + its.StockMinNumber
  2857. }
  2858. //更新基础库存
  2859. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2860. //剩余库存
  2861. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2862. }
  2863. }
  2864. }
  2865. //耗材保存处方出库
  2866. if goodOutConfig.IsOpen == 1 {
  2867. //查询今日耗材出库数量
  2868. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2869. for _, item := range hisgoodlist {
  2870. //查询历史出库数据
  2871. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2872. var out_count_five int64
  2873. for _, item := range flowGood {
  2874. out_count_five += item.Count
  2875. }
  2876. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2877. if out_count_five != parseIntCount {
  2878. //查询耗材最后一次出库记录
  2879. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2880. //查询默认出库仓库库存
  2881. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2882. if len(wareOut) > 0 {
  2883. for _, it := range wareOut {
  2884. //回退库存
  2885. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2886. //删除出库记录
  2887. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2888. }
  2889. }
  2890. timeStr := time.Now().Format("2006-01-02")
  2891. timeArr := strings.Split(timeStr, "-")
  2892. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2893. total = total + 1
  2894. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2895. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2896. number = number + total
  2897. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2898. operation_time := time.Now().Unix()
  2899. creater := c.GetAdminUserInfo().AdminUser.Id
  2900. recordDateStr := time.Now().Format("2006-01-02")
  2901. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2902. nowtime := recordDate.Unix()
  2903. warehouseOut := models.WarehouseOut{
  2904. WarehouseOutOrderNumber: warehousing_out_order,
  2905. OperationTime: operation_time,
  2906. OrgId: adminInfo.CurrentOrgId,
  2907. Creater: creater,
  2908. Ctime: time.Now().Unix(),
  2909. Status: 1,
  2910. WarehouseOutTime: nowtime,
  2911. Type: 1,
  2912. StorehouseId: storeConfig.StorehouseOutInfo,
  2913. IsCheck: 1,
  2914. IsSys: 1,
  2915. }
  2916. //查询是否生成出库单
  2917. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2918. if out.ID == 0 {
  2919. service.AddSigleWarehouseOut(&warehouseOut)
  2920. }
  2921. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2922. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2923. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2924. dialyPrepareOne := models.DialysisBeforePrepare{
  2925. GoodTypeId: goodObj.GoodTypeId,
  2926. GoodId: item.ProjectId,
  2927. PatientId: item.PatientId,
  2928. RecordDate: item.RecordDate,
  2929. UserOrgId: adminInfo.CurrentOrgId,
  2930. Count: parseIntCount,
  2931. Ctime: time.Now().Unix(),
  2932. Creater: creater,
  2933. Status: 1,
  2934. StorehouseId: houseConfig.StorehouseOutInfo,
  2935. ProjectId: item.ID,
  2936. }
  2937. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2938. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2939. //查询历史出库数据
  2940. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2941. var out_count int64
  2942. for _, item := range flowGood {
  2943. out_count += item.Count
  2944. }
  2945. //如果历史数和当前数据不想等才进行退库出库
  2946. if out_count != parseIntCount {
  2947. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2948. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2949. detail := models.AutomaticReduceDetail{
  2950. WarehouseOutId: 0,
  2951. WarehouseOutOrderNumber: "",
  2952. PatientId: item.PatientId,
  2953. Ctime: time.Now().Unix(),
  2954. Mtime: 0,
  2955. Status: 1,
  2956. RecordTime: item.RecordDate,
  2957. OrgId: item.UserOrgId,
  2958. GoodId: item.ProjectId,
  2959. GoodTypeId: 0,
  2960. Count: parseIntCount,
  2961. Type: 0,
  2962. ProjectId: item.ID,
  2963. StorehouseId: 0,
  2964. }
  2965. service.CreateAutoDetail(detail)
  2966. //查询剩余库存
  2967. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2968. var sum_count int64
  2969. for _, item := range goodList {
  2970. sum_count += item.StockCount
  2971. }
  2972. //更新剩余库存
  2973. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2974. //耗材
  2975. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2976. }
  2977. }
  2978. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2979. //查询历史出库数据
  2980. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2981. var out_count int64
  2982. for _, item := range flowGood {
  2983. out_count += item.Count
  2984. }
  2985. //如果历史数和当前数据不想等才进行退库出库
  2986. if out_count != parseIntCount {
  2987. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2988. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2989. detail := models.AutomaticReduceDetail{
  2990. WarehouseOutId: 0,
  2991. WarehouseOutOrderNumber: "",
  2992. PatientId: item.PatientId,
  2993. Ctime: time.Now().Unix(),
  2994. Mtime: 0,
  2995. Status: 1,
  2996. RecordTime: item.RecordDate,
  2997. OrgId: item.UserOrgId,
  2998. GoodId: item.ProjectId,
  2999. GoodTypeId: 0,
  3000. Count: parseIntCount,
  3001. Type: 0,
  3002. ProjectId: item.ID,
  3003. StorehouseId: 0,
  3004. }
  3005. service.CreateAutoDetail(detail)
  3006. //查询剩余库存
  3007. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3008. var sum_count int64
  3009. for _, item := range goodList {
  3010. sum_count += item.StockCount
  3011. }
  3012. //更新剩余库存
  3013. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3014. //耗材
  3015. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3016. }
  3017. }
  3018. }
  3019. }
  3020. }
  3021. }
  3022. //redisClient := service.RedisClient()
  3023. //defer redisClient.Close()
  3024. //
  3025. //list := models.HisList{
  3026. // Patient_id: patient_id,
  3027. // Advice_id:0,
  3028. // Record_date: 0,
  3029. // Advice: adviceList,
  3030. // Project: nil,
  3031. //}
  3032. //hisLis = append(hisLis, list)
  3033. //
  3034. //advice_json, _ := json.Marshal(&hisLis)
  3035. //redisClient.RPush("111", advice_json).Result()
  3036. //result, _ := redisClient.RPop("111").Result()
  3037. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3038. //
  3039. //var dat []map[string]interface{}
  3040. //json.Unmarshal([]byte(result), &dat)
  3041. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3042. //
  3043. //for k,v:=range dat{
  3044. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3045. //}
  3046. //project_json, _ := json.Marshal(&projectList)
  3047. //redisClient.LPush("222", project_json).Result()
  3048. if err == nil {
  3049. c.ServeSuccessJSON(map[string]interface{}{
  3050. "msg": "保存成功",
  3051. })
  3052. return
  3053. } else {
  3054. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3055. return
  3056. }
  3057. }
  3058. func (c *HisApiController) EditHisPrescription() {
  3059. record_date := c.GetString("record_date")
  3060. patient_id, _ := c.GetInt64("patient_id")
  3061. reg_type, _ := c.GetInt64("reg_type")
  3062. //diagnose, _ := c.GetInt64("diagnose", 0)
  3063. diagnose := c.GetString("diagnose")
  3064. sick_type, _ := c.GetInt64("sick_type")
  3065. sick_history := c.GetString("sick_history")
  3066. doctor_id, _ := c.GetInt64("doctor", 0)
  3067. department, _ := c.GetInt64("department", 0)
  3068. his_patient_id, _ := c.GetInt64("his_patient_id")
  3069. p_type, _ := c.GetInt64("p_type")
  3070. dataBody := make(map[string]interface{}, 0)
  3071. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3072. if err != nil {
  3073. utils.ErrorLog(err.Error())
  3074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3075. return
  3076. }
  3077. timeLayout := "2006-01-02"
  3078. loc, _ := time.LoadLocation("Local")
  3079. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3080. if err != nil {
  3081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3082. return
  3083. }
  3084. adminInfo := c.GetAdminUserInfo()
  3085. recordDateTime := theTime.Unix()
  3086. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3087. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3088. var hpInfo models.HisPrescriptionInfo
  3089. if info.ID == 0 {
  3090. var randNum int
  3091. randNum = rand.Intn(10000) + 1000
  3092. timestamp := time.Now().Unix()
  3093. tempTime := time.Unix(timestamp, 0)
  3094. timeFormat := tempTime.Format("20060102150405")
  3095. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3096. hpInfo = models.HisPrescriptionInfo{
  3097. UserOrgId: adminInfo.CurrentOrgId,
  3098. RecordDate: theTime.Unix(),
  3099. PatientId: patient_id,
  3100. Status: 1,
  3101. Ctime: time.Now().Unix(),
  3102. Mtime: time.Now().Unix(),
  3103. Creator: adminInfo.AdminUser.Id,
  3104. Modifier: adminInfo.AdminUser.Id,
  3105. Diagnosis: diagnose,
  3106. SickHistory: sick_history,
  3107. Departments: department,
  3108. RegisterType: reg_type,
  3109. PrescriptionNumber: p_number,
  3110. PrescriptionStatus: 1,
  3111. Doctor: role.UserName,
  3112. DoctorId: doctor_id,
  3113. SickType: sick_type,
  3114. PType: p_type,
  3115. }
  3116. service.SavePatientPrescriptionInfo(hpInfo)
  3117. } else {
  3118. hpInfo = models.HisPrescriptionInfo{
  3119. ID: info.ID,
  3120. UserOrgId: adminInfo.CurrentOrgId,
  3121. RecordDate: info.RecordDate,
  3122. PatientId: info.PatientId,
  3123. Status: 1,
  3124. Ctime: info.Ctime,
  3125. Mtime: time.Now().Unix(),
  3126. Creator: info.Creator,
  3127. Modifier: adminInfo.AdminUser.Id,
  3128. Diagnosis: diagnose,
  3129. SickHistory: sick_history,
  3130. Departments: department,
  3131. RegisterType: reg_type,
  3132. PrescriptionNumber: info.PrescriptionNumber,
  3133. Doctor: role.UserName,
  3134. PrescriptionStatus: info.PrescriptionStatus,
  3135. DoctorId: doctor_id,
  3136. SickType: sick_type,
  3137. PType: info.PType,
  3138. }
  3139. service.SavePatientPrescriptionInfo(hpInfo)
  3140. }
  3141. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3142. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3143. if len(prescriptions) > 0 {
  3144. for _, item := range prescriptions {
  3145. items := item.(map[string]interface{})
  3146. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3147. utils.ErrorLog("id")
  3148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3149. return
  3150. }
  3151. id := int64(items["id"].(float64))
  3152. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3153. utils.ErrorLog("type")
  3154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3155. return
  3156. }
  3157. types := int64(items["type"].(float64))
  3158. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3159. utils.ErrorLog("med_type")
  3160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3161. return
  3162. }
  3163. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3164. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3165. ctime := time.Now().Unix()
  3166. prescription := &models.HisPrescription{
  3167. ID: id,
  3168. PatientId: patient_id,
  3169. UserOrgId: adminInfo.CurrentOrgId,
  3170. RecordDate: recordDateTime,
  3171. Ctime: ctime,
  3172. Mtime: ctime,
  3173. Type: types,
  3174. Modifier: adminInfo.AdminUser.Id,
  3175. Creator: adminInfo.AdminUser.Id,
  3176. Status: 1,
  3177. Doctor: role.UserName,
  3178. HisPatientId: his_patient_id,
  3179. OrderStatus: 1,
  3180. BatchNumber: "",
  3181. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3182. PType: hpInfo.PType,
  3183. MedType: med_type,
  3184. }
  3185. if historyPrescription.ID > 0 {
  3186. prescription.PreTime = historyPrescription.PreTime
  3187. }
  3188. service.SaveHisPrescription(prescription)
  3189. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3190. advices := items["advices"].([]interface{})
  3191. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3192. groupNo := int64(0)
  3193. ctime := time.Now().Unix()
  3194. mtime := ctime
  3195. if len(advices) > 0 {
  3196. for _, advice := range advices {
  3197. var s models.HisDoctorAdviceInfo
  3198. s.PrescriptionId = prescription.ID
  3199. s.AdviceType = 2
  3200. s.AdviceDoctor = adminInfo.AdminUser.Id
  3201. s.StopState = 2
  3202. s.ExecutionState = 2
  3203. s.AdviceDate = recordDateTime
  3204. s.Status = 1
  3205. s.UserOrgId = adminInfo.CurrentOrgId
  3206. s.RecordDate = recordDateTime
  3207. s.StartTime = prescription.PreTime
  3208. s.Groupno = groupNo
  3209. s.CreatedTime = ctime
  3210. s.UpdatedTime = mtime
  3211. s.PatientId = patient_id
  3212. s.HisPatientId = his_patient_id
  3213. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3214. if errcode > 0 {
  3215. c.ServeFailJSONWithSGJErrorCode(errcode)
  3216. return
  3217. }
  3218. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3219. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3220. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3221. if s.Price == 0 {
  3222. s.Price = lastWarehouse.RetailPrice
  3223. }
  3224. }
  3225. service.CreateHisDoctorAdvice(&s)
  3226. //记录日志
  3227. byterequest, _ := json.Marshal(s)
  3228. adviceLog := models.XtDoctorAdviceLog{
  3229. UserOrgId: s.UserOrgId,
  3230. PatientId: s.PatientId,
  3231. AdminUserId: adminInfo.AdminUser.Id,
  3232. Module: 1,
  3233. ErrLog: string(byterequest),
  3234. Status: 1,
  3235. Ctime: time.Now().Unix(),
  3236. Mtime: 0,
  3237. Source: "电脑端his医嘱修改",
  3238. RecordDate: s.AdviceDate,
  3239. }
  3240. service.CreateDoctorAdviceLog(adviceLog)
  3241. redis := service.RedisClient()
  3242. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3243. redis.Set(key, "", time.Second)
  3244. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3245. fmt.Println("keyOne", keyOne)
  3246. redis.Set(keyOne, "", time.Second)
  3247. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3248. redis.Set(keySeven, "", time.Second)
  3249. redis.Close()
  3250. }
  3251. }
  3252. }
  3253. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3254. projects := items["project"].([]interface{})
  3255. if len(projects) > 0 {
  3256. for _, project := range projects {
  3257. var p models.HisPrescriptionProject
  3258. p.PrescriptionId = prescription.ID
  3259. p.Ctime = time.Now().Unix()
  3260. p.Mtime = time.Now().Unix()
  3261. p.PatientId = patient_id
  3262. p.RecordDate = recordDateTime
  3263. p.UserOrgId = adminInfo.CurrentOrgId
  3264. p.HisPatientId = his_patient_id
  3265. p.Status = 1
  3266. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3267. if errcode > 0 {
  3268. c.ServeFailJSONWithSGJErrorCode(errcode)
  3269. return
  3270. }
  3271. service.CreateHisProjectTwo(&p)
  3272. //记录日志
  3273. byterequest, _ := json.Marshal(p)
  3274. adviceLog := models.XtDoctorAdviceLog{
  3275. UserOrgId: p.UserOrgId,
  3276. PatientId: p.PatientId,
  3277. AdminUserId: adminInfo.AdminUser.Id,
  3278. Module: 1,
  3279. ErrLog: string(byterequest),
  3280. Status: 1,
  3281. Ctime: time.Now().Unix(),
  3282. Mtime: 0,
  3283. Source: "电脑端his项目修改",
  3284. RecordDate: p.RecordDate,
  3285. }
  3286. service.CreateDoctorAdviceLog(adviceLog)
  3287. }
  3288. }
  3289. }
  3290. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3291. addition := items["addition"].([]interface{})
  3292. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3293. ctime := time.Now().Unix()
  3294. mtime := ctime
  3295. if len(addition) > 0 {
  3296. for _, item := range addition {
  3297. var s models.HisAdditionalCharge
  3298. s.PrescriptionId = prescription.ID
  3299. s.Status = 1
  3300. s.UserOrgId = adminInfo.CurrentOrgId
  3301. s.RecordDate = recordDateTime
  3302. s.CreatedTime = ctime
  3303. s.UpdatedTime = mtime
  3304. s.PatientId = patient_id
  3305. s.HisPatientId = his_patient_id
  3306. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3307. if errcode > 0 {
  3308. c.ServeFailJSONWithSGJErrorCode(errcode)
  3309. return
  3310. }
  3311. service.CreateAdditionalCharge(&s)
  3312. }
  3313. }
  3314. }
  3315. }
  3316. }
  3317. }
  3318. if err == nil {
  3319. c.ServeSuccessJSON(map[string]interface{}{
  3320. "msg": "保存成功",
  3321. })
  3322. return
  3323. } else {
  3324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3325. return
  3326. }
  3327. }
  3328. func (c *HisApiController) DeletePrescription() {
  3329. prescription_id, _ := c.GetInt64("id")
  3330. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3331. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3332. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3333. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3334. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3335. //耗材保存处方出库
  3336. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3337. //已收费和已发药限制逻辑
  3338. isCharge := false
  3339. isMedicine := false
  3340. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3341. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3342. for _, item := range new_prescriptions {
  3343. if item.IsMedicine == 1 {
  3344. isMedicine = true
  3345. }
  3346. }
  3347. for _, item := range new_prescriptions {
  3348. if item.OrderStatus == 4 {
  3349. isCharge = true
  3350. }
  3351. }
  3352. if p_err != nil {
  3353. if new_prescription.ID > 0 {
  3354. if new_prescription.OrderStatus == 2 {
  3355. isCharge = true
  3356. }
  3357. }
  3358. }
  3359. for _, item := range advices {
  3360. if item.IsMedicine == 1 {
  3361. isMedicine = true
  3362. }
  3363. }
  3364. if isCharge {
  3365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3366. return
  3367. }
  3368. if isMedicine {
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3370. return
  3371. }
  3372. //已收费和已发药限制逻辑
  3373. if len(projects) > 0 {
  3374. for _, item := range projects {
  3375. service.DeletePrintInfo(item.ID) //删除打印信息
  3376. if goodOutConfig.IsOpen != 1 {
  3377. if stockConfig.IsOpen == 1 {
  3378. if item.Type == 3 && item.IsOut == 1 {
  3379. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3380. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3381. good.Total = good.Total + f_count
  3382. service.UpdateGoodInfo(&good)
  3383. operation_time := time.Now().Unix()
  3384. creater := c.GetAdminUserInfo().AdminUser.Id
  3385. //创建退库单
  3386. timeStr := time.Now().Format("2006-01-02")
  3387. timeArr := strings.Split(timeStr, "-")
  3388. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3389. total = total + 1
  3390. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3391. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3392. cancelStock := models.CancelStock{
  3393. OrderNumber: orderNumber,
  3394. OperaTime: operation_time,
  3395. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3396. Creater: creater,
  3397. Ctime: time.Now().Unix(),
  3398. Status: 1,
  3399. ReturnTime: item.RecordDate,
  3400. Type: 1,
  3401. StorehouseId: houseConfig.StorehouseOutInfo,
  3402. IsCheck: 1,
  3403. }
  3404. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3405. if msgerrkonde == gorm.ErrRecordNotFound {
  3406. service.AddSigleCancelStock(&cancelStock)
  3407. }
  3408. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3409. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3410. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3411. //查询该耗材是否出库
  3412. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3413. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3414. deaerler, _ := service.GetDealerById(info.Dealer)
  3415. var total_count int64
  3416. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3417. total_count += count
  3418. if info.ID > 0 {
  3419. if info.Count >= total_count {
  3420. //回退库存
  3421. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3422. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3423. var flush_count int64
  3424. for _, it := range goodList {
  3425. flush_count += it.StockCount
  3426. }
  3427. cancelStockInfo := models.CancelStockInfo{
  3428. GoodId: item.ProjectId,
  3429. CancelStockId: cancel.ID,
  3430. GoodTypeId: good.GoodTypeId,
  3431. Count: prescribingNumber,
  3432. Price: info.Price,
  3433. Total: 0,
  3434. ProductDate: info.ProductDate,
  3435. ExpiryDate: info.ExpiryDate,
  3436. Ctime: time.Now().Unix(),
  3437. Status: 1,
  3438. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3439. OrderNumber: cancel.OrderNumber,
  3440. Type: 0,
  3441. Dealer: deaerler.DealerName,
  3442. Manufacturer: manufacturer.ManufacturerName,
  3443. Number: info.Number,
  3444. RegisterAccount: "",
  3445. Remark: "",
  3446. WarehouseInfoId: info.WarehouseInfotId,
  3447. PatientId: info.PatientId,
  3448. RecordDate: info.SysRecordTime,
  3449. StorehouseId: houseConfig.StorehouseOutInfo,
  3450. IsCheck: 1,
  3451. }
  3452. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3453. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3454. flow := models.VmStockFlow{
  3455. WarehousingId: info.WarehouseInfotId,
  3456. GoodId: item.ProjectId,
  3457. Number: info.Number,
  3458. LicenseNumber: info.LicenseNumber,
  3459. Count: prescribingNumber,
  3460. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3461. PatientId: item.PatientId,
  3462. SystemTime: info.SysRecordTime,
  3463. ConsumableType: 7,
  3464. IsSys: 0,
  3465. WarehousingOrder: "",
  3466. WarehouseOutId: info.WarehouseOutId,
  3467. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3468. IsEdit: 0,
  3469. CancelStockId: cancel.ID,
  3470. CancelOrderNumber: cancel.OrderNumber,
  3471. Manufacturer: manufacturer.ID,
  3472. Dealer: 0,
  3473. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3474. UpdateCreator: 0,
  3475. Status: 1,
  3476. Ctime: time.Now().Unix(),
  3477. Mtime: 0,
  3478. Price: info.Price,
  3479. WarehousingDetailId: info.WarehouseInfotId,
  3480. WarehouseOutDetailId: info.ID,
  3481. CancelOutDetailId: cancelInfo.ID,
  3482. ProductDate: info.ProductDate,
  3483. ExpireDate: info.ExpiryDate,
  3484. StorehouseId: houseConfig.StorehouseOutInfo,
  3485. OverCount: flush_count,
  3486. }
  3487. service.CreateStockFlowOne(flow)
  3488. //退库数量增加
  3489. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3490. //出库数量减少
  3491. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3492. }
  3493. if info.Count < total_count {
  3494. //回退库存
  3495. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3496. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3497. var flush_count int64
  3498. for _, it := range goodList {
  3499. flush_count += it.StockCount
  3500. }
  3501. cancelStockInfo := models.CancelStockInfo{
  3502. GoodId: item.ProjectId,
  3503. CancelStockId: cancel.ID,
  3504. GoodTypeId: good.GoodTypeId,
  3505. Count: info.Count,
  3506. Price: info.Price,
  3507. Total: 0,
  3508. ProductDate: info.ProductDate,
  3509. ExpiryDate: info.ExpiryDate,
  3510. Ctime: time.Now().Unix(),
  3511. Status: 1,
  3512. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3513. OrderNumber: cancel.OrderNumber,
  3514. Type: 0,
  3515. Dealer: deaerler.DealerName,
  3516. Manufacturer: manufacturer.ManufacturerName,
  3517. Number: info.Number,
  3518. RegisterAccount: "",
  3519. Remark: "",
  3520. WarehouseInfoId: info.WarehouseInfotId,
  3521. PatientId: info.PatientId,
  3522. RecordDate: info.SysRecordTime,
  3523. StorehouseId: houseConfig.StorehouseOutInfo,
  3524. IsCheck: 1,
  3525. }
  3526. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3527. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3528. flow := models.VmStockFlow{
  3529. WarehousingId: info.WarehouseInfotId,
  3530. GoodId: item.ProjectId,
  3531. Number: info.Number,
  3532. LicenseNumber: info.LicenseNumber,
  3533. Count: info.Count,
  3534. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3535. PatientId: item.PatientId,
  3536. SystemTime: info.SysRecordTime,
  3537. ConsumableType: 7,
  3538. IsSys: 0,
  3539. WarehousingOrder: "",
  3540. WarehouseOutId: info.WarehouseOutId,
  3541. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3542. IsEdit: 0,
  3543. CancelStockId: cancel.ID,
  3544. CancelOrderNumber: cancel.OrderNumber,
  3545. Manufacturer: manufacturer.ID,
  3546. Dealer: 0,
  3547. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3548. UpdateCreator: 0,
  3549. Status: 1,
  3550. Ctime: time.Now().Unix(),
  3551. Mtime: 0,
  3552. Price: info.Price,
  3553. WarehousingDetailId: info.WarehouseInfotId,
  3554. WarehouseOutDetailId: info.ID,
  3555. CancelOutDetailId: cancelInfo.ID,
  3556. ProductDate: info.ProductDate,
  3557. ExpireDate: info.ExpiryDate,
  3558. StorehouseId: houseConfig.StorehouseOutInfo,
  3559. OverCount: flush_count,
  3560. }
  3561. service.CreateStockFlowOne(flow)
  3562. //退库数量增加
  3563. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3564. //出库数量减少
  3565. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3566. }
  3567. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3568. var flush_count int64
  3569. for _, it := range goodList {
  3570. flush_count += it.StockCount
  3571. }
  3572. //查询已出库数量
  3573. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3574. if prescribingNumber < dialysisInfo.Count {
  3575. //改变数量
  3576. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3577. }
  3578. if prescribingNumber >= dialysisInfo.Count {
  3579. //删除出库表
  3580. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3581. }
  3582. //更新库存
  3583. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3584. //更新基础库库存
  3585. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3586. }
  3587. }
  3588. }
  3589. }
  3590. //保存耗材出库
  3591. if goodOutConfig.IsOpen == 1 {
  3592. if item.Type == 3 {
  3593. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3594. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3595. good.Total = good.Total + f_count
  3596. service.UpdateGoodInfo(&good)
  3597. operation_time := time.Now().Unix()
  3598. creater := c.GetAdminUserInfo().AdminUser.Id
  3599. //创建退库单
  3600. timeStr := time.Now().Format("2006-01-02")
  3601. timeArr := strings.Split(timeStr, "-")
  3602. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3603. total = total + 1
  3604. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3605. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3606. cancelStock := models.CancelStock{
  3607. OrderNumber: orderNumber,
  3608. OperaTime: operation_time,
  3609. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3610. Creater: creater,
  3611. Ctime: time.Now().Unix(),
  3612. Status: 1,
  3613. ReturnTime: item.RecordDate,
  3614. Type: 1,
  3615. StorehouseId: houseConfig.StorehouseOutInfo,
  3616. IsCheck: 1,
  3617. }
  3618. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3619. if msgerrkonde == gorm.ErrRecordNotFound {
  3620. service.AddSigleCancelStock(&cancelStock)
  3621. }
  3622. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3623. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3624. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3625. //查询该耗材是否出库
  3626. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3627. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3628. deaerler, _ := service.GetDealerById(info.Dealer)
  3629. var total_count int64
  3630. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3631. total_count += count
  3632. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3633. var flush_count int64
  3634. for _, it := range goodList {
  3635. flush_count += it.StockCount
  3636. }
  3637. fmt.Println("历史出库数据", info.Count)
  3638. fmt.Println("出库数量", total_count)
  3639. if info.ID > 0 {
  3640. cancelStockInfo := models.CancelStockInfo{
  3641. GoodId: item.ProjectId,
  3642. CancelStockId: cancel.ID,
  3643. GoodTypeId: good.GoodTypeId,
  3644. Count: prescribingNumber,
  3645. Price: info.Price,
  3646. Total: 0,
  3647. ProductDate: info.ProductDate,
  3648. ExpiryDate: info.ExpiryDate,
  3649. Ctime: time.Now().Unix(),
  3650. Status: 1,
  3651. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3652. OrderNumber: cancel.OrderNumber,
  3653. Type: 0,
  3654. Dealer: deaerler.DealerName,
  3655. Manufacturer: manufacturer.ManufacturerName,
  3656. Number: info.Number,
  3657. RegisterAccount: "",
  3658. Remark: "",
  3659. WarehouseInfoId: info.WarehouseInfotId,
  3660. PatientId: info.PatientId,
  3661. RecordDate: info.SysRecordTime,
  3662. StorehouseId: houseConfig.StorehouseOutInfo,
  3663. IsCheck: 1,
  3664. }
  3665. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3666. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3667. //查询出库数量
  3668. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3669. //出库数据 大于 退库数量
  3670. if len(list) > 0 {
  3671. for _, it := range list {
  3672. //回退库存
  3673. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3674. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3675. var flush_count_one int64
  3676. for _, it := range goodList {
  3677. flush_count_one += it.StockCount
  3678. }
  3679. //查询该批次是否有退库数据
  3680. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3681. creater := c.GetAdminUserInfo().AdminUser.Id
  3682. flow := models.VmStockFlow{
  3683. WarehousingId: it.WarehouseInfotId,
  3684. GoodId: it.GoodId,
  3685. Number: it.Number,
  3686. LicenseNumber: it.LicenseNumber,
  3687. Count: it.Count,
  3688. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3689. PatientId: it.PatientId,
  3690. SystemTime: it.SysRecordTime,
  3691. ConsumableType: 7,
  3692. IsSys: 0,
  3693. WarehousingOrder: "",
  3694. WarehouseOutId: it.WarehouseOutId,
  3695. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3696. IsEdit: 0,
  3697. CancelStockId: cancel.ID,
  3698. CancelOrderNumber: cancel.OrderNumber,
  3699. Manufacturer: manufacturer.ID,
  3700. Dealer: 0,
  3701. Creator: creater,
  3702. UpdateCreator: 0,
  3703. Status: 1,
  3704. Ctime: time.Now().Unix(),
  3705. Mtime: 0,
  3706. Price: it.Price,
  3707. WarehousingDetailId: it.WarehouseInfotId,
  3708. WarehouseOutDetailId: it.ID,
  3709. CancelOutDetailId: cancelInfo.ID,
  3710. ProductDate: it.ProductDate,
  3711. ExpireDate: it.ExpiryDate,
  3712. StorehouseId: houseConfig.StorehouseOutInfo,
  3713. OverCount: flush_count_one,
  3714. }
  3715. service.CreateStockFlowOne(flow)
  3716. //if flow.ID > 0 {
  3717. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3718. //}
  3719. }
  3720. }
  3721. //flow := models.VmStockFlow{
  3722. // WarehousingId: info.WarehouseInfotId,
  3723. // GoodId: item.ProjectId,
  3724. // Number: info.Number,
  3725. // LicenseNumber: info.LicenseNumber,
  3726. // Count: prescribingNumber,
  3727. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3728. // PatientId: item.PatientId,
  3729. // SystemTime: info.SysRecordTime,
  3730. // ConsumableType: 7,
  3731. // IsSys: 0,
  3732. // WarehousingOrder: "",
  3733. // WarehouseOutId: info.WarehouseOutId,
  3734. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3735. // IsEdit: 0,
  3736. // CancelStockId: cancel.ID,
  3737. // CancelOrderNumber: cancel.OrderNumber,
  3738. // Manufacturer: manufacturer.ID,
  3739. // Dealer: 0,
  3740. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3741. // UpdateCreator: 0,
  3742. // Status: 1,
  3743. // Ctime: time.Now().Unix(),
  3744. // Mtime: 0,
  3745. // Price: info.Price,
  3746. // WarehousingDetailId: info.WarehouseInfotId,
  3747. // WarehouseOutDetailId: info.ID,
  3748. // CancelOutDetailId: cancelInfo.ID,
  3749. // ProductDate: info.ProductDate,
  3750. // ExpireDate: info.ExpiryDate,
  3751. // StorehouseId: houseConfig.StorehouseOutInfo,
  3752. // OverCount: flush_count,
  3753. //}
  3754. //service.CreateStockFlowOne(flow)
  3755. //退库数量增加
  3756. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3757. //出库数量减少
  3758. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3759. //查询已出库数量
  3760. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3761. if prescribingNumber < dialysisInfo.Count {
  3762. //改变数量
  3763. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3764. }
  3765. if prescribingNumber >= dialysisInfo.Count {
  3766. //删除出库表
  3767. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3768. }
  3769. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3770. var flush_count_one int64
  3771. for _, it := range goodList {
  3772. flush_count_one += it.StockCount
  3773. }
  3774. //更新库存
  3775. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3776. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3777. //更新基础库库存
  3778. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3779. }
  3780. }
  3781. }
  3782. }
  3783. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3784. fmt.Println(err)
  3785. }
  3786. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3787. fmt.Println(err)
  3788. if len(advices) > 0 {
  3789. for _, item := range advices {
  3790. redis := service.RedisClient()
  3791. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3792. redis.Set(keyFive, "", time.Second)
  3793. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3794. redis.Set(keyOne, "", time.Second)
  3795. redis.Close()
  3796. }
  3797. }
  3798. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3799. if len(advices) > 0 {
  3800. for _, item := range advices {
  3801. creater := c.GetAdminUserInfo().AdminUser.Id
  3802. service.DrugAutoAddCancelInfo(item, creater)
  3803. }
  3804. }
  3805. } else {
  3806. if drugOutConfig.IsOpen == 1 {
  3807. if len(advices) > 0 {
  3808. for _, item := range advices {
  3809. creater := c.GetAdminUserInfo().AdminUser.Id
  3810. service.DrugAutoAddCancelInfo(item, creater)
  3811. }
  3812. }
  3813. } else {
  3814. if len(advices) > 0 {
  3815. for _, item := range advices {
  3816. creater := c.GetAdminUserInfo().AdminUser.Id
  3817. service.DrugAutoAddCancelInfo(item, creater)
  3818. }
  3819. }
  3820. }
  3821. }
  3822. c.ServeSuccessJSON(map[string]interface{}{
  3823. "msg": "删除成功",
  3824. })
  3825. return
  3826. }
  3827. func (c *HisApiController) DeleteDoctorAdvice() {
  3828. id, _ := c.GetInt64("id")
  3829. advice, _ := service.GetHisDoctorAdvicesById(id)
  3830. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3831. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3832. //已收费和已发药的限制逻辑
  3833. isCharge := false
  3834. isMedicine := false
  3835. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3836. //获取今天该患者所有处方,判断是否发药或者收费
  3837. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3838. for _, item := range new_prescriptions {
  3839. if item.IsMedicine == 1 {
  3840. isMedicine = true
  3841. }
  3842. }
  3843. for _, item := range new_prescriptions {
  3844. if item.OrderStatus == 4 {
  3845. isCharge = true
  3846. }
  3847. }
  3848. if isMedicine {
  3849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3850. return
  3851. }
  3852. if isCharge {
  3853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3854. return
  3855. }
  3856. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3857. for _, item := range advices {
  3858. if item.IsMedicine == 1 {
  3859. isMedicine = true
  3860. }
  3861. }
  3862. if isMedicine {
  3863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3864. return
  3865. }
  3866. if new_prescription.ID > 0 {
  3867. if new_prescription.OrderStatus == 2 {
  3868. isCharge = true
  3869. }
  3870. }
  3871. if isCharge {
  3872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3873. return
  3874. }
  3875. //已收费和已发药的限制逻辑
  3876. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3877. redis := service.RedisClient()
  3878. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3879. redis.Set(keyFive, "", time.Second)
  3880. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3881. redis.Set(keyOne, "", time.Second)
  3882. defer redis.Close()
  3883. if err == nil {
  3884. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3885. //查询是否在处方中出库
  3886. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3887. if openConfig.IsOpen != 1 {
  3888. //判断该医嘱是否执行了
  3889. if advice.ExecutionState == 1 {
  3890. creater := c.GetAdminUserInfo().AdminUser.Id
  3891. service.DrugAutoAddCancelInfo(&advice, creater)
  3892. }
  3893. }
  3894. //开启保存处方扣减功能
  3895. if openConfig.IsOpen == 1 {
  3896. creater := c.GetAdminUserInfo().AdminUser.Id
  3897. service.DrugAutoAddCancelInfo(&advice, creater)
  3898. }
  3899. } else {
  3900. if drugOutConfig.IsOpen == 1 {
  3901. //查询是否在处方中出库
  3902. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3903. if openConfig.IsOpen != 1 {
  3904. //判断该医嘱是否执行了
  3905. if advice.ExecutionState == 1 {
  3906. creater := c.GetAdminUserInfo().AdminUser.Id
  3907. service.DrugAutoAddCancelInfo(&advice, creater)
  3908. }
  3909. }
  3910. //开启保存处方扣减功能
  3911. if openConfig.IsOpen == 1 {
  3912. creater := c.GetAdminUserInfo().AdminUser.Id
  3913. service.DrugAutoAddCancelInfo(&advice, creater)
  3914. }
  3915. } else {
  3916. //判断该医嘱是否执行了
  3917. if advice.ExecutionState == 1 {
  3918. creater := c.GetAdminUserInfo().AdminUser.Id
  3919. service.DrugAutoAddCancelInfo(&advice, creater)
  3920. }
  3921. }
  3922. }
  3923. c.ServeSuccessJSON(map[string]interface{}{
  3924. "msg": "删除成功",
  3925. })
  3926. return
  3927. } else {
  3928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3929. return
  3930. }
  3931. }
  3932. func (c *HisApiController) DeleteProject() {
  3933. id, _ := c.GetInt64("id")
  3934. adminInfo := c.GetAdminUserInfo()
  3935. project, _ := service.GetHisProjectByID(id)
  3936. // var consumable models.DialysisBeforePrepare
  3937. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3938. //耗材保存处方出库
  3939. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3940. isCharge := false
  3941. isMedicine := false
  3942. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3943. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3944. for _, item := range new_prescriptions {
  3945. if item.IsMedicine == 1 {
  3946. isMedicine = true
  3947. }
  3948. }
  3949. for _, item := range new_prescriptions {
  3950. if item.OrderStatus == 4 {
  3951. isCharge = true
  3952. }
  3953. }
  3954. if isMedicine {
  3955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3956. return
  3957. }
  3958. if isCharge {
  3959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3960. return
  3961. }
  3962. if new_prescription.ID > 0 {
  3963. if new_prescription.OrderStatus == 2 {
  3964. isCharge = true
  3965. }
  3966. }
  3967. if isCharge {
  3968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3969. return
  3970. }
  3971. service.DeletePrintInfo(id)
  3972. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3973. label.Status = 0
  3974. service.CreateHisLabelRecord(&label)
  3975. fmt.Println(goodOutConfig.IsOpen)
  3976. if goodOutConfig.IsOpen != 1 {
  3977. if stockConfig.IsOpen == 1 {
  3978. if project.Type == 2 {
  3979. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3980. fmt.Println(err)
  3981. }
  3982. if project.Type == 3 && project.IsOut == 1 {
  3983. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3984. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3985. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3986. operation_time := time.Now().Unix()
  3987. creater := adminInfo.AdminUser.Id
  3988. //创建退库单
  3989. timeStr := time.Now().Format("2006-01-02")
  3990. timeArr := strings.Split(timeStr, "-")
  3991. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3992. total = total + 1
  3993. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3994. cancelStock := models.CancelStock{
  3995. OrderNumber: orderNumber,
  3996. OperaTime: operation_time,
  3997. OrgId: adminInfo.CurrentOrgId,
  3998. Creater: creater,
  3999. Ctime: time.Now().Unix(),
  4000. Status: 1,
  4001. ReturnTime: project.RecordDate,
  4002. Type: 1,
  4003. StorehouseId: houseConfig.StorehouseOutInfo,
  4004. IsCheck: 1,
  4005. }
  4006. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4007. if msgerrkonde == gorm.ErrRecordNotFound {
  4008. service.AddSigleCancelStock(&cancelStock)
  4009. }
  4010. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4011. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4012. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4013. //查询是否有出库
  4014. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4015. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4016. deaerler, _ := service.GetDealerById(info.Dealer)
  4017. if info.ID > 0 {
  4018. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4019. if info.Count >= prescribingNumber {
  4020. cancelStockInfo := models.CancelStockInfo{
  4021. GoodId: project.ProjectId,
  4022. CancelStockId: cancel.ID,
  4023. GoodTypeId: good.GoodTypeId,
  4024. Count: prescribingNumber,
  4025. Price: info.Price,
  4026. Total: 0,
  4027. ProductDate: info.ProductDate,
  4028. ExpiryDate: info.ExpiryDate,
  4029. Ctime: time.Now().Unix(),
  4030. Status: 1,
  4031. OrgId: adminInfo.CurrentOrgId,
  4032. OrderNumber: cancel.OrderNumber,
  4033. Type: 0,
  4034. Dealer: deaerler.DealerName,
  4035. Manufacturer: manufacturer.ManufacturerName,
  4036. Number: info.Number,
  4037. RegisterAccount: "",
  4038. Remark: "",
  4039. WarehouseInfoId: info.WarehouseInfotId,
  4040. PatientId: info.PatientId,
  4041. RecordDate: info.SysRecordTime,
  4042. StorehouseId: houseConfig.StorehouseOutInfo,
  4043. IsCheck: 1,
  4044. }
  4045. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4046. //回退库存
  4047. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4048. //退库数量增加
  4049. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4050. //出库数量减少
  4051. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4052. }
  4053. if info.Count < prescribingNumber {
  4054. cancelStockInfo := models.CancelStockInfo{
  4055. GoodId: project.ProjectId,
  4056. CancelStockId: cancel.ID,
  4057. GoodTypeId: good.GoodTypeId,
  4058. Count: info.Count,
  4059. Price: info.Price,
  4060. Total: 0,
  4061. ProductDate: info.ProductDate,
  4062. ExpiryDate: info.ExpiryDate,
  4063. Ctime: time.Now().Unix(),
  4064. Status: 1,
  4065. OrgId: adminInfo.CurrentOrgId,
  4066. OrderNumber: cancel.OrderNumber,
  4067. Type: 0,
  4068. Dealer: deaerler.DealerName,
  4069. Manufacturer: manufacturer.ManufacturerName,
  4070. Number: info.Number,
  4071. RegisterAccount: "",
  4072. Remark: "",
  4073. WarehouseInfoId: info.WarehouseInfotId,
  4074. PatientId: info.PatientId,
  4075. RecordDate: info.SysRecordTime,
  4076. StorehouseId: houseConfig.StorehouseOutInfo,
  4077. IsCheck: 1,
  4078. }
  4079. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4080. //回退库存
  4081. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4082. //退库数量增加
  4083. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4084. //出库数量减少
  4085. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4086. }
  4087. //查询剩余库存
  4088. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4089. var over_count int64
  4090. for _, it := range goodList {
  4091. over_count += it.StockCount
  4092. }
  4093. //出库数据 大于 退库数量
  4094. if info.Count >= prescribingNumber {
  4095. flow := models.VmStockFlow{
  4096. WarehousingId: info.WarehouseInfotId,
  4097. GoodId: project.ProjectId,
  4098. Number: info.Number,
  4099. LicenseNumber: info.LicenseNumber,
  4100. Count: prescribingNumber,
  4101. UserOrgId: adminInfo.CurrentOrgId,
  4102. PatientId: project.PatientId,
  4103. SystemTime: info.SysRecordTime,
  4104. ConsumableType: 7,
  4105. IsSys: 0,
  4106. WarehousingOrder: "",
  4107. WarehouseOutId: info.WarehouseOutId,
  4108. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4109. IsEdit: 0,
  4110. CancelStockId: cancel.ID,
  4111. CancelOrderNumber: cancel.OrderNumber,
  4112. Manufacturer: manufacturer.ID,
  4113. Dealer: 0,
  4114. Creator: adminInfo.AdminUser.Id,
  4115. UpdateCreator: 0,
  4116. Status: 1,
  4117. Ctime: time.Now().Unix(),
  4118. Mtime: 0,
  4119. Price: info.Price,
  4120. WarehousingDetailId: info.WarehouseInfotId,
  4121. WarehouseOutDetailId: info.ID,
  4122. CancelOutDetailId: cancelInfo.ID,
  4123. ProductDate: info.ProductDate,
  4124. ExpireDate: info.ExpiryDate,
  4125. StorehouseId: houseConfig.StorehouseOutInfo,
  4126. OverCount: over_count,
  4127. }
  4128. service.CreateStockFlowOne(flow)
  4129. }
  4130. //出库数据小于退库数据
  4131. if info.Count < prescribingNumber {
  4132. flow := models.VmStockFlow{
  4133. WarehousingId: info.WarehouseInfotId,
  4134. GoodId: project.ProjectId,
  4135. Number: info.Number,
  4136. LicenseNumber: info.LicenseNumber,
  4137. Count: info.Count,
  4138. UserOrgId: adminInfo.CurrentOrgId,
  4139. PatientId: project.PatientId,
  4140. SystemTime: info.SysRecordTime,
  4141. ConsumableType: 7,
  4142. IsSys: 0,
  4143. WarehousingOrder: "",
  4144. WarehouseOutId: info.WarehouseOutId,
  4145. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4146. IsEdit: 0,
  4147. CancelStockId: cancel.ID,
  4148. CancelOrderNumber: cancel.OrderNumber,
  4149. Manufacturer: manufacturer.ID,
  4150. Dealer: 0,
  4151. Creator: adminInfo.AdminUser.Id,
  4152. UpdateCreator: 0,
  4153. Status: 1,
  4154. Ctime: time.Now().Unix(),
  4155. Mtime: 0,
  4156. Price: info.Price,
  4157. WarehousingDetailId: info.WarehouseInfotId,
  4158. WarehouseOutDetailId: info.ID,
  4159. CancelOutDetailId: cancelInfo.ID,
  4160. ProductDate: info.ProductDate,
  4161. ExpireDate: info.ExpiryDate,
  4162. StorehouseId: houseConfig.StorehouseOutInfo,
  4163. OverCount: over_count,
  4164. }
  4165. service.CreateStockFlowOne(flow)
  4166. }
  4167. //查询已出库数量
  4168. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4169. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4170. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4171. if prescribingNumber < dialysisInfo.Count {
  4172. //改变数量
  4173. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4174. }
  4175. if prescribingNumber >= dialysisInfo.Count {
  4176. //删除出库表
  4177. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4178. }
  4179. //更新剩余库存
  4180. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4181. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4182. var total_count_one int64
  4183. for _, it := range stockList {
  4184. total_count_one += it.StockCount
  4185. }
  4186. //基础库插入数据
  4187. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4188. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4189. var flush_count int64
  4190. for _, it := range goodListOne {
  4191. flush_count += it.StockCount
  4192. }
  4193. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4194. if errs != nil {
  4195. goodErrcode := models.XtGoodErrcode{
  4196. UserOrgId: project.UserOrgId,
  4197. Errcode: "手动出库更新剩余出库失败",
  4198. GoodId: project.ProjectId,
  4199. Status: 1,
  4200. Ctime: time.Now().Unix(),
  4201. Mtime: 0,
  4202. Count: 0,
  4203. StockCount: 0,
  4204. Creater: creater,
  4205. BatchNumberId: 0,
  4206. WarehouseOutId: 0,
  4207. }
  4208. service.CreateGoodErrcode(goodErrcode)
  4209. }
  4210. }
  4211. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4212. fmt.Println(err)
  4213. } else {
  4214. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4215. fmt.Println(err)
  4216. }
  4217. } else {
  4218. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4219. fmt.Println(err)
  4220. }
  4221. }
  4222. //保存处方出库
  4223. if goodOutConfig.IsOpen == 1 {
  4224. if project.Type == 3 {
  4225. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4226. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4227. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4228. operation_time := time.Now().Unix()
  4229. creater := adminInfo.AdminUser.Id
  4230. //创建退库单
  4231. timeStr := time.Now().Format("2006-01-02")
  4232. timeArr := strings.Split(timeStr, "-")
  4233. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4234. total = total + 1
  4235. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4236. cancelStock := models.CancelStock{
  4237. OrderNumber: orderNumber,
  4238. OperaTime: operation_time,
  4239. OrgId: adminInfo.CurrentOrgId,
  4240. Creater: creater,
  4241. Ctime: time.Now().Unix(),
  4242. Status: 1,
  4243. ReturnTime: project.RecordDate,
  4244. Type: 1,
  4245. StorehouseId: houseConfig.StorehouseOutInfo,
  4246. IsCheck: 1,
  4247. }
  4248. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4249. if msgerrkonde == gorm.ErrRecordNotFound {
  4250. service.AddSigleCancelStock(&cancelStock)
  4251. }
  4252. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4253. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4254. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4255. //获取出库数据
  4256. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4257. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4258. deaerler, _ := service.GetDealerById(info.Dealer)
  4259. if info.ID > 0 {
  4260. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4261. if info.Count >= prescribingNumber {
  4262. cancelStockInfo := models.CancelStockInfo{
  4263. GoodId: project.ProjectId,
  4264. CancelStockId: cancel.ID,
  4265. GoodTypeId: good.GoodTypeId,
  4266. Count: prescribingNumber,
  4267. Price: info.Price,
  4268. Total: 0,
  4269. ProductDate: info.ProductDate,
  4270. ExpiryDate: info.ExpiryDate,
  4271. Ctime: time.Now().Unix(),
  4272. Status: 1,
  4273. OrgId: adminInfo.CurrentOrgId,
  4274. OrderNumber: cancel.OrderNumber,
  4275. Type: 0,
  4276. Dealer: deaerler.DealerName,
  4277. Manufacturer: manufacturer.ManufacturerName,
  4278. Number: info.Number,
  4279. RegisterAccount: "",
  4280. Remark: "",
  4281. WarehouseInfoId: info.WarehouseInfotId,
  4282. PatientId: info.PatientId,
  4283. RecordDate: info.SysRecordTime,
  4284. StorehouseId: houseConfig.StorehouseOutInfo,
  4285. IsCheck: 1,
  4286. }
  4287. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4288. //退库数量增加
  4289. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4290. //出库数量减少
  4291. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4292. }
  4293. if info.Count < prescribingNumber {
  4294. cancelStockInfo := models.CancelStockInfo{
  4295. GoodId: project.ProjectId,
  4296. CancelStockId: cancel.ID,
  4297. GoodTypeId: good.GoodTypeId,
  4298. Count: prescribingNumber,
  4299. Price: info.Price,
  4300. Total: 0,
  4301. ProductDate: info.ProductDate,
  4302. ExpiryDate: info.ExpiryDate,
  4303. Ctime: time.Now().Unix(),
  4304. Status: 1,
  4305. OrgId: adminInfo.CurrentOrgId,
  4306. OrderNumber: cancel.OrderNumber,
  4307. Type: 0,
  4308. Dealer: deaerler.DealerName,
  4309. Manufacturer: manufacturer.ManufacturerName,
  4310. Number: info.Number,
  4311. RegisterAccount: "",
  4312. Remark: "",
  4313. WarehouseInfoId: info.WarehouseInfotId,
  4314. PatientId: info.PatientId,
  4315. RecordDate: info.SysRecordTime,
  4316. StorehouseId: houseConfig.StorehouseOutInfo,
  4317. IsCheck: 1,
  4318. }
  4319. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4320. //回退库存
  4321. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4322. }
  4323. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4324. var over_count int64
  4325. for _, it := range goodList {
  4326. over_count += it.StockCount
  4327. }
  4328. //查询出库数量
  4329. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4330. //出库数据 大于 退库数量
  4331. if len(list) > 0 {
  4332. for _, it := range list {
  4333. //回退库存
  4334. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4335. //退库数量增加
  4336. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4337. //出库数量减少
  4338. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4339. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4340. var over_count_one int64
  4341. for _, it := range goodList {
  4342. over_count_one += it.StockCount
  4343. }
  4344. //查询该批次是否有退库数据
  4345. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4346. flow := models.VmStockFlow{
  4347. WarehousingId: it.WarehouseInfotId,
  4348. GoodId: it.GoodId,
  4349. Number: it.Number,
  4350. LicenseNumber: it.LicenseNumber,
  4351. Count: it.Count,
  4352. UserOrgId: adminInfo.CurrentOrgId,
  4353. PatientId: it.PatientId,
  4354. SystemTime: it.SysRecordTime,
  4355. ConsumableType: 7,
  4356. IsSys: 0,
  4357. WarehousingOrder: "",
  4358. WarehouseOutId: it.WarehouseOutId,
  4359. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4360. IsEdit: 0,
  4361. CancelStockId: cancel.ID,
  4362. CancelOrderNumber: cancel.OrderNumber,
  4363. Manufacturer: manufacturer.ID,
  4364. Dealer: 0,
  4365. Creator: adminInfo.AdminUser.Id,
  4366. UpdateCreator: 0,
  4367. Status: 1,
  4368. Ctime: time.Now().Unix(),
  4369. Mtime: 0,
  4370. Price: it.Price,
  4371. WarehousingDetailId: it.WarehouseInfotId,
  4372. WarehouseOutDetailId: it.ID,
  4373. CancelOutDetailId: cancelInfo.ID,
  4374. ProductDate: it.ProductDate,
  4375. ExpireDate: it.ExpiryDate,
  4376. StorehouseId: houseConfig.StorehouseOutInfo,
  4377. OverCount: over_count_one,
  4378. }
  4379. service.CreateStockFlowOne(flow)
  4380. }
  4381. }
  4382. //查询已出库数量
  4383. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4384. if prescribingNumber < dialysisInfo.Count {
  4385. //改变数量
  4386. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4387. }
  4388. if prescribingNumber >= dialysisInfo.Count {
  4389. //删除出库表
  4390. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4391. }
  4392. //更新剩余库存
  4393. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4394. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4395. var total_count_one int64
  4396. for _, it := range stockList {
  4397. total_count_one += it.StockCount
  4398. }
  4399. //基础库插入数据
  4400. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4401. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4402. var flush_count int64
  4403. for _, it := range goodListOne {
  4404. flush_count += it.StockCount
  4405. }
  4406. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4407. if errs != nil {
  4408. goodErrcode := models.XtGoodErrcode{
  4409. UserOrgId: project.UserOrgId,
  4410. Errcode: "手动出库更新剩余出库失败",
  4411. GoodId: project.ProjectId,
  4412. Status: 1,
  4413. Ctime: time.Now().Unix(),
  4414. Mtime: 0,
  4415. Count: 0,
  4416. StockCount: 0,
  4417. Creater: creater,
  4418. BatchNumberId: 0,
  4419. WarehouseOutId: 0,
  4420. }
  4421. service.CreateGoodErrcode(goodErrcode)
  4422. }
  4423. }
  4424. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4425. fmt.Println(err)
  4426. } else {
  4427. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4428. fmt.Println(err)
  4429. }
  4430. }
  4431. c.ServeSuccessJSON(map[string]interface{}{
  4432. "msg": "删除成功",
  4433. })
  4434. return
  4435. }
  4436. func (c *HisApiController) CreateHisAdditionalCharge() {
  4437. his_patient_id, _ := c.GetInt64("his_patient_id")
  4438. patient_id, _ := c.GetInt64("patient_id")
  4439. record_date := c.GetString("record_date")
  4440. timeLayout := "2006-01-02"
  4441. loc, _ := time.LoadLocation("Local")
  4442. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4443. if err != nil {
  4444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4445. return
  4446. }
  4447. adminInfo := c.GetAdminUserInfo()
  4448. recordDateTime := theTime.Unix()
  4449. dataBody := make(map[string]interface{}, 0)
  4450. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4451. if err != nil {
  4452. utils.ErrorLog(err.Error())
  4453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4454. return
  4455. }
  4456. var additions []*models.HisAdditionalCharge
  4457. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4458. additions, _ := dataBody["addition"].([]interface{})
  4459. if len(additions) > 0 {
  4460. for _, item := range additions {
  4461. items := item.(map[string]interface{})
  4462. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4463. utils.ErrorLog("item_id")
  4464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4465. return
  4466. }
  4467. item_id := int64(items["item_id"].(float64))
  4468. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4469. utils.ErrorLog("item_name")
  4470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4471. return
  4472. }
  4473. item_name := items["item_name"].(string)
  4474. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4475. utils.ErrorLog("price")
  4476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4477. return
  4478. }
  4479. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4480. ctime := time.Now().Unix()
  4481. additional := &models.HisAdditionalCharge{
  4482. PatientId: patient_id,
  4483. HisPatientId: his_patient_id,
  4484. UserOrgId: adminInfo.CurrentOrgId,
  4485. RecordDate: recordDateTime,
  4486. CreatedTime: ctime,
  4487. UpdatedTime: ctime,
  4488. Modifier: adminInfo.AdminUser.Id,
  4489. Creator: adminInfo.AdminUser.Id,
  4490. Price: price,
  4491. ItemName: item_name,
  4492. ItemId: item_id,
  4493. Status: 1,
  4494. }
  4495. additions = append(additions, additional)
  4496. }
  4497. }
  4498. }
  4499. for _, item := range additions {
  4500. service.CreateAddtionalCharge(item)
  4501. }
  4502. c.ServeSuccessJSON(map[string]interface{}{
  4503. "msg": "创建成功",
  4504. })
  4505. }
  4506. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4507. blood_fat := c.GetString("blood_fat")
  4508. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4509. blood_sugar := c.GetString("blood_sugar")
  4510. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4511. chief_conplaint := c.GetString("chief_conplaint")
  4512. dbp := c.GetString("dbp")
  4513. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4514. delivery_way, _ := c.GetInt64("delivery_way")
  4515. diagnostic := c.GetString("diagnostic")
  4516. family_history := c.GetString("family_history")
  4517. height := c.GetString("height")
  4518. history_of_present_illness := c.GetString("history_of_present_illness")
  4519. is_infect, _ := c.GetInt64("is_infect")
  4520. past_history := c.GetString("past_history")
  4521. patient_id, _ := c.GetInt64("patient_id")
  4522. his_patient_id, _ := c.GetInt64("his_patient_id")
  4523. personal_history := c.GetString("personal_history")
  4524. pulse := c.GetString("pulse")
  4525. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4526. sbp := c.GetString("sbp")
  4527. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4528. heightfloat, _ := strconv.ParseFloat(height, 64)
  4529. sicktype := c.GetString("sick_type")
  4530. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4531. symptom := c.GetString("symptom")
  4532. sick_date := c.GetString("sick_date")
  4533. temperatures := c.GetString("temperature")
  4534. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4535. record_date := c.GetString("record_date")
  4536. breathing := c.GetString("breathing")
  4537. doctor_advice := c.GetString("doctor_advice")
  4538. remark := c.GetString("remark")
  4539. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4540. sick, _ := c.GetInt64("sick")
  4541. diagnose, _ := c.GetInt64("diagnose")
  4542. //id, _ := c.GetInt64("id")
  4543. timeLayout := "2006-01-02"
  4544. loc, _ := time.LoadLocation("Local")
  4545. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4546. allergic_history := c.GetString("allergic_history")
  4547. if err != nil {
  4548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4549. return
  4550. }
  4551. recordDateTime := theTime.Unix()
  4552. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4553. if err != nil {
  4554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4555. return
  4556. }
  4557. sickTimes := sickTime.Unix()
  4558. ctime := time.Now().Unix()
  4559. primary_disease := c.GetString("primary_disease")
  4560. confirm_failure_date := c.GetString("confirm_failure_date")
  4561. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4562. drug_allergy_history := c.GetString("drug_allergy_history")
  4563. physical_examination := c.GetString("physical_examination")
  4564. special_inspection := c.GetString("special_inspection")
  4565. lab_apparatus := c.GetString("lab_apparatus")
  4566. caseHistory := models.HisPatientCaseHistory{
  4567. HisPatientId: his_patient_id,
  4568. PatientId: patient_id,
  4569. Temperature: temperature,
  4570. BloodSugar: bloodsugarfloat,
  4571. Pulse: pulsefloat,
  4572. Sbp: sbpfloat,
  4573. Dbp: dbpfloat,
  4574. Height: heightfloat,
  4575. BloodFat: bloodfatfloat,
  4576. SickType: sick_type,
  4577. Symptom: symptom,
  4578. SickDate: sickTimes,
  4579. IsInfect: is_infect,
  4580. HistoryOfPresentIllness: history_of_present_illness,
  4581. PastHistory: past_history,
  4582. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4583. ChiefConplaint: chief_conplaint,
  4584. PersonalHistory: personal_history,
  4585. FamilyHistory: family_history,
  4586. Diagnostic: diagnostic,
  4587. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4588. Status: 1,
  4589. Ctime: ctime,
  4590. Mtime: ctime,
  4591. RecordDate: recordDateTime,
  4592. DeliveryWay: delivery_way,
  4593. Breathing: breathingfloat,
  4594. DoctorAdvice: doctor_advice,
  4595. Remark: remark,
  4596. Sick: sick,
  4597. Diagnose: diagnose,
  4598. AllergicHistory: allergic_history,
  4599. PrimaryDisease: primary_disease,
  4600. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4601. DrugAllergyHistory: drug_allergy_history,
  4602. PhysicalExamination: physical_examination,
  4603. SpecialInspection: special_inspection,
  4604. LabApparatus: lab_apparatus,
  4605. }
  4606. //查询该患者是否有病历
  4607. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4608. if errcodes == gorm.ErrRecordNotFound {
  4609. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4610. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4611. if err != nil {
  4612. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4613. return
  4614. }
  4615. c.ServeSuccessJSON(map[string]interface{}{
  4616. "caseHistory": caseHistory,
  4617. "historyInfo": historyInfo,
  4618. })
  4619. return
  4620. } else if errcodes == nil {
  4621. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4622. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4623. if err != nil {
  4624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4625. return
  4626. }
  4627. c.ServeSuccessJSON(map[string]interface{}{
  4628. "caseHistory": caseHistory,
  4629. "historyInfo": historyInfo,
  4630. })
  4631. }
  4632. //查询该患者是否有病历
  4633. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4634. //if errcode == gorm.ErrRecordNotFound {
  4635. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4636. // if err != nil {
  4637. // c.ServeSuccessJSON(map[string]interface{}{
  4638. // "msg": "保存成功",
  4639. // })
  4640. // }
  4641. //} else if errcode == nil {
  4642. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4643. // return
  4644. //}
  4645. }
  4646. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4647. patient_id, _ := c.GetInt64("patient_id", 0)
  4648. adminUser := c.GetAdminUserInfo()
  4649. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4650. c.ServeSuccessJSON(map[string]interface{}{
  4651. "list": caseHistorys,
  4652. })
  4653. }
  4654. func (c *HisApiController) GetHisPatientCaseHistory() {
  4655. record_date, _ := c.GetInt64("record_date", 0)
  4656. patient_id, _ := c.GetInt64("patient_id", 0)
  4657. admin := c.GetAdminUserInfo()
  4658. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4659. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4660. c.ServeSuccessJSON(map[string]interface{}{
  4661. "info": info,
  4662. "case_history": case_history,
  4663. })
  4664. }
  4665. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4666. template_name := c.GetString("template_name")
  4667. template_remark := c.GetString("template_remark")
  4668. doctor := c.GetAdminUserInfo().AdminUser.Id
  4669. diagnostic := c.GetString("diagnostic")
  4670. chief_conplaint := c.GetString("chief_conplain")
  4671. history_of_present_illness := c.GetString("history_of_present_illness")
  4672. past_history := c.GetString("past_history")
  4673. personal_history := c.GetString("personal_history")
  4674. family_history := c.GetString("family_history")
  4675. user_name := c.GetString("user_name")
  4676. doctor_advice := c.GetString("doctor_advice")
  4677. remark := c.GetString("remark")
  4678. //record_date := c.GetString("record_date")
  4679. //fmt.Println("record_date--------",record_date)
  4680. //timeLayout := "2006-01-02"
  4681. //loc, _ := time.LoadLocation("Local")
  4682. //
  4683. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4684. //if err != nil {
  4685. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4686. // return
  4687. //}
  4688. //recordDateTime := theTime.Unix()
  4689. ctime := time.Now().Unix()
  4690. template := models.HisCaseHistoryTemplate{
  4691. HistoryOfPresentIllness: history_of_present_illness,
  4692. PastHistory: past_history,
  4693. ChiefConplaint: chief_conplaint,
  4694. PersonalHistory: personal_history,
  4695. FamilyHistory: family_history,
  4696. Diagnostic: diagnostic,
  4697. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4698. Status: 1,
  4699. Ctime: ctime,
  4700. Mtime: ctime,
  4701. RecordDate: time.Now().Unix(),
  4702. TemplateName: template_name,
  4703. TemplateRemark: template_remark,
  4704. Creator: doctor,
  4705. Modifier: doctor,
  4706. UserName: user_name,
  4707. DoctorAdvice: doctor_advice,
  4708. Remark: remark,
  4709. }
  4710. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4711. if err == nil {
  4712. c.ServeSuccessJSON(map[string]interface{}{
  4713. "msg": "保存成功",
  4714. })
  4715. } else {
  4716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4717. return
  4718. }
  4719. }
  4720. func (c *HisApiController) GetCaseHistoryTemplate() {
  4721. timeLayout := "2006-01-02"
  4722. loc, _ := time.LoadLocation("Local")
  4723. keyword := c.GetString("keyword")
  4724. start_time := c.GetString("start_time")
  4725. end_time := c.GetString("end_time")
  4726. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4727. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4728. admin := c.GetAdminUserInfo()
  4729. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4730. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4731. c.ServeSuccessJSON(map[string]interface{}{
  4732. "template": template,
  4733. //"history": history,
  4734. })
  4735. }
  4736. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4737. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4738. utils.ErrorLog("drug_name")
  4739. return enums.ErrorCodeParamWrong
  4740. }
  4741. adviceName, _ := json["drug_name"].(string)
  4742. if len(adviceName) == 0 {
  4743. utils.ErrorLog("len(advice_name) == 0")
  4744. return enums.ErrorCodeParamWrong
  4745. }
  4746. advice.AdviceName = adviceName
  4747. adviceDesc, _ := json["advice_desc"].(string)
  4748. advice.AdviceDesc = adviceDesc
  4749. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4750. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4751. advice.DrugSpec = drugSpec
  4752. }
  4753. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4754. remark, _ := json["remark"].(string)
  4755. advice.Remark = remark
  4756. }
  4757. if json["id"] == nil {
  4758. advice.DrugId = 0
  4759. } else {
  4760. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4761. drug_id := int64(json["id"].(float64))
  4762. advice.DrugId = drug_id
  4763. }
  4764. }
  4765. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4766. advice_id := int64(json["advice_id"].(float64))
  4767. advice.ID = advice_id
  4768. if advice.ID > 0 {
  4769. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4770. if err == nil {
  4771. if hisAdvice.ID > 0 {
  4772. advice.ExecutionTime = hisAdvice.ExecutionTime
  4773. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4774. advice.ExecutionState = hisAdvice.ExecutionState
  4775. advice.CheckTime = hisAdvice.CheckTime
  4776. advice.Checker = hisAdvice.Checker
  4777. advice.CheckState = hisAdvice.CheckState
  4778. advice.StartTime = hisAdvice.StartTime
  4779. advice.FeedetlSn = hisAdvice.FeedetlSn
  4780. }
  4781. }
  4782. }
  4783. }
  4784. //
  4785. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4786. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4787. // advice.ExecutionTime = execution_time
  4788. //}
  4789. //
  4790. //
  4791. //
  4792. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4793. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4794. // advice.ExecutionStaff = execution_staff
  4795. //}
  4796. //
  4797. //
  4798. //
  4799. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4800. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4801. // advice.ExecutionState = execution_state
  4802. //}
  4803. //
  4804. //
  4805. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4806. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4807. // advice.CheckTime = check_time
  4808. //}
  4809. //
  4810. //
  4811. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4812. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4813. // advice.CheckState = check_state
  4814. //}
  4815. //
  4816. //
  4817. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4818. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4819. // advice.Checker = checker
  4820. //}
  4821. //
  4822. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4823. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4824. // advice.StartTime = start_time
  4825. //}
  4826. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4827. drugSpecUnit, _ := json["min_unit"].(string)
  4828. advice.DrugSpecUnit = drugSpecUnit
  4829. }
  4830. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4831. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4832. advice.SingleDose = singleDose
  4833. }
  4834. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4835. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4836. advice.SingleDoseUnit = singleDoseUnit
  4837. }
  4838. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4839. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4840. advice.PrescribingNumber = prescribingNumber
  4841. }
  4842. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4843. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4844. advice.PrescribingNumberUnit = prescribingNumberUnit
  4845. }
  4846. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4847. deliveryWay, _ := json["delivery_way"].(string)
  4848. advice.DeliveryWay = deliveryWay
  4849. }
  4850. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4851. executionFrequency, _ := json["execution_frequency"].(string)
  4852. advice.ExecutionFrequency = executionFrequency
  4853. }
  4854. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4855. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4856. advice.Price = price
  4857. }
  4858. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4859. med_list_codg, _ := json["medical_insurance_number"].(string)
  4860. advice.MedListCodg = med_list_codg
  4861. }
  4862. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4863. day := int64(json["day"].(float64))
  4864. advice.Day = day
  4865. }
  4866. return 0
  4867. }
  4868. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4869. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4870. id := int64(json["id"].(float64))
  4871. project.ID = id
  4872. historyProject, _ := service.GetHisProjectByID(id)
  4873. project.FeedetlSn = historyProject.FeedetlSn
  4874. }
  4875. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4876. project_id := int64(json["project_id"].(float64))
  4877. project.ProjectId = project_id
  4878. }
  4879. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4880. // price := int64(json["price"].(float64))
  4881. // formatInt_price := strconv.FormatInt(price, 10)
  4882. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4883. // project.Price = float_price
  4884. // }
  4885. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4886. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4887. project.Price = price
  4888. }
  4889. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4890. total, _ := json["total"].(string)
  4891. project.Count = total
  4892. }
  4893. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4894. medical_code, _ := json["medical_code"].(string)
  4895. project.MedListCodg = medical_code
  4896. }
  4897. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4898. single_dose, _ := json["single_dose"].(string)
  4899. project.SingleDose = single_dose
  4900. }
  4901. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4902. delivery_way, _ := json["delivery_way"].(string)
  4903. project.DeliveryWay = delivery_way
  4904. }
  4905. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4906. execution_frequency, _ := json["execution_frequency"].(string)
  4907. project.ExecutionFrequency = execution_frequency
  4908. }
  4909. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4910. remark, _ := json["remark"].(string)
  4911. project.Remark = remark
  4912. }
  4913. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4914. day, _ := json["number_days"].(string)
  4915. project.Day = day
  4916. }
  4917. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4918. unit, _ := json["unit"].(string)
  4919. project.Unit = unit
  4920. }
  4921. return 0
  4922. }
  4923. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4924. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4925. id := int64(json["id"].(float64))
  4926. historyAddtions, _ := service.GetHisAdditionByID(id)
  4927. additionalCharge.ID = id
  4928. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4929. }
  4930. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4931. item_id := int64(json["item_id"].(float64))
  4932. additionalCharge.ItemId = item_id
  4933. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4934. if config.ID > 0 {
  4935. if len(config.Code) > 0 {
  4936. additionalCharge.MedListCodg = config.Code
  4937. }
  4938. }
  4939. }
  4940. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4941. // price := int64(json["price"].(float64))
  4942. // formatInt_price := strconv.FormatInt(price, 10)
  4943. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4944. // additionalCharge.Price = float_price
  4945. // }
  4946. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4947. // price := int64(json["price"].(float64))
  4948. // formatInt_price := strconv.FormatInt(price, 10)
  4949. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4950. // additionalCharge.Price = float_price
  4951. //}
  4952. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4953. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4954. additionalCharge.Price = price
  4955. }
  4956. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4957. count, _ := json["count"].(string)
  4958. counts, _ := strconv.ParseInt(count, 10, 64)
  4959. additionalCharge.Count = counts
  4960. }
  4961. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4962. item_name, _ := json["item_name"].(string)
  4963. additionalCharge.ItemName = item_name
  4964. }
  4965. return 0
  4966. }
  4967. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4968. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4969. utils.ErrorLog("drug_name")
  4970. return enums.ErrorCodeParamWrong
  4971. }
  4972. adviceName, _ := json["drug_name"].(string)
  4973. if len(adviceName) == 0 {
  4974. utils.ErrorLog("len(advice_name) == 0")
  4975. return enums.ErrorCodeParamWrong
  4976. }
  4977. advice.AdviceName = adviceName
  4978. adviceDesc, _ := json["advice_desc"].(string)
  4979. advice.AdviceDesc = adviceDesc
  4980. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4981. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4982. advice.DrugSpec = drugSpec
  4983. }
  4984. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4985. remark, _ := json["remark"].(string)
  4986. advice.Remark = remark
  4987. }
  4988. if json["id"] == nil {
  4989. advice.DrugId = 0
  4990. } else {
  4991. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4992. drug_id := int64(json["id"].(float64))
  4993. advice.DrugId = drug_id
  4994. }
  4995. }
  4996. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4997. groupno := int64(json["groupno"].(float64))
  4998. advice.Groupno = groupno
  4999. }
  5000. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5001. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5002. advice.HospApprFlag = hosp_appr_flag
  5003. }
  5004. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5005. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5006. advice.PrescribingNumber = prescribingNumber
  5007. }
  5008. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5009. // frequency_type := int64(json["frequency_type"].(float64))
  5010. // advice.FrequencyType = frequency_type
  5011. //}
  5012. //
  5013. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5014. // day_count := int64(json["day_count"].(float64))
  5015. // advice.DayCount = day_count
  5016. //}
  5017. //
  5018. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5019. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5020. // week_day, _ := json["week_day"].(string)
  5021. // advice.WeekDay = week_day
  5022. //}
  5023. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5024. drugSpecUnit, _ := json["min_unit"].(string)
  5025. advice.DrugSpecUnit = drugSpecUnit
  5026. }
  5027. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5028. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5029. advice.SingleDose = singleDose
  5030. }
  5031. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5032. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5033. advice.SingleDoseUnit = singleDoseUnit
  5034. }
  5035. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5036. deliveryWay, _ := json["delivery_way"].(string)
  5037. advice.DeliveryWay = deliveryWay
  5038. }
  5039. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5040. executionFrequency, _ := json["execution_frequency"].(string)
  5041. advice.ExecutionFrequency = executionFrequency
  5042. }
  5043. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5044. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5045. advice.Price = price
  5046. }
  5047. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5048. med_list_codg, _ := json["medical_insurance_number"].(string)
  5049. advice.MedListCodg = med_list_codg
  5050. }
  5051. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5052. day := int64(json["day"].(float64))
  5053. advice.Day = day
  5054. }
  5055. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5056. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5057. advice.PrescribingNumberUnit = prescribingNumberUnit
  5058. }
  5059. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5060. advice_id := int64(json["advice_id"].(float64))
  5061. advice.ID = advice_id
  5062. if advice.ID > 0 {
  5063. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5064. if err == nil {
  5065. if hisAdvice.ID > 0 {
  5066. advice.ExecutionTime = hisAdvice.ExecutionTime
  5067. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5068. advice.ExecutionState = hisAdvice.ExecutionState
  5069. advice.CheckTime = hisAdvice.CheckTime
  5070. advice.Checker = hisAdvice.Checker
  5071. advice.CheckState = hisAdvice.CheckState
  5072. advice.StartTime = hisAdvice.StartTime
  5073. advice.HospApprFlag = hisAdvice.HospApprFlag
  5074. advice.IsMedicine = hisAdvice.IsMedicine
  5075. if hisAdvice.UserOrgId == 10028 {
  5076. 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 {
  5077. advice.ExecutionTime = 0
  5078. advice.ExecutionStaff = 0
  5079. advice.ExecutionState = 2
  5080. advice.CheckTime = 0
  5081. advice.Checker = 0
  5082. advice.CheckState = 2
  5083. }
  5084. } else {
  5085. 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 {
  5086. advice.ExecutionTime = 0
  5087. advice.ExecutionStaff = 0
  5088. advice.ExecutionState = 2
  5089. advice.CheckTime = 0
  5090. advice.Checker = 0
  5091. advice.CheckState = 2
  5092. }
  5093. }
  5094. //advice.Groupno = hisAdvice.Groupno
  5095. }
  5096. }
  5097. }
  5098. }
  5099. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5100. //
  5101. //if drugStockConfig.IsOpen == 1 {
  5102. //
  5103. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5104. // if advice.ID == 0 { //医嘱不存在
  5105. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5106. // drug.Total = drug.Total - advice.PrescribingNumber
  5107. // service.UpdateBaseDrugLib(&drug)
  5108. //
  5109. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5110. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5111. // drug.Total = drug.Total - num
  5112. // service.UpdateBaseDrugLib(&drug)
  5113. // }
  5114. //
  5115. // } else if advice.ID > 0 { //医嘱存在
  5116. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5117. // var num float64
  5118. //
  5119. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5120. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5121. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5122. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5123. // drug.Total = drug.Total + num
  5124. // service.UpdateBaseDrugLib(&drug)
  5125. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5126. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5127. // drug.Total = drug.Total - num
  5128. // service.UpdateBaseDrugLib(&drug)
  5129. // }
  5130. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5131. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5132. // if num2 > advice.PrescribingNumber {
  5133. // num = num2 - advice.PrescribingNumber
  5134. // drug.Total = drug.Total + num
  5135. // service.UpdateBaseDrugLib(&drug)
  5136. // } else if num2 < advice.PrescribingNumber {
  5137. // num = advice.PrescribingNumber - num2
  5138. // drug.Total = drug.Total - num
  5139. // service.UpdateBaseDrugLib(&drug)
  5140. // }
  5141. //
  5142. // }
  5143. //
  5144. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5145. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5146. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5147. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5148. // if num1 > num2 {
  5149. // num = num1 - num2
  5150. // drug.Total = drug.Total + num
  5151. // service.UpdateBaseDrugLib(&drug)
  5152. // } else if num1 < num2 {
  5153. // num = num2 - num1
  5154. // drug.Total = drug.Total - num
  5155. // service.UpdateBaseDrugLib(&drug)
  5156. // }
  5157. //
  5158. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5159. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5160. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5161. // if hisAdvice.PrescribingNumber > num2 {
  5162. // num = hisAdvice.PrescribingNumber - num2
  5163. // drug.Total = drug.Total + num
  5164. // service.UpdateBaseDrugLib(&drug)
  5165. // } else if num2 < advice.PrescribingNumber {
  5166. // num = num2 - hisAdvice.PrescribingNumber
  5167. // drug.Total = drug.Total - num
  5168. // service.UpdateBaseDrugLib(&drug)
  5169. // }
  5170. //
  5171. // }
  5172. // }
  5173. // }
  5174. //}
  5175. //
  5176. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5177. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5178. // advice.ExecutionTime = execution_time
  5179. //}
  5180. //
  5181. //
  5182. //
  5183. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5184. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5185. // advice.ExecutionStaff = execution_staff
  5186. //}
  5187. //
  5188. //
  5189. //
  5190. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5191. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5192. // advice.ExecutionState = execution_state
  5193. //}
  5194. //
  5195. //
  5196. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5197. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5198. // advice.CheckTime = check_time
  5199. //}
  5200. //
  5201. //
  5202. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5203. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5204. // advice.CheckState = check_state
  5205. //}
  5206. //
  5207. //
  5208. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5209. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5210. // advice.Checker = checker
  5211. //}
  5212. //
  5213. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5214. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5215. // advice.StartTime = start_time
  5216. //}
  5217. return 0
  5218. }
  5219. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5220. project.ExecutionStaff = 0
  5221. project.ExecutionState = 2
  5222. project.ExecutionTime = 0
  5223. project.Checker = 0
  5224. project.CheckState = 2
  5225. project.CheckTime = 0
  5226. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5227. id := int64(json["id"].(float64))
  5228. project.ID = id
  5229. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5230. project.ExecutionStaff = temp_project.ExecutionStaff
  5231. project.ExecutionState = temp_project.ExecutionState
  5232. project.ExecutionTime = temp_project.ExecutionTime
  5233. project.Checker = temp_project.Checker
  5234. project.CheckState = temp_project.CheckState
  5235. project.CheckTime = temp_project.CheckTime
  5236. project.TeamId = temp_project.TeamId
  5237. }
  5238. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5239. types := int64(json["type"].(float64))
  5240. project.Type = types
  5241. }
  5242. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5243. project_id := int64(json["project_id"].(float64))
  5244. project.ProjectId = project_id
  5245. }
  5246. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5247. team_id := int64(json["team_id"].(float64))
  5248. project.TeamId = team_id
  5249. }
  5250. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5251. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5252. project.Price = price
  5253. }
  5254. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5255. total, _ := json["total"].(string)
  5256. //totals, _ := strconv.ParseInt(total, 10, 64)
  5257. project.Count = total
  5258. }
  5259. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5260. medical_code, _ := json["medical_code"].(string)
  5261. project.MedListCodg = medical_code
  5262. }
  5263. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5264. single_dose, _ := json["single_dose"].(string)
  5265. project.SingleDose = single_dose
  5266. }
  5267. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5268. delivery_way, _ := json["delivery_way"].(string)
  5269. project.DeliveryWay = delivery_way
  5270. }
  5271. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5272. execution_frequency, _ := json["execution_frequency"].(string)
  5273. project.ExecutionFrequency = execution_frequency
  5274. }
  5275. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5276. remark, _ := json["remark"].(string)
  5277. project.Remark = remark
  5278. }
  5279. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5280. day, _ := json["number_days"].(string)
  5281. project.Day = day
  5282. }
  5283. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5284. unit, _ := json["unit"].(string)
  5285. project.Unit = unit
  5286. }
  5287. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5288. // frequency_type := int64(json["frequency_type"].(float64))
  5289. // project.FrequencyType = frequency_type
  5290. //}
  5291. //
  5292. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5293. // day_count := int64(json["day_count"].(float64))
  5294. // project.DayCount = day_count
  5295. //}
  5296. //
  5297. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5298. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5299. // week_day, _ := json["week_day"].(string)
  5300. // project.WeekDay = week_day
  5301. //}
  5302. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5303. //
  5304. //if project.ID == 0 {
  5305. // if stockConfig.IsOpen == 1 {
  5306. // if project.Type == 3 {
  5307. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5308. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5309. // good.Total = good.Total - f_count
  5310. // service.UpdateGoodInfo(&good)
  5311. // }
  5312. // }
  5313. //
  5314. //} else {
  5315. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5316. //
  5317. // if stockConfig.IsOpen == 1 {
  5318. // if project.Type == 3 {
  5319. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5320. // if project.Count < temp_project.Count {
  5321. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5322. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5323. //
  5324. // other_count := f_count_two - f_count_one
  5325. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5326. // good.Total = good.Total + other_count_two
  5327. // service.UpdateGoodInfo(&good)
  5328. // } else if project.Count > temp_project.Count {
  5329. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5330. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5331. //
  5332. // other_count := f_count_one - f_count_two
  5333. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5334. // good.Total = good.Total - other_count_two
  5335. // service.UpdateGoodInfo(&good)
  5336. // }
  5337. //
  5338. // }
  5339. // }
  5340. //
  5341. //}
  5342. return 0
  5343. }
  5344. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5345. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5346. id := int64(json["id"].(float64))
  5347. additionalCharge.ID = id
  5348. }
  5349. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5350. item_id := int64(json["item_id"].(float64))
  5351. additionalCharge.ItemId = item_id
  5352. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5353. if config.ID > 0 {
  5354. if len(config.Code) > 0 {
  5355. additionalCharge.MedListCodg = config.Code
  5356. }
  5357. }
  5358. }
  5359. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5360. // price := int64(json["price"].(float64))
  5361. // formatInt_price := strconv.FormatInt(price, 10)
  5362. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5363. // additionalCharge.Price = float_price
  5364. // }
  5365. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5366. // price := int64(json["price"].(float64))
  5367. // formatInt_price := strconv.FormatInt(price, 10)
  5368. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5369. // additionalCharge.Price = float_price
  5370. //}
  5371. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5372. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5373. additionalCharge.Price = price
  5374. }
  5375. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5376. count, _ := json["count"].(string)
  5377. counts, _ := strconv.ParseInt(count, 10, 64)
  5378. additionalCharge.Count = counts
  5379. }
  5380. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5381. item_name, _ := json["item_name"].(string)
  5382. additionalCharge.ItemName = item_name
  5383. }
  5384. return 0
  5385. }
  5386. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5387. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5388. utils.ErrorLog("drug_name")
  5389. return enums.ErrorCodeParamWrong
  5390. }
  5391. adviceName, _ := json["drug_name"].(string)
  5392. if len(adviceName) == 0 {
  5393. utils.ErrorLog("len(advice_name) == 0")
  5394. return enums.ErrorCodeParamWrong
  5395. }
  5396. advice.AdviceName = adviceName
  5397. adviceDesc, _ := json["advice_desc"].(string)
  5398. advice.AdviceDesc = adviceDesc
  5399. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5400. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5401. advice.DrugSpec = drugSpec
  5402. }
  5403. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5404. remark, _ := json["remark"].(string)
  5405. advice.Remark = remark
  5406. }
  5407. if json["id"] == nil {
  5408. advice.DrugId = 0
  5409. } else {
  5410. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5411. drug_id := int64(json["id"].(float64))
  5412. advice.DrugId = drug_id
  5413. }
  5414. }
  5415. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5416. groupno := int64(json["groupno"].(float64))
  5417. advice.Groupno = groupno
  5418. }
  5419. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5420. drugSpecUnit, _ := json["min_unit"].(string)
  5421. advice.DrugSpecUnit = drugSpecUnit
  5422. }
  5423. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5424. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5425. advice.SingleDose = singleDose
  5426. }
  5427. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5428. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5429. advice.SingleDoseUnit = singleDoseUnit
  5430. }
  5431. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5432. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5433. advice.PrescribingNumber = prescribingNumber
  5434. }
  5435. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5436. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5437. advice.PrescribingNumberUnit = prescribingNumberUnit
  5438. }
  5439. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5440. deliveryWay, _ := json["delivery_way"].(string)
  5441. advice.DeliveryWay = deliveryWay
  5442. }
  5443. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5444. executionFrequency, _ := json["execution_frequency"].(string)
  5445. advice.ExecutionFrequency = executionFrequency
  5446. }
  5447. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5448. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5449. advice.Price = price
  5450. }
  5451. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5452. med_list_codg, _ := json["medical_insurance_number"].(string)
  5453. advice.MedListCodg = med_list_codg
  5454. }
  5455. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5456. day := int64(json["day"].(float64))
  5457. advice.Day = day
  5458. }
  5459. advice.FrequencyType = 1
  5460. return 0
  5461. }
  5462. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5463. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5464. types := int64(json["type"].(float64))
  5465. project.Type = types
  5466. }
  5467. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5468. project_id := int64(json["project_id"].(float64))
  5469. project.ProjectId = project_id
  5470. }
  5471. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5472. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5473. project.Price = price
  5474. }
  5475. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5476. total, _ := json["total"].(string)
  5477. //totals, _ := strconv.ParseInt(total, 10, 64)
  5478. project.Count = total
  5479. }
  5480. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5481. medical_code, _ := json["medical_code"].(string)
  5482. project.MedListCodg = medical_code
  5483. }
  5484. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5485. single_dose, _ := json["single_dose"].(string)
  5486. project.SingleDose = single_dose
  5487. }
  5488. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5489. delivery_way, _ := json["delivery_way"].(string)
  5490. project.DeliveryWay = delivery_way
  5491. }
  5492. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5493. execution_frequency, _ := json["execution_frequency"].(string)
  5494. project.ExecutionFrequency = execution_frequency
  5495. }
  5496. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5497. remark, _ := json["remark"].(string)
  5498. project.Remark = remark
  5499. }
  5500. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5501. day, _ := json["number_days"].(string)
  5502. project.Day = day
  5503. }
  5504. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5505. unit, _ := json["unit"].(string)
  5506. project.Unit = unit
  5507. }
  5508. project.FrequencyType = 1
  5509. return 0
  5510. }
  5511. func (c *HisApiController) GetHisOrderList() {
  5512. page, _ := c.GetInt64("page", -1)
  5513. limit, _ := c.GetInt64("limit", -1)
  5514. start_time := c.GetString("start_time")
  5515. end_time := c.GetString("end_time")
  5516. types, _ := c.GetInt64("type", 0)
  5517. keywords := c.GetString("keywords")
  5518. p_type, _ := c.GetInt64("p_type", 0)
  5519. sort_type, _ := c.GetInt64("sort_type", 0)
  5520. charge_type, _ := c.GetInt64("charge_type", 0)
  5521. sch_type, _ := c.GetInt64("sch_type", 0)
  5522. zone_type, _ := c.GetInt64("zone_type", 0)
  5523. med_type, _ := c.GetInt64("med_type", 0)
  5524. timeLayout := "2006-01-02"
  5525. loc, _ := time.LoadLocation("Local")
  5526. var startTime int64
  5527. if len(start_time) > 0 {
  5528. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5529. if err != nil {
  5530. //fmt.Println(err)
  5531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5532. return
  5533. }
  5534. startTime = theTime.Unix()
  5535. }
  5536. var endTime int64
  5537. if len(end_time) > 0 {
  5538. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5539. if err != nil {
  5540. utils.ErrorLog(err.Error())
  5541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5542. return
  5543. }
  5544. endTime = theTime.Unix()
  5545. }
  5546. adminUser := c.GetAdminUserInfo()
  5547. org_id := adminUser.CurrentOrgId
  5548. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  5549. for _, item := range order {
  5550. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5551. item.DoctorName = info.Doctor
  5552. item.DepartmentName = info.XtHisDepartment.Name
  5553. }
  5554. if err == nil {
  5555. c.ServeSuccessJSON(map[string]interface{}{
  5556. "order": order,
  5557. "total": total,
  5558. })
  5559. } else {
  5560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5561. return
  5562. }
  5563. }
  5564. func (c *HisApiController) GetHisOrder() {
  5565. patient_id, _ := c.GetInt64("patient_id", 0)
  5566. number := c.GetString("number")
  5567. adminInfo := c.GetAdminUserInfo()
  5568. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5569. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5570. if err == nil {
  5571. c.ServeSuccessJSON(map[string]interface{}{
  5572. "order": order,
  5573. "prescription": prescriptions,
  5574. })
  5575. } else {
  5576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5577. return
  5578. }
  5579. }
  5580. func (c *HisApiController) GetHisPrescriptionList() {
  5581. record_date := c.GetString("record_date")
  5582. keywords := c.GetString("keywords")
  5583. page, _ := c.GetInt64("page")
  5584. limit, _ := c.GetInt64("limit")
  5585. sch_type, _ := c.GetInt64("sch_type")
  5586. timeLayout := "2006-01-02"
  5587. loc, _ := time.LoadLocation("Local")
  5588. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5589. if err != nil {
  5590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5591. return
  5592. }
  5593. recordDateTime := theTime.Unix()
  5594. adminInfo := c.GetAdminUserInfo()
  5595. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5596. //adminInfo := c.GetAdminUserInfo()
  5597. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5598. //fmt.Println(prescriptionOrder)
  5599. if err == nil {
  5600. c.ServeSuccessJSON(map[string]interface{}{
  5601. "order": prescriptionOrder,
  5602. "total": total,
  5603. })
  5604. } else {
  5605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5606. return
  5607. }
  5608. }
  5609. func (c *HisApiController) GetHisPrescriptionInfo() {
  5610. id, _ := c.GetInt64("id")
  5611. adminInfo := c.GetAdminUserInfo()
  5612. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5613. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5614. if err == nil {
  5615. c.ServeSuccessJSON(map[string]interface{}{
  5616. "order": prescriptionOrder,
  5617. "prescription": prescription,
  5618. })
  5619. } else {
  5620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5621. return
  5622. }
  5623. }
  5624. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5625. adminUser := c.GetAdminUserInfo()
  5626. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5627. c.ServeSuccessJSON(map[string]interface{}{
  5628. "config": config,
  5629. })
  5630. }
  5631. type ResultTwo struct {
  5632. ErrMsg interface{} `json:"err_msg"`
  5633. InfRefmsgid string `json:"inf_refmsgid"`
  5634. Infcode int64 `json:"infcode"`
  5635. Output struct {
  5636. Baseinfo struct {
  5637. Age float64 `json:"age"`
  5638. Brdy string `json:"brdy"`
  5639. Certno string `json:"certno"`
  5640. Gend string `json:"gend"`
  5641. Naty string `json:"naty"`
  5642. PsnCertType string `json:"psn_cert_type"`
  5643. PsnName string `json:"psn_name"`
  5644. PsnNo string `json:"psn_no"`
  5645. } `json:"baseinfo"`
  5646. Idetinfo []interface{} `json:"idetinfo"`
  5647. Iinfo []struct {
  5648. Balc float64 `json:"balc"`
  5649. CvlservFlag string `json:"cvlserv_flag"`
  5650. EmpName string `json:"emp_name"`
  5651. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5652. Insutype string `json:"insutype"`
  5653. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5654. PausInsuDate interface{} `json:"paus_insu_date"`
  5655. PsnInsuDate string `json:"psn_insu_date"`
  5656. PsnInsuStas string `json:"psn_insu_stas"`
  5657. PsnType string `json:"psn_type"`
  5658. } `json:"insuinfo"`
  5659. } `json:"output"`
  5660. RefmsgTime string `json:"refmsg_time"`
  5661. RespondTime string `json:"respond_time"`
  5662. Signtype interface{} `json:"signtype"`
  5663. WarnInfo interface{} `json:"warn_info"`
  5664. }
  5665. type ResultThree struct {
  5666. Cainfo interface{} `json:"cainfo"`
  5667. ErrMsg interface{} `json:"err_msg"`
  5668. InfRefmsgid string `json:"inf_refmsgid"`
  5669. Infcode int64 `json:"infcode"`
  5670. Output struct {
  5671. Data struct {
  5672. IptOtpNo string `json:"ipt_otp_no"`
  5673. MdtrtID string `json:"mdtrt_id"`
  5674. PsnNo string `json:"psn_no"`
  5675. } `json:"data"`
  5676. } `json:"output"`
  5677. RefmsgTime string `json:"refmsg_time"`
  5678. RespondTime string `json:"respond_time"`
  5679. Signtype interface{} `json:"signtype"`
  5680. WarnMsg interface{} `json:"warn_msg"`
  5681. }
  5682. type ResultFour struct {
  5683. Cainfo string `json:"cainfo"`
  5684. ErrMsg string `json:"err_msg"`
  5685. InfRefmsgid string `json:"inf_refmsgid"`
  5686. Infcode int64 `json:"infcode"`
  5687. Output struct {
  5688. Result []struct {
  5689. BasMednFlag string `json:"bas_medn_flag"`
  5690. ChldMedcFlag string `json:"chld_medc_flag"`
  5691. ChrgitmLv string `json:"chrgitm_lv"`
  5692. Cnt float64 `json:"cnt"`
  5693. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5694. DrtReimFlag string `json:"drt_reim_flag"`
  5695. FeedetlSn string `json:"feedetl_sn"`
  5696. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5697. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5698. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5699. ListSpItemFlag string `json:"list_sp_item_flag"`
  5700. LmtUsedFlag string `json:"lmt_used_flag"`
  5701. MedChrgitmType string `json:"med_chrgitm_type"`
  5702. Memo string `json:"memo"`
  5703. OverlmtAmt float64 `json:"overlmt_amt"`
  5704. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5705. Pric float64 `json:"pric"`
  5706. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5707. SelfpayProp float64 `json:"selfpay_prop"`
  5708. } `json:"result"`
  5709. } `json:"output"`
  5710. RefmsgTime string `json:"refmsg_time"`
  5711. RespondTime string `json:"respond_time"`
  5712. Signtype string `json:"signtype"`
  5713. WarnMsg string `json:"warn_msg"`
  5714. }
  5715. type ResultFive struct {
  5716. Insutype string `json:"insutype"`
  5717. }
  5718. type ResultSix struct {
  5719. Cainfo interface{} `json:"cainfo"`
  5720. ErrMsg interface{} `json:"err_msg"`
  5721. InfRefmsgid string `json:"inf_refmsgid"`
  5722. Infcode int64 `json:"infcode"`
  5723. Output struct {
  5724. } `json:"output"`
  5725. RefmsgTime string `json:"refmsg_time"`
  5726. RespondTime string `json:"respond_time"`
  5727. Signtype interface{} `json:"signtype"`
  5728. WarnMsg interface{} `json:"warn_msg"`
  5729. }
  5730. type ResultSeven struct {
  5731. Cainfo string `json:"cainfo"`
  5732. ErrMsg string `json:"err_msg"`
  5733. InfRefmsgid string `json:"inf_refmsgid"`
  5734. Infcode int64 `json:"infcode"`
  5735. Output struct {
  5736. Setldetail []interface{} `json:"setldetail"`
  5737. Setlinfo struct {
  5738. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5739. AcctPay float64 `json:"acct_pay"`
  5740. ActPayDedc float64 `json:"act_pay_dedc"`
  5741. Age float64 `json:"age"`
  5742. Balc float64 `json:"balc"`
  5743. Brdy string `json:"brdy"`
  5744. Certno string `json:"certno"`
  5745. ClrOptins string `json:"clr_optins"`
  5746. ClrType string `json:"clr_type"`
  5747. ClrWay string `json:"clr_way"`
  5748. CvlservFlag string `json:"cvlserv_flag"`
  5749. CvlservPay float64 `json:"cvlserv_pay"`
  5750. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5751. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5752. Gend string `json:"gend"`
  5753. HifesPay float64 `json:"hifes_pay"`
  5754. HifmiPay float64 `json:"hifmi_pay"`
  5755. HifobPay float64 `json:"hifob_pay"`
  5756. HifpPay float64 `json:"hifp_pay"`
  5757. HospPartAmt float64 `json:"hosp_part_amt"`
  5758. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5759. Insutype string `json:"insutype"`
  5760. MafPay float64 `json:"maf_pay"`
  5761. MdtrtCertType string `json:"mdtrt_cert_type"`
  5762. MdtrtID string `json:"mdtrt_id"`
  5763. MedType string `json:"med_type"`
  5764. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5765. MedinsSetlID string `json:"medins_setl_id"`
  5766. Naty string `json:"naty"`
  5767. OthPay float64 `json:"oth_pay"`
  5768. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5769. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5770. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5771. PsnCashPay float64 `json:"psn_cash_pay"`
  5772. PsnCertType string `json:"psn_cert_type"`
  5773. PsnName string `json:"psn_name"`
  5774. PsnNo string `json:"psn_no"`
  5775. PsnPartAmt float64 `json:"psn_part_amt"`
  5776. PsnType string `json:"psn_type"`
  5777. SetlID string `json:"setl_id"`
  5778. SetlTime string `json:"setl_time"`
  5779. } `json:"setlinfo"`
  5780. } `json:"output"`
  5781. RefmsgTime string `json:"refmsg_time"`
  5782. RespondTime string `json:"respond_time"`
  5783. Signtype interface{} `json:"signtype"`
  5784. WarnMsg interface{} `json:"warn_msg"`
  5785. }
  5786. type ResultEight struct {
  5787. Cainfo string `json:"cainfo"`
  5788. ErrMsg string `json:"err_msg"`
  5789. InfRefmsgid string `json:"inf_refmsgid"`
  5790. Infcode int64 `json:"infcode"`
  5791. Output struct {
  5792. Stmtinfo struct {
  5793. SetlOptins string `json:"setl_optins"`
  5794. StmtRslt string `json:"stmt_rslt"`
  5795. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5796. } `json:"stmtinfo"`
  5797. } `json:"output"`
  5798. RefmsgTime string `json:"refmsg_time"`
  5799. RespondTime string `json:"respond_time"`
  5800. Signtype interface{} `json:"signtype"`
  5801. WarnMsg interface{} `json:"warn_msg"`
  5802. }
  5803. type ResultNine struct {
  5804. Cainfo string `json:"cainfo"`
  5805. ErrMsg string `json:"err_msg"`
  5806. InfRefmsgid string `json:"inf_refmsgid"`
  5807. Infcode int64 `json:"infcode"`
  5808. Output struct {
  5809. FileQuryNo string `json:"file_qury_no"`
  5810. } `json:"output"`
  5811. RefmsgTime string `json:"refmsg_time"`
  5812. RespondTime string `json:"respond_time"`
  5813. Signtype interface{} `json:"signtype"`
  5814. WarnMsg interface{} `json:"warn_msg"`
  5815. }
  5816. type ResultTen struct {
  5817. Cainfo string `json:"cainfo"`
  5818. ErrMsg string `json:"err_msg"`
  5819. InfRefmsgid string `json:"inf_refmsgid"`
  5820. Infcode int64 `json:"infcode"`
  5821. Output struct {
  5822. DldEndtime string `json:"dld_endtime"`
  5823. FileQuryNo string `json:"file_qury_no"`
  5824. Filename string `json:"filename"`
  5825. } `json:"output"`
  5826. RefmsgTime string `json:"refmsg_time"`
  5827. RespondTime string `json:"respond_time"`
  5828. Signtype interface{} `json:"signtype"`
  5829. WarnMsg interface{} `json:"warn_msg"`
  5830. }
  5831. type ResultEleven struct {
  5832. Cainfo string `json:"cainfo"`
  5833. ErrMsg string `json:"err_msg"`
  5834. InfRefmsgid string `json:"inf_refmsgid"`
  5835. Infcode int64 `json:"infcode"`
  5836. Output struct {
  5837. Setlinfo struct {
  5838. FixmedinsName string `json:"fixmedins_name"`
  5839. FixmedinsCode string `json:"fixmedins_code"`
  5840. PsnNo string `json:"psn_no"`
  5841. PsnName string `json:"psn_name"`
  5842. HifobPay float64 `json:"hifob_pay"`
  5843. Gend string `json:"gend"`
  5844. Brdy string `json:"brdy"`
  5845. PsnCertType string `json:"psn_cert_type"`
  5846. PsnType string `json:"psn_type"`
  5847. EmpName string `json:"emp_name"`
  5848. Certno string `json:"certno"`
  5849. Insutype string `json:"insutype"`
  5850. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5851. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5852. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5853. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5854. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5855. ActPayDedc float64 `json:"act_pay_dedc"`
  5856. HifpPay float64 `json:"hifp_pay"`
  5857. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5858. CvlservPay float64 `json:"cvlserv_pay"`
  5859. HifesPay float64 `json:"hifes_pay"`
  5860. HifmiPay float64 `json:"hifmi_pay"`
  5861. MafPay float64 `json:"maf_pay"`
  5862. OthPay float64 `json:"oth_pay"`
  5863. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5864. PsnPay float64 `json:"psn_pay"`
  5865. AcctPay float64 `json:"acct_pay"`
  5866. CashPayamt float64 `json:"cash_payamt"`
  5867. Balc float64 `json:"balc"`
  5868. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5869. MedinsSetlId string `json:"medins_setl_id"`
  5870. RefdSetlFlag string `json:"refd_setl_flag"`
  5871. SetlTime string `json:"setl_time"`
  5872. MedType string `json:"med_type"`
  5873. } `json:"setlinfo"`
  5874. } `json:"output"`
  5875. RefmsgTime string `json:"refmsg_time"`
  5876. RespondTime string `json:"respond_time"`
  5877. Signtype interface{} `json:"signtype"`
  5878. WarnMsg interface{} `json:"warn_msg"`
  5879. }
  5880. type Custom struct {
  5881. DetItemFeeSumamt string
  5882. Cut string
  5883. FeedetlSn string
  5884. Price string
  5885. MedListCodg string
  5886. Type int64
  5887. AdviceId int64
  5888. ProjectId int64
  5889. ItemId int64
  5890. }
  5891. // 获取个人信息----挂号-----上传就诊信息
  5892. func (c *HisApiController) GetRegisterInfo() {
  5893. id, _ := c.GetInt64("id")
  5894. record_time := c.GetString("record_time")
  5895. settlementValue, _ := c.GetInt64("settlement_value")
  5896. medical_insurance_card := c.GetString("medical_insurance_card")
  5897. name := c.GetString("name")
  5898. id_card_type, _ := c.GetInt64("id_card_type")
  5899. certificates, _ := c.GetInt64("certificates")
  5900. medical_care, _ := c.GetInt64("medical_care")
  5901. birthday := c.GetString("birthday")
  5902. age, _ := c.GetInt64("age")
  5903. id_card := c.GetString("id_card")
  5904. register_type, _ := c.GetInt64("register")
  5905. doctor, _ := c.GetInt64("doctor")
  5906. department, _ := c.GetInt64("department")
  5907. gender, _ := c.GetInt64("sex")
  5908. phone := c.GetString("phone")
  5909. registration_fee, _ := c.GetFloat("registration_fee")
  5910. medical_expenses, _ := c.GetFloat("medical_expenses")
  5911. social_type, _ := c.GetInt64("social_type")
  5912. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5913. diagnosis_ids := c.GetString("diagnosis")
  5914. sick_type, _ := c.GetInt64("sick_type")
  5915. reg_type := c.GetString("p_type")
  5916. timeLayout := "2006-01-02"
  5917. loc, _ := time.LoadLocation("Local")
  5918. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5919. birthUnix := birthdays.Unix()
  5920. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5921. if err != nil {
  5922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5923. return
  5924. }
  5925. recordDateTime := theTime.Unix()
  5926. adminInfo := c.GetAdminUserInfo()
  5927. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5928. if tempPatient.ID == 0 {
  5929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5930. return
  5931. }
  5932. var patient service.Patients
  5933. if id == 0 {
  5934. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5935. } else {
  5936. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5937. }
  5938. if patient.ID == 0 {
  5939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5940. return
  5941. }
  5942. if len(patient.IdCardNo) == 0 {
  5943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5944. return
  5945. }
  5946. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5947. if len(his) >= 1 {
  5948. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5949. if len(his) >= 1 && order.ID == 0 {
  5950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5951. return
  5952. }
  5953. }
  5954. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5955. fmt.Println(timeStr)
  5956. timeArr := strings.Split(timeStr, " ")
  5957. fmt.Println(timeArr)
  5958. timeArrTwo := strings.Split(timeArr[0], "-")
  5959. timeArrThree := strings.Split(timeArr[1], ":")
  5960. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5961. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5962. if len(lists) == 0 {
  5963. var hisPatient models.XtHisPatient
  5964. hisPatient = models.XtHisPatient{
  5965. Name: name,
  5966. Age: age,
  5967. Gender: gender,
  5968. Birthday: birthUnix,
  5969. Phone: phone,
  5970. MedicalTreatmentType: medical_care,
  5971. IdType: certificates,
  5972. IdCardNo: id_card,
  5973. BalanceAccountsType: settlementValue,
  5974. SocialType: social_type,
  5975. MedicalInsuranceNumber: medical_insurance_card,
  5976. RegisterType: register_type,
  5977. RegisterCost: registration_fee,
  5978. TreatmentCost: medical_expenses,
  5979. AdminUserId: adminInfo.AdminUser.Id,
  5980. UserOrgId: adminInfo.CurrentOrgId,
  5981. Status: 1,
  5982. RecordDate: recordDateTime,
  5983. IsReturn: 1,
  5984. PatientId: patient.ID,
  5985. Ctime: time.Now().Unix(),
  5986. Mtime: time.Now().Unix(),
  5987. Number: str,
  5988. IdCardType: id_card_type,
  5989. Departments: department,
  5990. Doctor: doctor,
  5991. PType: reg_type,
  5992. Diagnosis: diagnosis_ids,
  5993. SickType: sick_type,
  5994. }
  5995. service.CreateHisPatient(&hisPatient)
  5996. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5997. c.ServeSuccessJSON(map[string]interface{}{
  5998. "his_info": hisPatient,
  5999. })
  6000. } else {
  6001. //chrgBchno := rand.Intn(1000000) + 10000
  6002. var hisPatient models.XtHisPatient
  6003. hisPatient = models.XtHisPatient{
  6004. Name: name,
  6005. Age: age,
  6006. Gender: gender,
  6007. Birthday: birthUnix,
  6008. Phone: phone,
  6009. MedicalTreatmentType: medical_care,
  6010. IdType: certificates,
  6011. IdCardNo: id_card,
  6012. BalanceAccountsType: settlementValue,
  6013. SocialType: social_type,
  6014. MedicalInsuranceNumber: medical_insurance_card,
  6015. RegisterType: register_type,
  6016. RegisterCost: registration_fee,
  6017. TreatmentCost: medical_expenses,
  6018. AdminUserId: adminInfo.AdminUser.Id,
  6019. UserOrgId: adminInfo.CurrentOrgId,
  6020. Status: 1,
  6021. RecordDate: recordDateTime,
  6022. IsReturn: 1,
  6023. PatientId: patient.ID,
  6024. Ctime: time.Now().Unix(),
  6025. Mtime: time.Now().Unix(),
  6026. Number: str,
  6027. IdCardType: id_card_type,
  6028. Departments: department,
  6029. Doctor: doctor,
  6030. PType: reg_type,
  6031. Diagnosis: diagnosis_ids,
  6032. SickType: sick_type,
  6033. }
  6034. service.CreateHisPatient(&hisPatient)
  6035. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6036. c.ServeSuccessJSON(map[string]interface{}{
  6037. "his_info": hisPatient,
  6038. })
  6039. }
  6040. }
  6041. // 上传明细----结算
  6042. func (c *HisApiController) GetUploadInfo() {
  6043. id, _ := c.GetInt64("id")
  6044. record_time := c.GetString("record_time")
  6045. his_patient_id, _ := c.GetInt64("his_patient_id")
  6046. oth_desc := c.GetString("oth_desc")
  6047. pay_way, _ := c.GetInt64("pay_way")
  6048. pay_ways := c.GetString("pay_ways")
  6049. pay_price, _ := c.GetFloat("pay_price")
  6050. pay_card_no := c.GetString("pay_card_no")
  6051. discount_price, _ := c.GetFloat("discount_price")
  6052. preferential_price, _ := c.GetFloat("preferential_price")
  6053. reality_price, _ := c.GetFloat("reality_price")
  6054. found_price, _ := c.GetFloat("found_price")
  6055. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6056. private_price, _ := c.GetFloat("private_price")
  6057. timeLayout := "2006-01-02"
  6058. loc, _ := time.LoadLocation("Local")
  6059. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6060. fapiao_code := c.GetString("fapiao_code")
  6061. fapiao_number := c.GetString("fapiao_number")
  6062. diagnosis_id := c.GetString("diagnosis")
  6063. sick_type, _ := c.GetInt64("sick_type")
  6064. reg_type, _ := c.GetInt64("p_type")
  6065. order_id, _ := c.GetInt64("order_id")
  6066. cash_pay := c.GetString("cash_pay")
  6067. wechat_pay := c.GetString("wechat_pay")
  6068. ali_pay := c.GetString("ali_pay")
  6069. jifen_pay := c.GetString("jifen_pay")
  6070. band_card_pay := c.GetString("band_card_pay")
  6071. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6072. tmp_decimal := c.GetString("tmp_decimal")
  6073. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6074. var decimal float64 //本次使用的押金
  6075. var errmsg error
  6076. tx := service.XTWriteDB().Begin() //开了事务
  6077. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6078. defer func() {
  6079. if errmsg != nil {
  6080. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6081. tx.Rollback()
  6082. } else {
  6083. tx.Commit()
  6084. }
  6085. }()
  6086. fmt.Println("dec_way", dec_way)
  6087. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6088. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6089. return
  6090. }
  6091. if len(tmp_decimal) > 0 {
  6092. if tmp_decimal[0] == 45 {
  6093. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6094. return
  6095. }
  6096. }
  6097. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6098. fmt.Println(errs)
  6099. decimal = tt
  6100. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6101. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6102. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6103. if err != nil {
  6104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6105. return
  6106. }
  6107. recordDateTime := theTime.Unix()
  6108. adminUser := c.GetAdminUserInfo()
  6109. var prescriptions []*models.HisPrescription
  6110. var prescriptionsOne []*models.HisPrescription
  6111. var start_time int64
  6112. var end_time int64
  6113. ids_str := c.GetString("ids")
  6114. ids_arr := strings.Split(ids_str, ",")
  6115. if tempOrder.ID == 0 {
  6116. if settle_accounts_type == 1 { //日结
  6117. fmt.Println(reg_type)
  6118. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6119. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6120. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6121. } else {
  6122. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6123. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6124. }
  6125. } else { //月结
  6126. start_time_str := c.GetString("start_time")
  6127. end_time_str := c.GetString("end_time")
  6128. timeLayout := "2006-01-02"
  6129. loc, _ := time.LoadLocation("Local")
  6130. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6131. if err != nil {
  6132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6133. return
  6134. }
  6135. recordStartTime := theStartTime.Unix()
  6136. start_time = recordStartTime
  6137. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6138. if err != nil {
  6139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6140. return
  6141. }
  6142. recordEndTime := theEndTime.Unix()
  6143. end_time = recordEndTime
  6144. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6145. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6146. }
  6147. var goods []*models.DialysisBeforePrepareGoods
  6148. var newGoods []*models.NewDialysisBeforePrepareGoods
  6149. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6150. var infos []*models.HisDoctorAdviceInfo
  6151. var infoList []*models.HisDoctorAdviceInfo
  6152. var hisAdvice []*models.HisDoctorAdviceInfo
  6153. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6154. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6155. //判断库存不足
  6156. //结算出库开关
  6157. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6158. if settConfig.IsOpen == 1 {
  6159. //判断库存的地方
  6160. for _, info := range prescriptions {
  6161. if info.Type == 1 {
  6162. infos = append(infos, info.HisDoctorAdviceInfo...)
  6163. }
  6164. if info.Type == 2 {
  6165. for _, sumItem := range info.HisPrescriptionProject {
  6166. if sumItem.Type == 3 {
  6167. var good models.DialysisBeforePrepareGoods
  6168. var newGood models.NewDialysisBeforePrepareGoods
  6169. good.GoodId = sumItem.GoodInfo.ID
  6170. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6171. count, _ := strconv.Atoi(sumItem.Count)
  6172. good.Count = int64(count)
  6173. good.StorehouseId = houseConfig.StorehouseOutInfo
  6174. good.ProjectId = sumItem.ID
  6175. goods = append(goods, &good)
  6176. newGood.GoodId = sumItem.GoodInfo.ID
  6177. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6178. count2, _ := strconv.Atoi(sumItem.Count)
  6179. newGood.Count = int64(count2)
  6180. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6181. newGood.ProjectId = sumItem.ID
  6182. newGoods = append(newGoods, &newGood)
  6183. }
  6184. }
  6185. }
  6186. }
  6187. for _, info := range prescriptionsOne {
  6188. if info.Type == 1 {
  6189. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6190. }
  6191. if info.Type == 2 {
  6192. for _, sumItem := range info.HisPrescriptionProject {
  6193. if sumItem.Type == 3 {
  6194. var newGood models.NewDialysisBeforePrepareGoods
  6195. newGood.GoodId = sumItem.GoodInfo.ID
  6196. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6197. count2, _ := strconv.Atoi(sumItem.Count)
  6198. newGood.Count = int64(count2)
  6199. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6200. newGood.ProjectId = sumItem.ID
  6201. newGoodOne = append(newGoodOne, &newGood)
  6202. }
  6203. }
  6204. }
  6205. }
  6206. //判断
  6207. for _, itemOne := range infos {
  6208. for _, itemTwo := range hisAdvice {
  6209. if itemOne.DrugId == itemTwo.DrugId {
  6210. itemTwo.Child = append(itemTwo.Child, itemOne)
  6211. }
  6212. }
  6213. }
  6214. for _, itemTwo := range hisAdvice {
  6215. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6216. var sum_out_count int64
  6217. for _, itemThree := range itemTwo.Child {
  6218. var prescribing_number int64
  6219. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6220. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6221. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6222. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6223. }
  6224. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6225. prescribing_number = parseIntPrescribingNumber
  6226. }
  6227. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6228. prescribing_number = parseIntPrescribingNumber
  6229. }
  6230. sum_out_count += prescribing_number
  6231. }
  6232. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6233. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6234. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6235. if sum_out_count > drugStockOut.FlushCount {
  6236. c.ServeSuccessJSON(map[string]interface{}{
  6237. "msg": "2",
  6238. "drug": medical,
  6239. })
  6240. return
  6241. }
  6242. }
  6243. fmt.Println("newGoods99999988882os", newGoods)
  6244. for _, itemOne := range newGoods {
  6245. for _, item := range newGoodOne {
  6246. if itemOne.GoodId == item.GoodId {
  6247. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6248. }
  6249. }
  6250. }
  6251. for _, item := range newGoodOne {
  6252. var sum_out_count_one int64
  6253. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6254. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6255. sum_out_count_one += itemOne.Count
  6256. }
  6257. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6258. fmt.Println("sum_out_count_one", sum_out_count_one)
  6259. fmt.Println("list.FlushCount", list.FlushCount)
  6260. if sum_out_count_one > list.FlushCount {
  6261. c.ServeSuccessJSON(map[string]interface{}{
  6262. "msg": "3",
  6263. "good": good,
  6264. })
  6265. return
  6266. }
  6267. }
  6268. }
  6269. timestamp := time.Now().Unix()
  6270. tempTime := time.Unix(timestamp, 0)
  6271. timeFormat := tempTime.Format("20060102150405")
  6272. chrgBchno := rand.Intn(100000) + 10000
  6273. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6274. strconv.FormatInt(his.PatientId, 10)
  6275. var ids []int64
  6276. for _, item := range prescriptions {
  6277. ids = append(ids, item.ID)
  6278. }
  6279. var total float64
  6280. for _, item := range prescriptions {
  6281. fmt.Println(item)
  6282. if item.Type == 1 { //药品
  6283. for _, subItem := range item.HisDoctorAdviceInfo {
  6284. total = total + (subItem.Price * subItem.PrescribingNumber)
  6285. }
  6286. }
  6287. if item.Type == 2 { //项目
  6288. for _, subItem := range item.HisPrescriptionProject {
  6289. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6290. total = total + (subItem.Price * cnt)
  6291. }
  6292. }
  6293. for _, subItem := range item.HisAdditionalCharge {
  6294. total = total + (subItem.Price * float64(subItem.Count))
  6295. }
  6296. }
  6297. if reg_type == 1111 || reg_type == 1112 {
  6298. reg_type = 11
  6299. }
  6300. tm := time.Unix(time.Now().Unix(), 0)
  6301. allTotal := fmt.Sprintf("%.4f", total)
  6302. totals, _ := strconv.ParseFloat(allTotal, 64)
  6303. order := &models.HisOrder{
  6304. UserOrgId: adminUser.CurrentOrgId,
  6305. HisPatientId: his.ID,
  6306. PatientId: id,
  6307. SettleAccountsDate: recordDateTime,
  6308. Ctime: time.Now().Unix(),
  6309. Mtime: time.Now().Unix(),
  6310. Status: 1,
  6311. OrderStatus: 2,
  6312. MdtrtId: his.Number,
  6313. Number: chrg_bchno,
  6314. MedfeeSumamt: totals,
  6315. PayWay: pay_way,
  6316. PayWays: pay_ways,
  6317. PayPrice: pay_price,
  6318. MedType: strconv.Itoa(int(reg_type)),
  6319. PayCardNo: pay_card_no,
  6320. DiscountPrice: discount_price,
  6321. PreferentialPrice: preferential_price,
  6322. RealityPrice: reality_price,
  6323. FoundPrice: found_price,
  6324. MedicalInsurancePrice: medical_insurance_price,
  6325. PrivatePrice: private_price,
  6326. SettleEndTime: end_time,
  6327. SettleStartTime: start_time,
  6328. PsnPartAmt: totals,
  6329. PsnCashPay: totals,
  6330. SettleType: settle_accounts_type,
  6331. FaPiaoCode: fapiao_code,
  6332. FaPiaoNumber: fapiao_number,
  6333. Diagnosis: diagnosis_id,
  6334. PType: 2,
  6335. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6336. Decimal: decimal,
  6337. OthDesc: oth_desc,
  6338. CashPay: cash_pay,
  6339. WechatPay: wechat_pay,
  6340. AliPay: ali_pay,
  6341. JifenPay: jifen_pay,
  6342. BandCardPay: band_card_pay,
  6343. }
  6344. err = service.CreateOrderTX(order, tx)
  6345. if err != nil {
  6346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6347. return
  6348. }
  6349. var customs []*Custom
  6350. for _, item := range prescriptions {
  6351. if item.Type == 1 { //药品a
  6352. for _, subItem := range item.HisDoctorAdviceInfo {
  6353. cus := &Custom{
  6354. AdviceId: subItem.ID,
  6355. ProjectId: 0,
  6356. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6357. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6358. FeedetlSn: subItem.FeedetlSn,
  6359. Price: fmt.Sprintf("%.4f", subItem.Price),
  6360. MedListCodg: subItem.MedListCodg,
  6361. Type: 1,
  6362. }
  6363. customs = append(customs, cus)
  6364. }
  6365. }
  6366. if item.Type == 2 { //项目
  6367. for _, subItem := range item.HisPrescriptionProject {
  6368. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6369. cus := &Custom{
  6370. AdviceId: 0,
  6371. ProjectId: subItem.ID,
  6372. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6373. Cut: fmt.Sprintf("%.4f", cnt),
  6374. FeedetlSn: subItem.FeedetlSn,
  6375. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6376. MedListCodg: subItem.MedListCodg,
  6377. Type: 2,
  6378. }
  6379. customs = append(customs, cus)
  6380. }
  6381. }
  6382. for _, item := range item.HisAdditionalCharge {
  6383. cus := &Custom{
  6384. ItemId: item.ID,
  6385. AdviceId: 0,
  6386. ProjectId: 0,
  6387. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6388. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6389. FeedetlSn: item.FeedetlSn,
  6390. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6391. MedListCodg: item.XtHisAddtionConfig.Code,
  6392. Type: 3,
  6393. }
  6394. customs = append(customs, cus)
  6395. }
  6396. }
  6397. for _, item := range customs {
  6398. var advice_id int64 = 0
  6399. var project_id int64 = 0
  6400. var item_id int64 = 0
  6401. var types int64 = 0
  6402. if item.Type == 1 {
  6403. advice_id = item.AdviceId
  6404. project_id = 0
  6405. item_id = 0
  6406. } else if item.Type == 2 {
  6407. advice_id = 0
  6408. item_id = 0
  6409. project_id = item.ProjectId
  6410. } else if item.Type == 3 {
  6411. advice_id = 0
  6412. item_id = item.ItemId
  6413. project_id = 0
  6414. }
  6415. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6416. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6417. pric, _ := strconv.ParseFloat(item.Price, 32)
  6418. info := &models.HisOrderInfo{
  6419. OrderNumber: order.Number,
  6420. UploadDate: time.Now().Unix(),
  6421. AdviceId: advice_id,
  6422. DetItemFeeSumamt: detItemFeeSumamt,
  6423. Cnt: cut,
  6424. Pric: pric,
  6425. PatientId: id,
  6426. Status: 1,
  6427. Mtime: time.Now().Unix(),
  6428. Ctime: time.Now().Unix(),
  6429. UserOrgId: adminUser.CurrentOrgId,
  6430. HisPatientId: his.ID,
  6431. OrderId: order.ID,
  6432. ProjectId: project_id,
  6433. Type: types,
  6434. ItemId: item_id,
  6435. }
  6436. service.CreateOrderInfoTX(info, tx)
  6437. }
  6438. his.Diagnosis = diagnosis_id
  6439. his.SickType = sick_type
  6440. his.RegisterType = reg_type
  6441. his.MedicalTreatmentType = reg_type
  6442. service.UpdataHisPateintTX(&his, tx)
  6443. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6444. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6445. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6446. //判断是否使用了押金
  6447. if dec_way == "true" {
  6448. tmpstring := strconv.FormatInt(order.ID, 10)
  6449. //扣押金
  6450. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6451. order.Decimal = decimal
  6452. service.UpDateOrderTwo(order, tx)
  6453. if errmsg != nil {
  6454. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6455. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6456. return
  6457. }
  6458. }
  6459. if err == nil {
  6460. for _, info := range prescriptions {
  6461. if info.Type == 1 {
  6462. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6463. }
  6464. if info.Type == 2 {
  6465. for _, sumItem := range info.HisPrescriptionProject {
  6466. if sumItem.Type == 3 {
  6467. var good models.DialysisBeforePrepareGoods
  6468. var newGood models.NewDialysisBeforePrepareGoods
  6469. var oldGood models.OldDialysisBeforePrepareGoods
  6470. good.GoodId = sumItem.GoodInfo.ID
  6471. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6472. count, _ := strconv.Atoi(sumItem.Count)
  6473. good.Count = int64(count)
  6474. good.StorehouseId = houseConfig.StorehouseOutInfo
  6475. good.ProjectId = sumItem.ID
  6476. good.PatientId = sumItem.PatientId
  6477. goods = append(goods, &good)
  6478. newGood.GoodId = sumItem.GoodInfo.ID
  6479. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6480. count2, _ := strconv.Atoi(sumItem.Count)
  6481. newGood.Count = int64(count2)
  6482. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6483. newGood.ProjectId = sumItem.ID
  6484. newGood.PatientId = sumItem.HisPatientId
  6485. newGoods = append(newGoods, &newGood)
  6486. oldGood.GoodId = sumItem.GoodInfo.ID
  6487. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6488. count3, _ := strconv.Atoi(sumItem.Count)
  6489. oldGood.Count = int64(count3)
  6490. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6491. oldGood.ProjectId = sumItem.ID
  6492. oldGood.RecordDate = sumItem.RecordDate
  6493. oldGood.PatientId = sumItem.HisPatientId
  6494. oldGoods = append(oldGoods, &oldGood)
  6495. }
  6496. }
  6497. }
  6498. }
  6499. if settConfig.IsOpen == 1 {
  6500. for _, item := range infoList {
  6501. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6502. if medical.IsUse == 2 {
  6503. //药品出库
  6504. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6505. //查询默认仓库
  6506. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6507. //查询默认仓库剩余多少库存
  6508. var sum_count int64
  6509. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6510. for _, its := range stockInfo {
  6511. if its.MaxUnit == medical.MaxUnit {
  6512. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6513. }
  6514. sum_count += its.StockMaxNumber + its.StockMinNumber
  6515. }
  6516. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6517. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6518. }
  6519. }
  6520. orgId := c.GetAdminUserInfo().CurrentOrgId
  6521. if len(oldGoods) > 0 {
  6522. timeStr := time.Now().Format("2006-01-02")
  6523. timeArr := strings.Split(timeStr, "-")
  6524. total, _ := service.FindAllWarehouseOut(orgId)
  6525. total = total + 1
  6526. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6527. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6528. number = number + total
  6529. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6530. operation_time := time.Now().Unix()
  6531. creater := c.GetAdminUserInfo().AdminUser.Id
  6532. //查询默认出库仓库库存
  6533. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6534. recordDateStr := time.Now().Format("2006-01-02")
  6535. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6536. nowtime := recordDate.Unix()
  6537. warehouseOut := models.WarehouseOut{
  6538. WarehouseOutOrderNumber: warehousing_out_order,
  6539. OperationTime: operation_time,
  6540. OrgId: orgId,
  6541. Creater: creater,
  6542. Ctime: time.Now().Unix(),
  6543. Status: 1,
  6544. WarehouseOutTime: nowtime,
  6545. Type: 1,
  6546. StorehouseId: storeConfig.StorehouseOutInfo,
  6547. IsCheck: 1,
  6548. OrderId: order.ID,
  6549. IsSys: 5,
  6550. }
  6551. //查询是否生成出库单
  6552. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6553. if out.ID == 0 {
  6554. service.AddSigleWarehouseOut(&warehouseOut)
  6555. }
  6556. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6557. for _, item := range oldGoods {
  6558. dialyPrepareOne := models.DialysisBeforePrepare{
  6559. GoodTypeId: item.GoodTypeId,
  6560. GoodId: item.GoodId,
  6561. PatientId: his.PatientId,
  6562. RecordDate: item.RecordDate,
  6563. UserOrgId: adminUser.CurrentOrgId,
  6564. Count: item.Count,
  6565. Ctime: time.Now().Unix(),
  6566. Creater: adminUser.AdminUser.Id,
  6567. CommdityCode: item.CommdityCode,
  6568. Status: 1,
  6569. StorehouseId: houseConfig.StorehouseOutInfo,
  6570. }
  6571. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6572. //非零用
  6573. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6574. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6575. //查询剩余库存
  6576. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6577. var sum_count int64
  6578. for _, item := range goodList {
  6579. sum_count += item.StockCount
  6580. }
  6581. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6582. //耗材
  6583. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6584. }
  6585. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6586. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6587. //查询剩余库存
  6588. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6589. var sum_count int64
  6590. for _, item := range goodList {
  6591. sum_count += item.StockCount
  6592. }
  6593. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6594. //耗材
  6595. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6596. }
  6597. }
  6598. }
  6599. }
  6600. c.ServeSuccessJSON(map[string]interface{}{
  6601. "msg": "结算成功",
  6602. })
  6603. }
  6604. }
  6605. }
  6606. // 退款
  6607. func (c *HisApiController) Refund() {
  6608. order_id, _ := c.GetInt64("order_id")
  6609. order, _ := service.GetHisOrderByID(order_id)
  6610. adminUser := c.GetAdminUserInfo()
  6611. orgid := c.GetAdminUserInfo().CurrentOrgId
  6612. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6613. if err != nil {
  6614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6615. return
  6616. }
  6617. tmp := strconv.FormatInt(order.ID, 10)
  6618. //当押金不为零时产生退费记录
  6619. if order.Decimal != 0 {
  6620. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6621. if err != nil {
  6622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6623. return
  6624. }
  6625. }
  6626. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6627. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6628. var goods []*models.DialysisBeforePrepareGoods
  6629. var newGoods []*models.NewDialysisBeforePrepareGoods
  6630. var infos []*models.HisDoctorAdviceInfo
  6631. for _, info := range orders {
  6632. if info.AdviceId > 0 && info.ProjectId == 0 {
  6633. infos = append(infos, &info.HisDoctorAdviceInfo)
  6634. }
  6635. if info.ProjectId > 0 && info.AdviceId == 0 {
  6636. if info.HisPrescriptionProject.Type == 3 {
  6637. var good models.DialysisBeforePrepareGoods
  6638. var newGood models.NewDialysisBeforePrepareGoods
  6639. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6640. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6641. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6642. good.Count = int64(count)
  6643. good.StorehouseId = houseConfig.StorehouseOutInfo
  6644. good.ProjectId = info.HisPrescriptionProject.ID
  6645. good.PatientId = info.PatientId
  6646. good.OrderId = order_id
  6647. goods = append(goods, &good)
  6648. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6649. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6650. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6651. newGood.Count = int64(count2)
  6652. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6653. newGood.ProjectId = info.HisPrescriptionProject.ID
  6654. newGood.RecordDate = order.SettleAccountsDate
  6655. newGood.UserOrgId = order.UserOrgId
  6656. newGood.PatientId = info.PatientId
  6657. newGood.OrderId = order_id
  6658. newGoods = append(newGoods, &newGood)
  6659. }
  6660. }
  6661. }
  6662. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6663. if settConfig.IsOpen == 1 {
  6664. for _, item := range infos {
  6665. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6666. }
  6667. for _, item := range newGoods {
  6668. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6669. }
  6670. }
  6671. c.ServeSuccessJSON(map[string]interface{}{
  6672. "msg": "退费成功",
  6673. })
  6674. }
  6675. func (c *HisApiController) RefundNumber() {
  6676. his_patient_id, _ := c.GetInt64("id")
  6677. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6678. info.Status = 0
  6679. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6680. if count > 0 {
  6681. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6682. return
  6683. }
  6684. err := service.SaveHisPatient(info)
  6685. if err == nil {
  6686. c.ServeSuccessJSON(map[string]interface{}{
  6687. "msg": "退号成功",
  6688. })
  6689. } else {
  6690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6691. return
  6692. }
  6693. }
  6694. func (this *HisApiController) AdditionalCharge() {
  6695. dataBody := make(map[string]interface{}, 0)
  6696. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6697. fmt.Println(err)
  6698. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6699. patient_id := int64(dataBody["patient_id"].(float64))
  6700. medicineData, _ := dataBody["medicineData"].([]interface{})
  6701. adminUserInfo := this.GetAdminUserInfo()
  6702. orgId := adminUserInfo.CurrentOrgId
  6703. admin_user_id := adminUserInfo.AdminUser.Id
  6704. timeStr := time.Now().Format("2006-01-02")
  6705. timeLayout := "2006-01-02 15:04:05"
  6706. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6707. timenow := timeStringToTime.Unix()
  6708. var additionalCharges []*models.HisAdditionalCharge
  6709. for _, item := range medicineData {
  6710. var randNum int
  6711. randNum = rand.Intn(10000) + 1000
  6712. timestamp := time.Now().Unix()
  6713. tempTime := time.Unix(timestamp, 0)
  6714. timeFormat := tempTime.Format("20060102150405")
  6715. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6716. items := item.(map[string]interface{})
  6717. money := items["price"].(string)
  6718. item_id_str := items["item_id"].(string)
  6719. name := items["name"].(string)
  6720. id_str := items["id"].(string)
  6721. moneys, _ := strconv.ParseInt(money, 10, 64)
  6722. monStr := strconv.FormatInt(moneys, 10)
  6723. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6724. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6725. id, _ := strconv.ParseInt(id_str, 10, 64)
  6726. additionalCharge := &models.HisAdditionalCharge{
  6727. ID: id,
  6728. HisPatientId: his_patient_id,
  6729. UserOrgId: orgId,
  6730. PatientId: patient_id,
  6731. RecordDate: timenow,
  6732. Price: monneyStr,
  6733. Status: 1,
  6734. ItemName: name,
  6735. ItemId: item_id,
  6736. AdminUserId: admin_user_id,
  6737. CreatedTime: time.Now().Unix(),
  6738. OrderStatus: 0,
  6739. PrescriptionNumber: "",
  6740. BatchNumber: "",
  6741. FeedetlSn: p_number,
  6742. }
  6743. service.CreateAdditionalCharge(additionalCharge)
  6744. additionalCharges = append(additionalCharges, additionalCharge)
  6745. }
  6746. this.ServeSuccessJSON(map[string]interface{}{
  6747. "msg": "添加成功",
  6748. "additional_charges": additionalCharges,
  6749. })
  6750. }
  6751. func (this *HisApiController) DeleteAddition() {
  6752. id, _ := this.GetInt64("id")
  6753. //TODO 需要判断是否已经结算
  6754. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6755. if err == nil {
  6756. this.ServeSuccessJSON(map[string]interface{}{
  6757. "msg": "删除成功",
  6758. })
  6759. return
  6760. } else {
  6761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6762. return
  6763. }
  6764. }
  6765. func (this *HisApiController) GetAdminUsers() {
  6766. adminUser := this.GetAdminUserInfo()
  6767. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6768. this.ServeSuccessJSON(map[string]interface{}{
  6769. "doctors": doctors,
  6770. })
  6771. }
  6772. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6773. change_type, _ := this.GetInt64("type", 0)
  6774. record_date := this.GetString("record_time")
  6775. patient_id, _ := this.GetInt64("patient_id", 0)
  6776. p_type, _ := this.GetInt64("p_type", 0)
  6777. timeLayout := "2006-01-02"
  6778. loc, _ := time.LoadLocation("Local")
  6779. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6780. record_time := theAdviceRecordTime.Unix()
  6781. adminUserInfo := this.GetAdminUserInfo()
  6782. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6783. if err == nil {
  6784. if len(prescriptions) == 0 {
  6785. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6786. return
  6787. } else {
  6788. this.ServeSuccessJSON(map[string]interface{}{
  6789. "prescriptions": prescriptions,
  6790. })
  6791. return
  6792. }
  6793. } else {
  6794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6795. return
  6796. }
  6797. }
  6798. func (this *HisApiController) GetCallHisPrescription() {
  6799. patient_id, _ := this.GetInt64("patient_id", 0)
  6800. timeLayout := "2006-01-02"
  6801. loc, _ := time.LoadLocation("Local")
  6802. start_time := this.GetString("start_time")
  6803. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6804. end_time := this.GetString("end_time")
  6805. p_type, _ := this.GetInt64("p_type")
  6806. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6807. adminUserInfo := this.GetAdminUserInfo()
  6808. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6809. if err == nil {
  6810. this.ServeSuccessJSON(map[string]interface{}{
  6811. "prescriptions": prescriptions,
  6812. })
  6813. return
  6814. } else {
  6815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6816. return
  6817. }
  6818. }
  6819. func (this *HisApiController) GetHisDayPrescription() {
  6820. timeLayout := "2006-01-02"
  6821. loc, _ := time.LoadLocation("Local")
  6822. start_time := this.GetString("start_time")
  6823. patient_id, _ := this.GetInt64("patient_id", 0)
  6824. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6825. end_time := this.GetString("end_time")
  6826. p_type, _ := this.GetInt64("p_type")
  6827. order_status, _ := this.GetInt64("type")
  6828. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6829. adminUserInfo := this.GetAdminUserInfo()
  6830. var dayHisPrescription []*models.HisPrescription
  6831. var err error
  6832. if order_status == 1 || order_status == 0 {
  6833. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6834. } else if order_status == 2 {
  6835. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6836. }
  6837. var settle_total float64
  6838. for _, item := range dayHisPrescription {
  6839. if len(item.HisPrescriptionProject) > 0 {
  6840. for _, subItem := range item.HisPrescriptionProject {
  6841. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6842. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6843. settle_total = settle_total + total
  6844. }
  6845. }
  6846. if len(item.HisDoctorAdviceInfo) > 0 {
  6847. for _, subItem := range item.HisDoctorAdviceInfo {
  6848. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6849. settle_total = settle_total + total
  6850. }
  6851. }
  6852. }
  6853. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6854. if err == nil {
  6855. this.ServeSuccessJSON(map[string]interface{}{
  6856. "day_prescription": dayHisPrescription,
  6857. "settle_total": settle_total,
  6858. })
  6859. return
  6860. } else {
  6861. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6862. return
  6863. }
  6864. }
  6865. func (c *HisApiController) GetHisChargePatientList() {
  6866. record_date := c.GetString("record_date")
  6867. order_status, _ := c.GetInt64("type")
  6868. sch_type, _ := c.GetInt64("sch_type")
  6869. timeLayout := "2006-01-02"
  6870. loc, _ := time.LoadLocation("Local")
  6871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6872. if err != nil {
  6873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6874. return
  6875. }
  6876. recordDateTime := theTime.Unix()
  6877. adminInfo := c.GetAdminUserInfo()
  6878. var tempPatients []*service.NewTempPatients
  6879. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6880. if order_status != 2 {
  6881. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6882. } else {
  6883. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  6884. }
  6885. var patients []*service.NewTempPatients
  6886. var patients_two []*service.NewTempPatients
  6887. for _, item := range tempPatients {
  6888. //过滤掉没挂号的和没开处方的
  6889. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6890. patients = append(patients, item)
  6891. }
  6892. //过滤掉没挂号的
  6893. if len(item.HisPatient) > 0 {
  6894. patients_two = append(patients_two, item)
  6895. }
  6896. }
  6897. c.ServeSuccessJSON(map[string]interface{}{
  6898. "list": patients,
  6899. "list_two": patients_two,
  6900. })
  6901. }
  6902. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6903. record_date := c.GetString("record_date")
  6904. timeLayout := "2006-01-02"
  6905. loc, _ := time.LoadLocation("Local")
  6906. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6907. if err != nil {
  6908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6909. return
  6910. }
  6911. recordDateTime := theTime.Unix()
  6912. adminUser := c.GetAdminUserInfo()
  6913. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6914. var patients []*service.Patients
  6915. for _, item := range tempPatients {
  6916. if item.HisPatient.ID == 0 {
  6917. patients = append(patients, item)
  6918. }
  6919. }
  6920. c.ServeSuccessJSON(map[string]interface{}{
  6921. "list": patients,
  6922. //"list_two": patients_two,
  6923. })
  6924. }
  6925. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6926. newArr = make([]*service.Patients, 0)
  6927. for i := 0; i < len(patient); i++ {
  6928. repeat := false
  6929. for j := i + 1; j < len(patient); j++ {
  6930. if patient[i].ID == patient[j].ID {
  6931. repeat = true
  6932. break
  6933. }
  6934. }
  6935. if !repeat {
  6936. newArr = append(newArr, patient[i])
  6937. }
  6938. }
  6939. return
  6940. }
  6941. func (c *HisApiController) GetHisChargePatientInfo() {
  6942. patient_id, _ := c.GetInt64("patient_id")
  6943. his_patient_id, _ := c.GetInt64("his_patient_id")
  6944. record_date := c.GetString("record_date")
  6945. //start_time := c.GetString("start_time")
  6946. //end_time := c.GetString("end_time")
  6947. order_status, _ := c.GetInt64("type", 0)
  6948. p_type, _ := c.GetInt64("p_type", 0)
  6949. order_id, _ := c.GetInt64("order_id", 0)
  6950. timeLayout := "2006-01-02"
  6951. loc, _ := time.LoadLocation("Local")
  6952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6953. if err != nil {
  6954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6955. return
  6956. }
  6957. recordDateTime := theTime.Unix()
  6958. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6959. //if err != nil {
  6960. //
  6961. //}
  6962. //startRecordDateTime := startTime.Unix()
  6963. //
  6964. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6965. //if err != nil {
  6966. //
  6967. //}
  6968. //endRecordDateTime := endTime.Unix()
  6969. admin := c.GetAdminUserInfo()
  6970. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6971. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6972. var prescriptions []*models.HisPrescription
  6973. //var unChargeMonthPrescriptions []*models.HisPrescription
  6974. order, _ := service.GetHisOrderByID(order_id)
  6975. if order_status == 1 || order_status == 0 {
  6976. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6977. } else if order_status == 2 {
  6978. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6979. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6980. }
  6981. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6982. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6983. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6984. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6985. //获取所有科室信息
  6986. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6987. c.ServeSuccessJSON(map[string]interface{}{
  6988. "his_info": his_patient_info,
  6989. "xt_info": xt_patient_info,
  6990. "prescription": prescriptions,
  6991. "case_history": case_history,
  6992. "info": patientPrescriptionInfo,
  6993. "last_info": lastPatientPrescriptionInfo,
  6994. "order": order,
  6995. "doctors": doctors,
  6996. "department": department,
  6997. })
  6998. return
  6999. }
  7000. func (c *HisApiController) GetAllOrderDetail() {
  7001. order_id, _ := c.GetInt64("id", 0)
  7002. order, _ := service.GetHisOrderByID(order_id)
  7003. if order.ID == 0 {
  7004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7005. return
  7006. }
  7007. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7008. org_id := c.GetAdminUserInfo().CurrentOrgId
  7009. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7010. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7011. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7012. c.ServeSuccessJSON(map[string]interface{}{
  7013. "order": order,
  7014. "order_info": order_info,
  7015. "patient": patient,
  7016. "admin_info": adminInfo,
  7017. "hospital_record": record,
  7018. })
  7019. return
  7020. }
  7021. func (c *HisApiController) GetAllOrderDetailCollect() {
  7022. order_id, _ := c.GetInt64("id", 0)
  7023. order, _ := service.GetHisOrderByID(order_id)
  7024. if order.ID == 0 {
  7025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7026. return
  7027. }
  7028. org_id := c.GetAdminUserInfo().CurrentOrgId
  7029. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7030. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7031. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7032. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7033. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7034. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7035. var bedCostTotal float64 = 0 //床位总费
  7036. //var bedCostSelfTotal float64 = 0 //床位自费
  7037. var operationCostTotal float64 = 0 //手术费
  7038. //var operationCostSelfTotal float64 = 0 //手术费
  7039. var otherCostTotal float64 = 0 //其他费用
  7040. //var otherCostSelfTotal float64 = 0 //其他费用
  7041. var materialCostTotal float64 = 0 //材料费
  7042. //var materialCostSelfTotal float64 = 0 //材料费
  7043. var westernMedicineCostTotal float64 = 0 //西药费
  7044. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7045. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7046. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7047. var checkCostTotal float64 = 0 //检查费
  7048. //var checkCostSelfTotal float64 = 0 //检查费
  7049. var laboratoryCostTotal float64 = 0 //化验费
  7050. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7051. var treatCostTotal float64 = 0 //治疗费用
  7052. //var treatCostSelfTotal float64 = 0 //治疗费用
  7053. var zhenChaCostTotal float64 = 0 //其他费用
  7054. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7055. decimal.DivisionPrecision = 2
  7056. var BalanceAccountsType int64
  7057. if his.ID > 0 {
  7058. BalanceAccountsType = his.BalanceAccountsType
  7059. } else {
  7060. BalanceAccountsType = record.BalanceAccountsType
  7061. }
  7062. if BalanceAccountsType != 2 {
  7063. for _, item := range order_info {
  7064. if org_id == 10215 {
  7065. if item.MedChrgitmType == "01" { //床位费
  7066. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7067. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7068. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7069. }
  7070. if item.MedChrgitmType == "02" { //诊察费
  7071. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7072. //zhenChaCostSelfTotal = zhenChaCostTotal
  7073. }
  7074. if item.MedChrgitmType == "03" { //检查费
  7075. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7076. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7077. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7078. }
  7079. //if item.MedChrgitmType == "02" { //检查费
  7080. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7081. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7082. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7083. //}
  7084. if item.MedChrgitmType == "04" { //化验费
  7085. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7086. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7087. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7088. }
  7089. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7090. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7091. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7092. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7093. }
  7094. if item.MedChrgitmType == "06" { //手术费
  7095. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7096. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7097. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7098. }
  7099. if item.MedChrgitmType == "08" { //材料费
  7100. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7101. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7102. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7103. }
  7104. if item.MedChrgitmType == "09" { //西药费
  7105. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7106. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7107. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7108. }
  7109. if item.MedChrgitmType == "11" { //中成费
  7110. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7111. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7112. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7113. }
  7114. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7115. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7116. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7117. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7118. }
  7119. } else if org_id == 10188 || org_id == 10217 {
  7120. if item.MedChrgitmType == "01" { //床位费
  7121. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7122. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7123. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7124. }
  7125. if item.MedChrgitmType == "02" { //诊察费
  7126. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7127. //zhenChaCostSelfTotal = zhenChaCostTotal
  7128. }
  7129. if item.MedChrgitmType == "03" { //检查费
  7130. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7131. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7132. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7133. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7134. }
  7135. //if item.MedChrgitmType == "02" { //检查费
  7136. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7137. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7138. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7139. //}
  7140. if item.MedChrgitmType == "04" { //化验费
  7141. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7142. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7143. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7144. }
  7145. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7146. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7147. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7148. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7149. }
  7150. if item.MedChrgitmType == "06" { //手术费
  7151. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7152. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7153. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7154. }
  7155. if item.MedChrgitmType == "08" { //材料费
  7156. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7157. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7158. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7159. }
  7160. if item.MedChrgitmType == "09" { //西药费
  7161. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7162. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7163. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7164. }
  7165. if item.MedChrgitmType == "11" { //中成费
  7166. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7167. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7168. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7169. }
  7170. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7171. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7172. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7173. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7174. }
  7175. } else {
  7176. if item.MedChrgitmType == "01" { //床位费
  7177. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7178. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7179. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7180. }
  7181. //if item.MedChrgitmType == "02" { //诊察费
  7182. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7183. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7184. //}
  7185. if item.MedChrgitmType == "03" { //检查费
  7186. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7187. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7188. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7189. }
  7190. //if item.MedChrgitmType == "02" { //检查费
  7191. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7192. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7193. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7194. //}
  7195. if item.MedChrgitmType == "04" { //化验费
  7196. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7197. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7198. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7199. }
  7200. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7201. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7202. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7203. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7204. }
  7205. if item.MedChrgitmType == "06" { //手术费
  7206. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7207. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7208. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7209. }
  7210. if item.MedChrgitmType == "08" { //材料费
  7211. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7212. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7213. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7214. }
  7215. if item.MedChrgitmType == "09" { //西药费
  7216. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7217. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7218. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7219. }
  7220. if item.MedChrgitmType == "11" { //中成费
  7221. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7222. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7223. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7224. }
  7225. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7226. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7227. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7228. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7229. }
  7230. }
  7231. }
  7232. c.ServeSuccessJSON(map[string]interface{}{
  7233. "order": order,
  7234. "order_info": order_info,
  7235. "patient": patient,
  7236. "admin_info": adminInfo,
  7237. "his_hospital": record,
  7238. "bedCostTotal": bedCostTotal,
  7239. "operationCostTotal": operationCostTotal,
  7240. "otherCostTotal": otherCostTotal,
  7241. "materialCostTotal": materialCostTotal,
  7242. "westernMedicineCostTotal": westernMedicineCostTotal,
  7243. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7244. "checkCostTotal": checkCostTotal,
  7245. "zhenChaCostTotal": zhenChaCostTotal,
  7246. "laboratoryCostTotal": laboratoryCostTotal,
  7247. "treatCostTotal": treatCostTotal,
  7248. })
  7249. } else {
  7250. for _, item := range order_info {
  7251. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7252. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7253. item.MedChrgitmType = "09"
  7254. }
  7255. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7256. if item.HisPrescriptionProject.Type == 2 {
  7257. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7258. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7259. case 0:
  7260. item.MedChrgitmType = "0"
  7261. break
  7262. case 1:
  7263. item.MedChrgitmType = "14"
  7264. break
  7265. case 2:
  7266. item.MedChrgitmType = "05"
  7267. break
  7268. case 3:
  7269. item.MedChrgitmType = "03"
  7270. break
  7271. case 4:
  7272. item.MedChrgitmType = "03"
  7273. break
  7274. case 5:
  7275. item.MedChrgitmType = "08"
  7276. break
  7277. case 6:
  7278. item.MedChrgitmType = "14"
  7279. break
  7280. case 7:
  7281. item.MedChrgitmType = "14"
  7282. break
  7283. case 8:
  7284. item.MedChrgitmType = "03"
  7285. break
  7286. case 9:
  7287. item.MedChrgitmType = "14"
  7288. break
  7289. case 10:
  7290. item.MedChrgitmType = "14"
  7291. break
  7292. case 11:
  7293. item.MedChrgitmType = "06"
  7294. break
  7295. case 12:
  7296. item.MedChrgitmType = "12"
  7297. break
  7298. case 13:
  7299. item.MedChrgitmType = "01"
  7300. break
  7301. case 14:
  7302. item.MedChrgitmType = "04"
  7303. break
  7304. case 15:
  7305. item.MedChrgitmType = "14"
  7306. break
  7307. }
  7308. } else {
  7309. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7310. case 1:
  7311. item.MedChrgitmType = "14"
  7312. break
  7313. case 2:
  7314. item.MedChrgitmType = "05"
  7315. break
  7316. case 3:
  7317. item.MedChrgitmType = "04"
  7318. break
  7319. case 4:
  7320. item.MedChrgitmType = "14"
  7321. break
  7322. case 5:
  7323. item.MedChrgitmType = "08"
  7324. break
  7325. case 6:
  7326. item.MedChrgitmType = "14"
  7327. break
  7328. case 7:
  7329. item.MedChrgitmType = "14"
  7330. break
  7331. case 8:
  7332. item.MedChrgitmType = "03"
  7333. break
  7334. case 9:
  7335. item.MedChrgitmType = "14"
  7336. break
  7337. }
  7338. }
  7339. } else if item.HisPrescriptionProject.Type == 3 {
  7340. item.MedChrgitmType = "08"
  7341. }
  7342. }
  7343. }
  7344. for _, item := range order_info {
  7345. if org_id == 10215 {
  7346. if item.MedChrgitmType == "01" { //床位费
  7347. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7348. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7349. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7350. }
  7351. if item.MedChrgitmType == "02" { //诊察费
  7352. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7353. //zhenChaCostSelfTotal = zhenChaCostTotal
  7354. }
  7355. if item.MedChrgitmType == "03" { //检查费
  7356. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7357. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7358. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7359. }
  7360. //if item.MedChrgitmType == "02" { //检查费
  7361. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7362. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7363. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7364. //}
  7365. if item.MedChrgitmType == "04" { //化验费
  7366. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7367. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7368. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7369. }
  7370. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7371. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7372. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7373. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7374. }
  7375. if item.MedChrgitmType == "06" { //手术费
  7376. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7377. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7378. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7379. }
  7380. if item.MedChrgitmType == "08" { //材料费
  7381. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7382. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7383. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7384. }
  7385. if item.MedChrgitmType == "09" { //西药费
  7386. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7387. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7388. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7389. }
  7390. if item.MedChrgitmType == "11" { //中成费
  7391. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7392. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7393. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7394. }
  7395. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7396. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7397. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7398. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7399. }
  7400. } else {
  7401. if item.MedChrgitmType == "01" { //床位费
  7402. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7403. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7404. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7405. }
  7406. //if item.MedChrgitmType == "02" { //诊察费
  7407. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7408. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7409. //}
  7410. if item.MedChrgitmType == "03" { //检查费
  7411. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7412. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7413. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7414. }
  7415. //if item.MedChrgitmType == "02" { //检查费
  7416. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7417. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7418. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7419. //}
  7420. if item.MedChrgitmType == "04" { //化验费
  7421. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7422. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7423. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7424. }
  7425. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7426. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7427. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7428. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7429. }
  7430. if item.MedChrgitmType == "06" { //手术费
  7431. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7432. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7433. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7434. }
  7435. if item.MedChrgitmType == "08" { //材料费
  7436. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7437. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7438. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7439. }
  7440. if item.MedChrgitmType == "09" { //西药费
  7441. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7442. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7443. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7444. }
  7445. if item.MedChrgitmType == "11" { //中成费
  7446. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7447. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7448. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7449. }
  7450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7452. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7453. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7454. }
  7455. }
  7456. }
  7457. c.ServeSuccessJSON(map[string]interface{}{
  7458. "order": order,
  7459. "order_info": order_info,
  7460. "patient": patient,
  7461. "admin_info": adminInfo,
  7462. "his_hospital": record,
  7463. "bedCostTotal": bedCostTotal,
  7464. "operationCostTotal": operationCostTotal,
  7465. "otherCostTotal": otherCostTotal,
  7466. "materialCostTotal": materialCostTotal,
  7467. "westernMedicineCostTotal": westernMedicineCostTotal,
  7468. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7469. "checkCostTotal": checkCostTotal,
  7470. "zhenChaCostTotal": zhenChaCostTotal,
  7471. "laboratoryCostTotal": laboratoryCostTotal,
  7472. "treatCostTotal": treatCostTotal,
  7473. })
  7474. }
  7475. }
  7476. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7477. page, _ := c.GetInt64("page")
  7478. limit, _ := c.GetInt64("limit")
  7479. keywords := c.GetString("keywords")
  7480. start_time := c.GetString("start_time")
  7481. end_time := c.GetString("end_time")
  7482. //clr_type := c.GetString("clr_type")
  7483. insutype := c.GetString("insutype")
  7484. timeLayout := "2006-01-02"
  7485. loc, _ := time.LoadLocation("Local")
  7486. var theStartTIme int64
  7487. if len(start_time) > 0 {
  7488. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7489. theStartTIme = theTime.Unix()
  7490. }
  7491. var theEndtTIme int64
  7492. if len(end_time) > 0 {
  7493. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7494. theEndtTIme = theTime.Unix()
  7495. }
  7496. if page <= 0 {
  7497. page = 1
  7498. }
  7499. if limit <= 0 {
  7500. limit = 10
  7501. }
  7502. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7503. c.ServeSuccessJSON(map[string]interface{}{
  7504. "total": total,
  7505. "list": list,
  7506. })
  7507. return
  7508. }
  7509. func (c *HisApiController) GetPutOnRecordList() {
  7510. page, _ := c.GetInt64("page")
  7511. limit, _ := c.GetInt64("limit")
  7512. keywords := c.GetString("keywords")
  7513. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7514. if page <= 0 {
  7515. page = 1
  7516. }
  7517. if limit <= 0 {
  7518. limit = 10
  7519. }
  7520. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7521. c.ServeSuccessJSON(map[string]interface{}{
  7522. "total": total,
  7523. "list": list,
  7524. })
  7525. return
  7526. }
  7527. func (c *HisApiController) GetCompareData() {
  7528. start_time := c.GetString("start_time")
  7529. end_time := c.GetString("end_time")
  7530. insutype := c.GetString("insutype")
  7531. clr_type := c.GetString("clr_type")
  7532. timeLayout := "2006-01-02"
  7533. loc, _ := time.LoadLocation("Local")
  7534. var theStartTIme int64
  7535. if len(start_time) > 0 {
  7536. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7537. if err != nil {
  7538. theStartTIme = 0
  7539. }
  7540. theStartTIme = theTime.Unix()
  7541. }
  7542. var theEndtTIme int64
  7543. if len(end_time) > 0 {
  7544. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7545. if err != nil {
  7546. theEndtTIme = 0
  7547. }
  7548. theEndtTIme = theTime.Unix()
  7549. }
  7550. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7551. fmt.Println(err)
  7552. if err == nil {
  7553. c.ServeSuccessJSON(map[string]interface{}{
  7554. "list": formData,
  7555. })
  7556. } else {
  7557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7558. return
  7559. }
  7560. }
  7561. func (c *HisApiController) GetFaPiaoData() {
  7562. order_id, _ := c.GetInt64("order_id")
  7563. patient_id, _ := c.GetInt64("patient_id")
  7564. //number := c.GetString("number")
  7565. adminUser := c.GetAdminUserInfo()
  7566. order, _ := service.GetHisOrderByID(order_id)
  7567. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7568. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7569. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7570. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7571. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7572. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7573. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7574. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7575. var bedCostTotal float64 = 0 //床位总费
  7576. var bedCostSelfTotal float64 = 0 //床位自费
  7577. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7578. var operationCostTotal float64 = 0 //手术费
  7579. var operationCostSelfTotal float64 = 0 //手术费
  7580. var operationCostPartSelfTotal float64 = 0 //手术费
  7581. var otherCostTotal float64 = 0 //其他费用
  7582. var otherCostSelfTotal float64 = 0 //其他费用
  7583. var otherCostPartSelfTotal float64 = 0 //其他费用
  7584. var materialCostTotal float64 = 0 //材料费
  7585. var materialCostSelfTotal float64 = 0 //材料费
  7586. var materialCostPartSelfTotal float64 = 0 //材料费
  7587. var westernMedicineCostTotal float64 = 0 //西药费
  7588. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7589. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7590. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7591. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7592. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7593. var checkCostTotal float64 = 0 //检查费
  7594. var checkCostSelfTotal float64 = 0 //检查费
  7595. var checkCostPartSelfTotal float64 = 0 //检查费
  7596. var hiliCostTotal float64 = 0 //护理费
  7597. var hiliCostSelfTotal float64 = 0 //护理费
  7598. var hiliCostPartSelfTotal float64 = 0 //护理费
  7599. var laboratoryCostTotal float64 = 0 //化验费
  7600. var laboratoryCostSelfTotal float64 = 0 //化验费
  7601. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7602. var treatCostTotal float64 = 0 //治疗费用
  7603. var treatCostSelfTotal float64 = 0 //治疗费用
  7604. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7605. var zhenChaCostTotal float64 = 0 //其他费用
  7606. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7607. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7608. decimal.DivisionPrecision = 2
  7609. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7610. var balanceAccountsType int64
  7611. if his.ID > 0 {
  7612. balanceAccountsType = his.BalanceAccountsType
  7613. } else {
  7614. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7615. }
  7616. if balanceAccountsType == 2 {
  7617. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7618. for _, item := range orderInfos_two {
  7619. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7620. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7621. item.MedChrgitmType = "09"
  7622. }
  7623. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7624. if item.HisPrescriptionProject.Type == 2 {
  7625. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7626. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7627. case 0:
  7628. item.MedChrgitmType = "0"
  7629. break
  7630. case 1:
  7631. item.MedChrgitmType = "14"
  7632. break
  7633. case 2:
  7634. item.MedChrgitmType = "05"
  7635. break
  7636. case 3:
  7637. item.MedChrgitmType = "03"
  7638. break
  7639. case 4:
  7640. item.MedChrgitmType = "03"
  7641. break
  7642. case 5:
  7643. item.MedChrgitmType = "08"
  7644. break
  7645. case 6:
  7646. item.MedChrgitmType = "14"
  7647. break
  7648. case 7:
  7649. item.MedChrgitmType = "14"
  7650. break
  7651. case 8:
  7652. item.MedChrgitmType = "03"
  7653. break
  7654. case 9:
  7655. item.MedChrgitmType = "14"
  7656. break
  7657. case 10:
  7658. item.MedChrgitmType = "14"
  7659. break
  7660. case 11:
  7661. item.MedChrgitmType = "06"
  7662. break
  7663. case 12:
  7664. item.MedChrgitmType = "12"
  7665. break
  7666. case 13:
  7667. item.MedChrgitmType = "01"
  7668. break
  7669. case 14:
  7670. item.MedChrgitmType = "04"
  7671. break
  7672. case 15:
  7673. item.MedChrgitmType = "02"
  7674. break
  7675. }
  7676. } else {
  7677. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7678. case 1:
  7679. item.MedChrgitmType = "14"
  7680. break
  7681. case 2:
  7682. item.MedChrgitmType = "05"
  7683. break
  7684. case 3:
  7685. item.MedChrgitmType = "03"
  7686. break
  7687. case 4:
  7688. item.MedChrgitmType = "03"
  7689. break
  7690. case 5:
  7691. item.MedChrgitmType = "08"
  7692. break
  7693. case 6:
  7694. item.MedChrgitmType = "14"
  7695. break
  7696. case 7:
  7697. item.MedChrgitmType = "14"
  7698. break
  7699. case 8:
  7700. item.MedChrgitmType = "03"
  7701. break
  7702. case 9:
  7703. item.MedChrgitmType = "14"
  7704. break
  7705. }
  7706. }
  7707. } else if item.HisPrescriptionProject.Type == 3 {
  7708. item.MedChrgitmType = "08"
  7709. }
  7710. }
  7711. }
  7712. for _, item := range orderInfos_two {
  7713. fmt.Println(item.MedChrgitmType)
  7714. if item.MedChrgitmType == "07" { //床位费
  7715. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7716. hiliCostSelfTotal = hiliCostTotal
  7717. }
  7718. if item.MedChrgitmType == "01" { //床位费
  7719. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7720. bedCostSelfTotal = bedCostTotal
  7721. }
  7722. if item.MedChrgitmType == "02" { //诊察费
  7723. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7724. zhenChaCostSelfTotal = zhenChaCostTotal
  7725. }
  7726. if item.MedChrgitmType == "03" { //检查费
  7727. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7728. checkCostSelfTotal = checkCostTotal
  7729. }
  7730. if item.MedChrgitmType == "04" { //化验费
  7731. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7732. laboratoryCostSelfTotal = laboratoryCostTotal
  7733. }
  7734. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7735. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7736. treatCostSelfTotal = treatCostTotal
  7737. }
  7738. if item.MedChrgitmType == "06" { //手术费
  7739. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7740. operationCostSelfTotal = treatCostTotal
  7741. }
  7742. if item.MedChrgitmType == "08" { //材料费
  7743. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7744. materialCostSelfTotal = materialCostTotal
  7745. }
  7746. if item.MedChrgitmType == "09" { //西药费
  7747. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7748. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7749. }
  7750. if item.MedChrgitmType == "11" { //中成费
  7751. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7752. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7753. }
  7754. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7755. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7756. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7757. otherCostSelfTotal = otherCostTotal
  7758. }
  7759. } else {
  7760. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7761. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7762. otherCostSelfTotal = otherCostTotal
  7763. }
  7764. }
  7765. }
  7766. } else {
  7767. for _, item := range orderInfos {
  7768. if item.MedChrgitmType == "01" { //床位费
  7769. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7770. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7771. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7772. }
  7773. if item.MedChrgitmType == "02" { //诊察费
  7774. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7775. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7776. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7777. }
  7778. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7779. if item.MedChrgitmType == "03" { //检查费
  7780. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7781. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7782. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7783. }
  7784. } else {
  7785. if item.MedChrgitmType == "03" { //检查费
  7786. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7787. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7788. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7789. }
  7790. }
  7791. if item.MedChrgitmType == "04" { //化验费
  7792. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7793. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7794. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7795. }
  7796. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7797. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7798. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7799. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7800. }
  7801. if item.MedChrgitmType == "06" { //手术费
  7802. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7803. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7804. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7805. }
  7806. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7807. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7808. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7809. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7810. }
  7811. if item.MedChrgitmType == "07" { //西药费
  7812. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7813. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7814. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7815. }
  7816. if item.MedChrgitmType == "09" { //西药费
  7817. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7818. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7819. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7820. }
  7821. if item.MedChrgitmType == "11" { //中成费
  7822. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7823. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7824. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7825. }
  7826. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7827. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7828. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7829. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7830. }
  7831. }
  7832. }
  7833. timeLayout := "2006-01-02"
  7834. loc, _ := time.LoadLocation("Local")
  7835. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7836. if err != nil {
  7837. }
  7838. startRecordDateTime := startTime.Unix()
  7839. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7840. if err != nil {
  7841. }
  7842. endRecordDateTime := endTime.Unix()
  7843. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7844. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7845. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7846. c.ServeSuccessJSON(map[string]interface{}{
  7847. "order_number": order.Number, //业务流水号
  7848. "id_card_no": his.IdCardNo, //社会保障号
  7849. "patient": patient,
  7850. "department_name": department.Name, //科室
  7851. "number": his.Number, //门诊号
  7852. "date": order.SettleAccountsDate, //结算日期
  7853. "name": order.PsnName, //姓名
  7854. "gender": patient.Gender, //性别
  7855. "psn_cash_money": order.PsnCashPay, //个人支付
  7856. "pay_way": "门诊", //结算方式
  7857. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7858. "admin_user_name": admin.UserName, //收款员
  7859. "order": order,
  7860. "order_info": orderInfos_two,
  7861. "his": his,
  7862. "bedCostTotal": bedCostTotal,
  7863. "bedCostSelfTotal": bedCostSelfTotal,
  7864. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7865. "operationCostTotal": operationCostTotal,
  7866. "operationCostSelfTotal": operationCostSelfTotal,
  7867. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7868. "otherCostTotal": otherCostTotal,
  7869. "otherCostSelfTotal": otherCostSelfTotal,
  7870. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7871. "materialCostTotal": materialCostTotal,
  7872. "materialCostSelfTotal": materialCostSelfTotal,
  7873. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7874. "westernMedicineCostTotal": westernMedicineCostTotal,
  7875. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7876. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7877. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7878. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7879. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7880. "checkCostTotal": checkCostTotal,
  7881. "checkCostSelfTotal": checkCostSelfTotal,
  7882. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7883. "laboratoryCostTotal": laboratoryCostTotal,
  7884. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7885. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7886. "treatCostTotal": treatCostTotal,
  7887. "treatCostSelfTotal": treatCostSelfTotal,
  7888. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7889. "zhenChaCostTotal": zhenChaCostTotal,
  7890. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7891. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7892. "his_hospital_record": his_hospital_record,
  7893. "pre_pay_money": pre_pay_money,
  7894. "refund_sum": sum,
  7895. "doctor_info": doctor_info,
  7896. "hiliCostTotal": hiliCostTotal,
  7897. "hiliCostSelfTotal": hiliCostSelfTotal,
  7898. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  7899. })
  7900. }
  7901. //func (c *HisApiController) GetFaPiaoDatas() {
  7902. // order_ids := c.GetString("order_ids")
  7903. // patient_id, _ := c.GetInt64("patient_id")
  7904. // adminUser := c.GetAdminUserInfo()
  7905. //
  7906. // orders := strings.Split(order_ids, ",")
  7907. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7908. //
  7909. // for _, item := range orders {
  7910. // order_id, _ := strconv.ParseInt(item, 10, 64)
  7911. // order, _ := service.GetHisOrderByID(order_id)
  7912. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7913. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7914. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7915. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7916. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7917. //
  7918. // }
  7919. //
  7920. // var bedCostTotal float64 = 0 //床位总费
  7921. // var bedCostSelfTotal float64 = 0 //床位自费
  7922. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7923. //
  7924. // var operationCostTotal float64 = 0 //手术费
  7925. // var operationCostSelfTotal float64 = 0 //手术费
  7926. // var operationCostPartSelfTotal float64 = 0 //手术费
  7927. //
  7928. // var otherCostTotal float64 = 0 //其他费用
  7929. // var otherCostSelfTotal float64 = 0 //其他费用
  7930. // var otherCostPartSelfTotal float64 = 0 //其他费用
  7931. //
  7932. // var materialCostTotal float64 = 0 //材料费
  7933. // var materialCostSelfTotal float64 = 0 //材料费
  7934. // var materialCostPartSelfTotal float64 = 0 //材料费
  7935. //
  7936. // var westernMedicineCostTotal float64 = 0 //西药费
  7937. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  7938. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7939. //
  7940. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7941. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7942. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7943. //
  7944. // var checkCostTotal float64 = 0 //检查费
  7945. // var checkCostSelfTotal float64 = 0 //检查费
  7946. // var checkCostPartSelfTotal float64 = 0 //检查费
  7947. //
  7948. // var laboratoryCostTotal float64 = 0 //化验费
  7949. // var laboratoryCostSelfTotal float64 = 0 //化验费
  7950. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7951. //
  7952. // var treatCostTotal float64 = 0 //治疗费用
  7953. // var treatCostSelfTotal float64 = 0 //治疗费用
  7954. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  7955. //
  7956. // var zhenChaCostTotal float64 = 0 //其他费用
  7957. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  7958. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7959. //
  7960. // decimal.DivisionPrecision = 2
  7961. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7962. //
  7963. // var balanceAccountsType int64
  7964. // if his.ID > 0 {
  7965. // balanceAccountsType = his.BalanceAccountsType
  7966. // } else {
  7967. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  7968. // }
  7969. // if balanceAccountsType == 2 {
  7970. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7971. // for _, item := range orderInfos_two {
  7972. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7973. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7974. // item.MedChrgitmType = "09"
  7975. // }
  7976. //
  7977. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7978. // if item.HisPrescriptionProject.Type == 2 {
  7979. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7980. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7981. // case 0:
  7982. // item.MedChrgitmType = "0"
  7983. // break
  7984. // case 1:
  7985. // item.MedChrgitmType = "14"
  7986. // break
  7987. // case 2:
  7988. // item.MedChrgitmType = "05"
  7989. //
  7990. // break
  7991. // case 3:
  7992. // item.MedChrgitmType = "03"
  7993. //
  7994. // break
  7995. // case 4:
  7996. // item.MedChrgitmType = "03"
  7997. //
  7998. // break
  7999. // case 5:
  8000. // item.MedChrgitmType = "08"
  8001. //
  8002. // break
  8003. // case 6:
  8004. // item.MedChrgitmType = "14"
  8005. //
  8006. // break
  8007. // case 7:
  8008. // item.MedChrgitmType = "14"
  8009. //
  8010. // break
  8011. // case 8:
  8012. // item.MedChrgitmType = "03"
  8013. // break
  8014. // case 9:
  8015. // item.MedChrgitmType = "14"
  8016. // break
  8017. // case 10:
  8018. // item.MedChrgitmType = "14"
  8019. // break
  8020. // case 11:
  8021. // item.MedChrgitmType = "06"
  8022. // break
  8023. // case 12:
  8024. // item.MedChrgitmType = "12"
  8025. // break
  8026. // case 13:
  8027. // item.MedChrgitmType = "01"
  8028. // break
  8029. // case 14:
  8030. // item.MedChrgitmType = "04"
  8031. // break
  8032. // case 15:
  8033. // item.MedChrgitmType = "02"
  8034. // break
  8035. //
  8036. // }
  8037. //
  8038. // } else {
  8039. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8040. //
  8041. // case 1:
  8042. // item.MedChrgitmType = "14"
  8043. // break
  8044. // case 2:
  8045. // item.MedChrgitmType = "05"
  8046. //
  8047. // break
  8048. // case 3:
  8049. // item.MedChrgitmType = "03"
  8050. //
  8051. // break
  8052. // case 4:
  8053. // item.MedChrgitmType = "03"
  8054. //
  8055. // break
  8056. // case 5:
  8057. // item.MedChrgitmType = "08"
  8058. //
  8059. // break
  8060. // case 6:
  8061. // item.MedChrgitmType = "14"
  8062. //
  8063. // break
  8064. // case 7:
  8065. // item.MedChrgitmType = "14"
  8066. //
  8067. // break
  8068. // case 8:
  8069. // item.MedChrgitmType = "03"
  8070. // break
  8071. // case 9:
  8072. // item.MedChrgitmType = "14"
  8073. // break
  8074. //
  8075. // }
  8076. //
  8077. // }
  8078. //
  8079. // } else if item.HisPrescriptionProject.Type == 3 {
  8080. // item.MedChrgitmType = "08"
  8081. // }
  8082. // }
  8083. // }
  8084. //
  8085. // for _, item := range orderInfos_two {
  8086. // fmt.Println(item.MedChrgitmType)
  8087. // if item.MedChrgitmType == "01" { //床位费
  8088. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8089. // bedCostSelfTotal = bedCostTotal
  8090. // }
  8091. //
  8092. // if item.MedChrgitmType == "02" { //诊察费
  8093. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8094. // zhenChaCostSelfTotal = zhenChaCostTotal
  8095. // }
  8096. //
  8097. // if item.MedChrgitmType == "03" { //检查费
  8098. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8099. // checkCostSelfTotal = checkCostTotal
  8100. // }
  8101. //
  8102. // if item.MedChrgitmType == "04" { //化验费
  8103. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8104. // laboratoryCostSelfTotal = laboratoryCostTotal
  8105. // }
  8106. //
  8107. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8108. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8109. // treatCostSelfTotal = treatCostTotal
  8110. // }
  8111. //
  8112. // if item.MedChrgitmType == "06" { //手术费
  8113. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8114. // operationCostSelfTotal = treatCostTotal
  8115. // }
  8116. //
  8117. // if item.MedChrgitmType == "08" { //材料费
  8118. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8119. // materialCostSelfTotal = materialCostTotal
  8120. // }
  8121. //
  8122. // if item.MedChrgitmType == "09" { //西药费
  8123. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8124. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8125. // }
  8126. //
  8127. // if item.MedChrgitmType == "11" { //中成费
  8128. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8129. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8130. // }
  8131. //
  8132. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8133. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8134. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8135. // otherCostSelfTotal = otherCostTotal
  8136. // }
  8137. // } else {
  8138. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8139. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8140. // otherCostSelfTotal = otherCostTotal
  8141. // }
  8142. //
  8143. // }
  8144. //
  8145. // }
  8146. //
  8147. // } else {
  8148. // for _, item := range orderInfos {
  8149. // if item.MedChrgitmType == "01" { //床位费
  8150. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8151. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8152. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8153. // }
  8154. //
  8155. // if item.MedChrgitmType == "02" { //诊察费
  8156. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8157. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8158. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8159. // }
  8160. //
  8161. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8162. // if item.MedChrgitmType == "03" { //检查费
  8163. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8164. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8165. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8166. //
  8167. // }
  8168. // } else {
  8169. // if item.MedChrgitmType == "03" { //检查费
  8170. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8171. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8172. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8173. // }
  8174. //
  8175. // }
  8176. //
  8177. // if item.MedChrgitmType == "04" { //化验费
  8178. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8179. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8180. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8181. //
  8182. // }
  8183. //
  8184. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8185. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8186. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8187. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8188. //
  8189. // }
  8190. //
  8191. // if item.MedChrgitmType == "06" { //手术费
  8192. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8193. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8194. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8195. // }
  8196. //
  8197. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8198. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8199. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8200. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8201. // }
  8202. //
  8203. // if item.MedChrgitmType == "09" { //西药费
  8204. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8205. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8206. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8207. // }
  8208. //
  8209. // if item.MedChrgitmType == "11" { //中成费
  8210. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8211. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8212. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8213. // }
  8214. //
  8215. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8216. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8217. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8218. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8219. // }
  8220. //
  8221. // }
  8222. // }
  8223. // timeLayout := "2006-01-02"
  8224. // loc, _ := time.LoadLocation("Local")
  8225. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8226. // if err != nil {
  8227. // }
  8228. // startRecordDateTime := startTime.Unix()
  8229. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8230. // if err != nil {
  8231. // }
  8232. // endRecordDateTime := endTime.Unix()
  8233. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8234. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8235. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8236. //
  8237. // c.ServeSuccessJSON(map[string]interface{}{
  8238. // "order_number": order.Number, //业务流水号
  8239. // "id_card_no": his.IdCardNo, //社会保障号
  8240. // "department_name": department.Name, //科室
  8241. // "number": his.Number, //门诊号
  8242. // "date": order.SettleAccountsDate, //结算日期
  8243. // "name": order.PsnName, //姓名
  8244. // "gender": patient.Gender, //性别
  8245. // "psn_cash_money": order.PsnCashPay, //个人支付
  8246. // "pay_way": "门诊", //结算方式
  8247. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8248. // "admin_user_name": admin.UserName, //收款员
  8249. // "order": order,
  8250. // "order_info": orderInfos_two,
  8251. // "his": his,
  8252. // "bedCostTotal": bedCostTotal,
  8253. // "bedCostSelfTotal": bedCostSelfTotal,
  8254. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8255. // "operationCostTotal": operationCostTotal,
  8256. // "operationCostSelfTotal": operationCostSelfTotal,
  8257. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8258. // "otherCostTotal": otherCostTotal,
  8259. // "otherCostSelfTotal": otherCostSelfTotal,
  8260. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8261. // "materialCostTotal": materialCostTotal,
  8262. // "materialCostSelfTotal": materialCostSelfTotal,
  8263. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8264. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8265. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8266. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8267. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8268. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8269. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8270. // "checkCostTotal": checkCostTotal,
  8271. // "checkCostSelfTotal": checkCostSelfTotal,
  8272. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8273. // "laboratoryCostTotal": laboratoryCostTotal,
  8274. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8275. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8276. // "treatCostTotal": treatCostTotal,
  8277. // "treatCostSelfTotal": treatCostSelfTotal,
  8278. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8279. // "zhenChaCostTotal": zhenChaCostTotal,
  8280. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8281. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8282. // "his_hospital_record": his_hospital_record,
  8283. // "pre_pay_money": pre_pay_money,
  8284. // "refund_sum": sum,
  8285. // })
  8286. //
  8287. //}
  8288. func (this *HisApiController) GetIncomeStatisticsData() {
  8289. start_time := this.GetString("start_time")
  8290. end_time := this.GetString("end_time")
  8291. key_words := this.GetString("key_words")
  8292. limit, _ := this.GetInt64("limit")
  8293. page, _ := this.GetInt64("page")
  8294. if page <= 0 {
  8295. page = 1
  8296. }
  8297. if limit <= 0 {
  8298. limit = 10
  8299. }
  8300. statistics_type, _ := this.GetInt64("statistics_type")
  8301. admin := this.GetAdminUserInfo()
  8302. timeLayout := "2006-01-02"
  8303. loc, _ := time.LoadLocation("Local")
  8304. var theStartTIme int64
  8305. if len(start_time) > 0 {
  8306. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8307. if err != nil {
  8308. theStartTIme = 0
  8309. }
  8310. theStartTIme = theTime.Unix()
  8311. }
  8312. var theEndtTIme int64
  8313. if len(end_time) > 0 {
  8314. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8315. if err != nil {
  8316. theEndtTIme = 0
  8317. }
  8318. theEndtTIme = theTime.Unix()
  8319. }
  8320. if statistics_type == 1 {
  8321. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8322. this.ServeSuccessJSON(map[string]interface{}{
  8323. "list": list,
  8324. "total": total,
  8325. })
  8326. } else {
  8327. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8328. this.ServeSuccessJSON(map[string]interface{}{
  8329. "list": list,
  8330. "total": total,
  8331. })
  8332. }
  8333. }
  8334. func (c *HisApiController) PostProjectInformation() {
  8335. adminUser := c.GetAdminUserInfo()
  8336. orgId := adminUser.CurrentOrgId
  8337. dataBody := make(map[string]interface{}, 0)
  8338. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8339. if err != nil {
  8340. utils.ErrorLog(err.Error())
  8341. return
  8342. }
  8343. utils.ErrorLog("%v", dataBody)
  8344. var projectList []*models.HisProject
  8345. var total_goods []interface{}
  8346. tempProjects := dataBody["projects"].([]interface{})
  8347. total_goods = tempProjects
  8348. for index, projectMap := range tempProjects {
  8349. projectM := projectMap.(map[string]interface{})
  8350. var project models.HisProject
  8351. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8352. utils.ErrorLog("project_name")
  8353. return
  8354. }
  8355. project_name, _ := projectM["project_name"].(string)
  8356. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8357. err_log := models.ExportErrLog{
  8358. LogType: 6,
  8359. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8360. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8361. Status: 1,
  8362. CreateTime: time.Now().Unix(),
  8363. UpdateTime: time.Now().Unix(),
  8364. ExportTime: time.Now().Unix(),
  8365. }
  8366. service.CreateExportErrLog(&err_log)
  8367. continue
  8368. }
  8369. project.ProjectName = project_name
  8370. prices := projectM["price"].(string)
  8371. price, _ := strconv.ParseFloat(prices, 64)
  8372. if price <= 0 { //名字为空则生成一条导入错误日志
  8373. err_log := models.ExportErrLog{
  8374. LogType: 6,
  8375. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8376. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8377. Status: 1,
  8378. CreateTime: time.Now().Unix(),
  8379. UpdateTime: time.Now().Unix(),
  8380. ExportTime: time.Now().Unix(),
  8381. }
  8382. service.CreateExportErrLog(&err_log)
  8383. continue
  8384. }
  8385. project.Price = price
  8386. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8387. utils.ErrorLog("unit_id")
  8388. return
  8389. }
  8390. unit := projectM["unit"].(string)
  8391. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8392. err_log := models.ExportErrLog{
  8393. LogType: 6,
  8394. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8395. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8396. Status: 1,
  8397. CreateTime: time.Now().Unix(),
  8398. UpdateTime: time.Now().Unix(),
  8399. ExportTime: time.Now().Unix(),
  8400. }
  8401. service.CreateExportErrLog(&err_log)
  8402. continue
  8403. }
  8404. project.Unit = unit
  8405. cost_classify := projectM["cost_classify"].(string)
  8406. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8407. err_log := models.ExportErrLog{
  8408. LogType: 6,
  8409. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8410. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8411. Status: 1,
  8412. CreateTime: time.Now().Unix(),
  8413. UpdateTime: time.Now().Unix(),
  8414. ExportTime: time.Now().Unix(),
  8415. }
  8416. service.CreateExportErrLog(&err_log)
  8417. continue
  8418. }
  8419. var costClassify = "费用类别"
  8420. var cost_classify_id int64
  8421. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8422. if len(cost_classify) != 0 {
  8423. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8424. if errcode == gorm.ErrRecordNotFound {
  8425. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8426. dataconfig := models.DictDataconfig{
  8427. ParentId: costClassifyConfig.ID,
  8428. Module: "system",
  8429. OrgId: orgId,
  8430. Name: cost_classify,
  8431. FieldName: "",
  8432. Value: costConfig.Value + 1,
  8433. CreatedTime: "",
  8434. UpdatedTime: "",
  8435. CreateUserId: adminUser.AdminUser.Id,
  8436. Status: 1,
  8437. Remark: "",
  8438. DeleteIdSystem: 0,
  8439. Title: "",
  8440. Content: "",
  8441. Order: 0,
  8442. Code: "",
  8443. }
  8444. service.CreatedDicConfig(&dataconfig)
  8445. }
  8446. }
  8447. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8448. for _, it := range costClassList {
  8449. if cost_classify == it.Name {
  8450. cost_classify_id = int64(it.Value)
  8451. }
  8452. }
  8453. project.CostClassify = cost_classify_id
  8454. executive_section := projectM["executive_section"].(string)
  8455. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8456. err_log := models.ExportErrLog{
  8457. LogType: 6,
  8458. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8459. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8460. Status: 1,
  8461. CreateTime: time.Now().Unix(),
  8462. UpdateTime: time.Now().Unix(),
  8463. ExportTime: time.Now().Unix(),
  8464. }
  8465. service.CreateExportErrLog(&err_log)
  8466. continue
  8467. }
  8468. if len(executive_section) != 0 {
  8469. //查找科室是否有内容
  8470. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8471. if errcodedepart == gorm.ErrRecordNotFound {
  8472. department := models.XtHisDepartment{
  8473. Name: executive_section,
  8474. Status: 1,
  8475. UserOrgId: adminUser.CurrentOrgId,
  8476. CreatedTime: time.Now().Unix(),
  8477. }
  8478. service.CreateDePartment(&department)
  8479. }
  8480. }
  8481. var executive_section_id int64
  8482. departMentList, _ := service.GetAllDepartMent(orgId)
  8483. for _, it := range departMentList {
  8484. if executive_section == it.Name {
  8485. executive_section_id = it.ID
  8486. }
  8487. }
  8488. project.ExecutiveSection = executive_section_id
  8489. medical_coverage := projectM["medical_coverage"].(string)
  8490. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8491. err_log := models.ExportErrLog{
  8492. LogType: 6,
  8493. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8494. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8495. Status: 1,
  8496. CreateTime: time.Now().Unix(),
  8497. UpdateTime: time.Now().Unix(),
  8498. ExportTime: time.Now().Unix(),
  8499. }
  8500. service.CreateExportErrLog(&err_log)
  8501. continue
  8502. }
  8503. var medicalCoverage = "医保等级"
  8504. var medical_coverage_id int64
  8505. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8506. if len(medical_coverage) != 0 {
  8507. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8508. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8509. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8510. dataconfig := models.DictDataconfig{
  8511. ParentId: medicalCoverageConfig.ID,
  8512. Module: "system",
  8513. OrgId: orgId,
  8514. Name: medical_coverage,
  8515. FieldName: "",
  8516. Value: medicalCoverageConfig.Value + 1,
  8517. CreatedTime: "",
  8518. UpdatedTime: "",
  8519. CreateUserId: adminUser.AdminUser.Id,
  8520. Status: 1,
  8521. Remark: "",
  8522. DeleteIdSystem: 0,
  8523. Title: "",
  8524. Content: "",
  8525. Order: 0,
  8526. Code: "",
  8527. }
  8528. service.CreatedDicConfig(&dataconfig)
  8529. }
  8530. }
  8531. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8532. for _, it := range medicalCoverageList {
  8533. if medical_coverage == it.Name {
  8534. medical_coverage_id = int64(it.Value)
  8535. }
  8536. }
  8537. project.MedicalCoverage = medical_coverage_id
  8538. pinyin := projectM["pinyin"].(string)
  8539. project.Pinyin = pinyin
  8540. wubi := projectM["wubi"].(string)
  8541. project.Wubi = wubi
  8542. statistical_classification := projectM["statistical_classification"].(string)
  8543. var statisticalClassification = "统计分类"
  8544. var statistical_classification_id int64
  8545. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8546. if len(statistical_classification) != 0 {
  8547. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8548. if classificationerrcodes == gorm.ErrRecordNotFound {
  8549. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8550. dataconfig := models.DictDataconfig{
  8551. ParentId: classiFication.ID,
  8552. Module: "system",
  8553. OrgId: orgId,
  8554. Name: statistical_classification,
  8555. FieldName: "",
  8556. Value: classiFicationConfig.Value + 1,
  8557. CreatedTime: "",
  8558. UpdatedTime: "",
  8559. CreateUserId: adminUser.AdminUser.Id,
  8560. Status: 1,
  8561. Remark: "",
  8562. DeleteIdSystem: 0,
  8563. Title: "",
  8564. Content: "",
  8565. Order: 0,
  8566. Code: "",
  8567. }
  8568. service.CreatedDicConfig(&dataconfig)
  8569. }
  8570. }
  8571. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8572. for _, it := range classiFicationList {
  8573. if statistical_classification == it.Name {
  8574. statistical_classification_id = int64(it.Value)
  8575. }
  8576. }
  8577. project.StatisticalClassification = statistical_classification_id
  8578. disease_directory := int64(projectM["disease_directory"].(float64))
  8579. project.DiseaseDirectory = disease_directory
  8580. is_record := int64(projectM["is_record"].(float64))
  8581. project.IsRecord = is_record
  8582. medical_code := projectM["medical_code"].(string)
  8583. project.MedicalCode = medical_code
  8584. tube_color := projectM["tube_color"].(string)
  8585. var tubeColor = "试管颜色"
  8586. var tube_color_id int64
  8587. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8588. if len(tube_color) != 0 {
  8589. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8590. if errcodetube == gorm.ErrRecordNotFound {
  8591. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8592. dataconfig := models.DictDataconfig{
  8593. ParentId: tubeColorConfig.ID,
  8594. Module: "system",
  8595. OrgId: orgId,
  8596. Name: tube_color,
  8597. FieldName: "",
  8598. Value: tubeConfig.Value + 1,
  8599. CreatedTime: "",
  8600. UpdatedTime: "",
  8601. CreateUserId: adminUser.AdminUser.Id,
  8602. Status: 1,
  8603. Remark: "",
  8604. DeleteIdSystem: 0,
  8605. Title: "",
  8606. Content: "",
  8607. Order: 0,
  8608. Code: "",
  8609. }
  8610. service.CreatedDicConfig(&dataconfig)
  8611. }
  8612. }
  8613. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8614. for _, it := range tubeColorList {
  8615. if tube_color == it.Name {
  8616. tube_color_id = int64(it.Value)
  8617. }
  8618. }
  8619. project.TubeColor = tube_color_id
  8620. single_dose := projectM["single_dose"].(string)
  8621. project.SingleDose = single_dose
  8622. execution_frequency := projectM["execution_frequency"].(string)
  8623. project.ExecutionFrequency = execution_frequency
  8624. delivery_way := projectM["delivery_way"].(string)
  8625. project.DeliveryWay = delivery_way
  8626. number_days := projectM["number_days"].(string)
  8627. project.NumberDays = number_days
  8628. total := projectM["total"].(string)
  8629. project.Total = total
  8630. medical_status := int64(projectM["medical_status"].(float64))
  8631. project.MedicalStatus = medical_status
  8632. category := int64(projectM["category"].(float64))
  8633. project.Category = category
  8634. specail_project := int64(projectM["specail_project"].(float64))
  8635. project.SpecailProject = specail_project
  8636. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8637. project.SocialSecurityDirectoryCode = social_security_directory_code
  8638. remark := projectM["remark"].(string)
  8639. project.Remark = remark
  8640. record_date := projectM["record_date"].(string)
  8641. timeLayout := "2006-01-02"
  8642. loc, _ := time.LoadLocation("Local")
  8643. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8644. project.RecordDate = theTime.Unix()
  8645. projectList = append(projectList, &project)
  8646. }
  8647. export_time := time.Now().Unix()
  8648. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8649. if len(projectList) > 0 {
  8650. for _, item := range projectList {
  8651. project := models.HisProject{
  8652. ProjectName: item.ProjectName,
  8653. Price: item.Price,
  8654. Unit: item.Unit,
  8655. CostClassify: item.CostClassify,
  8656. ExecutiveSection: item.ExecutiveSection,
  8657. MedicalCoverage: item.MedicalCoverage,
  8658. UserOrgId: orgId,
  8659. Status: 1,
  8660. CreatedTime: time.Now().Unix(),
  8661. Pinyin: item.Pinyin,
  8662. Wubi: item.Wubi,
  8663. StatisticalClassification: item.StatisticalClassification,
  8664. DiseaseDirectory: item.DiseaseDirectory,
  8665. IsRecord: item.IsRecord,
  8666. MedicalCode: item.MedicalCode,
  8667. TubeColor: item.TubeColor,
  8668. SingleDose: item.SingleDose,
  8669. DeliveryWay: item.DeliveryWay,
  8670. NumberDays: item.NumberDays,
  8671. Total: item.Total,
  8672. Category: item.Category,
  8673. MedicalStatus: item.MedicalStatus,
  8674. SpecailProject: item.SpecailProject,
  8675. RecordDate: item.RecordDate,
  8676. Remark: item.Remark,
  8677. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8678. ExecutionFrequency: item.ExecutionFrequency,
  8679. }
  8680. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8681. if errcodeproject == gorm.ErrRecordNotFound {
  8682. service.CreateProjectInfomation(&project)
  8683. } else if errcodeproject == nil {
  8684. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8685. }
  8686. log := models.ExportLog{
  8687. LogType: 6,
  8688. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8689. TotalNum: int64(len(total_goods)),
  8690. FailNum: int64(len(errLogs)),
  8691. SuccessNum: int64(len(projectList)),
  8692. CreateTime: time.Now().Unix(),
  8693. UpdateTime: time.Now().Unix(),
  8694. ExportTime: export_time,
  8695. Status: 1,
  8696. }
  8697. service.CreateExportLog(&log)
  8698. c.ServeSuccessJSON(map[string]interface{}{
  8699. "msg": "导入成功",
  8700. "total_num": len(total_goods),
  8701. "success_num": len(projectList),
  8702. "fail_num": int64(len(errLogs)),
  8703. })
  8704. }
  8705. } else {
  8706. log := models.ExportLog{
  8707. LogType: 6,
  8708. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8709. TotalNum: int64(len(total_goods)),
  8710. FailNum: int64(len(errLogs)),
  8711. SuccessNum: int64(len(projectList)),
  8712. CreateTime: time.Now().Unix(),
  8713. UpdateTime: time.Now().Unix(),
  8714. ExportTime: export_time,
  8715. Status: 1,
  8716. }
  8717. service.CreateExportLog(&log)
  8718. c.ServeSuccessJSON(map[string]interface{}{
  8719. "msg": "导入成功",
  8720. "total_num": len(total_goods),
  8721. "success_num": len(projectList),
  8722. "fail_num": int64(len(errLogs)),
  8723. })
  8724. }
  8725. }
  8726. //func (this *HisApiController) EditProjectInformation(){
  8727. //
  8728. // id, _ := this.GetInt64("id")
  8729. // project_team := this.GetString("project_team")
  8730. // price := this.GetString("price")
  8731. // price_float, _ := strconv.ParseFloat(price, 64)
  8732. // pinyin := this.GetString("pinyin")
  8733. // wubi := this.GetString("wubi")
  8734. // tube_color, _ := this.GetInt64("tube_color")
  8735. // team_type, _ := this.GetInt64("team_type")
  8736. // remark := this.GetString("remark")
  8737. // ids := this.GetString("ids")
  8738. // item_id := this.GetString("item_id")
  8739. // projectTeam := models.XtHisProjectTeam{
  8740. // ProjectTeam: project_team,
  8741. // Price: price_float,
  8742. // Pinyin: pinyin,
  8743. // Wubi: wubi,
  8744. // TubeColor: tube_color,
  8745. // TeamType: team_type,
  8746. // Remark: remark,
  8747. // ProjectId: ids,
  8748. // ItemId: item_id,
  8749. // }
  8750. //
  8751. //
  8752. // dataBody := make(map[string]interface{}, 0)
  8753. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8754. // if err != nil {
  8755. // utils.ErrorLog(err.Error())
  8756. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8757. // return
  8758. // }
  8759. //
  8760. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8761. //
  8762. //
  8763. // if err != nil {
  8764. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8765. // return
  8766. // }
  8767. //
  8768. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8769. // infos, _ := dataBody["info"].([]interface{})
  8770. // if len(infos) > 0 {
  8771. // var ids []string
  8772. //
  8773. // for _, item := range infos {
  8774. // items := item.(map[string]interface{})
  8775. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8776. // utils.ErrorLog("id")
  8777. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8778. // return
  8779. // }
  8780. // id := int64(items["id"].(float64))
  8781. //
  8782. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8783. // utils.ErrorLog("type")
  8784. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8785. // return
  8786. // }
  8787. // types := int64(items["type"].(float64))
  8788. //
  8789. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8790. // utils.ErrorLog("number")
  8791. // }
  8792. //
  8793. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8794. //
  8795. // projectList := models.XtHisProjectList{
  8796. // Number: number,
  8797. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8798. // ProjectId: id,
  8799. // Status: 1,
  8800. // CreatedTime: time.Now().Unix(),
  8801. // UpdatedTime: time.Now().Unix(),
  8802. // TeamId: projectTeam.ID,
  8803. // Type: types,
  8804. // }
  8805. // list := projectList
  8806. //
  8807. // service.CreateProjectList(&list)
  8808. //
  8809. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8810. //
  8811. // }
  8812. // ids_str := strings.Join(ids, ",")
  8813. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8814. // service.SaveProjectTeam(&projectTeam)
  8815. // this.ServeSuccessJSON(map[string]interface{}{
  8816. // "projectTeam": projectTeam,
  8817. // })
  8818. // }
  8819. // }
  8820. //}
  8821. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8822. name := c.GetString("name")
  8823. mode_id, _ := c.GetInt64("mode", 0)
  8824. types, _ := c.GetInt64("type", 0)
  8825. patient_id, _ := c.GetInt64("patient_id", 0)
  8826. types = 1
  8827. adminInfo := c.GetAdminUserInfo()
  8828. template := &models.HisPrescriptionTemplate{
  8829. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8830. PatientId: patient_id,
  8831. Type: types,
  8832. Status: 1,
  8833. Ctime: time.Now().Unix(),
  8834. Mtime: time.Now().Unix(),
  8835. Name: name,
  8836. Mode: mode_id,
  8837. }
  8838. dataBody := make(map[string]interface{}, 0)
  8839. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8840. if err != nil {
  8841. utils.ErrorLog(err.Error())
  8842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8843. return
  8844. }
  8845. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8846. //如果已经存在记录则删除处方
  8847. if template_one.ID > 0 {
  8848. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8849. for _, item := range ps {
  8850. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8851. }
  8852. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8853. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8854. if len(prescriptions) > 0 {
  8855. for _, item := range prescriptions {
  8856. items := item.(map[string]interface{})
  8857. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8858. utils.ErrorLog("type")
  8859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8860. return
  8861. }
  8862. types := int64(items["type"].(float64))
  8863. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8864. utils.ErrorLog("med_type")
  8865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8866. return
  8867. }
  8868. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8869. ctime := time.Now().Unix()
  8870. prescription := &models.HisPrescriptionInfoTemplate{
  8871. PatientId: patient_id,
  8872. UserOrgId: adminInfo.CurrentOrgId,
  8873. Ctime: ctime,
  8874. Mtime: ctime,
  8875. Type: types,
  8876. Modifier: adminInfo.AdminUser.Id,
  8877. Creator: adminInfo.AdminUser.Id,
  8878. Status: 1,
  8879. PTemplateId: template_one.ID,
  8880. MedType: med_type,
  8881. }
  8882. service.CreateHisPrescriptionInfoTemplate(prescription)
  8883. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8884. advices := items["advices"].([]interface{})
  8885. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8886. ctime := time.Now().Unix()
  8887. mtime := ctime
  8888. if len(advices) > 0 {
  8889. for _, advice := range advices {
  8890. var s models.HisPrescriptionAdviceTemplate
  8891. s.PrescriptionId = prescription.ID
  8892. s.AdviceType = 2
  8893. s.StopState = 2
  8894. s.ExecutionState = 2
  8895. s.Status = 1
  8896. s.UserOrgId = adminInfo.CurrentOrgId
  8897. s.CreatedTime = ctime
  8898. s.UpdatedTime = mtime
  8899. s.PatientId = patient_id
  8900. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8901. if errcode > 0 {
  8902. c.ServeFailJSONWithSGJErrorCode(errcode)
  8903. return
  8904. }
  8905. service.CreateHisPrescriptionAdviceTemplate(&s)
  8906. }
  8907. }
  8908. }
  8909. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8910. projects := items["project"].([]interface{})
  8911. if len(projects) > 0 {
  8912. for _, project := range projects {
  8913. var p models.HisPrescriptionProjectTemplate
  8914. p.PrescriptionId = prescription.ID
  8915. p.Ctime = time.Now().Unix()
  8916. p.Mtime = time.Now().Unix()
  8917. p.PatientId = patient_id
  8918. p.UserOrgId = adminInfo.CurrentOrgId
  8919. p.Status = 1
  8920. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8921. if errcode > 0 {
  8922. c.ServeFailJSONWithSGJErrorCode(errcode)
  8923. return
  8924. }
  8925. service.CreateHisPrescriptionProjectTemplate(&p)
  8926. }
  8927. }
  8928. }
  8929. }
  8930. c.ServeSuccessJSON(map[string]interface{}{
  8931. "msg": "创建成功",
  8932. })
  8933. }
  8934. }
  8935. } else {
  8936. err = service.CreateHisPrescriptionTemplate(template)
  8937. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8938. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8939. if len(prescriptions) > 0 {
  8940. for _, item := range prescriptions {
  8941. items := item.(map[string]interface{})
  8942. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8943. utils.ErrorLog("type")
  8944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8945. return
  8946. }
  8947. types := int64(items["type"].(float64))
  8948. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8949. utils.ErrorLog("med_type")
  8950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8951. return
  8952. }
  8953. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8954. ctime := time.Now().Unix()
  8955. prescription := &models.HisPrescriptionInfoTemplate{
  8956. PatientId: patient_id,
  8957. UserOrgId: adminInfo.CurrentOrgId,
  8958. Ctime: ctime,
  8959. Mtime: ctime,
  8960. Type: types,
  8961. Modifier: adminInfo.AdminUser.Id,
  8962. Creator: adminInfo.AdminUser.Id,
  8963. Status: 1,
  8964. PTemplateId: template.ID,
  8965. MedType: med_type,
  8966. }
  8967. service.CreateHisPrescriptionInfoTemplate(prescription)
  8968. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8969. advices := items["advices"].([]interface{})
  8970. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8971. ctime := time.Now().Unix()
  8972. mtime := ctime
  8973. if len(advices) > 0 {
  8974. for _, advice := range advices {
  8975. var s models.HisPrescriptionAdviceTemplate
  8976. s.PrescriptionId = prescription.ID
  8977. s.AdviceType = 2
  8978. s.StopState = 2
  8979. s.ExecutionState = 2
  8980. s.Status = 1
  8981. s.UserOrgId = adminInfo.CurrentOrgId
  8982. s.CreatedTime = ctime
  8983. s.UpdatedTime = mtime
  8984. s.PatientId = patient_id
  8985. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8986. if errcode > 0 {
  8987. c.ServeFailJSONWithSGJErrorCode(errcode)
  8988. return
  8989. }
  8990. service.CreateHisPrescriptionAdviceTemplate(&s)
  8991. }
  8992. }
  8993. }
  8994. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8995. projects := items["project"].([]interface{})
  8996. if len(projects) > 0 {
  8997. for _, project := range projects {
  8998. var p models.HisPrescriptionProjectTemplate
  8999. p.PrescriptionId = prescription.ID
  9000. p.Ctime = time.Now().Unix()
  9001. p.Mtime = time.Now().Unix()
  9002. p.PatientId = patient_id
  9003. p.UserOrgId = adminInfo.CurrentOrgId
  9004. p.Status = 1
  9005. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9006. if errcode > 0 {
  9007. c.ServeFailJSONWithSGJErrorCode(errcode)
  9008. return
  9009. }
  9010. service.CreateHisPrescriptionProjectTemplate(&p)
  9011. }
  9012. }
  9013. }
  9014. }
  9015. c.ServeSuccessJSON(map[string]interface{}{
  9016. "msg": "创建成功",
  9017. })
  9018. }
  9019. }
  9020. }
  9021. }
  9022. func (c *HisApiController) PreSettle() {
  9023. id, _ := c.GetInt64("id")
  9024. record_time := c.GetString("record_time")
  9025. his_patient_id, _ := c.GetInt64("his_patient_id")
  9026. timeLayout := "2006-01-02"
  9027. loc, _ := time.LoadLocation("Local")
  9028. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9029. diagnosis_id := c.GetString("diagnosis")
  9030. sick_type, _ := c.GetInt64("sick_type")
  9031. reg_type, _ := c.GetInt64("p_type")
  9032. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9033. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9034. if err != nil {
  9035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9036. return
  9037. }
  9038. recordDateTime := theTime.Unix()
  9039. adminUser := c.GetAdminUserInfo()
  9040. var prescriptions []*models.HisPrescription
  9041. var start_time int64
  9042. var end_time int64
  9043. ids_str := c.GetString("ids")
  9044. ids_arr := strings.Split(ids_str, ",")
  9045. fmt.Println(reg_type)
  9046. if settle_accounts_type == 1 { //日结
  9047. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9048. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9049. } else {
  9050. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9051. }
  9052. fmt.Println(prescriptions)
  9053. } else { //月结
  9054. start_time_str := c.GetString("start_time")
  9055. end_time_str := c.GetString("end_time")
  9056. timeLayout := "2006-01-02"
  9057. loc, _ := time.LoadLocation("Local")
  9058. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9059. if err != nil {
  9060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9061. return
  9062. }
  9063. recordStartTime := theStartTime.Unix()
  9064. start_time = recordStartTime
  9065. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9066. if err != nil {
  9067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9068. return
  9069. }
  9070. recordEndTime := theEndTime.Unix()
  9071. end_time = recordEndTime
  9072. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9073. }
  9074. if reg_type == 1111 || reg_type == 1112 {
  9075. reg_type = 11
  9076. }
  9077. timestamp := time.Now().Unix()
  9078. tempTime := time.Unix(timestamp, 0)
  9079. timeFormat := tempTime.Format("20060102150405")
  9080. chrgBchno := rand.Intn(100000) + 10000
  9081. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9082. strconv.FormatInt(his.PatientId, 10)
  9083. var ids []int64
  9084. for _, item := range prescriptions {
  9085. ids = append(ids, item.ID)
  9086. }
  9087. fmt.Println(ids)
  9088. var total float64
  9089. for _, item := range prescriptions {
  9090. fmt.Println(item)
  9091. if item.Type == 1 { //药品
  9092. for _, subItem := range item.HisDoctorAdviceInfo {
  9093. total = total + (subItem.Price * subItem.PrescribingNumber)
  9094. }
  9095. }
  9096. if item.Type == 2 { //项目
  9097. for _, subItem := range item.HisPrescriptionProject {
  9098. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9099. total = total + (subItem.Price * cnt)
  9100. }
  9101. }
  9102. for _, subItem := range item.HisAdditionalCharge {
  9103. total = total + (subItem.Price * float64(subItem.Count))
  9104. }
  9105. }
  9106. allTotal := fmt.Sprintf("%.2f", total)
  9107. totals, _ := strconv.ParseFloat(allTotal, 64)
  9108. order := &models.HisOrder{
  9109. UserOrgId: adminUser.CurrentOrgId,
  9110. HisPatientId: his.ID,
  9111. PatientId: id,
  9112. SettleAccountsDate: recordDateTime,
  9113. Ctime: time.Now().Unix(),
  9114. Mtime: time.Now().Unix(),
  9115. Status: 1,
  9116. OrderStatus: 1,
  9117. MdtrtId: his.Number,
  9118. Number: chrg_bchno,
  9119. MedfeeSumamt: totals,
  9120. SettleEndTime: end_time,
  9121. SettleStartTime: start_time,
  9122. SettleType: settle_accounts_type,
  9123. PsnPartAmt: totals,
  9124. PsnCashPay: totals,
  9125. PType: 2,
  9126. IsPre: 1,
  9127. MedType: strconv.Itoa(int(reg_type)),
  9128. Diagnosis: diagnosis_id,
  9129. }
  9130. err = service.CreateOrder(order)
  9131. if err != nil {
  9132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9133. return
  9134. }
  9135. var customs []*Custom
  9136. for _, item := range prescriptions {
  9137. fmt.Println(item.Type)
  9138. if item.Type == 1 { //药品
  9139. for _, subItem := range item.HisDoctorAdviceInfo {
  9140. cus := &Custom{
  9141. AdviceId: subItem.ID,
  9142. ProjectId: 0,
  9143. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9144. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9145. FeedetlSn: subItem.FeedetlSn,
  9146. Price: fmt.Sprintf("%.2f", subItem.Price),
  9147. MedListCodg: subItem.MedListCodg,
  9148. Type: 1,
  9149. }
  9150. customs = append(customs, cus)
  9151. }
  9152. }
  9153. if item.Type == 2 { //项目
  9154. for _, subItem := range item.HisPrescriptionProject {
  9155. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9156. cus := &Custom{
  9157. AdviceId: 0,
  9158. ProjectId: subItem.ID,
  9159. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9160. Cut: fmt.Sprintf("%.2f", cnt),
  9161. FeedetlSn: subItem.FeedetlSn,
  9162. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9163. MedListCodg: subItem.MedListCodg,
  9164. Type: 2,
  9165. }
  9166. customs = append(customs, cus)
  9167. }
  9168. }
  9169. for _, item := range item.HisAdditionalCharge {
  9170. cus := &Custom{
  9171. ItemId: item.ID,
  9172. AdviceId: 0,
  9173. ProjectId: 0,
  9174. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9175. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9176. FeedetlSn: item.FeedetlSn,
  9177. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9178. MedListCodg: item.XtHisAddtionConfig.Code,
  9179. Type: 3,
  9180. }
  9181. customs = append(customs, cus)
  9182. }
  9183. }
  9184. fmt.Println(customs)
  9185. for _, item := range customs {
  9186. var advice_id int64 = 0
  9187. var project_id int64 = 0
  9188. var item_id int64 = 0
  9189. var types int64 = 0
  9190. if item.Type == 1 {
  9191. advice_id = item.AdviceId
  9192. project_id = 0
  9193. item_id = 0
  9194. } else if item.Type == 2 {
  9195. advice_id = 0
  9196. item_id = 0
  9197. project_id = item.ProjectId
  9198. } else if item.Type == 3 {
  9199. advice_id = 0
  9200. item_id = item.ItemId
  9201. project_id = 0
  9202. }
  9203. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9204. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9205. pric, _ := strconv.ParseFloat(item.Price, 32)
  9206. info := &models.HisOrderInfo{
  9207. OrderNumber: order.Number,
  9208. UploadDate: time.Now().Unix(),
  9209. AdviceId: advice_id,
  9210. DetItemFeeSumamt: detItemFeeSumamt,
  9211. Cnt: cut,
  9212. Pric: pric,
  9213. PatientId: id,
  9214. Status: 1,
  9215. Mtime: time.Now().Unix(),
  9216. Ctime: time.Now().Unix(),
  9217. UserOrgId: adminUser.CurrentOrgId,
  9218. HisPatientId: his.ID,
  9219. OrderId: order.ID,
  9220. ProjectId: project_id,
  9221. Type: types,
  9222. ItemId: item_id,
  9223. }
  9224. service.CreateOrderInfo(info)
  9225. }
  9226. his.SickType = sick_type
  9227. service.UpdataHisPateint(&his)
  9228. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9229. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9230. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9231. if err == nil {
  9232. c.ServeSuccessJSON(map[string]interface{}{
  9233. "msg": "结算成功",
  9234. })
  9235. }
  9236. }
  9237. type CustomOrderInfo struct {
  9238. Name string
  9239. Spec string
  9240. Unit string
  9241. Count float64
  9242. Price float64
  9243. Total float64
  9244. }
  9245. func (c *HisApiController) GetPrivateExpensesInfo() {
  9246. order_id, _ := c.GetInt64("id", 0)
  9247. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9248. order, _ := service.GetHisOrderByID(order_id)
  9249. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9250. if order.ID == 0 {
  9251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9252. return
  9253. }
  9254. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9255. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9256. org_id := c.GetAdminUserInfo().CurrentOrgId
  9257. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9258. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9259. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9260. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9261. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9262. //var orderInfos_four []*models.HisOrderInfoTwo
  9263. //for _, item := range orderInfos_three {
  9264. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9265. // item.HisPrescriptionProject.IsCheckTeam = 1
  9266. // orderInfos_four = append(orderInfos_four, item)
  9267. //
  9268. // }
  9269. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9270. // item.HisPrescriptionProject.IsCheckTeam = 2
  9271. // orderInfos_two = append(orderInfos_two, item)
  9272. // }
  9273. //}
  9274. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9275. //var cus_slice []CustomOrderInfo
  9276. //for _, item := range new_order_info {
  9277. // var cus CustomOrderInfo
  9278. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9279. // cus.Unit = ""
  9280. // cus.Spec = ""
  9281. // var total float64
  9282. // for _, subItem := range orderInfos_four {
  9283. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9284. // total = total + subItem.DetItemFeeSumamt
  9285. // fmt.Println(subItem.DetItemFeeSumamt)
  9286. // }
  9287. // }
  9288. // cus.Count = 1
  9289. // cus.Total = total
  9290. // cus_slice = append(cus_slice, cus)
  9291. //}
  9292. orderInfos = append(orderInfos, orderInfos_two...)
  9293. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9294. //orderInfos = append(orderInfos, orderInfos_three...)
  9295. //}/**/
  9296. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9297. c.ServeSuccessJSON(map[string]interface{}{
  9298. "order": order,
  9299. "order_info": orderInfos,
  9300. "patient": patient,
  9301. "admin_info": adminInfo,
  9302. "his": his,
  9303. "current_admin": role,
  9304. "org_config": miConfig,
  9305. //"new_order_info": cus_slice,
  9306. })
  9307. }
  9308. func (this *HisApiController) ChangeMedType() {
  9309. med_type := this.GetString("med_type")
  9310. old_med_type := this.GetString("old_med_type")
  9311. ids := this.GetString("ids")
  9312. settle_type, _ := this.GetInt64("settle_type")
  9313. start_time := this.GetString("start_time")
  9314. end_time := this.GetString("end_time")
  9315. ids_arr := strings.Split(ids, ",")
  9316. if settle_type == 1 { //日结
  9317. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9318. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9319. prescription.MedType = med_type
  9320. err := service.SaveHisPrescription(&prescription)
  9321. if err == nil {
  9322. this.ServeSuccessJSON(map[string]interface{}{
  9323. "msg": "修改成功",
  9324. })
  9325. } else {
  9326. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9327. return
  9328. }
  9329. } else if settle_type == 2 {
  9330. timeLayout := "2006-01-02"
  9331. loc, _ := time.LoadLocation("Local")
  9332. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9333. if err != nil {
  9334. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9335. return
  9336. }
  9337. recordStartTime := theStartTime.Unix()
  9338. start_time_timestamp := recordStartTime
  9339. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9340. if err != nil {
  9341. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9342. return
  9343. }
  9344. recordEndTime := theEndTime.Unix()
  9345. end_time_timestamp := recordEndTime
  9346. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9347. if updateErr == nil {
  9348. this.ServeSuccessJSON(map[string]interface{}{
  9349. "msg": "修改成功",
  9350. })
  9351. } else {
  9352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9353. return
  9354. }
  9355. }
  9356. }
  9357. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9358. patient_id, _ := c.GetInt64("patient_id")
  9359. his_patient_id, _ := c.GetInt64("his_patient_id")
  9360. record_date := c.GetString("record_date")
  9361. start_time := c.GetString("start_time")
  9362. end_time := c.GetString("end_time")
  9363. order_status, _ := c.GetInt64("type", 0)
  9364. p_type, _ := c.GetInt64("p_type", 0)
  9365. order_id, _ := c.GetInt64("order_id", 0)
  9366. timeLayout := "2006-01-02"
  9367. loc, _ := time.LoadLocation("Local")
  9368. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9369. if err != nil {
  9370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9371. return
  9372. }
  9373. recordDateTime := theTime.Unix()
  9374. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9375. if err != nil {
  9376. }
  9377. startRecordDateTime := startTime.Unix()
  9378. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9379. if err != nil {
  9380. }
  9381. endRecordDateTime := endTime.Unix()
  9382. admin := c.GetAdminUserInfo()
  9383. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9384. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9385. order, _ := service.GetHisOrderByID(order_id)
  9386. var monthPrescriptions []*models.HisPrescription
  9387. if order_status == 1 || order_status == 0 {
  9388. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9389. } else if order_status == 2 {
  9390. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9391. }
  9392. var settle_total float64
  9393. for _, item := range monthPrescriptions {
  9394. if len(item.HisPrescriptionProject) > 0 {
  9395. for _, subItem := range item.HisPrescriptionProject {
  9396. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9397. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9398. settle_total = settle_total + total
  9399. }
  9400. }
  9401. if len(item.HisDoctorAdviceInfo) > 0 {
  9402. for _, subItem := range item.HisDoctorAdviceInfo {
  9403. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9404. settle_total = settle_total + total
  9405. }
  9406. }
  9407. }
  9408. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9409. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9410. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9411. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9412. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9413. //获取所有科室信息
  9414. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9415. c.ServeSuccessJSON(map[string]interface{}{
  9416. "his_info": his_patient_info,
  9417. "xt_info": xt_patient_info,
  9418. "case_history": case_history,
  9419. "info": patientPrescriptionInfo,
  9420. "last_info": lastPatientPrescriptionInfo,
  9421. "month_prescriptions": monthPrescriptions,
  9422. "order": order,
  9423. "doctors": doctors,
  9424. "department": department,
  9425. "settle_total": settle_total,
  9426. })
  9427. return
  9428. }
  9429. func (c *HisApiController) GetHisMonthPatientInfo() {
  9430. patient_id, _ := c.GetInt64("patient_id")
  9431. his_patient_id, _ := c.GetInt64("his_patient_id")
  9432. record_date := c.GetString("record_date")
  9433. number := c.GetString("number")
  9434. start_time := c.GetString("start_time")
  9435. end_time := c.GetString("end_time")
  9436. p_type, _ := c.GetInt64("p_type")
  9437. timeLayout := "2006-01-02"
  9438. loc, _ := time.LoadLocation("Local")
  9439. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9440. if err != nil {
  9441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9442. return
  9443. }
  9444. recordDateTime := theTime.Unix()
  9445. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9446. if err != nil {
  9447. }
  9448. startRecordDateTime := startTime.Unix()
  9449. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9450. if err != nil {
  9451. }
  9452. endRecordDateTime := endTime.Unix()
  9453. admin := c.GetAdminUserInfo()
  9454. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9455. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9456. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9457. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9458. var settle_total float64
  9459. for _, item := range monthPrescriptions {
  9460. if len(item.HisPrescriptionProject) > 0 {
  9461. for _, subItem := range item.HisPrescriptionProject {
  9462. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9463. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9464. settle_total = settle_total + total
  9465. }
  9466. }
  9467. if len(item.HisDoctorAdviceInfo) > 0 {
  9468. for _, subItem := range item.HisDoctorAdviceInfo {
  9469. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9470. settle_total = settle_total + total
  9471. }
  9472. }
  9473. }
  9474. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9475. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9476. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9477. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9478. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9479. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9480. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9481. //获取所有科室信息
  9482. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9483. c.ServeSuccessJSON(map[string]interface{}{
  9484. "his_info": his_patient_info,
  9485. "xt_info": xt_patient_info,
  9486. "case_history": case_history,
  9487. "info": patientPrescriptionInfo,
  9488. "month_prescriptions": monthPrescriptions,
  9489. "order": order,
  9490. "doctors": doctors,
  9491. "department": department,
  9492. "count": count,
  9493. "drugStockConfig": drugStockConfig,
  9494. "last_info": lastPatientPrescriptionInfo,
  9495. "settle_total": settle_total,
  9496. })
  9497. return
  9498. }
  9499. func (c *HisApiController) GetAllOrder() {
  9500. org_id := c.GetAdminUserInfo().CurrentOrgId
  9501. orders, _ := service.GetNewHisOrderList(org_id)
  9502. c.ServeSuccessJSON(map[string]interface{}{
  9503. "order": orders,
  9504. })
  9505. return
  9506. }
  9507. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9508. newArr = make([]*models.HisOrderInfoTwo, 0)
  9509. for i := 0; i < len(arr); i++ {
  9510. repeat := false
  9511. for j := i + 1; j < len(arr); j++ {
  9512. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9513. repeat = true
  9514. break
  9515. }
  9516. }
  9517. if !repeat {
  9518. newArr = append(newArr, arr[i])
  9519. }
  9520. }
  9521. return
  9522. }
  9523. // 修改处方退库操作 参数传修改之前的处方数据
  9524. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9525. if advice.ExecutionState == 1 {
  9526. //查询该病人该药品是否有库存记录
  9527. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9528. if errcode == gorm.ErrRecordNotFound {
  9529. } else {
  9530. //退库
  9531. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9532. if advice.PrescribingNumberUnit == drug.MinUnit {
  9533. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9534. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9535. //退库
  9536. warehouseInfo := models.DrugWarehouseInfo{
  9537. StockMinNumber: prescribingNumber,
  9538. }
  9539. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9540. operation_time := time.Now().Unix()
  9541. creater := advice.AdviceDoctor
  9542. ctime := time.Now().Unix()
  9543. timeStr := time.Now().Format("2006-01-02")
  9544. timeArr := strings.Split(timeStr, "-")
  9545. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9546. total = total + 1
  9547. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9548. cancelStock := models.DrugCancelStock{
  9549. OrderNumber: orderNumber,
  9550. OperaTime: operation_time,
  9551. OrgId: advice.UserOrgId,
  9552. Creater: creater,
  9553. Ctime: ctime,
  9554. Status: 1,
  9555. ReturnTime: advice.AdviceDate,
  9556. Dealer: info.Dealer,
  9557. Manufacturer: info.Manufacturer,
  9558. Type: 1,
  9559. }
  9560. service.AddSigleDrugCancelStock(&cancelStock)
  9561. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9562. dealer, _ := service.GetDealerById(info.Dealer)
  9563. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9564. cancelStockInfo := models.DrugCancelStockInfo{
  9565. OrderNumber: cancelInfo.OrderNumber,
  9566. CancelStockId: cancelInfo.ID,
  9567. DrugId: info.DrugId,
  9568. Count: info.Count,
  9569. Status: 1,
  9570. Ctime: ctime,
  9571. OrgId: advice.UserOrgId,
  9572. Type: 1,
  9573. Manufacturer: manufactureName.ManufacturerName,
  9574. Dealer: dealer.DealerName,
  9575. Total: 0,
  9576. RetailPrice: info.RetailPrice,
  9577. RetailTotalPrice: info.RetailTotalPrice,
  9578. Price: info.Price,
  9579. RegisterAccount: "",
  9580. Remark: info.Remark,
  9581. BatchNumber: info.BatchNumber,
  9582. MaxUnit: info.CountUnit,
  9583. ProductDate: info.ProductDate,
  9584. ExpiryDate: info.ExpiryDate,
  9585. BatchNumberId: info.WarehouseInfoId,
  9586. }
  9587. flow := models.DrugFlow{
  9588. WarehousingId: 0,
  9589. DrugId: info.DrugId,
  9590. Number: "",
  9591. BatchNumber: info.BatchNumber,
  9592. Count: info.Count,
  9593. UserOrgId: advice.UserOrgId,
  9594. PatientId: 0,
  9595. SystemTime: ctime,
  9596. ConsumableType: 4,
  9597. IsSys: 0,
  9598. WarehousingOrder: "",
  9599. WarehouseOutId: 0,
  9600. WarehouseOutOrderNumber: "",
  9601. IsEdit: 0,
  9602. CancelStockId: cancelStock.ID,
  9603. CancelOrderNumber: cancelStock.OrderNumber,
  9604. Manufacturer: info.Manufacturer,
  9605. Dealer: info.Dealer,
  9606. Creator: advice.UserOrgId,
  9607. UpdateCreator: 0,
  9608. Status: 1,
  9609. Ctime: time.Now().Unix(),
  9610. Mtime: 0,
  9611. Price: info.Price,
  9612. WarehousingDetailId: 0,
  9613. WarehouseOutDetailId: 0,
  9614. CancelOutDetailId: 0,
  9615. ExpireDate: info.ExpiryDate,
  9616. ProductDate: info.ProductDate,
  9617. MaxUnit: info.CountUnit,
  9618. MinUnit: "",
  9619. }
  9620. service.CreatedCancelStock(cancelStockInfo)
  9621. service.CreateDrugFlowOne(flow)
  9622. } else {
  9623. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9624. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9625. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9626. warehouseInfo := models.DrugWarehouseInfo{
  9627. StockMinNumber: prescribingNumber,
  9628. }
  9629. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9630. }
  9631. operation_time := time.Now().Unix()
  9632. creater := advice.AdviceDoctor
  9633. ctime := time.Now().Unix()
  9634. timeStr := time.Now().Format("2006-01-02")
  9635. timeArr := strings.Split(timeStr, "-")
  9636. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9637. total = total + 1
  9638. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9639. cancelStock := models.DrugCancelStock{
  9640. OrderNumber: orderNumber,
  9641. OperaTime: operation_time,
  9642. OrgId: advice.UserOrgId,
  9643. Creater: creater,
  9644. Ctime: ctime,
  9645. Status: 1,
  9646. ReturnTime: advice.AdviceDate,
  9647. Dealer: info.Dealer,
  9648. Manufacturer: info.Manufacturer,
  9649. Type: 1,
  9650. }
  9651. service.AddSigleDrugCancelStock(&cancelStock)
  9652. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9653. dealer, _ := service.GetDealerById(info.Dealer)
  9654. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9655. cancelStockInfo := models.DrugCancelStockInfo{
  9656. OrderNumber: cancelInfo.OrderNumber,
  9657. CancelStockId: cancelInfo.ID,
  9658. DrugId: info.DrugId,
  9659. Count: info.Count,
  9660. Status: 1,
  9661. Ctime: ctime,
  9662. OrgId: advice.UserOrgId,
  9663. Type: 1,
  9664. Manufacturer: manufactureName.ManufacturerName,
  9665. Dealer: dealer.DealerName,
  9666. Total: 0,
  9667. RetailPrice: info.RetailPrice,
  9668. RetailTotalPrice: info.RetailTotalPrice,
  9669. Price: info.Price,
  9670. RegisterAccount: "",
  9671. Remark: info.Remark,
  9672. BatchNumber: info.BatchNumber,
  9673. MaxUnit: info.CountUnit,
  9674. ProductDate: info.ProductDate,
  9675. ExpiryDate: info.ExpiryDate,
  9676. BatchNumberId: info.WarehouseInfoId,
  9677. }
  9678. flow := models.DrugFlow{
  9679. WarehousingId: 0,
  9680. DrugId: info.DrugId,
  9681. Number: "",
  9682. BatchNumber: info.BatchNumber,
  9683. Count: info.Count,
  9684. UserOrgId: advice.UserOrgId,
  9685. PatientId: 0,
  9686. SystemTime: ctime,
  9687. ConsumableType: 4,
  9688. IsSys: 0,
  9689. WarehousingOrder: "",
  9690. WarehouseOutId: 0,
  9691. WarehouseOutOrderNumber: "",
  9692. IsEdit: 0,
  9693. CancelStockId: cancelStock.ID,
  9694. CancelOrderNumber: cancelStock.OrderNumber,
  9695. Manufacturer: info.Manufacturer,
  9696. Dealer: info.Dealer,
  9697. Creator: advice.AdviceDoctor,
  9698. UpdateCreator: 0,
  9699. Status: 1,
  9700. Ctime: time.Now().Unix(),
  9701. Mtime: 0,
  9702. Price: info.Price,
  9703. WarehousingDetailId: 0,
  9704. WarehouseOutDetailId: 0,
  9705. CancelOutDetailId: 0,
  9706. ExpireDate: info.ExpiryDate,
  9707. ProductDate: info.ProductDate,
  9708. MaxUnit: info.CountUnit,
  9709. MinUnit: "",
  9710. }
  9711. service.CreatedCancelStock(cancelStockInfo)
  9712. service.CreateDrugFlowOne(flow)
  9713. }
  9714. }
  9715. }
  9716. return err
  9717. }
  9718. func (this *HisApiController) DeleteNCDS() {
  9719. id, _ := this.GetInt64("id", 0)
  9720. if id > 0 {
  9721. service.DeletePsnNCDSRecordById(id)
  9722. this.ServeSuccessJSON(map[string]interface{}{
  9723. "msg": "删除成功",
  9724. })
  9725. } else {
  9726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9727. return
  9728. }
  9729. }
  9730. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9731. id, _ := c.GetInt64("id")
  9732. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9733. c.ServeSuccessJSON(map[string]interface{}{
  9734. "advice": advice,
  9735. })
  9736. return
  9737. }
  9738. func (c *HisApiController) GetHisMonthChargePatientList() {
  9739. record_date := c.GetString("record_date")
  9740. start_time := c.GetString("start_time")
  9741. end_time := c.GetString("end_time")
  9742. timeLayout := "2006-01-02"
  9743. loc, _ := time.LoadLocation("Local")
  9744. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9745. if err != nil {
  9746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9747. return
  9748. }
  9749. if err != nil {
  9750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9751. return
  9752. }
  9753. recordDateTime := theTime.Unix()
  9754. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9755. if err != nil {
  9756. }
  9757. startRecordDateTime := startTime.Unix()
  9758. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9759. if err != nil {
  9760. }
  9761. endRecordDateTime := endTime.Unix()
  9762. adminInfo := c.GetAdminUserInfo()
  9763. var tempMonthChargePatients []*service.MonthChargePatients
  9764. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9765. for _, item := range tempPatients {
  9766. //过滤没有处方的
  9767. if len(item.HisPrescription) == 0 {
  9768. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9769. }
  9770. }
  9771. c.ServeSuccessJSON(map[string]interface{}{
  9772. "list": tempMonthChargePatients,
  9773. })
  9774. }