his_api_controller.go 369KB

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