his_api_controller.go 406KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. }
  86. func (c *HisApiController) GetMonthHisPatient() {
  87. record_date := c.GetString("record_date")
  88. //order_status, _ := c.GetInt64("type")
  89. timeLayout := "2006-01-02"
  90. loc, _ := time.LoadLocation("Local")
  91. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  92. if err != nil {
  93. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  94. return
  95. }
  96. recordDateTime := theTime.Unix()
  97. adminInfo := c.GetAdminUserInfo()
  98. var tempPatients []service.NewTempPatients
  99. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  100. // 获取当前时间
  101. now := time.Now()
  102. // 获取本月的第一天
  103. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  104. // 获取下个月的第一天
  105. nextMonth := firstDay.AddDate(0, 1, 0)
  106. // 获取本月的最后一天
  107. lastDay := nextMonth.Add(-time.Nanosecond)
  108. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  109. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  110. var patients []service.NewTempPatients
  111. var patients_two []service.NewTempPatients
  112. for _, item := range tempPatients {
  113. //过滤掉没挂号的和没开处方的
  114. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  115. patients = append(patients, item)
  116. }
  117. ////过滤掉没挂号的
  118. //if len(item.HisPatient) > 0 {
  119. // patients_two = append(patients_two, item)
  120. //}
  121. }
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "list": patients,
  124. "list_two": patients_two,
  125. "chargePatients": chargePatients,
  126. })
  127. }
  128. func (c *HisApiController) GetBatchSettleAccounts() {
  129. order_ids := c.GetString("order_ids")
  130. admin_user_id, _ := c.GetInt64("admin_user_id")
  131. adminUser := c.GetAdminUserInfo()
  132. orders := strings.Split(order_ids, ",")
  133. var newOrders []models.Orders
  134. for _, item := range orders {
  135. order, _ := service.GetHisOrderByIDTenOne(item)
  136. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  137. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  138. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  139. orderInfos = append(orderInfos, orderInfos_two...)
  140. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  141. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  142. var diagnosis_ids []string
  143. if his.ID > 0 {
  144. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  145. } else {
  146. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  147. }
  148. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  149. var dia_config []*models.HisXtDiagnoseConfig
  150. var name string
  151. for _, item := range diagnosis_ids {
  152. id, _ := strconv.ParseInt(item, 10, 64)
  153. diagnosisConfig, _ := service.FindDiagnoseById(id)
  154. dia_config = append(dia_config, diagnosisConfig)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. var bedCostTotal float64 = 0 //床位总费
  162. var bedCostSelfTotal float64 = 0 //床位自费
  163. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  164. var bedSelfTotal float64 = 0 //床位部分项目自费
  165. var bedInscpTotal float64 = 0 //床位部分项目自费
  166. var operationCostTotal float64 = 0 //手术费
  167. var operationCostSelfTotal float64 = 0 //手术费
  168. var operationCostPartSelfTotal float64 = 0 //手术费
  169. var operationSelfTotal float64 = 0 //床位部分项目自费
  170. var operationInscpTotal float64 = 0 //床位部分项目自费
  171. var otherCostTotal float64 = 0 //其他费用
  172. var otherCostSelfTotal float64 = 0 //其他费用
  173. var otherCostPartSelfTotal float64 = 0 //其他费用
  174. var otherSelfTotal float64 = 0 //床位部分项目自费
  175. var otherInscpTotal float64 = 0 //床位部分项目自费
  176. var materialCostTotal float64 = 0 //材料费
  177. var materialCostSelfTotal float64 = 0 //材料费
  178. var materialCostPartSelfTotal float64 = 0 //材料费
  179. var materialSelfTotal float64 = 0 //床位部分项目自费
  180. var materialInscpTotal float64 = 0 //床位部分项目自费
  181. var westernMedicineCostTotal float64 = 0 //西药费
  182. var westernMedicineCostSelfTotal float64 = 0 //西药费
  183. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  184. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  185. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  186. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  187. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  188. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  189. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  190. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  191. var checkCostTotal float64 = 0 //检查费
  192. var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var checkSelfTotal float64 = 0 //床位部分项目自费
  195. var checkInscpTotal float64 = 0 //床位部分项目自费
  196. var laboratoryCostTotal float64 = 0 //化验费
  197. var laboratoryCostSelfTotal float64 = 0 //化验费
  198. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  199. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  200. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  201. var treatCostTotal float64 = 0 //治疗费用
  202. var treatCostSelfTotal float64 = 0 //治疗费用
  203. var treatCostPartSelfTotal float64 = 0 //治疗费用
  204. var treatSelfTotal float64 = 0 //床位部分项目自费
  205. var treatInscpTotal float64 = 0 //床位部分项目自费
  206. decimal.DivisionPrecision = 2
  207. for _, item := range orderInfos {
  208. if item.MedChrgitmType == "01" { //床位费
  209. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  210. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  211. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  212. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  213. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  214. }
  215. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  216. if item.MedChrgitmType == "03" { //检查费
  217. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  218. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  219. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  220. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  221. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  222. }
  223. } else {
  224. if item.MedChrgitmType == "03" { //检查费
  225. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  230. }
  231. }
  232. if item.MedChrgitmType == "04" { //化验费
  233. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  234. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  235. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  236. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  237. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  238. }
  239. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  240. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  241. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  242. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  243. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  244. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  245. }
  246. if item.MedChrgitmType == "06" { //手术费
  247. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  248. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  249. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  250. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  251. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  252. }
  253. if item.MedChrgitmType == "08" { //材料费
  254. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  255. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  256. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  257. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  258. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  259. }
  260. if item.MedChrgitmType == "09" { //西药费
  261. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  262. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  263. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  264. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  265. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  266. }
  267. if item.MedChrgitmType == "11" { //中成费
  268. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  269. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  270. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  271. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  272. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  273. }
  274. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  275. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  276. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  277. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  278. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  279. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  280. }
  281. }
  282. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  283. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  284. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  285. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  286. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  287. var doctor_name string
  288. if roles.ID == 0 {
  289. doctor_name = "管理员"
  290. } else {
  291. doctor_name = roles.UserName
  292. }
  293. yiliao_leibie := ""
  294. switch order.MedType {
  295. case "11":
  296. yiliao_leibie = "普通门诊"
  297. break
  298. case "12":
  299. yiliao_leibie = "门诊挂号"
  300. break
  301. case "13":
  302. yiliao_leibie = "急诊"
  303. break
  304. case "14":
  305. yiliao_leibie = "门诊特殊病"
  306. break
  307. case "15":
  308. yiliao_leibie = "门诊统筹"
  309. break
  310. case "16":
  311. yiliao_leibie = "门诊慢性病"
  312. break
  313. case "21":
  314. yiliao_leibie = "普通住院"
  315. break
  316. }
  317. var newOrder models.Orders
  318. newOrder.Diagnosis = name
  319. newOrder.OrderInfos = orderInfos
  320. newOrder.Number = order.MdtrtId
  321. newOrder.Date = order.SettleAccountsDate
  322. newOrder.ChargeAdmin = charge_admin
  323. newOrder.PrintorAdmin = printor_admin
  324. newOrder.Order = order
  325. newOrder.BedCostTotal = bedCostTotal
  326. newOrder.BedCostSelfTotal = bedCostSelfTotal
  327. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  328. newOrder.BedSelfTotal = bedSelfTotal
  329. newOrder.BedInscpTotal = bedInscpTotal
  330. newOrder.OperationCostTotal = operationCostTotal
  331. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  332. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  333. newOrder.OperationSelfTotal = operationSelfTotal
  334. newOrder.OperationInscpTotal = operationInscpTotal
  335. newOrder.OtherCostTotal = otherCostTotal
  336. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  337. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  338. newOrder.OtherSelfTotal = otherSelfTotal
  339. newOrder.OtherInscpTotal = otherInscpTotal
  340. newOrder.MaterialCostTotal = materialCostTotal
  341. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  342. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  343. newOrder.MaterialSelfTotal = materialSelfTotal
  344. newOrder.MaterialInscpTotal = materialInscpTotal
  345. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  346. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  347. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  348. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  349. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  350. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  351. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  352. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  353. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  354. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  355. newOrder.CheckCostTotal = checkCostTotal
  356. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  357. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  358. newOrder.CheckSelfTotal = checkSelfTotal
  359. newOrder.CheckInscpTotal = checkInscpTotal
  360. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  361. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  362. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  363. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  364. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  365. newOrder.TreatCostTotal = treatCostTotal
  366. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  367. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  368. newOrder.TreatSelfTotal = treatSelfTotal
  369. newOrder.TreatInscpTotal = treatInscpTotal
  370. newOrder.DoctorInfo = doctor_info
  371. newOrder.DoctorName = doctor_name
  372. newOrder.HealthCardNo = order.PsnNo
  373. newOrder.YiliaoLeibie = yiliao_leibie
  374. newOrder.Patient = patient
  375. newOrder.OrgName = miConfig.OrgName
  376. newOrder.OrgCode = miConfig.Code
  377. newOrder.OrderNumber = order.Number
  378. newOrder.HisPatient = his
  379. newOrder.DiaConfig = dia_config
  380. newOrders = append(newOrders, newOrder)
  381. }
  382. c.ServeSuccessJSON(map[string]interface{}{
  383. "orders": newOrders,
  384. })
  385. }
  386. func (c *HisApiController) GetTestOrder() {
  387. order_id, _ := c.GetInt64("order_id")
  388. admin_user_id, _ := c.GetInt64("admin_user_id")
  389. adminUser := c.GetAdminUserInfo()
  390. order, _ := service.GetHisOrderByID(order_id)
  391. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  392. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  393. orderInfos = append(orderInfos, orderInfos_two...)
  394. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  395. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  396. var dia_config []*models.HisXtDiagnoseConfig
  397. var name string
  398. var bedCostTotal float64 = 0 //床位总费
  399. var bedCostSelfTotal float64 = 0 //床位自费
  400. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  401. var bedSelfTotal float64 = 0 //床位部分项目自费
  402. var bedInscpTotal float64 = 0 //床位部分项目自费
  403. var operationCostTotal float64 = 0 //手术费
  404. var operationCostSelfTotal float64 = 0 //手术费
  405. var operationCostPartSelfTotal float64 = 0 //手术费
  406. var operationSelfTotal float64 = 0 //床位部分项目自费
  407. var operationInscpTotal float64 = 0 //床位部分项目自费
  408. var otherCostTotal float64 = 0 //其他费用
  409. var otherCostSelfTotal float64 = 0 //其他费用
  410. var otherCostPartSelfTotal float64 = 0 //其他费用
  411. var otherSelfTotal float64 = 0 //床位部分项目自费
  412. var otherInscpTotal float64 = 0 //床位部分项目自费
  413. var materialCostTotal float64 = 0 //材料费
  414. var materialCostSelfTotal float64 = 0 //材料费
  415. var materialCostPartSelfTotal float64 = 0 //材料费
  416. var materialSelfTotal float64 = 0 //床位部分项目自费
  417. var materialInscpTotal float64 = 0 //床位部分项目自费
  418. var westernMedicineCostTotal float64 = 0 //西药费
  419. var westernMedicineCostSelfTotal float64 = 0 //西药费
  420. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  421. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  422. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  423. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  424. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  425. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  426. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  427. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  428. var checkCostTotal float64 = 0 //检查费
  429. var checkCostSelfTotal float64 = 0 //检查费
  430. var checkCostPartSelfTotal float64 = 0 //检查费
  431. var checkSelfTotal float64 = 0 //床位部分项目自费
  432. var checkInscpTotal float64 = 0 //床位部分项目自费
  433. var laboratoryCostTotal float64 = 0 //化验费
  434. var laboratoryCostSelfTotal float64 = 0 //化验费
  435. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  436. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  437. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  438. var treatCostTotal float64 = 0 //治疗费用
  439. var treatCostSelfTotal float64 = 0 //治疗费用
  440. var treatCostPartSelfTotal float64 = 0 //治疗费用
  441. var treatSelfTotal float64 = 0 //床位部分项目自费
  442. var treatInscpTotal float64 = 0 //床位部分项目自费
  443. decimal.DivisionPrecision = 2
  444. for _, item := range orderInfos {
  445. if item.MedChrgitmType == "01" { //床位费
  446. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  447. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  448. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  449. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  450. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  451. }
  452. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  453. if item.MedChrgitmType == "03" { //检查费
  454. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  455. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  456. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  457. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  458. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  459. }
  460. } else {
  461. if item.MedChrgitmType == "03" { //检查费
  462. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  463. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  464. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  465. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  466. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  467. }
  468. }
  469. if item.MedChrgitmType == "04" { //化验费
  470. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  471. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  472. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  473. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  474. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  475. }
  476. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  477. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  478. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  479. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  480. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  481. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  482. }
  483. if item.MedChrgitmType == "06" { //手术费
  484. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  485. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  486. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  487. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  488. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  489. }
  490. if item.MedChrgitmType == "08" { //材料费
  491. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  492. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  493. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  494. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  495. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  496. }
  497. if item.MedChrgitmType == "09" { //西药费
  498. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  499. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  500. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  501. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  502. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  503. }
  504. if item.MedChrgitmType == "11" { //中成费
  505. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  506. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  507. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  508. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  509. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  510. }
  511. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  512. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  513. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  514. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  515. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  516. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  517. }
  518. }
  519. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  520. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  521. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  522. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  523. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  524. var doctor_name string
  525. if roles.ID == 0 {
  526. doctor_name = "管理员"
  527. } else {
  528. doctor_name = roles.UserName
  529. }
  530. yiliao_leibie := ""
  531. switch order.MedType {
  532. case "11":
  533. yiliao_leibie = "普通门诊"
  534. break
  535. case "12":
  536. yiliao_leibie = "门诊挂号"
  537. break
  538. case "13":
  539. yiliao_leibie = "急诊"
  540. break
  541. case "14":
  542. yiliao_leibie = "门诊特殊病"
  543. break
  544. case "15":
  545. yiliao_leibie = "门诊统筹"
  546. break
  547. case "16":
  548. yiliao_leibie = "门诊慢性病"
  549. break
  550. case "21":
  551. yiliao_leibie = "普通住院"
  552. break
  553. }
  554. c.ServeSuccessJSON(map[string]interface{}{
  555. "diagnosis": name,
  556. "order_infos": orderInfos,
  557. "number": order.MdtrtId,
  558. "date": order.SettleAccountsDate,
  559. "charge_admin": charge_admin,
  560. "printor_admin": printor_admin,
  561. "info": order,
  562. "order": order,
  563. "bedCostTotal": bedCostTotal,
  564. "bedCostSelfTotal": bedCostSelfTotal,
  565. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  566. "bedSelfTotal": bedSelfTotal,
  567. "bedInscpTotal": bedInscpTotal,
  568. "operationCostTotal": operationCostTotal,
  569. "operationCostSelfTotal": operationCostSelfTotal,
  570. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  571. "operationSelfTotal": operationSelfTotal,
  572. "operationInscpTotal": operationInscpTotal,
  573. "otherCostTotal": otherCostTotal,
  574. "otherCostSelfTotal": otherCostSelfTotal,
  575. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  576. "otherSelfTotal": otherSelfTotal,
  577. "otherInscpTotal": otherInscpTotal,
  578. "materialCostTotal": materialCostTotal,
  579. "materialCostSelfTotal": materialCostSelfTotal,
  580. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  581. "materialSelfTotal": materialSelfTotal,
  582. "materialInscpTotal": materialInscpTotal,
  583. "westernMedicineCostTotal": westernMedicineCostTotal,
  584. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  585. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  586. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  587. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  588. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  589. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  590. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  591. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  592. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  593. "checkCostTotal": checkCostTotal,
  594. "checkCostSelfTotal": checkCostSelfTotal,
  595. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  596. "checkSelfTotal": checkSelfTotal,
  597. "checkInscpTotal": checkInscpTotal,
  598. "laboratoryCostTotal": laboratoryCostTotal,
  599. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  600. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  601. "laboratorySelfTotal": laboratorySelfTotal,
  602. "laboratoryInscpTotal": laboratoryInscpTotal,
  603. "treatCostTotal": treatCostTotal,
  604. "treatCostSelfTotal": treatCostSelfTotal,
  605. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  606. "treatSelfTotal": treatSelfTotal,
  607. "treatInscpTotal": treatInscpTotal,
  608. "doctor_info": doctor_info,
  609. "doctor_name": doctor_name,
  610. "health_card_no": order.PsnNo,
  611. "yiliao_leibie": yiliao_leibie,
  612. "patient": patient,
  613. "org_name": miConfig.OrgName,
  614. "org_code": miConfig.Code,
  615. "order_number": order.Number,
  616. "his_hospital": his_hospital,
  617. "dia_config": dia_config,
  618. })
  619. }
  620. func (c *PublicApiController) GetBaiLinExportData() {
  621. data := service.GetBaiLinOrderData()
  622. fmt.Println(len(data))
  623. var new_data []*models.NewCustomHisOrder
  624. for _, item := range data {
  625. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  626. new_data = append(new_data, item)
  627. }
  628. }
  629. fmt.Println(len(new_data))
  630. c.ServeSuccessJSON(map[string]interface{}{
  631. "list": new_data,
  632. })
  633. }
  634. func (c *HisApiController) GetHisUnChargePatientList() {
  635. record_date := c.GetString("record_date")
  636. timeLayout := "2006-01-02"
  637. loc, _ := time.LoadLocation("Local")
  638. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  639. if err != nil {
  640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  641. return
  642. }
  643. recordDateTime := theTime.Unix()
  644. adminInfo := c.GetAdminUserInfo()
  645. var tempPatients []*service.NewTempPatients
  646. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  647. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  648. var patients []*service.NewTempPatients
  649. var patients_two []*service.NewTempPatients
  650. for _, item := range tempPatients {
  651. //过滤掉没挂号的和没开处方的
  652. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  653. patients = append(patients, item)
  654. }
  655. //过滤掉没挂号的
  656. if len(item.HisPatient) > 0 {
  657. patients_two = append(patients_two, item)
  658. }
  659. }
  660. c.ServeSuccessJSON(map[string]interface{}{
  661. "list": patients,
  662. "list_two": patients_two,
  663. })
  664. }
  665. func (c *HisApiController) GetPrivateExpensesOrder() {
  666. //id, _ := c.GetInt64("id")
  667. //record_time := c.GetString("record_time")
  668. order_id, _ := c.GetInt64("order_id")
  669. admin_user_id, _ := c.GetInt64("admin_user_id")
  670. //timeLayout := "2006-01-02"
  671. //loc, _ := time.LoadLocation("Local")
  672. //
  673. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  674. //if err != nil {
  675. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  676. // return
  677. //}
  678. //recordDateTime := theTime.Unix()
  679. adminUser := c.GetAdminUserInfo()
  680. order, _ := service.GetHisOrderByID(order_id)
  681. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  682. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  683. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  684. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  685. //var config []*models.HisXtDiagnoseConfig
  686. var name string
  687. if order.PType == 1 {
  688. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  689. for _, item := range diagnosis_ids {
  690. id, _ := strconv.ParseInt(item, 10, 64)
  691. diagnosisConfig, _ := service.FindDiagnoseById(id)
  692. if len(name) == 0 {
  693. name = diagnosisConfig.ClassName
  694. } else {
  695. name = name + "," + diagnosisConfig.ClassName
  696. }
  697. }
  698. } else {
  699. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  700. for _, item := range diagnosis_ids {
  701. id, _ := strconv.ParseInt(item, 10, 64)
  702. diagnosisConfig, _ := service.FindDiagnoseById(id)
  703. if len(name) == 0 {
  704. name = diagnosisConfig.ClassName
  705. } else {
  706. name = name + "," + diagnosisConfig.ClassName
  707. }
  708. }
  709. }
  710. var bedCostTotal float64 = 0 //床位总费
  711. //var bedCostSelfTotal float64 = 0 //床位自费
  712. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  713. var operationCostTotal float64 = 0 //手术费
  714. //var operationCostSelfTotal float64 = 0 //手术费
  715. var operationCostPartSelfTotal float64 = 0 //手术费
  716. var otherCostTotal float64 = 0 //其他费用
  717. //var otherCostSelfTotal float64 = 0 //其他费用
  718. var otherCostPartSelfTotal float64 = 0 //其他费用
  719. var materialCostTotal float64 = 0 //材料费
  720. //var materialCostSelfTotal float64 = 0 //材料费
  721. var materialCostPartSelfTotal float64 = 0 //材料费
  722. var westernMedicineCostTotal float64 = 0 //西药费
  723. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  724. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  725. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  726. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  727. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  728. var checkCostTotal float64 = 0 //检查费
  729. //var checkCostSelfTotal float64 = 0 //检查费
  730. var checkCostPartSelfTotal float64 = 0 //检查费
  731. var laboratoryCostTotal float64 = 0 //化验费
  732. //var laboratoryCostSelfTotal float64 = 0 //化验费
  733. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  734. var treatCostTotal float64 = 0 //治疗费用
  735. //var treatCostSelfTotal float64 = 0 //治疗费用
  736. var treatCostPartSelfTotal float64 = 0 //治疗费用
  737. var zhenChaCostTotal float64 = 0 //其他费用
  738. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  739. decimal.DivisionPrecision = 2
  740. for _, item := range orderInfos {
  741. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  742. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  743. item.MedChrgitmType = "09"
  744. }
  745. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  746. if item.HisPrescriptionProject.Type == 2 {
  747. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  748. fmt.Println("CostClassify")
  749. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  750. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  751. case 0:
  752. item.MedChrgitmType = "0"
  753. break
  754. case 1:
  755. item.MedChrgitmType = "14"
  756. break
  757. case 2:
  758. item.MedChrgitmType = "05"
  759. break
  760. case 3:
  761. item.MedChrgitmType = "03"
  762. break
  763. case 4:
  764. item.MedChrgitmType = "03"
  765. break
  766. case 5:
  767. item.MedChrgitmType = "08"
  768. break
  769. case 6:
  770. item.MedChrgitmType = "14"
  771. break
  772. case 7:
  773. item.MedChrgitmType = "14"
  774. break
  775. case 8:
  776. item.MedChrgitmType = "03"
  777. break
  778. case 9:
  779. item.MedChrgitmType = "14"
  780. break
  781. case 10:
  782. item.MedChrgitmType = "14"
  783. break
  784. case 11:
  785. item.MedChrgitmType = "06"
  786. break
  787. case 12:
  788. item.MedChrgitmType = "12"
  789. break
  790. case 13:
  791. item.MedChrgitmType = "01"
  792. break
  793. case 14:
  794. item.MedChrgitmType = "04"
  795. break
  796. case 15:
  797. item.MedChrgitmType = "14"
  798. break
  799. }
  800. } else {
  801. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  802. case 1:
  803. item.MedChrgitmType = "14"
  804. break
  805. case 2:
  806. item.MedChrgitmType = "05"
  807. break
  808. case 3:
  809. item.MedChrgitmType = "04"
  810. break
  811. case 4:
  812. item.MedChrgitmType = "14"
  813. break
  814. case 5:
  815. item.MedChrgitmType = "08"
  816. break
  817. case 6:
  818. item.MedChrgitmType = "14"
  819. break
  820. case 7:
  821. item.MedChrgitmType = "14"
  822. break
  823. case 8:
  824. item.MedChrgitmType = "03"
  825. break
  826. case 9:
  827. item.MedChrgitmType = "14"
  828. break
  829. }
  830. }
  831. } else if item.HisPrescriptionProject.Type == 3 {
  832. item.MedChrgitmType = "08"
  833. }
  834. }
  835. }
  836. order.PsnCashPay = order.MedfeeSumamt
  837. for _, item := range orderInfos {
  838. if item.MedChrgitmType == "01" { //床位费
  839. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  840. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  841. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  842. }
  843. if item.MedChrgitmType == "02" { //诊察费
  844. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  845. //zhenChaCostSelfTotal = zhenChaCostTotal
  846. }
  847. if item.MedChrgitmType == "03" { //检查费
  848. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  849. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  850. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  851. }
  852. if item.MedChrgitmType == "02" { //检查费
  853. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  854. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  855. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  856. }
  857. if item.MedChrgitmType == "04" { //化验费
  858. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  859. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  860. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  861. }
  862. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  863. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  864. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  865. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  866. }
  867. if item.MedChrgitmType == "06" { //手术费
  868. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  869. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  870. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  871. }
  872. if item.MedChrgitmType == "08" { //材料费
  873. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  874. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  875. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  876. }
  877. if item.MedChrgitmType == "09" { //西药费
  878. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  879. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  880. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  881. }
  882. if item.MedChrgitmType == "11" { //中成费
  883. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  884. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  885. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  886. }
  887. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  888. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  889. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  890. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  891. }
  892. }
  893. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  894. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  895. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  896. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  897. c.ServeSuccessJSON(map[string]interface{}{
  898. "patient": patient,
  899. "order_infos": orderInfos,
  900. "diagnosis": name,
  901. "bedCostTotal": bedCostTotal,
  902. "bedCostSelfTotal": bedCostTotal,
  903. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  904. "operationCostTotal": operationCostTotal,
  905. "operationCostSelfTotal": operationCostTotal,
  906. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  907. "otherCostTotal": otherCostTotal,
  908. "otherCostSelfTotal": otherCostTotal,
  909. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  910. "materialCostTotal": materialCostTotal,
  911. "materialCostSelfTotal": materialCostTotal,
  912. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  913. "westernMedicineCostTotal": westernMedicineCostTotal,
  914. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  915. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  916. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  917. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  918. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  919. "checkCostTotal": checkCostTotal,
  920. "checkCostSelfTotal": checkCostTotal,
  921. "zhenChaCostTotal": zhenChaCostTotal,
  922. "zhenChaCostSelfTotal": zhenChaCostTotal,
  923. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  924. "laboratoryCostTotal": laboratoryCostTotal,
  925. "laboratoryCostSelfTotal": laboratoryCostTotal,
  926. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  927. "treatCostTotal": treatCostTotal,
  928. "treatCostSelfTotal": treatCostTotal,
  929. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  930. "charge_admin": charge_admin,
  931. "printor_admin": printor_admin,
  932. "org_name": org.OrgName,
  933. "org_code": miConfig.Code,
  934. "name": patient.Name,
  935. "number": order.MdtrtId,
  936. "date": order.SettleAccountsDate,
  937. "info": order,
  938. "his_hospital": his_hospital,
  939. "his": his,
  940. })
  941. }
  942. func (c *HisApiController) RefudDetail() {
  943. order_id, _ := c.GetInt64("order_id")
  944. order, _ := service.GetHisOrderByID(order_id)
  945. adminUser := c.GetAdminUserInfo()
  946. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  947. c.ServeSuccessJSON(map[string]interface{}{
  948. "msg": "撤销成功",
  949. })
  950. }
  951. func (c *HisApiController) Sscard() {
  952. //r := CardInit()
  953. //if r == 0 {
  954. // GetBaseInfo()
  955. //}
  956. //c.ServeSuccessJSON(map[string]interface{}{
  957. // "list": "11",
  958. //})
  959. }
  960. func GetBaseInfo() error {
  961. //handle := syscall.MustLoadDLL("SSCard.dll")
  962. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  963. //
  964. //str := make([]byte, 256)
  965. //str1 := make([]byte, 256)
  966. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  967. //if ferr != nil {
  968. // fmt.Println("ReadCardBas 报错", ferr.Error())
  969. // return ferr
  970. //}
  971. //
  972. //fmt.Println(string(str))
  973. //
  974. //fmt.Println(r)
  975. return nil
  976. }
  977. func CardInit() int {
  978. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  979. //add := DllTestDef.MustFindProc("Init")
  980. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  981. //if err != nil {
  982. // fmt.Println("SSCard的运算结果为:", ret)
  983. //}
  984. //result := int(ret)
  985. return 0
  986. }
  987. func IntPtr(n int) uintptr {
  988. return uintptr(n)
  989. }
  990. func StrPtr(s string) uintptr {
  991. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  992. }
  993. func (c *HisApiController) GetHisPatientList() {
  994. //types, _ := c.GetInt64("type", 0)
  995. record_date := c.GetString("record_date")
  996. sch_type, _ := c.GetInt64("sch_type")
  997. timeLayout := "2006-01-02"
  998. loc, _ := time.LoadLocation("Local")
  999. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1000. if err != nil {
  1001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1002. return
  1003. }
  1004. recordDateTime := theTime.Unix()
  1005. adminInfo := c.GetAdminUserInfo()
  1006. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1007. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1008. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1009. //获取当前用户的信息
  1010. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1011. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1012. //获取所有科室信息
  1013. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1014. c.ServeSuccessJSON(map[string]interface{}{
  1015. "list": patients,
  1016. "list_two": patients_two,
  1017. "info": adminUserInfo,
  1018. "doctors": doctors,
  1019. "department": department,
  1020. })
  1021. }
  1022. type CustomTemplate struct {
  1023. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1024. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1025. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1026. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1027. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1028. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1029. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1030. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1031. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1032. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1033. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1034. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1035. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1036. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1037. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1038. }
  1039. func (c *HisApiController) GetHisPatientInfo() {
  1040. patient_id, _ := c.GetInt64("patient_id")
  1041. his_patient_id, _ := c.GetInt64("his_patient_id")
  1042. record_date := c.GetString("record_date")
  1043. number := c.GetString("number")
  1044. //start_time := c.GetString("start_time")
  1045. //end_time := c.GetString("end_time")
  1046. p_type, _ := c.GetInt64("p_type")
  1047. timeLayout := "2006-01-02"
  1048. loc, _ := time.LoadLocation("Local")
  1049. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1050. if err != nil {
  1051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1052. return
  1053. }
  1054. recordDateTime := theTime.Unix()
  1055. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1056. //if err != nil {
  1057. //
  1058. //}
  1059. //startRecordDateTime := startTime.Unix()
  1060. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1061. //if err != nil {
  1062. //
  1063. //}
  1064. //endRecordDateTime := endTime.Unix()
  1065. admin := c.GetAdminUserInfo()
  1066. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1067. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1068. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1069. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1070. var prescriptions []*models.HisPrescription
  1071. var last_prescriptions []*models.HisPrescription
  1072. var sch_prescriptions []CustomTemplate
  1073. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1074. if p_type == 1 { //住院
  1075. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1076. for _, item := range prescriptions {
  1077. for _, subItem := range item.HisDoctorAdviceInfo {
  1078. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1079. if info.RetailPrice > 0 {
  1080. subItem.Drug.MinPrice = info.RetailPrice
  1081. }
  1082. }
  1083. }
  1084. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1085. } else { //门诊
  1086. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1087. for _, item := range prescriptions {
  1088. for _, subItem := range item.HisDoctorAdviceInfo {
  1089. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1090. if info.RetailPrice > 0 {
  1091. subItem.Drug.MinPrice = info.RetailPrice
  1092. }
  1093. }
  1094. }
  1095. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1096. }
  1097. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1098. if sch.ID > 0 {
  1099. var week string
  1100. t := time.Now()
  1101. switch t.Weekday().String() {
  1102. case "Monday":
  1103. week = "周一"
  1104. break
  1105. case "Tuesday":
  1106. week = "周二"
  1107. break
  1108. case "Wednesday":
  1109. week = "周三"
  1110. break
  1111. case "Thursday":
  1112. week = "周四"
  1113. break
  1114. case "Friday":
  1115. week = "周五"
  1116. break
  1117. case "Saturday":
  1118. week = "周六"
  1119. break
  1120. case "Sunday":
  1121. week = "周日"
  1122. break
  1123. }
  1124. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1125. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1126. //根据推送频率组装新的数组
  1127. for _, item := range temp_sch_prescriptions {
  1128. var cus CustomTemplate
  1129. cus.ID = item.ID
  1130. cus.UserOrgId = item.UserOrgId
  1131. cus.PatientId = item.PatientId
  1132. cus.MedType = item.MedType
  1133. cus.RecordDate = item.RecordDate
  1134. cus.Type = item.Type
  1135. cus.PType = item.PType
  1136. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1137. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1138. if subItem.FrequencyType == 1 { //每次必推
  1139. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1140. }
  1141. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1142. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1143. }
  1144. if subItem.FrequencyType == 2 { //按照天数频率
  1145. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1146. now := p.Unix()
  1147. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1148. dayStr2 := "-" + dayStr
  1149. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1150. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1151. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1152. if len(advices) == 0 {
  1153. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1154. }
  1155. }
  1156. }
  1157. }
  1158. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1159. if subItem.Type == 2 {
  1160. if subItem.XtHisProject.MedicalStatus != 1 {
  1161. if subItem.FrequencyType == 1 {
  1162. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1163. }
  1164. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1165. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1166. }
  1167. if subItem.FrequencyType == 2 {
  1168. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1169. now := p.Unix()
  1170. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1171. dayStr2 := "-" + dayStr
  1172. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1173. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1174. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1175. if len(projects) == 0 {
  1176. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1177. }
  1178. }
  1179. }
  1180. } else if subItem.Type == 3 {
  1181. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1182. if subItem.FrequencyType == 1 {
  1183. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1184. }
  1185. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1186. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1187. }
  1188. if subItem.FrequencyType == 2 {
  1189. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1190. now := p.Unix()
  1191. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1192. dayStr2 := "-" + dayStr
  1193. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1194. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1195. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1196. if len(projects) == 0 {
  1197. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1198. }
  1199. }
  1200. }
  1201. }
  1202. }
  1203. sch_prescriptions = append(sch_prescriptions, cus)
  1204. }
  1205. for _, item := range sch_prescriptions {
  1206. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1207. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1208. }
  1209. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1210. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1211. }
  1212. }
  1213. }
  1214. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1215. if config.ID > 0 && config.IsOpen == 1 {
  1216. for _, item := range sch_prescriptions {
  1217. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1218. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1219. if info.RetailPrice > 0 {
  1220. subItem.Drug.MinPrice = info.RetailPrice
  1221. }
  1222. }
  1223. }
  1224. }
  1225. if config.ID > 0 && config.IsOpen == 1 {
  1226. for _, item := range sch_prescriptions {
  1227. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1228. if subItem.Type == 3 {
  1229. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1230. if info.Price > 0 {
  1231. subItem.GoodInfo.PackingPrice = info.Price
  1232. }
  1233. }
  1234. }
  1235. }
  1236. }
  1237. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1238. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1239. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1240. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1241. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1242. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1243. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1244. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1245. //获取所有科室信息
  1246. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1247. c.ServeSuccessJSON(map[string]interface{}{
  1248. "his_info": his_patient_info,
  1249. "xt_info": xt_patient_info,
  1250. "prescription": prescriptions,
  1251. "case_history": case_history,
  1252. "info": patientPrescriptionInfo,
  1253. //"month_prescriptions": monthPrescriptions,
  1254. "order": order,
  1255. "doctors": doctors,
  1256. "department": department,
  1257. "sch_prescriptions": sch_prescriptions,
  1258. "last_prescriptions": last_prescriptions,
  1259. "schedule": sch,
  1260. "count": count,
  1261. "drugStockConfig": drugStockConfig,
  1262. "last_info": lastPatientPrescriptionInfo,
  1263. })
  1264. return
  1265. }
  1266. func (c *HisApiController) GetHisPrescriptionConfig() {
  1267. adminInfo := c.GetAdminUserInfo()
  1268. //获取医嘱模版
  1269. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1270. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1271. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1272. //获取所有基础药
  1273. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1274. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1275. if config.ID > 0 && config.IsOpen == 1 {
  1276. for _, item := range drugs {
  1277. var index = 0
  1278. for _, subItem := range item.OtherDrugWarehouseInfo {
  1279. if index == 0 {
  1280. index = index + 1
  1281. if subItem.RetailPrice > 0 {
  1282. item.MinPrice = subItem.RetailPrice
  1283. }
  1284. }
  1285. }
  1286. }
  1287. }
  1288. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1289. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1290. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1291. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1292. //获取所有科室信息
  1293. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1294. //获取诊断信息
  1295. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1296. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1297. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1298. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1299. //获取是否开启保存耗材出库的开关
  1300. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1301. c.ServeSuccessJSON(map[string]interface{}{
  1302. "drugs": drugs,
  1303. "advices_template": advices,
  1304. "drugways": drugways,
  1305. "efs": efs,
  1306. "doctors": doctors,
  1307. "department": department,
  1308. "sick": sick,
  1309. "additions": additions,
  1310. "diagnose": diagnose,
  1311. "manufacturers": manufacturers,
  1312. "goodOutOpen": goodOutOpen,
  1313. "patientDiagnose": patientDiagnose,
  1314. })
  1315. }
  1316. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1317. //获取所有基础药
  1318. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1319. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1320. if config.ID > 0 && config.IsOpen == 1 {
  1321. for _, item := range drugs {
  1322. var index = 0
  1323. for _, subItem := range item.OtherDrugWarehouseInfo {
  1324. if index == 0 {
  1325. index = index + 1
  1326. if subItem.RetailPrice > 0 {
  1327. item.MinPrice = subItem.RetailPrice
  1328. }
  1329. }
  1330. }
  1331. }
  1332. }
  1333. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1334. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1335. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1336. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1337. //获取所有科室信息
  1338. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1339. //获取诊断信息
  1340. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1341. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1342. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1343. //获取是否开启保存耗材出库的开关
  1344. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1345. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1346. c.ServeSuccessJSON(map[string]interface{}{
  1347. "drugs": drugs,
  1348. "advices_template": advices,
  1349. "drugways": drugways,
  1350. "efs": efs,
  1351. "doctors": doctors,
  1352. "department": department,
  1353. "sick": sick,
  1354. "additions": additions,
  1355. "diagnose": diagnose,
  1356. "manufacturers": manufacturers,
  1357. "goodOutOpen": goodOutOpen,
  1358. "patientDiagnose": patientDiagnose,
  1359. })
  1360. }
  1361. }
  1362. func (c *HisApiController) CreateHisPrescription() {
  1363. record_date := c.GetString("record_date")
  1364. patient_id, _ := c.GetInt64("patient_id")
  1365. reg_type, _ := c.GetInt64("reg_type")
  1366. diagnose := c.GetString("diagnose")
  1367. sick_type, _ := c.GetInt64("sick_type")
  1368. sick_history := c.GetString("sick_history")
  1369. doctor_id, _ := c.GetInt64("doctor", 0)
  1370. department, _ := c.GetInt64("department", 0)
  1371. his_patient_id, _ := c.GetInt64("his_patient_id")
  1372. p_type, _ := c.GetInt64("p_type")
  1373. patient_diagnose := c.GetString("patient_diagnose")
  1374. dataBody := make(map[string]interface{}, 0)
  1375. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1376. if err != nil {
  1377. utils.ErrorLog(err.Error())
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1379. return
  1380. }
  1381. timeLayout := "2006-01-02"
  1382. loc, _ := time.LoadLocation("Local")
  1383. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1384. if err != nil {
  1385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1386. return
  1387. }
  1388. adminInfo := c.GetAdminUserInfo()
  1389. recordDateTime := theTime.Unix()
  1390. //查询默认出库仓库库存
  1391. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1392. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1393. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1394. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1395. if len(lists) == 1 {
  1396. his_patient_id = lists[0].ID
  1397. }
  1398. }
  1399. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1400. //保存处方出库
  1401. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1402. //自动出库
  1403. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1404. //耗材保存处方出库
  1405. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1406. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1407. //已发药和已收费限制逻辑
  1408. isMidicine := false
  1409. isCharge := false
  1410. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1411. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1412. if len(prescriptions) > 0 {
  1413. for _, item := range prescriptions {
  1414. items := item.(map[string]interface{})
  1415. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1416. utils.ErrorLog("id")
  1417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1418. return
  1419. }
  1420. id := int64(items["id"].(float64))
  1421. if id > 0 {
  1422. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1423. if err != nil {
  1424. if new_prescription.OrderStatus == 4 {
  1425. isCharge = true
  1426. }
  1427. }
  1428. }
  1429. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1430. advices := items["advices"].([]interface{})
  1431. if len(advices) > 0 {
  1432. for _, advice := range advices {
  1433. var adviceId int64
  1434. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1435. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1436. }
  1437. if adviceId > 0 {
  1438. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1439. if err == nil {
  1440. if his_advice_info.IsMedicine == 1 {
  1441. isMidicine = true
  1442. }
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. if isMidicine == true {
  1452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1453. return
  1454. }
  1455. if isCharge == true {
  1456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1457. return
  1458. }
  1459. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1460. //药品发药出库
  1461. if pharmacyConfig.IsOpen == 1 {
  1462. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1463. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1464. if len(prescriptions) > 0 {
  1465. for _, item := range prescriptions {
  1466. items := item.(map[string]interface{})
  1467. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1468. advices := items["advices"].([]interface{})
  1469. if len(advices) > 0 {
  1470. for _, advice := range advices {
  1471. var drug_id int64
  1472. var prescribing_number float64
  1473. var prescribingNumberUnit string
  1474. var adviceId int64
  1475. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1476. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1477. }
  1478. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1479. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1480. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1481. }
  1482. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1483. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1484. }
  1485. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1486. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1487. }
  1488. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1489. if drug.ID == 0 {
  1490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1491. return
  1492. }
  1493. //查询药品的所有库存
  1494. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1495. var total_count int64
  1496. for _, it := range list {
  1497. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1498. }
  1499. totals := strconv.FormatInt(total_count, 10)
  1500. //查询该药品是否存在开药记录
  1501. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1502. //新增处方
  1503. if advicelist.ID == 0 {
  1504. all_count, _ := strconv.ParseFloat(totals, 64)
  1505. if prescribingNumberUnit == drug.MinUnit {
  1506. if drug.IsUse != 1 {
  1507. if prescribing_number > all_count {
  1508. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1509. return
  1510. }
  1511. }
  1512. }
  1513. if prescribingNumberUnit == drug.MaxUnit {
  1514. num := prescribing_number * float64(drug.MinNumber)
  1515. if drug.IsUse != 1 {
  1516. if num > all_count {
  1517. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1518. return
  1519. }
  1520. }
  1521. }
  1522. }
  1523. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1524. if drugOutConfig.IsOpen != 1 {
  1525. //修改处方
  1526. for _, advice := range advices {
  1527. var drug_id int64
  1528. var prescribing_number float64
  1529. var prescribingNumberUnit string
  1530. var prescribingNumber string
  1531. var adviceId int64
  1532. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1533. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1534. }
  1535. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1536. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1537. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1538. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1539. }
  1540. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1541. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1542. }
  1543. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1544. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1545. }
  1546. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1547. if drug.ID == 0 {
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1549. return
  1550. }
  1551. //查询药品的所有库存
  1552. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1553. var total_count int64
  1554. for _, it := range list {
  1555. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1556. }
  1557. totals := strconv.FormatInt(total_count, 10)
  1558. //查询该药品是否存在开药记录
  1559. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1560. //新增处方
  1561. if advicelist.ID == 0 {
  1562. all_count, _ := strconv.ParseFloat(totals, 64)
  1563. if prescribingNumberUnit == drug.MinUnit {
  1564. if drug.IsUse != 1 {
  1565. if prescribing_number > all_count {
  1566. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1567. return
  1568. }
  1569. }
  1570. } else {
  1571. if prescribingNumberUnit == drug.MaxUnit {
  1572. num := prescribing_number * float64(drug.MinNumber)
  1573. if drug.IsUse != 1 {
  1574. if num > all_count {
  1575. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1576. return
  1577. }
  1578. }
  1579. }
  1580. }
  1581. }
  1582. //修改处方
  1583. if advicelist.ID > 0 {
  1584. var device_number int64
  1585. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1586. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1587. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1588. device_number = prescribingNumberInt * drug.MinNumber
  1589. }
  1590. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1591. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1592. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1593. device_number = prescribingNumberInt
  1594. }
  1595. var number_count int64
  1596. if prescribingNumberUnit == drug.MaxUnit {
  1597. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1598. number_count = prescribingNumberInt * drug.MinNumber
  1599. }
  1600. if prescribingNumberUnit == drug.MinUnit {
  1601. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1602. number_count = prescribingNumberInt
  1603. }
  1604. //如果修改的数量大于之前修改的数量
  1605. if (number_count - device_number) > 0 {
  1606. //如果修改的差数量 大于库存数量
  1607. if drug.IsUse != 1 {
  1608. if (number_count - device_number) > total_count {
  1609. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1610. return
  1611. }
  1612. }
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. }
  1620. }
  1621. }
  1622. }
  1623. }
  1624. //已发药和已收费限制逻辑
  1625. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1626. //校验库存总量
  1627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1629. if len(prescriptions) > 0 {
  1630. for _, item := range prescriptions {
  1631. items := item.(map[string]interface{})
  1632. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1633. advices := items["advices"].([]interface{})
  1634. if len(advices) > 0 {
  1635. for _, advice := range advices {
  1636. var drug_id int64
  1637. var prescribing_number float64
  1638. var prescribingNumberUnit string
  1639. var adviceId int64
  1640. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1641. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1642. }
  1643. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1644. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1645. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1646. }
  1647. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1648. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1649. }
  1650. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1651. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1652. }
  1653. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1654. if drug.ID == 0 {
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. //查询药品的所有库存
  1659. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1660. var total_count int64
  1661. for _, it := range list {
  1662. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1663. }
  1664. totals := strconv.FormatInt(total_count, 10)
  1665. //查询该药品是否存在开药记录
  1666. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1667. //查询最新批次库存
  1668. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1669. var batch_number_count int64
  1670. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1671. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1672. //新增处方
  1673. if advicelist.ID == 0 {
  1674. all_count, _ := strconv.ParseFloat(totals, 64)
  1675. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1676. if prescribingNumberUnit == drug.MinUnit {
  1677. if drug.IsUse != 1 {
  1678. if prescribing_number > all_count {
  1679. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1680. return
  1681. }
  1682. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1683. if prescribing_number > batch_number_all_count {
  1684. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1685. return
  1686. }
  1687. }
  1688. }
  1689. }
  1690. if prescribingNumberUnit == drug.MaxUnit {
  1691. num := prescribing_number * float64(drug.MinNumber)
  1692. if drug.IsUse != 1 {
  1693. if num > all_count {
  1694. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1695. return
  1696. }
  1697. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1698. if num > batch_number_all_count {
  1699. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1700. return
  1701. }
  1702. }
  1703. }
  1704. }
  1705. }
  1706. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1707. if drugOutConfig.IsOpen != 1 {
  1708. //修改处方
  1709. for _, advice := range advices {
  1710. var drug_id int64
  1711. var prescribing_number float64
  1712. var prescribingNumberUnit string
  1713. var prescribingNumber string
  1714. var adviceId int64
  1715. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1716. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1717. }
  1718. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1719. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1720. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1721. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1722. }
  1723. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1724. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1725. }
  1726. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1727. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1728. }
  1729. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1730. if drug.ID == 0 {
  1731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1732. return
  1733. }
  1734. //查询药品的所有库存
  1735. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1736. var total_count int64
  1737. for _, it := range list {
  1738. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1739. }
  1740. totals := strconv.FormatInt(total_count, 10)
  1741. //查询该药品是否存在开药记录
  1742. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1743. //新增处方
  1744. if advicelist.ID == 0 {
  1745. //查询最新批次库存
  1746. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1747. var batch_number_count int64
  1748. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1749. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1750. all_count, _ := strconv.ParseFloat(totals, 64)
  1751. if prescribingNumberUnit == drug.MinUnit {
  1752. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1753. if drug.IsUse != 1 {
  1754. if prescribing_number > all_count {
  1755. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1756. return
  1757. }
  1758. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1759. if prescribing_number > batch_number_all_count {
  1760. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1761. return
  1762. }
  1763. }
  1764. }
  1765. } else {
  1766. if prescribingNumberUnit == drug.MaxUnit {
  1767. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1768. num := prescribing_number * float64(drug.MinNumber)
  1769. if drug.IsUse != 1 {
  1770. if num > all_count {
  1771. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1772. return
  1773. }
  1774. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1775. if prescribing_number > batch_number_all_count {
  1776. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1777. return
  1778. }
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. //修改处方
  1785. if advicelist.ID > 0 {
  1786. //查询最新批次库存
  1787. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1788. var batch_number_count int64
  1789. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1790. var device_number int64
  1791. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1792. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1793. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1794. device_number = prescribingNumberInt * drug.MinNumber
  1795. }
  1796. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1797. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1798. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1799. device_number = prescribingNumberInt
  1800. }
  1801. var number_count int64
  1802. if prescribingNumberUnit == drug.MaxUnit {
  1803. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1804. number_count = prescribingNumberInt * drug.MinNumber
  1805. }
  1806. if prescribingNumberUnit == drug.MinUnit {
  1807. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1808. number_count = prescribingNumberInt
  1809. }
  1810. //如果修改的数量大于之前修改的数量
  1811. if (number_count - device_number) > 0 {
  1812. //如果修改的差数量 大于库存数量
  1813. if drug.IsUse != 1 {
  1814. if (number_count - device_number) > total_count {
  1815. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1816. return
  1817. }
  1818. if (number_count - device_number) > batch_number_count {
  1819. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1820. return
  1821. }
  1822. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1823. // 查询该药品最后一次出库记录
  1824. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1825. var out_count int64
  1826. var in_count int64
  1827. var stock_max_number int64
  1828. var stock_min_number int64
  1829. for _, it := range outInfo {
  1830. if it.CountUnit == drug.MaxUnit {
  1831. it.Count = it.Count * drug.MinNumber
  1832. }
  1833. out_count += it.Count
  1834. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1835. stock_max_number = warehouseInfoList.StockMaxNumber
  1836. stock_min_number = warehouseInfoList.StockMinNumber
  1837. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1838. }
  1839. if out_count > 0 {
  1840. if (number_count - device_number) > in_count {
  1841. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1842. return
  1843. }
  1844. }
  1845. // 未出库
  1846. if out_count == 0 {
  1847. var sum_in_count int64
  1848. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1849. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1850. fmt.Println("sum_in_count", sum_in_count)
  1851. //如果修改的数量大于有库存的第一个批次
  1852. if number_count > sum_in_count {
  1853. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1854. return
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1861. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1862. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1863. if pharmacyConfig.IsOpen != 1 {
  1864. if device_number != number_count {
  1865. // 查询该药品最后一次出库记录
  1866. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1867. //回退库存
  1868. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1869. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1870. }
  1871. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1872. var stock_max_number int64
  1873. var stock_min_number int64
  1874. if number_count >= drug.MinNumber {
  1875. stock_max_number = device_number / drug.MinNumber
  1876. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1877. stock_min_number = device_number % drug.MinNumber
  1878. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1879. } else {
  1880. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1881. }
  1882. }
  1883. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1884. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1885. }
  1886. //删除记录
  1887. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1888. //查询默认仓库剩余多少库存
  1889. var sum_count int64
  1890. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1891. for _, its := range stockInfo {
  1892. if its.MaxUnit == drug.MaxUnit {
  1893. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1894. }
  1895. sum_count += its.StockMaxNumber + its.StockMinNumber
  1896. }
  1897. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1898. }
  1899. }
  1900. }
  1901. }
  1902. }
  1903. //保存处方开药
  1904. if drugOutConfig.IsOpen == 1 {
  1905. //修改处方
  1906. for _, advice := range advices {
  1907. var drug_id int64
  1908. var prescribing_number float64
  1909. var prescribingNumberUnit string
  1910. var prescribingNumber string
  1911. var adviceId int64
  1912. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1913. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1914. }
  1915. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1916. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1917. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1918. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1919. }
  1920. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1921. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1922. }
  1923. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1924. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1925. }
  1926. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1927. if drug.ID == 0 {
  1928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1929. return
  1930. }
  1931. //查询药品的所有库存
  1932. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1933. var total_count int64
  1934. for _, it := range list {
  1935. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1936. }
  1937. totals := strconv.FormatInt(total_count, 10)
  1938. //查询该药品是否存在开药记录
  1939. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1940. //新增处方
  1941. if advicelist.ID == 0 {
  1942. //查询最新批次库存
  1943. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1944. var batch_number_count int64
  1945. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1946. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1947. all_count, _ := strconv.ParseFloat(totals, 64)
  1948. if prescribingNumberUnit == drug.MinUnit {
  1949. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1950. if drug.IsUse != 1 {
  1951. if prescribing_number > all_count {
  1952. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1953. return
  1954. }
  1955. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1956. if prescribing_number > batch_number_all_count {
  1957. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1958. return
  1959. }
  1960. }
  1961. }
  1962. } else {
  1963. if prescribingNumberUnit == drug.MaxUnit {
  1964. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1965. num := prescribing_number * float64(drug.MinNumber)
  1966. if drug.IsUse != 1 {
  1967. if num > all_count {
  1968. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1969. return
  1970. }
  1971. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1972. if prescribing_number > batch_number_all_count {
  1973. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1974. return
  1975. }
  1976. }
  1977. }
  1978. }
  1979. }
  1980. }
  1981. //修改处方
  1982. if advicelist.ID > 0 {
  1983. //查询最新批次库存
  1984. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1985. var batch_number_count int64
  1986. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1987. var device_number int64
  1988. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1989. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1990. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1991. device_number = prescribingNumberInt * drug.MinNumber
  1992. }
  1993. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1994. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1995. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1996. device_number = prescribingNumberInt
  1997. }
  1998. var number_count int64
  1999. if prescribingNumberUnit == drug.MaxUnit {
  2000. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2001. number_count = prescribingNumberInt * drug.MinNumber
  2002. }
  2003. if prescribingNumberUnit == drug.MinUnit {
  2004. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2005. number_count = prescribingNumberInt
  2006. }
  2007. //如果修改的数量大于之前修改的数量
  2008. if (number_count - device_number) > 0 {
  2009. //如果修改的差数量 大于库存数量
  2010. if drug.IsUse != 1 {
  2011. if (number_count - device_number) > total_count {
  2012. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2013. return
  2014. }
  2015. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2016. if (number_count - device_number) > batch_number_count {
  2017. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2018. return
  2019. }
  2020. }
  2021. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2022. //查询历史出库数据总批次
  2023. // 查询该药品最后一次出库记录
  2024. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2025. var out_count int64
  2026. var in_count int64
  2027. var stock_max_number int64
  2028. var stock_min_number int64
  2029. for _, it := range outInfo {
  2030. if it.CountUnit == drug.MaxUnit {
  2031. it.Count = it.Count * drug.MinNumber
  2032. }
  2033. out_count += it.Count
  2034. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2035. stock_max_number = warehouseInfoList.StockMaxNumber
  2036. stock_min_number = warehouseInfoList.StockMinNumber
  2037. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2038. }
  2039. if out_count > 0 {
  2040. if (number_count - device_number) > in_count {
  2041. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2042. return
  2043. }
  2044. }
  2045. // 未出库
  2046. if out_count == 0 {
  2047. var sum_in_count int64
  2048. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2049. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2050. //如果修改的数量大于有库存的第一个批次
  2051. if number_count > sum_in_count {
  2052. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2053. return
  2054. }
  2055. }
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. //校验耗材库存
  2070. if goodOutConfig.IsOpen == 1 {
  2071. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2072. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2073. if len(prescriptions) > 0 {
  2074. for _, item := range prescriptions {
  2075. items := item.(map[string]interface{})
  2076. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2077. projects := items["project"].([]interface{})
  2078. if len(projects) > 0 {
  2079. for _, project := range projects {
  2080. var project_id int64
  2081. var project_type int64
  2082. var totals float64
  2083. var project_name string
  2084. var parsetotal int64
  2085. var id int64
  2086. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2087. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2088. }
  2089. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2090. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2091. }
  2092. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2093. total, _ := project.(map[string]interface{})["total"].(string)
  2094. totals, _ = strconv.ParseFloat(total, 64)
  2095. }
  2096. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2097. project_name = project.(map[string]interface{})["project_name"].(string)
  2098. }
  2099. if project_type == 3 {
  2100. //查找该耗材的出库记录
  2101. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2102. if len(goodWarehouseInfo) == 0 {
  2103. //查询耗材库存
  2104. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2105. var stock_count int64
  2106. for _, it := range list {
  2107. stock_count += it.StockCount
  2108. }
  2109. stock_counts := strconv.FormatInt(stock_count, 10)
  2110. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2111. if totals > stock_total_count {
  2112. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2113. return
  2114. }
  2115. }
  2116. if len(goodWarehouseInfo) > 0 {
  2117. //查询该患者耗材的历史数据
  2118. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2119. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2120. //数量发生改变
  2121. if parsetotal != count {
  2122. //如果现在的数量大于历史数量,就要看库存是否足够
  2123. if parsetotal > count {
  2124. //查询耗材所有库存
  2125. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2126. var stock_count int64
  2127. for _, it := range list {
  2128. stock_count += it.StockCount
  2129. }
  2130. //库存不足
  2131. if (parsetotal - count) > stock_count {
  2132. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2133. return
  2134. }
  2135. }
  2136. }
  2137. }
  2138. }
  2139. }
  2140. }
  2141. }
  2142. }
  2143. }
  2144. }
  2145. }
  2146. //不使用耗材保存处方出库
  2147. if goodOutConfig.IsOpen != 1 {
  2148. if stockConfig.IsOpen == 1 {
  2149. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2150. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2151. if len(prescriptions) > 0 {
  2152. for _, item := range prescriptions {
  2153. items := item.(map[string]interface{})
  2154. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2155. projects := items["project"].([]interface{})
  2156. if len(projects) > 0 {
  2157. for _, project := range projects {
  2158. var project_id int64
  2159. var project_type int64
  2160. var totals float64
  2161. var project_name string
  2162. var parsetotal int64
  2163. var id int64
  2164. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2165. id = int64(project.(map[string]interface{})["id"].(float64))
  2166. }
  2167. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2168. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2169. }
  2170. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2171. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2172. }
  2173. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2174. total, _ := project.(map[string]interface{})["total"].(string)
  2175. totals, _ = strconv.ParseFloat(total, 64)
  2176. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2177. }
  2178. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2179. project_name = project.(map[string]interface{})["project_name"].(string)
  2180. }
  2181. if project_type == 3 {
  2182. //查找该耗材的出库记录
  2183. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2184. //没有出库记录
  2185. if len(goodWarehouseInfo) == 0 {
  2186. //查询耗材库存
  2187. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2188. var stock_count int64
  2189. for _, it := range list {
  2190. stock_count += it.StockCount
  2191. }
  2192. stock_counts := strconv.FormatInt(stock_count, 10)
  2193. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2194. if totals > stock_total_count {
  2195. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2196. return
  2197. }
  2198. //查找今日该患者已经出库的所有耗材
  2199. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2200. for _, item := range goodList {
  2201. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2202. var flush_count int64
  2203. for _, it := range goodListSix {
  2204. flush_count += it.StockCount
  2205. }
  2206. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2207. creater := adminInfo.AdminUser.Id
  2208. if errs != nil {
  2209. goodErrcode := models.XtGoodErrcode{
  2210. UserOrgId: item.OrgId,
  2211. Errcode: "手动出库更新剩余出库失败",
  2212. GoodId: item.GoodId,
  2213. Status: 1,
  2214. Ctime: time.Now().Unix(),
  2215. Mtime: 0,
  2216. Count: 0,
  2217. StockCount: 0,
  2218. Creater: creater,
  2219. BatchNumberId: 0,
  2220. WarehouseOutId: 0,
  2221. }
  2222. service.CreateGoodErrcode(goodErrcode)
  2223. }
  2224. }
  2225. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2226. }
  2227. //有出库记录
  2228. if len(goodWarehouseInfo) > 0 {
  2229. //查询该患者耗材的历史数据
  2230. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2231. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2232. //数量发生改变
  2233. if parsetotal != count {
  2234. //查找今日该患者已经出库的所有耗材
  2235. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2236. for _, item := range goodList {
  2237. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2238. var flush_count int64
  2239. for _, it := range goodListSix {
  2240. flush_count += it.StockCount
  2241. }
  2242. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2243. //减少出库数量
  2244. creater := adminInfo.AdminUser.Id
  2245. if errs != nil {
  2246. goodErrcode := models.XtGoodErrcode{
  2247. UserOrgId: item.OrgId,
  2248. Errcode: "手动出库更新剩余出库失败",
  2249. GoodId: item.GoodId,
  2250. Status: 1,
  2251. Ctime: time.Now().Unix(),
  2252. Mtime: 0,
  2253. Count: 0,
  2254. StockCount: 0,
  2255. Creater: creater,
  2256. BatchNumberId: 0,
  2257. WarehouseOutId: 0,
  2258. }
  2259. service.CreateGoodErrcode(goodErrcode)
  2260. }
  2261. //查询默认仓库
  2262. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2263. var total_count int64
  2264. for _, it := range stockList {
  2265. total_count += it.StockCount
  2266. }
  2267. //基础库插入数据
  2268. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2269. }
  2270. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2271. }
  2272. }
  2273. }
  2274. }
  2275. }
  2276. }
  2277. }
  2278. }
  2279. }
  2280. }
  2281. }
  2282. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2283. var hpInfo models.HisPrescriptionInfo
  2284. if info.ID == 0 {
  2285. var randNum int
  2286. randNum = rand.Intn(10000) + 1000
  2287. timestamp := time.Now().Unix()
  2288. tempTime := time.Unix(timestamp, 0)
  2289. timeFormat := tempTime.Format("20060102150405")
  2290. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2291. hpInfo = models.HisPrescriptionInfo{
  2292. HisPatientId: his_patient_id,
  2293. UserOrgId: adminInfo.CurrentOrgId,
  2294. RecordDate: theTime.Unix(),
  2295. PatientId: patient_id,
  2296. Status: 1,
  2297. Ctime: time.Now().Unix(),
  2298. Mtime: time.Now().Unix(),
  2299. Creator: adminInfo.AdminUser.Id,
  2300. Modifier: adminInfo.AdminUser.Id,
  2301. Diagnosis: diagnose,
  2302. SickHistory: sick_history,
  2303. Departments: department,
  2304. RegisterType: reg_type,
  2305. PrescriptionNumber: p_number,
  2306. PrescriptionStatus: 1,
  2307. Doctor: role.UserName,
  2308. DoctorId: doctor_id,
  2309. SickType: sick_type,
  2310. PType: p_type,
  2311. PatientDiagnosis: patient_diagnose,
  2312. }
  2313. service.SavePatientPrescriptionInfo(hpInfo)
  2314. //创建步骤表
  2315. finish := models.XtDialysisFinish{
  2316. IsFinish: 1,
  2317. UserOrgId: adminInfo.CurrentOrgId,
  2318. Status: 1,
  2319. Ctime: time.Now().Unix(),
  2320. Mtime: 0,
  2321. Module: 4,
  2322. RecordDate: theTime.Unix(),
  2323. Sourse: 1,
  2324. PatientId: patient_id,
  2325. }
  2326. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2327. if dialysisFinish.ID == 0 {
  2328. service.CreateDialysisFinish(finish)
  2329. }
  2330. redis := service.RedisClient()
  2331. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2332. redis.Set(key, "", time.Second)
  2333. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2334. redis.Set(keyOne, "", time.Second)
  2335. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2336. redis.Set(keySeven, "", time.Second)
  2337. defer redis.Close()
  2338. } else {
  2339. hpInfo = models.HisPrescriptionInfo{
  2340. ID: info.ID,
  2341. UserOrgId: adminInfo.CurrentOrgId,
  2342. RecordDate: info.RecordDate,
  2343. PatientId: info.PatientId,
  2344. Status: 1,
  2345. Ctime: info.Ctime,
  2346. Mtime: time.Now().Unix(),
  2347. Creator: info.Creator,
  2348. Modifier: adminInfo.AdminUser.Id,
  2349. Diagnosis: diagnose,
  2350. SickHistory: sick_history,
  2351. Departments: department,
  2352. RegisterType: reg_type,
  2353. PrescriptionNumber: info.PrescriptionNumber,
  2354. Doctor: role.UserName,
  2355. PrescriptionStatus: info.PrescriptionStatus,
  2356. DoctorId: doctor_id,
  2357. SickType: sick_type,
  2358. PType: info.PType,
  2359. HisPatientId: info.HisPatientId,
  2360. PatientDiagnosis: patient_diagnose,
  2361. }
  2362. service.SavePatientPrescriptionInfo(hpInfo)
  2363. //创建步骤表
  2364. finish := models.XtDialysisFinish{
  2365. IsFinish: 1,
  2366. UserOrgId: adminInfo.CurrentOrgId,
  2367. Status: 1,
  2368. Ctime: time.Now().Unix(),
  2369. Mtime: 0,
  2370. Module: 4,
  2371. RecordDate: info.RecordDate,
  2372. Sourse: 1,
  2373. PatientId: info.PatientId,
  2374. }
  2375. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2376. if dialysisFinish.ID == 0 {
  2377. service.CreateDialysisFinish(finish)
  2378. }
  2379. redis := service.RedisClient()
  2380. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2381. redis.Set(key, "", time.Second)
  2382. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2383. redis.Set(keyOne, "", time.Second)
  2384. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2385. redis.Set(keySeven, "", time.Second)
  2386. defer redis.Close()
  2387. }
  2388. //定义切片
  2389. var adviceList []models.HisDoctorAdviceInfo
  2390. var projectList []models.HisPrescriptionProject
  2391. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2392. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2393. var tempPrescription *models.HisPrescription
  2394. if len(prescriptions) > 0 {
  2395. for _, item := range prescriptions {
  2396. items := item.(map[string]interface{})
  2397. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2398. utils.ErrorLog("id")
  2399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2400. return
  2401. }
  2402. id := int64(items["id"].(float64))
  2403. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2404. tempPrescription = &new_prescription
  2405. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2406. utils.ErrorLog("type")
  2407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2408. return
  2409. }
  2410. types := int64(items["type"].(float64))
  2411. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2412. utils.ErrorLog("med_type")
  2413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2414. return
  2415. }
  2416. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2417. if med_type == "0" {
  2418. med_type = "14"
  2419. }
  2420. //if order_status == 0 {
  2421. // order_status = 1
  2422. //}
  2423. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2424. utils.ErrorLog("pre_time")
  2425. }
  2426. preTime, _ := items["pre_time"].(string)
  2427. timeLayout := "2006-01-02"
  2428. loc, _ := time.LoadLocation("Local")
  2429. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2430. if err != nil {
  2431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2432. return
  2433. }
  2434. pTime := theTime2.Unix()
  2435. ctime := time.Now().Unix()
  2436. if tempPrescription.ID == 0 {
  2437. prescription := &models.HisPrescription{
  2438. ID: 0,
  2439. PatientId: patient_id,
  2440. UserOrgId: adminInfo.CurrentOrgId,
  2441. RecordDate: recordDateTime,
  2442. Ctime: ctime,
  2443. Mtime: ctime,
  2444. Type: types,
  2445. Modifier: adminInfo.AdminUser.Id,
  2446. Creator: adminInfo.AdminUser.Id,
  2447. Status: 1,
  2448. Doctor: role.UserName,
  2449. HisPatientId: his_patient_id,
  2450. OrderStatus: 1,
  2451. BatchNumber: "",
  2452. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2453. PreTime: pTime,
  2454. PType: p_type,
  2455. MedType: med_type,
  2456. }
  2457. tempPrescription = prescription
  2458. service.SaveHisPrescription(tempPrescription)
  2459. redis := service.RedisClient()
  2460. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2461. redis.Set(key, "", time.Second)
  2462. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2463. redis.Set(keyOne, "", time.Second)
  2464. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2465. redis.Set(keySeven, "", time.Second)
  2466. defer redis.Close()
  2467. } else {
  2468. tempPrescription.ID = id
  2469. tempPrescription.Type = types
  2470. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2471. tempPrescription.Mtime = time.Now().Unix()
  2472. tempPrescription.Doctor = role.UserName
  2473. //tempPrescription.OrderStatus = order_status
  2474. tempPrescription.PreTime = pTime
  2475. tempPrescription.MedType = med_type
  2476. service.SaveHisPrescription(tempPrescription)
  2477. redis := service.RedisClient()
  2478. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2479. redis.Set(key, "", time.Second)
  2480. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2481. redis.Set(keyOne, "", time.Second)
  2482. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2483. redis.Set(keySeven, "", time.Second)
  2484. defer redis.Close()
  2485. }
  2486. //service.SaveHisPrescription(prescription)
  2487. //更改患者挂号状态
  2488. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2489. fmt.Println("更改失败", err2)
  2490. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2491. advices := items["advices"].([]interface{})
  2492. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2493. groupNo := int64(0)
  2494. ctime := time.Now().Unix()
  2495. mtime := ctime
  2496. if len(advices) > 0 {
  2497. for _, advice := range advices {
  2498. var s models.HisDoctorAdviceInfo
  2499. s.PrescriptionId = tempPrescription.ID
  2500. s.AdviceType = 2
  2501. s.AdviceDoctor = doctor_id
  2502. s.StopState = 2
  2503. s.ExecutionState = 2
  2504. s.AdviceDate = recordDateTime
  2505. s.Status = 1
  2506. s.UserOrgId = adminInfo.CurrentOrgId
  2507. s.RecordDate = recordDateTime
  2508. s.StartTime = tempPrescription.PreTime
  2509. s.Groupno = groupNo
  2510. s.CreatedTime = ctime
  2511. s.UpdatedTime = mtime
  2512. s.PatientId = patient_id
  2513. s.HisPatientId = his_patient_id
  2514. s.StartTime = pTime
  2515. s.IsSettle = 2
  2516. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2517. if errcode > 0 {
  2518. c.ServeFailJSONWithSGJErrorCode(errcode)
  2519. return
  2520. }
  2521. s.StartTime = pTime
  2522. var total_count int64 //处方总库存
  2523. //查询改药品信息
  2524. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2525. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2526. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2527. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2528. total_count += prescribingNumberSeven * medical.MinNumber
  2529. }
  2530. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2531. total_count += prescribingNumberSeven
  2532. }
  2533. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2534. total_count += prescribingNumberSeven
  2535. }
  2536. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2537. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2538. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2539. if s.Price != lastWarehouse.RetailPrice {
  2540. s.Price = lastWarehouse.RetailPrice
  2541. }
  2542. }
  2543. service.CreateHisDoctorAdvice(&s)
  2544. //存储切片中
  2545. adviceList = append(adviceList, s)
  2546. redis := service.RedisClient()
  2547. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2548. redis.Set(key, "", time.Second)
  2549. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2550. redis.Set(keyOne, "", time.Second)
  2551. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2552. redis.Set(keySeven, "", time.Second)
  2553. var randNum int
  2554. randNum = rand.Intn(10000) + 1000
  2555. timestamp := time.Now().Unix()
  2556. tempTime := time.Unix(timestamp, 0)
  2557. timeFormat := tempTime.Format("20060102150405")
  2558. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2559. service.CreateHisDoctorAdvice(&s)
  2560. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2561. redis.Set(keySix, "", time.Second)
  2562. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2563. redis.Set(keyFive, "", time.Second)
  2564. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2565. redis.Set(keyEight, "", time.Second)
  2566. defer redis.Close()
  2567. }
  2568. }
  2569. }
  2570. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2571. projects := items["project"].([]interface{})
  2572. if len(projects) > 0 {
  2573. for _, project := range projects {
  2574. var p models.HisPrescriptionProject
  2575. p.PrescriptionId = tempPrescription.ID
  2576. p.Ctime = time.Now().Unix()
  2577. p.Mtime = time.Now().Unix()
  2578. p.PatientId = patient_id
  2579. p.RecordDate = recordDateTime
  2580. p.Doctor = doctor_id
  2581. p.UserOrgId = adminInfo.CurrentOrgId
  2582. p.HisPatientId = his_patient_id
  2583. p.Status = 1
  2584. p.StartTime = pTime
  2585. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2586. if errcode > 0 {
  2587. c.ServeFailJSONWithSGJErrorCode(errcode)
  2588. return
  2589. }
  2590. if p.ID == 0 {
  2591. p.IsOut = 2
  2592. }
  2593. if p.ID > 0 {
  2594. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2595. p.IsOut = projectDetail.IsOut
  2596. }
  2597. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2598. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2599. if p.Type == 3 {
  2600. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2601. if p.Price != lastWarehouse.PackingPrice {
  2602. p.Price = lastWarehouse.PackingPrice
  2603. }
  2604. }
  2605. }
  2606. service.CreateHisProjectTwo(&p)
  2607. projectList = append(projectList, p)
  2608. var randNum int
  2609. randNum = rand.Intn(10000) + 1000
  2610. timestamp := time.Now().Unix()
  2611. tempTime := time.Unix(timestamp, 0)
  2612. timeFormat := tempTime.Format("20060102150405")
  2613. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2614. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2615. //新增或者编辑项目,修改对应的标签数据
  2616. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2617. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2618. var label models.HisLabelPrintInfo
  2619. project, _ := service.GetProjectDetail(p.ProjectId)
  2620. if project.CostClassify == 3 { //类别为检验检查
  2621. if p.TeamId > 0 { //检验检查组套
  2622. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2623. if tempLabel.ID == 0 {
  2624. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2625. label.Number = tempPrescription.PrescriptionNumber
  2626. label.ProjectId = project.ID
  2627. label.Status = 1
  2628. label.IsPrint = 2
  2629. label.DoctorId = info.DoctorId
  2630. label.UserOrgId = p.UserOrgId
  2631. label.PatientId = patient_id
  2632. label.RecordDate = recordDateTime
  2633. label.Ctime = time.Now().Unix()
  2634. label.Mtime = time.Now().Unix()
  2635. label.ItemId = p.TeamId
  2636. label.FeedetlSn = p.FeedetlSn
  2637. label.PProjectId = p.ID
  2638. label.ProjectName = team.ProjectTeam
  2639. label.PatientName = patient.Name
  2640. service.CreateHisLabelRecord(&label)
  2641. }
  2642. } else { //单条检验检查项目
  2643. label.Number = tempPrescription.PrescriptionNumber
  2644. label.ProjectId = project.ID
  2645. label.Status = 1
  2646. label.DoctorId = info.DoctorId
  2647. label.UserOrgId = p.UserOrgId
  2648. label.PatientId = patient_id
  2649. label.RecordDate = recordDateTime
  2650. label.IsPrint = 2
  2651. label.Ctime = time.Now().Unix()
  2652. label.Mtime = time.Now().Unix()
  2653. label.FeedetlSn = p.FeedetlSn
  2654. label.PProjectId = p.ID
  2655. label.ItemId = p.TeamId
  2656. label.ProjectName = project.ProjectName
  2657. label.PatientName = patient.Name
  2658. service.CreateHisLabelRecord(&label)
  2659. }
  2660. }
  2661. }
  2662. }
  2663. service.SaveHisProjectTwo(&p)
  2664. }
  2665. }
  2666. }
  2667. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2668. // addition := items["addition"].([]interface{})
  2669. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2670. // ctime := time.Now().Unix()
  2671. // mtime := ctime
  2672. // if len(addition) > 0 {
  2673. // for _, item := range addition {
  2674. // var s models.HisAdditionalCharge
  2675. // s.PrescriptionId = tempPrescription.ID
  2676. // s.Status = 1
  2677. // s.UserOrgId = adminInfo.CurrentOrgId
  2678. // s.RecordDate = recordDateTime
  2679. // s.CreatedTime = ctime
  2680. // s.UpdatedTime = mtime
  2681. // s.PatientId = patient_id
  2682. // s.HisPatientId = his_patient_id
  2683. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2684. // if errcode > 0 {
  2685. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2686. // return
  2687. // }
  2688. // service.CreateAdditionalCharge(&s)
  2689. // var randNum int
  2690. // randNum = rand.Intn(10000) + 1000
  2691. // timestamp := time.Now().Unix()
  2692. // tempTime := time.Unix(timestamp, 0)
  2693. // timeFormat := tempTime.Format("20060102150405")
  2694. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2695. // service.CreateAdditionalCharge(&s)
  2696. //
  2697. // }
  2698. // }
  2699. //}
  2700. }
  2701. }
  2702. //查询今日该患者开的药品处方
  2703. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2704. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2705. //药品出库
  2706. if drugOutConfig.IsOpen == 1 {
  2707. for _, item := range hisdoctorlist {
  2708. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2709. // 查询该药品最后一次出库记录
  2710. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2711. if len(druginfo) > 0 {
  2712. //回退库存
  2713. for _, it := range druginfo {
  2714. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2715. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2716. }
  2717. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2718. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2719. }
  2720. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2721. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2722. }
  2723. }
  2724. }
  2725. //删除记录
  2726. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2727. //查询最后一次数据
  2728. if drugOutConfig.IsOpen == 1 {
  2729. //出库
  2730. if drug.IsUse == 2 {
  2731. creater := adminInfo.AdminUser.Id
  2732. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2733. }
  2734. //更新字典里面的库存
  2735. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2736. var sum_count int64
  2737. for _, its := range stockInfo {
  2738. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2739. if its.MaxUnit == baseDrug.MaxUnit {
  2740. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2741. }
  2742. sum_count += its.StockMaxNumber + its.StockMinNumber
  2743. }
  2744. //更新基础库存
  2745. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2746. //剩余库存
  2747. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2748. }
  2749. }
  2750. }
  2751. //耗材保存处方出库
  2752. if goodOutConfig.IsOpen == 1 {
  2753. //查询今日耗材出库数量
  2754. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2755. for _, item := range hisgoodlist {
  2756. //查询历史出库数据
  2757. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2758. var out_count_five int64
  2759. for _, item := range flowGood {
  2760. out_count_five += item.Count
  2761. }
  2762. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2763. if out_count_five != parseIntCount {
  2764. //查询耗材最后一次出库记录
  2765. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2766. //查询默认出库仓库库存
  2767. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2768. if len(wareOut) > 0 {
  2769. for _, it := range wareOut {
  2770. //回退库存
  2771. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2772. //删除出库记录
  2773. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2774. }
  2775. }
  2776. timeStr := time.Now().Format("2006-01-02")
  2777. timeArr := strings.Split(timeStr, "-")
  2778. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2779. total = total + 1
  2780. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2781. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2782. number = number + total
  2783. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2784. operation_time := time.Now().Unix()
  2785. creater := c.GetAdminUserInfo().AdminUser.Id
  2786. recordDateStr := time.Now().Format("2006-01-02")
  2787. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2788. nowtime := recordDate.Unix()
  2789. warehouseOut := models.WarehouseOut{
  2790. WarehouseOutOrderNumber: warehousing_out_order,
  2791. OperationTime: operation_time,
  2792. OrgId: adminInfo.CurrentOrgId,
  2793. Creater: creater,
  2794. Ctime: time.Now().Unix(),
  2795. Status: 1,
  2796. WarehouseOutTime: nowtime,
  2797. Type: 1,
  2798. StorehouseId: storeConfig.StorehouseOutInfo,
  2799. IsCheck: 1,
  2800. IsSys: 1,
  2801. }
  2802. //查询是否生成出库单
  2803. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2804. if out.ID == 0 {
  2805. service.AddSigleWarehouseOut(&warehouseOut)
  2806. }
  2807. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2808. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2809. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2810. dialyPrepareOne := models.DialysisBeforePrepare{
  2811. GoodTypeId: goodObj.GoodTypeId,
  2812. GoodId: item.ProjectId,
  2813. PatientId: item.PatientId,
  2814. RecordDate: item.RecordDate,
  2815. UserOrgId: adminInfo.CurrentOrgId,
  2816. Count: parseIntCount,
  2817. Ctime: time.Now().Unix(),
  2818. Creater: creater,
  2819. Status: 1,
  2820. StorehouseId: houseConfig.StorehouseOutInfo,
  2821. ProjectId: item.ID,
  2822. }
  2823. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2824. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2825. //查询历史出库数据
  2826. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2827. var out_count int64
  2828. for _, item := range flowGood {
  2829. out_count += item.Count
  2830. }
  2831. //如果历史数和当前数据不想等才进行退库出库
  2832. if out_count != parseIntCount {
  2833. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2834. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2835. detail := models.AutomaticReduceDetail{
  2836. WarehouseOutId: 0,
  2837. WarehouseOutOrderNumber: "",
  2838. PatientId: item.PatientId,
  2839. Ctime: time.Now().Unix(),
  2840. Mtime: 0,
  2841. Status: 1,
  2842. RecordTime: item.RecordDate,
  2843. OrgId: item.UserOrgId,
  2844. GoodId: item.ProjectId,
  2845. GoodTypeId: 0,
  2846. Count: parseIntCount,
  2847. Type: 0,
  2848. ProjectId: item.ID,
  2849. StorehouseId: 0,
  2850. }
  2851. service.CreateAutoDetail(detail)
  2852. //查询剩余库存
  2853. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2854. var sum_count int64
  2855. for _, item := range goodList {
  2856. sum_count += item.StockCount
  2857. }
  2858. //更新剩余库存
  2859. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2860. //耗材
  2861. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2862. }
  2863. }
  2864. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2865. //查询历史出库数据
  2866. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2867. var out_count int64
  2868. for _, item := range flowGood {
  2869. out_count += item.Count
  2870. }
  2871. //如果历史数和当前数据不想等才进行退库出库
  2872. if out_count != parseIntCount {
  2873. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2874. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2875. detail := models.AutomaticReduceDetail{
  2876. WarehouseOutId: 0,
  2877. WarehouseOutOrderNumber: "",
  2878. PatientId: item.PatientId,
  2879. Ctime: time.Now().Unix(),
  2880. Mtime: 0,
  2881. Status: 1,
  2882. RecordTime: item.RecordDate,
  2883. OrgId: item.UserOrgId,
  2884. GoodId: item.ProjectId,
  2885. GoodTypeId: 0,
  2886. Count: parseIntCount,
  2887. Type: 0,
  2888. ProjectId: item.ID,
  2889. StorehouseId: 0,
  2890. }
  2891. service.CreateAutoDetail(detail)
  2892. //查询剩余库存
  2893. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2894. var sum_count int64
  2895. for _, item := range goodList {
  2896. sum_count += item.StockCount
  2897. }
  2898. //更新剩余库存
  2899. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2900. //耗材
  2901. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2902. }
  2903. }
  2904. }
  2905. }
  2906. }
  2907. }
  2908. //redisClient := service.RedisClient()
  2909. //defer redisClient.Close()
  2910. //
  2911. //list := models.HisList{
  2912. // Patient_id: patient_id,
  2913. // Advice_id:0,
  2914. // Record_date: 0,
  2915. // Advice: adviceList,
  2916. // Project: nil,
  2917. //}
  2918. //hisLis = append(hisLis, list)
  2919. //
  2920. //advice_json, _ := json.Marshal(&hisLis)
  2921. //redisClient.RPush("111", advice_json).Result()
  2922. //result, _ := redisClient.RPop("111").Result()
  2923. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2924. //
  2925. //var dat []map[string]interface{}
  2926. //json.Unmarshal([]byte(result), &dat)
  2927. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2928. //
  2929. //for k,v:=range dat{
  2930. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2931. //}
  2932. //project_json, _ := json.Marshal(&projectList)
  2933. //redisClient.LPush("222", project_json).Result()
  2934. if err == nil {
  2935. c.ServeSuccessJSON(map[string]interface{}{
  2936. "msg": "保存成功",
  2937. })
  2938. return
  2939. } else {
  2940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2941. return
  2942. }
  2943. }
  2944. func (c *HisApiController) EditHisPrescription() {
  2945. record_date := c.GetString("record_date")
  2946. patient_id, _ := c.GetInt64("patient_id")
  2947. reg_type, _ := c.GetInt64("reg_type")
  2948. //diagnose, _ := c.GetInt64("diagnose", 0)
  2949. diagnose := c.GetString("diagnose")
  2950. sick_type, _ := c.GetInt64("sick_type")
  2951. sick_history := c.GetString("sick_history")
  2952. doctor_id, _ := c.GetInt64("doctor", 0)
  2953. department, _ := c.GetInt64("department", 0)
  2954. his_patient_id, _ := c.GetInt64("his_patient_id")
  2955. p_type, _ := c.GetInt64("p_type")
  2956. dataBody := make(map[string]interface{}, 0)
  2957. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2958. if err != nil {
  2959. utils.ErrorLog(err.Error())
  2960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2961. return
  2962. }
  2963. timeLayout := "2006-01-02"
  2964. loc, _ := time.LoadLocation("Local")
  2965. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2966. if err != nil {
  2967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2968. return
  2969. }
  2970. adminInfo := c.GetAdminUserInfo()
  2971. recordDateTime := theTime.Unix()
  2972. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2973. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2974. var hpInfo models.HisPrescriptionInfo
  2975. if info.ID == 0 {
  2976. var randNum int
  2977. randNum = rand.Intn(10000) + 1000
  2978. timestamp := time.Now().Unix()
  2979. tempTime := time.Unix(timestamp, 0)
  2980. timeFormat := tempTime.Format("20060102150405")
  2981. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2982. hpInfo = models.HisPrescriptionInfo{
  2983. UserOrgId: adminInfo.CurrentOrgId,
  2984. RecordDate: theTime.Unix(),
  2985. PatientId: patient_id,
  2986. Status: 1,
  2987. Ctime: time.Now().Unix(),
  2988. Mtime: time.Now().Unix(),
  2989. Creator: adminInfo.AdminUser.Id,
  2990. Modifier: adminInfo.AdminUser.Id,
  2991. Diagnosis: diagnose,
  2992. SickHistory: sick_history,
  2993. Departments: department,
  2994. RegisterType: reg_type,
  2995. PrescriptionNumber: p_number,
  2996. PrescriptionStatus: 1,
  2997. Doctor: role.UserName,
  2998. DoctorId: doctor_id,
  2999. SickType: sick_type,
  3000. PType: p_type,
  3001. }
  3002. service.SavePatientPrescriptionInfo(hpInfo)
  3003. } else {
  3004. hpInfo = models.HisPrescriptionInfo{
  3005. ID: info.ID,
  3006. UserOrgId: adminInfo.CurrentOrgId,
  3007. RecordDate: info.RecordDate,
  3008. PatientId: info.PatientId,
  3009. Status: 1,
  3010. Ctime: info.Ctime,
  3011. Mtime: time.Now().Unix(),
  3012. Creator: info.Creator,
  3013. Modifier: adminInfo.AdminUser.Id,
  3014. Diagnosis: diagnose,
  3015. SickHistory: sick_history,
  3016. Departments: department,
  3017. RegisterType: reg_type,
  3018. PrescriptionNumber: info.PrescriptionNumber,
  3019. Doctor: role.UserName,
  3020. PrescriptionStatus: info.PrescriptionStatus,
  3021. DoctorId: doctor_id,
  3022. SickType: sick_type,
  3023. PType: info.PType,
  3024. }
  3025. service.SavePatientPrescriptionInfo(hpInfo)
  3026. }
  3027. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3028. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3029. if len(prescriptions) > 0 {
  3030. for _, item := range prescriptions {
  3031. items := item.(map[string]interface{})
  3032. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3033. utils.ErrorLog("id")
  3034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3035. return
  3036. }
  3037. id := int64(items["id"].(float64))
  3038. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3039. utils.ErrorLog("type")
  3040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3041. return
  3042. }
  3043. types := int64(items["type"].(float64))
  3044. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3045. utils.ErrorLog("med_type")
  3046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3047. return
  3048. }
  3049. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3050. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3051. ctime := time.Now().Unix()
  3052. prescription := &models.HisPrescription{
  3053. ID: id,
  3054. PatientId: patient_id,
  3055. UserOrgId: adminInfo.CurrentOrgId,
  3056. RecordDate: recordDateTime,
  3057. Ctime: ctime,
  3058. Mtime: ctime,
  3059. Type: types,
  3060. Modifier: adminInfo.AdminUser.Id,
  3061. Creator: adminInfo.AdminUser.Id,
  3062. Status: 1,
  3063. Doctor: role.UserName,
  3064. HisPatientId: his_patient_id,
  3065. OrderStatus: 1,
  3066. BatchNumber: "",
  3067. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3068. PType: hpInfo.PType,
  3069. MedType: med_type,
  3070. }
  3071. if historyPrescription.ID > 0 {
  3072. prescription.PreTime = historyPrescription.PreTime
  3073. }
  3074. service.SaveHisPrescription(prescription)
  3075. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3076. advices := items["advices"].([]interface{})
  3077. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3078. groupNo := int64(0)
  3079. ctime := time.Now().Unix()
  3080. mtime := ctime
  3081. if len(advices) > 0 {
  3082. for _, advice := range advices {
  3083. var s models.HisDoctorAdviceInfo
  3084. s.PrescriptionId = prescription.ID
  3085. s.AdviceType = 2
  3086. s.AdviceDoctor = adminInfo.AdminUser.Id
  3087. s.StopState = 2
  3088. s.ExecutionState = 2
  3089. s.AdviceDate = recordDateTime
  3090. s.Status = 1
  3091. s.UserOrgId = adminInfo.CurrentOrgId
  3092. s.RecordDate = recordDateTime
  3093. s.StartTime = prescription.PreTime
  3094. s.Groupno = groupNo
  3095. s.CreatedTime = ctime
  3096. s.UpdatedTime = mtime
  3097. s.PatientId = patient_id
  3098. s.HisPatientId = his_patient_id
  3099. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3100. if errcode > 0 {
  3101. c.ServeFailJSONWithSGJErrorCode(errcode)
  3102. return
  3103. }
  3104. service.CreateHisDoctorAdvice(&s)
  3105. redis := service.RedisClient()
  3106. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3107. redis.Set(key, "", time.Second)
  3108. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3109. fmt.Println("keyOne", keyOne)
  3110. redis.Set(keyOne, "", time.Second)
  3111. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3112. redis.Set(keySeven, "", time.Second)
  3113. redis.Close()
  3114. }
  3115. }
  3116. }
  3117. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3118. projects := items["project"].([]interface{})
  3119. if len(projects) > 0 {
  3120. for _, project := range projects {
  3121. var p models.HisPrescriptionProject
  3122. p.PrescriptionId = prescription.ID
  3123. p.Ctime = time.Now().Unix()
  3124. p.Mtime = time.Now().Unix()
  3125. p.PatientId = patient_id
  3126. p.RecordDate = recordDateTime
  3127. p.UserOrgId = adminInfo.CurrentOrgId
  3128. p.HisPatientId = his_patient_id
  3129. p.Status = 1
  3130. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3131. if errcode > 0 {
  3132. c.ServeFailJSONWithSGJErrorCode(errcode)
  3133. return
  3134. }
  3135. service.CreateHisProjectTwo(&p)
  3136. }
  3137. }
  3138. }
  3139. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3140. addition := items["addition"].([]interface{})
  3141. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3142. ctime := time.Now().Unix()
  3143. mtime := ctime
  3144. if len(addition) > 0 {
  3145. for _, item := range addition {
  3146. var s models.HisAdditionalCharge
  3147. s.PrescriptionId = prescription.ID
  3148. s.Status = 1
  3149. s.UserOrgId = adminInfo.CurrentOrgId
  3150. s.RecordDate = recordDateTime
  3151. s.CreatedTime = ctime
  3152. s.UpdatedTime = mtime
  3153. s.PatientId = patient_id
  3154. s.HisPatientId = his_patient_id
  3155. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3156. if errcode > 0 {
  3157. c.ServeFailJSONWithSGJErrorCode(errcode)
  3158. return
  3159. }
  3160. service.CreateAdditionalCharge(&s)
  3161. }
  3162. }
  3163. }
  3164. }
  3165. }
  3166. }
  3167. if err == nil {
  3168. c.ServeSuccessJSON(map[string]interface{}{
  3169. "msg": "保存成功",
  3170. })
  3171. return
  3172. } else {
  3173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3174. return
  3175. }
  3176. }
  3177. func (c *HisApiController) DeletePrescription() {
  3178. prescription_id, _ := c.GetInt64("id")
  3179. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3180. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3181. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3182. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3183. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3184. //耗材保存处方出库
  3185. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3186. //已收费和已发药限制逻辑
  3187. isCharge := false
  3188. isMedicine := false
  3189. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3190. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3191. for _, item := range new_prescriptions {
  3192. if item.IsMedicine == 1 {
  3193. isMedicine = true
  3194. }
  3195. }
  3196. for _, item := range new_prescriptions {
  3197. if item.OrderStatus == 4 {
  3198. isCharge = true
  3199. }
  3200. }
  3201. if p_err != nil {
  3202. if new_prescription.ID > 0 {
  3203. if new_prescription.OrderStatus == 2 {
  3204. isCharge = true
  3205. }
  3206. }
  3207. }
  3208. for _, item := range advices {
  3209. if item.IsMedicine == 1 {
  3210. isMedicine = true
  3211. }
  3212. }
  3213. if isCharge {
  3214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3215. return
  3216. }
  3217. if isMedicine {
  3218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3219. return
  3220. }
  3221. //已收费和已发药限制逻辑
  3222. if len(projects) > 0 {
  3223. for _, item := range projects {
  3224. service.DeletePrintInfo(item.ID) //删除打印信息
  3225. if goodOutConfig.IsOpen != 1 {
  3226. if stockConfig.IsOpen == 1 {
  3227. if item.Type == 3 && item.IsOut == 1 {
  3228. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3229. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3230. good.Total = good.Total + f_count
  3231. service.UpdateGoodInfo(&good)
  3232. operation_time := time.Now().Unix()
  3233. creater := c.GetAdminUserInfo().AdminUser.Id
  3234. //创建退库单
  3235. timeStr := time.Now().Format("2006-01-02")
  3236. timeArr := strings.Split(timeStr, "-")
  3237. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3238. total = total + 1
  3239. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3240. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3241. cancelStock := models.CancelStock{
  3242. OrderNumber: orderNumber,
  3243. OperaTime: operation_time,
  3244. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3245. Creater: creater,
  3246. Ctime: time.Now().Unix(),
  3247. Status: 1,
  3248. ReturnTime: item.RecordDate,
  3249. Type: 1,
  3250. StorehouseId: houseConfig.StorehouseOutInfo,
  3251. IsCheck: 1,
  3252. }
  3253. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3254. if msgerrkonde == gorm.ErrRecordNotFound {
  3255. service.AddSigleCancelStock(&cancelStock)
  3256. }
  3257. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3258. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3259. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3260. //查询该耗材是否出库
  3261. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3262. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3263. deaerler, _ := service.GetDealerById(info.Dealer)
  3264. var total_count int64
  3265. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3266. total_count += count
  3267. if info.ID > 0 {
  3268. if info.Count >= total_count {
  3269. //回退库存
  3270. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3271. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3272. var flush_count int64
  3273. for _, it := range goodList {
  3274. flush_count += it.StockCount
  3275. }
  3276. cancelStockInfo := models.CancelStockInfo{
  3277. GoodId: item.ProjectId,
  3278. CancelStockId: cancel.ID,
  3279. GoodTypeId: good.GoodTypeId,
  3280. Count: prescribingNumber,
  3281. Price: info.Price,
  3282. Total: 0,
  3283. ProductDate: info.ProductDate,
  3284. ExpiryDate: info.ExpiryDate,
  3285. Ctime: time.Now().Unix(),
  3286. Status: 1,
  3287. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3288. OrderNumber: cancel.OrderNumber,
  3289. Type: 0,
  3290. Dealer: deaerler.DealerName,
  3291. Manufacturer: manufacturer.ManufacturerName,
  3292. Number: info.Number,
  3293. RegisterAccount: "",
  3294. Remark: "",
  3295. WarehouseInfoId: info.WarehouseInfotId,
  3296. PatientId: info.PatientId,
  3297. RecordDate: info.SysRecordTime,
  3298. StorehouseId: houseConfig.StorehouseOutInfo,
  3299. IsCheck: 1,
  3300. }
  3301. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3302. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3303. flow := models.VmStockFlow{
  3304. WarehousingId: info.WarehouseInfotId,
  3305. GoodId: item.ProjectId,
  3306. Number: info.Number,
  3307. LicenseNumber: info.LicenseNumber,
  3308. Count: prescribingNumber,
  3309. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3310. PatientId: item.PatientId,
  3311. SystemTime: info.SysRecordTime,
  3312. ConsumableType: 7,
  3313. IsSys: 0,
  3314. WarehousingOrder: "",
  3315. WarehouseOutId: info.WarehouseOutId,
  3316. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3317. IsEdit: 0,
  3318. CancelStockId: cancel.ID,
  3319. CancelOrderNumber: cancel.OrderNumber,
  3320. Manufacturer: manufacturer.ID,
  3321. Dealer: 0,
  3322. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3323. UpdateCreator: 0,
  3324. Status: 1,
  3325. Ctime: time.Now().Unix(),
  3326. Mtime: 0,
  3327. Price: info.Price,
  3328. WarehousingDetailId: info.WarehouseInfotId,
  3329. WarehouseOutDetailId: info.ID,
  3330. CancelOutDetailId: cancelInfo.ID,
  3331. ProductDate: info.ProductDate,
  3332. ExpireDate: info.ExpiryDate,
  3333. StorehouseId: houseConfig.StorehouseOutInfo,
  3334. OverCount: flush_count,
  3335. }
  3336. service.CreateStockFlowOne(flow)
  3337. //退库数量增加
  3338. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3339. //出库数量减少
  3340. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3341. }
  3342. if info.Count < total_count {
  3343. //回退库存
  3344. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3345. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3346. var flush_count int64
  3347. for _, it := range goodList {
  3348. flush_count += it.StockCount
  3349. }
  3350. cancelStockInfo := models.CancelStockInfo{
  3351. GoodId: item.ProjectId,
  3352. CancelStockId: cancel.ID,
  3353. GoodTypeId: good.GoodTypeId,
  3354. Count: info.Count,
  3355. Price: info.Price,
  3356. Total: 0,
  3357. ProductDate: info.ProductDate,
  3358. ExpiryDate: info.ExpiryDate,
  3359. Ctime: time.Now().Unix(),
  3360. Status: 1,
  3361. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3362. OrderNumber: cancel.OrderNumber,
  3363. Type: 0,
  3364. Dealer: deaerler.DealerName,
  3365. Manufacturer: manufacturer.ManufacturerName,
  3366. Number: info.Number,
  3367. RegisterAccount: "",
  3368. Remark: "",
  3369. WarehouseInfoId: info.WarehouseInfotId,
  3370. PatientId: info.PatientId,
  3371. RecordDate: info.SysRecordTime,
  3372. StorehouseId: houseConfig.StorehouseOutInfo,
  3373. IsCheck: 1,
  3374. }
  3375. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3376. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3377. flow := models.VmStockFlow{
  3378. WarehousingId: info.WarehouseInfotId,
  3379. GoodId: item.ProjectId,
  3380. Number: info.Number,
  3381. LicenseNumber: info.LicenseNumber,
  3382. Count: info.Count,
  3383. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3384. PatientId: item.PatientId,
  3385. SystemTime: info.SysRecordTime,
  3386. ConsumableType: 7,
  3387. IsSys: 0,
  3388. WarehousingOrder: "",
  3389. WarehouseOutId: info.WarehouseOutId,
  3390. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3391. IsEdit: 0,
  3392. CancelStockId: cancel.ID,
  3393. CancelOrderNumber: cancel.OrderNumber,
  3394. Manufacturer: manufacturer.ID,
  3395. Dealer: 0,
  3396. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3397. UpdateCreator: 0,
  3398. Status: 1,
  3399. Ctime: time.Now().Unix(),
  3400. Mtime: 0,
  3401. Price: info.Price,
  3402. WarehousingDetailId: info.WarehouseInfotId,
  3403. WarehouseOutDetailId: info.ID,
  3404. CancelOutDetailId: cancelInfo.ID,
  3405. ProductDate: info.ProductDate,
  3406. ExpireDate: info.ExpiryDate,
  3407. StorehouseId: houseConfig.StorehouseOutInfo,
  3408. OverCount: flush_count,
  3409. }
  3410. service.CreateStockFlowOne(flow)
  3411. //退库数量增加
  3412. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3413. //出库数量减少
  3414. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3415. }
  3416. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3417. var flush_count int64
  3418. for _, it := range goodList {
  3419. flush_count += it.StockCount
  3420. }
  3421. //查询已出库数量
  3422. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3423. if prescribingNumber < dialysisInfo.Count {
  3424. //改变数量
  3425. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3426. }
  3427. if prescribingNumber >= dialysisInfo.Count {
  3428. //删除出库表
  3429. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3430. }
  3431. //更新库存
  3432. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3433. //更新基础库库存
  3434. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3435. }
  3436. }
  3437. }
  3438. }
  3439. //保存耗材出库
  3440. if goodOutConfig.IsOpen == 1 {
  3441. if item.Type == 3 {
  3442. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3443. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3444. good.Total = good.Total + f_count
  3445. service.UpdateGoodInfo(&good)
  3446. operation_time := time.Now().Unix()
  3447. creater := c.GetAdminUserInfo().AdminUser.Id
  3448. //创建退库单
  3449. timeStr := time.Now().Format("2006-01-02")
  3450. timeArr := strings.Split(timeStr, "-")
  3451. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3452. total = total + 1
  3453. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3454. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3455. cancelStock := models.CancelStock{
  3456. OrderNumber: orderNumber,
  3457. OperaTime: operation_time,
  3458. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3459. Creater: creater,
  3460. Ctime: time.Now().Unix(),
  3461. Status: 1,
  3462. ReturnTime: item.RecordDate,
  3463. Type: 1,
  3464. StorehouseId: houseConfig.StorehouseOutInfo,
  3465. IsCheck: 1,
  3466. }
  3467. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3468. if msgerrkonde == gorm.ErrRecordNotFound {
  3469. service.AddSigleCancelStock(&cancelStock)
  3470. }
  3471. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3472. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3473. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3474. //查询该耗材是否出库
  3475. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3476. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3477. deaerler, _ := service.GetDealerById(info.Dealer)
  3478. var total_count int64
  3479. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3480. total_count += count
  3481. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3482. var flush_count int64
  3483. for _, it := range goodList {
  3484. flush_count += it.StockCount
  3485. }
  3486. fmt.Println("历史出库数据", info.Count)
  3487. fmt.Println("出库数量", total_count)
  3488. if info.ID > 0 {
  3489. cancelStockInfo := models.CancelStockInfo{
  3490. GoodId: item.ProjectId,
  3491. CancelStockId: cancel.ID,
  3492. GoodTypeId: good.GoodTypeId,
  3493. Count: prescribingNumber,
  3494. Price: info.Price,
  3495. Total: 0,
  3496. ProductDate: info.ProductDate,
  3497. ExpiryDate: info.ExpiryDate,
  3498. Ctime: time.Now().Unix(),
  3499. Status: 1,
  3500. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3501. OrderNumber: cancel.OrderNumber,
  3502. Type: 0,
  3503. Dealer: deaerler.DealerName,
  3504. Manufacturer: manufacturer.ManufacturerName,
  3505. Number: info.Number,
  3506. RegisterAccount: "",
  3507. Remark: "",
  3508. WarehouseInfoId: info.WarehouseInfotId,
  3509. PatientId: info.PatientId,
  3510. RecordDate: info.SysRecordTime,
  3511. StorehouseId: houseConfig.StorehouseOutInfo,
  3512. IsCheck: 1,
  3513. }
  3514. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3515. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3516. //查询出库数量
  3517. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3518. //出库数据 大于 退库数量
  3519. if len(list) > 0 {
  3520. for _, it := range list {
  3521. //回退库存
  3522. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3523. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3524. var flush_count_one int64
  3525. for _, it := range goodList {
  3526. flush_count_one += it.StockCount
  3527. }
  3528. //查询该批次是否有退库数据
  3529. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3530. creater := c.GetAdminUserInfo().AdminUser.Id
  3531. flow := models.VmStockFlow{
  3532. WarehousingId: it.WarehouseInfotId,
  3533. GoodId: it.GoodId,
  3534. Number: it.Number,
  3535. LicenseNumber: it.LicenseNumber,
  3536. Count: it.Count,
  3537. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3538. PatientId: it.PatientId,
  3539. SystemTime: it.SysRecordTime,
  3540. ConsumableType: 7,
  3541. IsSys: 0,
  3542. WarehousingOrder: "",
  3543. WarehouseOutId: it.WarehouseOutId,
  3544. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3545. IsEdit: 0,
  3546. CancelStockId: cancel.ID,
  3547. CancelOrderNumber: cancel.OrderNumber,
  3548. Manufacturer: manufacturer.ID,
  3549. Dealer: 0,
  3550. Creator: creater,
  3551. UpdateCreator: 0,
  3552. Status: 1,
  3553. Ctime: time.Now().Unix(),
  3554. Mtime: 0,
  3555. Price: it.Price,
  3556. WarehousingDetailId: it.WarehouseInfotId,
  3557. WarehouseOutDetailId: it.ID,
  3558. CancelOutDetailId: cancelInfo.ID,
  3559. ProductDate: it.ProductDate,
  3560. ExpireDate: it.ExpiryDate,
  3561. StorehouseId: houseConfig.StorehouseOutInfo,
  3562. OverCount: flush_count_one,
  3563. }
  3564. service.CreateStockFlowOne(flow)
  3565. //if flow.ID > 0 {
  3566. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3567. //}
  3568. }
  3569. }
  3570. //flow := models.VmStockFlow{
  3571. // WarehousingId: info.WarehouseInfotId,
  3572. // GoodId: item.ProjectId,
  3573. // Number: info.Number,
  3574. // LicenseNumber: info.LicenseNumber,
  3575. // Count: prescribingNumber,
  3576. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3577. // PatientId: item.PatientId,
  3578. // SystemTime: info.SysRecordTime,
  3579. // ConsumableType: 7,
  3580. // IsSys: 0,
  3581. // WarehousingOrder: "",
  3582. // WarehouseOutId: info.WarehouseOutId,
  3583. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3584. // IsEdit: 0,
  3585. // CancelStockId: cancel.ID,
  3586. // CancelOrderNumber: cancel.OrderNumber,
  3587. // Manufacturer: manufacturer.ID,
  3588. // Dealer: 0,
  3589. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3590. // UpdateCreator: 0,
  3591. // Status: 1,
  3592. // Ctime: time.Now().Unix(),
  3593. // Mtime: 0,
  3594. // Price: info.Price,
  3595. // WarehousingDetailId: info.WarehouseInfotId,
  3596. // WarehouseOutDetailId: info.ID,
  3597. // CancelOutDetailId: cancelInfo.ID,
  3598. // ProductDate: info.ProductDate,
  3599. // ExpireDate: info.ExpiryDate,
  3600. // StorehouseId: houseConfig.StorehouseOutInfo,
  3601. // OverCount: flush_count,
  3602. //}
  3603. //service.CreateStockFlowOne(flow)
  3604. //退库数量增加
  3605. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3606. //出库数量减少
  3607. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3608. //查询已出库数量
  3609. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3610. if prescribingNumber < dialysisInfo.Count {
  3611. //改变数量
  3612. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3613. }
  3614. if prescribingNumber >= dialysisInfo.Count {
  3615. //删除出库表
  3616. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3617. }
  3618. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3619. var flush_count_one int64
  3620. for _, it := range goodList {
  3621. flush_count_one += it.StockCount
  3622. }
  3623. //更新库存
  3624. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3625. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3626. //更新基础库库存
  3627. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3628. }
  3629. }
  3630. }
  3631. }
  3632. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3633. fmt.Println(err)
  3634. }
  3635. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3636. fmt.Println(err)
  3637. if len(advices) > 0 {
  3638. for _, item := range advices {
  3639. redis := service.RedisClient()
  3640. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3641. redis.Set(keyFive, "", time.Second)
  3642. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3643. redis.Set(keyOne, "", time.Second)
  3644. redis.Close()
  3645. }
  3646. }
  3647. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3648. if len(advices) > 0 {
  3649. for _, item := range advices {
  3650. creater := c.GetAdminUserInfo().AdminUser.Id
  3651. service.DrugAutoAddCancelInfo(item, creater)
  3652. }
  3653. }
  3654. } else {
  3655. if drugOutConfig.IsOpen == 1 {
  3656. if len(advices) > 0 {
  3657. for _, item := range advices {
  3658. creater := c.GetAdminUserInfo().AdminUser.Id
  3659. service.DrugAutoAddCancelInfo(item, creater)
  3660. }
  3661. }
  3662. } else {
  3663. if len(advices) > 0 {
  3664. for _, item := range advices {
  3665. creater := c.GetAdminUserInfo().AdminUser.Id
  3666. service.DrugAutoAddCancelInfo(item, creater)
  3667. }
  3668. }
  3669. }
  3670. }
  3671. c.ServeSuccessJSON(map[string]interface{}{
  3672. "msg": "删除成功",
  3673. })
  3674. return
  3675. }
  3676. func (c *HisApiController) DeleteDoctorAdvice() {
  3677. id, _ := c.GetInt64("id")
  3678. advice, _ := service.GetHisDoctorAdvicesById(id)
  3679. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3680. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3681. //已收费和已发药的限制逻辑
  3682. isCharge := false
  3683. isMedicine := false
  3684. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3685. //获取今天该患者所有处方,判断是否发药或者收费
  3686. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3687. for _, item := range new_prescriptions {
  3688. if item.IsMedicine == 1 {
  3689. isMedicine = true
  3690. }
  3691. }
  3692. for _, item := range new_prescriptions {
  3693. if item.OrderStatus == 4 {
  3694. isCharge = true
  3695. }
  3696. }
  3697. if isMedicine {
  3698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3699. return
  3700. }
  3701. if isCharge {
  3702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3703. return
  3704. }
  3705. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3706. for _, item := range advices {
  3707. if item.IsMedicine == 1 {
  3708. isMedicine = true
  3709. }
  3710. }
  3711. if isMedicine {
  3712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3713. return
  3714. }
  3715. if new_prescription.ID > 0 {
  3716. if new_prescription.OrderStatus == 2 {
  3717. isCharge = true
  3718. }
  3719. }
  3720. if isCharge {
  3721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3722. return
  3723. }
  3724. //已收费和已发药的限制逻辑
  3725. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3726. redis := service.RedisClient()
  3727. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3728. redis.Set(keyFive, "", time.Second)
  3729. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3730. redis.Set(keyOne, "", time.Second)
  3731. defer redis.Close()
  3732. if err == nil {
  3733. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3734. //查询是否在处方中出库
  3735. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3736. if openConfig.IsOpen != 1 {
  3737. //判断该医嘱是否执行了
  3738. if advice.ExecutionState == 1 {
  3739. creater := c.GetAdminUserInfo().AdminUser.Id
  3740. service.DrugAutoAddCancelInfo(&advice, creater)
  3741. }
  3742. }
  3743. //开启保存处方扣减功能
  3744. if openConfig.IsOpen == 1 {
  3745. creater := c.GetAdminUserInfo().AdminUser.Id
  3746. service.DrugAutoAddCancelInfo(&advice, creater)
  3747. }
  3748. } else {
  3749. if drugOutConfig.IsOpen == 1 {
  3750. //查询是否在处方中出库
  3751. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3752. if openConfig.IsOpen != 1 {
  3753. //判断该医嘱是否执行了
  3754. if advice.ExecutionState == 1 {
  3755. creater := c.GetAdminUserInfo().AdminUser.Id
  3756. service.DrugAutoAddCancelInfo(&advice, creater)
  3757. }
  3758. }
  3759. //开启保存处方扣减功能
  3760. if openConfig.IsOpen == 1 {
  3761. creater := c.GetAdminUserInfo().AdminUser.Id
  3762. service.DrugAutoAddCancelInfo(&advice, creater)
  3763. }
  3764. } else {
  3765. //判断该医嘱是否执行了
  3766. if advice.ExecutionState == 1 {
  3767. creater := c.GetAdminUserInfo().AdminUser.Id
  3768. service.DrugAutoAddCancelInfo(&advice, creater)
  3769. }
  3770. }
  3771. }
  3772. c.ServeSuccessJSON(map[string]interface{}{
  3773. "msg": "删除成功",
  3774. })
  3775. return
  3776. } else {
  3777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3778. return
  3779. }
  3780. }
  3781. func (c *HisApiController) DeleteProject() {
  3782. id, _ := c.GetInt64("id")
  3783. adminInfo := c.GetAdminUserInfo()
  3784. project, _ := service.GetHisProjectByID(id)
  3785. // var consumable models.DialysisBeforePrepare
  3786. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3787. //耗材保存处方出库
  3788. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3789. isCharge := false
  3790. isMedicine := false
  3791. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3792. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3793. for _, item := range new_prescriptions {
  3794. if item.IsMedicine == 1 {
  3795. isMedicine = true
  3796. }
  3797. }
  3798. for _, item := range new_prescriptions {
  3799. if item.OrderStatus == 4 {
  3800. isCharge = true
  3801. }
  3802. }
  3803. if isMedicine {
  3804. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3805. return
  3806. }
  3807. if isCharge {
  3808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3809. return
  3810. }
  3811. if new_prescription.ID > 0 {
  3812. if new_prescription.OrderStatus == 2 {
  3813. isCharge = true
  3814. }
  3815. }
  3816. if isCharge {
  3817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3818. return
  3819. }
  3820. service.DeletePrintInfo(id)
  3821. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3822. label.Status = 0
  3823. service.CreateHisLabelRecord(&label)
  3824. fmt.Println(goodOutConfig.IsOpen)
  3825. if goodOutConfig.IsOpen != 1 {
  3826. if stockConfig.IsOpen == 1 {
  3827. if project.Type == 2 {
  3828. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3829. fmt.Println(err)
  3830. }
  3831. if project.Type == 3 && project.IsOut == 1 {
  3832. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3833. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3834. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3835. operation_time := time.Now().Unix()
  3836. creater := adminInfo.AdminUser.Id
  3837. //创建退库单
  3838. timeStr := time.Now().Format("2006-01-02")
  3839. timeArr := strings.Split(timeStr, "-")
  3840. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3841. total = total + 1
  3842. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3843. cancelStock := models.CancelStock{
  3844. OrderNumber: orderNumber,
  3845. OperaTime: operation_time,
  3846. OrgId: adminInfo.CurrentOrgId,
  3847. Creater: creater,
  3848. Ctime: time.Now().Unix(),
  3849. Status: 1,
  3850. ReturnTime: project.RecordDate,
  3851. Type: 1,
  3852. StorehouseId: houseConfig.StorehouseOutInfo,
  3853. IsCheck: 1,
  3854. }
  3855. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3856. if msgerrkonde == gorm.ErrRecordNotFound {
  3857. service.AddSigleCancelStock(&cancelStock)
  3858. }
  3859. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3860. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3861. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3862. //查询是否有出库
  3863. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3864. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3865. deaerler, _ := service.GetDealerById(info.Dealer)
  3866. if info.ID > 0 {
  3867. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3868. if info.Count >= prescribingNumber {
  3869. cancelStockInfo := models.CancelStockInfo{
  3870. GoodId: project.ProjectId,
  3871. CancelStockId: cancel.ID,
  3872. GoodTypeId: good.GoodTypeId,
  3873. Count: prescribingNumber,
  3874. Price: info.Price,
  3875. Total: 0,
  3876. ProductDate: info.ProductDate,
  3877. ExpiryDate: info.ExpiryDate,
  3878. Ctime: time.Now().Unix(),
  3879. Status: 1,
  3880. OrgId: adminInfo.CurrentOrgId,
  3881. OrderNumber: cancel.OrderNumber,
  3882. Type: 0,
  3883. Dealer: deaerler.DealerName,
  3884. Manufacturer: manufacturer.ManufacturerName,
  3885. Number: info.Number,
  3886. RegisterAccount: "",
  3887. Remark: "",
  3888. WarehouseInfoId: info.WarehouseInfotId,
  3889. PatientId: info.PatientId,
  3890. RecordDate: info.SysRecordTime,
  3891. StorehouseId: houseConfig.StorehouseOutInfo,
  3892. IsCheck: 1,
  3893. }
  3894. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3895. //回退库存
  3896. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3897. //退库数量增加
  3898. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3899. //出库数量减少
  3900. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3901. }
  3902. if info.Count < prescribingNumber {
  3903. cancelStockInfo := models.CancelStockInfo{
  3904. GoodId: project.ProjectId,
  3905. CancelStockId: cancel.ID,
  3906. GoodTypeId: good.GoodTypeId,
  3907. Count: info.Count,
  3908. Price: info.Price,
  3909. Total: 0,
  3910. ProductDate: info.ProductDate,
  3911. ExpiryDate: info.ExpiryDate,
  3912. Ctime: time.Now().Unix(),
  3913. Status: 1,
  3914. OrgId: adminInfo.CurrentOrgId,
  3915. OrderNumber: cancel.OrderNumber,
  3916. Type: 0,
  3917. Dealer: deaerler.DealerName,
  3918. Manufacturer: manufacturer.ManufacturerName,
  3919. Number: info.Number,
  3920. RegisterAccount: "",
  3921. Remark: "",
  3922. WarehouseInfoId: info.WarehouseInfotId,
  3923. PatientId: info.PatientId,
  3924. RecordDate: info.SysRecordTime,
  3925. StorehouseId: houseConfig.StorehouseOutInfo,
  3926. IsCheck: 1,
  3927. }
  3928. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3929. //回退库存
  3930. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3931. //退库数量增加
  3932. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3933. //出库数量减少
  3934. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3935. }
  3936. //查询剩余库存
  3937. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3938. var over_count int64
  3939. for _, it := range goodList {
  3940. over_count += it.StockCount
  3941. }
  3942. //出库数据 大于 退库数量
  3943. if info.Count >= prescribingNumber {
  3944. flow := models.VmStockFlow{
  3945. WarehousingId: info.WarehouseInfotId,
  3946. GoodId: project.ProjectId,
  3947. Number: info.Number,
  3948. LicenseNumber: info.LicenseNumber,
  3949. Count: prescribingNumber,
  3950. UserOrgId: adminInfo.CurrentOrgId,
  3951. PatientId: project.PatientId,
  3952. SystemTime: info.SysRecordTime,
  3953. ConsumableType: 7,
  3954. IsSys: 0,
  3955. WarehousingOrder: "",
  3956. WarehouseOutId: info.WarehouseOutId,
  3957. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3958. IsEdit: 0,
  3959. CancelStockId: cancel.ID,
  3960. CancelOrderNumber: cancel.OrderNumber,
  3961. Manufacturer: manufacturer.ID,
  3962. Dealer: 0,
  3963. Creator: adminInfo.AdminUser.Id,
  3964. UpdateCreator: 0,
  3965. Status: 1,
  3966. Ctime: time.Now().Unix(),
  3967. Mtime: 0,
  3968. Price: info.Price,
  3969. WarehousingDetailId: info.WarehouseInfotId,
  3970. WarehouseOutDetailId: info.ID,
  3971. CancelOutDetailId: cancelInfo.ID,
  3972. ProductDate: info.ProductDate,
  3973. ExpireDate: info.ExpiryDate,
  3974. StorehouseId: houseConfig.StorehouseOutInfo,
  3975. OverCount: over_count,
  3976. }
  3977. service.CreateStockFlowOne(flow)
  3978. }
  3979. //出库数据小于退库数据
  3980. if info.Count < prescribingNumber {
  3981. flow := models.VmStockFlow{
  3982. WarehousingId: info.WarehouseInfotId,
  3983. GoodId: project.ProjectId,
  3984. Number: info.Number,
  3985. LicenseNumber: info.LicenseNumber,
  3986. Count: info.Count,
  3987. UserOrgId: adminInfo.CurrentOrgId,
  3988. PatientId: project.PatientId,
  3989. SystemTime: info.SysRecordTime,
  3990. ConsumableType: 7,
  3991. IsSys: 0,
  3992. WarehousingOrder: "",
  3993. WarehouseOutId: info.WarehouseOutId,
  3994. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3995. IsEdit: 0,
  3996. CancelStockId: cancel.ID,
  3997. CancelOrderNumber: cancel.OrderNumber,
  3998. Manufacturer: manufacturer.ID,
  3999. Dealer: 0,
  4000. Creator: adminInfo.AdminUser.Id,
  4001. UpdateCreator: 0,
  4002. Status: 1,
  4003. Ctime: time.Now().Unix(),
  4004. Mtime: 0,
  4005. Price: info.Price,
  4006. WarehousingDetailId: info.WarehouseInfotId,
  4007. WarehouseOutDetailId: info.ID,
  4008. CancelOutDetailId: cancelInfo.ID,
  4009. ProductDate: info.ProductDate,
  4010. ExpireDate: info.ExpiryDate,
  4011. StorehouseId: houseConfig.StorehouseOutInfo,
  4012. OverCount: over_count,
  4013. }
  4014. service.CreateStockFlowOne(flow)
  4015. }
  4016. //查询已出库数量
  4017. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4018. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4019. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4020. if prescribingNumber < dialysisInfo.Count {
  4021. //改变数量
  4022. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4023. }
  4024. if prescribingNumber >= dialysisInfo.Count {
  4025. //删除出库表
  4026. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4027. }
  4028. //更新剩余库存
  4029. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4030. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4031. var total_count_one int64
  4032. for _, it := range stockList {
  4033. total_count_one += it.StockCount
  4034. }
  4035. //基础库插入数据
  4036. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4037. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4038. var flush_count int64
  4039. for _, it := range goodListOne {
  4040. flush_count += it.StockCount
  4041. }
  4042. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4043. if errs != nil {
  4044. goodErrcode := models.XtGoodErrcode{
  4045. UserOrgId: project.UserOrgId,
  4046. Errcode: "手动出库更新剩余出库失败",
  4047. GoodId: project.ProjectId,
  4048. Status: 1,
  4049. Ctime: time.Now().Unix(),
  4050. Mtime: 0,
  4051. Count: 0,
  4052. StockCount: 0,
  4053. Creater: creater,
  4054. BatchNumberId: 0,
  4055. WarehouseOutId: 0,
  4056. }
  4057. service.CreateGoodErrcode(goodErrcode)
  4058. }
  4059. }
  4060. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4061. fmt.Println(err)
  4062. } else {
  4063. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4064. fmt.Println(err)
  4065. }
  4066. } else {
  4067. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4068. fmt.Println(err)
  4069. }
  4070. }
  4071. //保存处方出库
  4072. if goodOutConfig.IsOpen == 1 {
  4073. if project.Type == 3 {
  4074. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4075. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4076. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4077. operation_time := time.Now().Unix()
  4078. creater := adminInfo.AdminUser.Id
  4079. //创建退库单
  4080. timeStr := time.Now().Format("2006-01-02")
  4081. timeArr := strings.Split(timeStr, "-")
  4082. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4083. total = total + 1
  4084. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4085. cancelStock := models.CancelStock{
  4086. OrderNumber: orderNumber,
  4087. OperaTime: operation_time,
  4088. OrgId: adminInfo.CurrentOrgId,
  4089. Creater: creater,
  4090. Ctime: time.Now().Unix(),
  4091. Status: 1,
  4092. ReturnTime: project.RecordDate,
  4093. Type: 1,
  4094. StorehouseId: houseConfig.StorehouseOutInfo,
  4095. IsCheck: 1,
  4096. }
  4097. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4098. if msgerrkonde == gorm.ErrRecordNotFound {
  4099. service.AddSigleCancelStock(&cancelStock)
  4100. }
  4101. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4102. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4103. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4104. //获取出库数据
  4105. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4106. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4107. deaerler, _ := service.GetDealerById(info.Dealer)
  4108. if info.ID > 0 {
  4109. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4110. if info.Count >= prescribingNumber {
  4111. cancelStockInfo := models.CancelStockInfo{
  4112. GoodId: project.ProjectId,
  4113. CancelStockId: cancel.ID,
  4114. GoodTypeId: good.GoodTypeId,
  4115. Count: prescribingNumber,
  4116. Price: info.Price,
  4117. Total: 0,
  4118. ProductDate: info.ProductDate,
  4119. ExpiryDate: info.ExpiryDate,
  4120. Ctime: time.Now().Unix(),
  4121. Status: 1,
  4122. OrgId: adminInfo.CurrentOrgId,
  4123. OrderNumber: cancel.OrderNumber,
  4124. Type: 0,
  4125. Dealer: deaerler.DealerName,
  4126. Manufacturer: manufacturer.ManufacturerName,
  4127. Number: info.Number,
  4128. RegisterAccount: "",
  4129. Remark: "",
  4130. WarehouseInfoId: info.WarehouseInfotId,
  4131. PatientId: info.PatientId,
  4132. RecordDate: info.SysRecordTime,
  4133. StorehouseId: houseConfig.StorehouseOutInfo,
  4134. IsCheck: 1,
  4135. }
  4136. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4137. //退库数量增加
  4138. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4139. //出库数量减少
  4140. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4141. }
  4142. if info.Count < prescribingNumber {
  4143. cancelStockInfo := models.CancelStockInfo{
  4144. GoodId: project.ProjectId,
  4145. CancelStockId: cancel.ID,
  4146. GoodTypeId: good.GoodTypeId,
  4147. Count: prescribingNumber,
  4148. Price: info.Price,
  4149. Total: 0,
  4150. ProductDate: info.ProductDate,
  4151. ExpiryDate: info.ExpiryDate,
  4152. Ctime: time.Now().Unix(),
  4153. Status: 1,
  4154. OrgId: adminInfo.CurrentOrgId,
  4155. OrderNumber: cancel.OrderNumber,
  4156. Type: 0,
  4157. Dealer: deaerler.DealerName,
  4158. Manufacturer: manufacturer.ManufacturerName,
  4159. Number: info.Number,
  4160. RegisterAccount: "",
  4161. Remark: "",
  4162. WarehouseInfoId: info.WarehouseInfotId,
  4163. PatientId: info.PatientId,
  4164. RecordDate: info.SysRecordTime,
  4165. StorehouseId: houseConfig.StorehouseOutInfo,
  4166. IsCheck: 1,
  4167. }
  4168. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4169. //回退库存
  4170. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4171. }
  4172. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4173. var over_count int64
  4174. for _, it := range goodList {
  4175. over_count += it.StockCount
  4176. }
  4177. //查询出库数量
  4178. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4179. //出库数据 大于 退库数量
  4180. if len(list) > 0 {
  4181. for _, it := range list {
  4182. //回退库存
  4183. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4184. //退库数量增加
  4185. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4186. //出库数量减少
  4187. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4188. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4189. var over_count_one int64
  4190. for _, it := range goodList {
  4191. over_count_one += it.StockCount
  4192. }
  4193. //查询该批次是否有退库数据
  4194. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4195. flow := models.VmStockFlow{
  4196. WarehousingId: it.WarehouseInfotId,
  4197. GoodId: it.GoodId,
  4198. Number: it.Number,
  4199. LicenseNumber: it.LicenseNumber,
  4200. Count: it.Count,
  4201. UserOrgId: adminInfo.CurrentOrgId,
  4202. PatientId: it.PatientId,
  4203. SystemTime: it.SysRecordTime,
  4204. ConsumableType: 7,
  4205. IsSys: 0,
  4206. WarehousingOrder: "",
  4207. WarehouseOutId: it.WarehouseOutId,
  4208. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4209. IsEdit: 0,
  4210. CancelStockId: cancel.ID,
  4211. CancelOrderNumber: cancel.OrderNumber,
  4212. Manufacturer: manufacturer.ID,
  4213. Dealer: 0,
  4214. Creator: adminInfo.AdminUser.Id,
  4215. UpdateCreator: 0,
  4216. Status: 1,
  4217. Ctime: time.Now().Unix(),
  4218. Mtime: 0,
  4219. Price: it.Price,
  4220. WarehousingDetailId: it.WarehouseInfotId,
  4221. WarehouseOutDetailId: it.ID,
  4222. CancelOutDetailId: cancelInfo.ID,
  4223. ProductDate: it.ProductDate,
  4224. ExpireDate: it.ExpiryDate,
  4225. StorehouseId: houseConfig.StorehouseOutInfo,
  4226. OverCount: over_count_one,
  4227. }
  4228. service.CreateStockFlowOne(flow)
  4229. }
  4230. }
  4231. //查询已出库数量
  4232. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4233. if prescribingNumber < dialysisInfo.Count {
  4234. //改变数量
  4235. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4236. }
  4237. if prescribingNumber >= dialysisInfo.Count {
  4238. //删除出库表
  4239. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4240. }
  4241. //更新剩余库存
  4242. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4243. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4244. var total_count_one int64
  4245. for _, it := range stockList {
  4246. total_count_one += it.StockCount
  4247. }
  4248. //基础库插入数据
  4249. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4250. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4251. var flush_count int64
  4252. for _, it := range goodListOne {
  4253. flush_count += it.StockCount
  4254. }
  4255. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4256. if errs != nil {
  4257. goodErrcode := models.XtGoodErrcode{
  4258. UserOrgId: project.UserOrgId,
  4259. Errcode: "手动出库更新剩余出库失败",
  4260. GoodId: project.ProjectId,
  4261. Status: 1,
  4262. Ctime: time.Now().Unix(),
  4263. Mtime: 0,
  4264. Count: 0,
  4265. StockCount: 0,
  4266. Creater: creater,
  4267. BatchNumberId: 0,
  4268. WarehouseOutId: 0,
  4269. }
  4270. service.CreateGoodErrcode(goodErrcode)
  4271. }
  4272. }
  4273. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4274. fmt.Println(err)
  4275. } else {
  4276. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4277. fmt.Println(err)
  4278. }
  4279. }
  4280. c.ServeSuccessJSON(map[string]interface{}{
  4281. "msg": "删除成功",
  4282. })
  4283. return
  4284. }
  4285. func (c *HisApiController) CreateHisAdditionalCharge() {
  4286. his_patient_id, _ := c.GetInt64("his_patient_id")
  4287. patient_id, _ := c.GetInt64("patient_id")
  4288. record_date := c.GetString("record_date")
  4289. timeLayout := "2006-01-02"
  4290. loc, _ := time.LoadLocation("Local")
  4291. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4292. if err != nil {
  4293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4294. return
  4295. }
  4296. adminInfo := c.GetAdminUserInfo()
  4297. recordDateTime := theTime.Unix()
  4298. dataBody := make(map[string]interface{}, 0)
  4299. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4300. if err != nil {
  4301. utils.ErrorLog(err.Error())
  4302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4303. return
  4304. }
  4305. var additions []*models.HisAdditionalCharge
  4306. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4307. additions, _ := dataBody["addition"].([]interface{})
  4308. if len(additions) > 0 {
  4309. for _, item := range additions {
  4310. items := item.(map[string]interface{})
  4311. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4312. utils.ErrorLog("item_id")
  4313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4314. return
  4315. }
  4316. item_id := int64(items["item_id"].(float64))
  4317. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4318. utils.ErrorLog("item_name")
  4319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4320. return
  4321. }
  4322. item_name := items["item_name"].(string)
  4323. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4324. utils.ErrorLog("price")
  4325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4326. return
  4327. }
  4328. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4329. ctime := time.Now().Unix()
  4330. additional := &models.HisAdditionalCharge{
  4331. PatientId: patient_id,
  4332. HisPatientId: his_patient_id,
  4333. UserOrgId: adminInfo.CurrentOrgId,
  4334. RecordDate: recordDateTime,
  4335. CreatedTime: ctime,
  4336. UpdatedTime: ctime,
  4337. Modifier: adminInfo.AdminUser.Id,
  4338. Creator: adminInfo.AdminUser.Id,
  4339. Price: price,
  4340. ItemName: item_name,
  4341. ItemId: item_id,
  4342. Status: 1,
  4343. }
  4344. additions = append(additions, additional)
  4345. }
  4346. }
  4347. }
  4348. for _, item := range additions {
  4349. service.CreateAddtionalCharge(item)
  4350. }
  4351. c.ServeSuccessJSON(map[string]interface{}{
  4352. "msg": "创建成功",
  4353. })
  4354. }
  4355. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4356. blood_fat := c.GetString("blood_fat")
  4357. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4358. blood_sugar := c.GetString("blood_sugar")
  4359. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4360. chief_conplaint := c.GetString("chief_conplaint")
  4361. dbp := c.GetString("dbp")
  4362. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4363. delivery_way, _ := c.GetInt64("delivery_way")
  4364. diagnostic := c.GetString("diagnostic")
  4365. family_history := c.GetString("family_history")
  4366. height := c.GetString("height")
  4367. history_of_present_illness := c.GetString("history_of_present_illness")
  4368. is_infect, _ := c.GetInt64("is_infect")
  4369. past_history := c.GetString("past_history")
  4370. patient_id, _ := c.GetInt64("patient_id")
  4371. his_patient_id, _ := c.GetInt64("his_patient_id")
  4372. personal_history := c.GetString("personal_history")
  4373. pulse := c.GetString("pulse")
  4374. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4375. sbp := c.GetString("sbp")
  4376. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4377. heightfloat, _ := strconv.ParseFloat(height, 64)
  4378. sicktype := c.GetString("sick_type")
  4379. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4380. symptom := c.GetString("symptom")
  4381. sick_date := c.GetString("sick_date")
  4382. temperatures := c.GetString("temperature")
  4383. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4384. record_date := c.GetString("record_date")
  4385. breathing := c.GetString("breathing")
  4386. doctor_advice := c.GetString("doctor_advice")
  4387. remark := c.GetString("remark")
  4388. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4389. sick, _ := c.GetInt64("sick")
  4390. diagnose, _ := c.GetInt64("diagnose")
  4391. //id, _ := c.GetInt64("id")
  4392. timeLayout := "2006-01-02"
  4393. loc, _ := time.LoadLocation("Local")
  4394. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4395. allergic_history := c.GetString("allergic_history")
  4396. if err != nil {
  4397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4398. return
  4399. }
  4400. recordDateTime := theTime.Unix()
  4401. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4402. if err != nil {
  4403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4404. return
  4405. }
  4406. sickTimes := sickTime.Unix()
  4407. ctime := time.Now().Unix()
  4408. primary_disease := c.GetString("primary_disease")
  4409. confirm_failure_date := c.GetString("confirm_failure_date")
  4410. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4411. drug_allergy_history := c.GetString("drug_allergy_history")
  4412. physical_examination := c.GetString("physical_examination")
  4413. special_inspection := c.GetString("special_inspection")
  4414. lab_apparatus := c.GetString("lab_apparatus")
  4415. caseHistory := models.HisPatientCaseHistory{
  4416. HisPatientId: his_patient_id,
  4417. PatientId: patient_id,
  4418. Temperature: temperature,
  4419. BloodSugar: bloodsugarfloat,
  4420. Pulse: pulsefloat,
  4421. Sbp: sbpfloat,
  4422. Dbp: dbpfloat,
  4423. Height: heightfloat,
  4424. BloodFat: bloodfatfloat,
  4425. SickType: sick_type,
  4426. Symptom: symptom,
  4427. SickDate: sickTimes,
  4428. IsInfect: is_infect,
  4429. HistoryOfPresentIllness: history_of_present_illness,
  4430. PastHistory: past_history,
  4431. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4432. ChiefConplaint: chief_conplaint,
  4433. PersonalHistory: personal_history,
  4434. FamilyHistory: family_history,
  4435. Diagnostic: diagnostic,
  4436. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4437. Status: 1,
  4438. Ctime: ctime,
  4439. Mtime: ctime,
  4440. RecordDate: recordDateTime,
  4441. DeliveryWay: delivery_way,
  4442. Breathing: breathingfloat,
  4443. DoctorAdvice: doctor_advice,
  4444. Remark: remark,
  4445. Sick: sick,
  4446. Diagnose: diagnose,
  4447. AllergicHistory: allergic_history,
  4448. PrimaryDisease: primary_disease,
  4449. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4450. DrugAllergyHistory: drug_allergy_history,
  4451. PhysicalExamination: physical_examination,
  4452. SpecialInspection: special_inspection,
  4453. LabApparatus: lab_apparatus,
  4454. }
  4455. //查询该患者是否有病历
  4456. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4457. if errcodes == gorm.ErrRecordNotFound {
  4458. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4459. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4460. if err != nil {
  4461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4462. return
  4463. }
  4464. c.ServeSuccessJSON(map[string]interface{}{
  4465. "caseHistory": caseHistory,
  4466. "historyInfo": historyInfo,
  4467. })
  4468. return
  4469. } else if errcodes == nil {
  4470. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4471. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4472. if err != nil {
  4473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4474. return
  4475. }
  4476. c.ServeSuccessJSON(map[string]interface{}{
  4477. "caseHistory": caseHistory,
  4478. "historyInfo": historyInfo,
  4479. })
  4480. }
  4481. //查询该患者是否有病历
  4482. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4483. //if errcode == gorm.ErrRecordNotFound {
  4484. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4485. // if err != nil {
  4486. // c.ServeSuccessJSON(map[string]interface{}{
  4487. // "msg": "保存成功",
  4488. // })
  4489. // }
  4490. //} else if errcode == nil {
  4491. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4492. // return
  4493. //}
  4494. }
  4495. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4496. patient_id, _ := c.GetInt64("patient_id", 0)
  4497. adminUser := c.GetAdminUserInfo()
  4498. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4499. c.ServeSuccessJSON(map[string]interface{}{
  4500. "list": caseHistorys,
  4501. })
  4502. }
  4503. func (c *HisApiController) GetHisPatientCaseHistory() {
  4504. record_date, _ := c.GetInt64("record_date", 0)
  4505. patient_id, _ := c.GetInt64("patient_id", 0)
  4506. admin := c.GetAdminUserInfo()
  4507. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4508. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4509. c.ServeSuccessJSON(map[string]interface{}{
  4510. "info": info,
  4511. "case_history": case_history,
  4512. })
  4513. }
  4514. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4515. template_name := c.GetString("template_name")
  4516. template_remark := c.GetString("template_remark")
  4517. doctor := c.GetAdminUserInfo().AdminUser.Id
  4518. diagnostic := c.GetString("diagnostic")
  4519. chief_conplaint := c.GetString("chief_conplain")
  4520. history_of_present_illness := c.GetString("history_of_present_illness")
  4521. past_history := c.GetString("past_history")
  4522. personal_history := c.GetString("personal_history")
  4523. family_history := c.GetString("family_history")
  4524. user_name := c.GetString("user_name")
  4525. doctor_advice := c.GetString("doctor_advice")
  4526. remark := c.GetString("remark")
  4527. //record_date := c.GetString("record_date")
  4528. //fmt.Println("record_date--------",record_date)
  4529. //timeLayout := "2006-01-02"
  4530. //loc, _ := time.LoadLocation("Local")
  4531. //
  4532. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4533. //if err != nil {
  4534. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4535. // return
  4536. //}
  4537. //recordDateTime := theTime.Unix()
  4538. ctime := time.Now().Unix()
  4539. template := models.HisCaseHistoryTemplate{
  4540. HistoryOfPresentIllness: history_of_present_illness,
  4541. PastHistory: past_history,
  4542. ChiefConplaint: chief_conplaint,
  4543. PersonalHistory: personal_history,
  4544. FamilyHistory: family_history,
  4545. Diagnostic: diagnostic,
  4546. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4547. Status: 1,
  4548. Ctime: ctime,
  4549. Mtime: ctime,
  4550. RecordDate: time.Now().Unix(),
  4551. TemplateName: template_name,
  4552. TemplateRemark: template_remark,
  4553. Creator: doctor,
  4554. Modifier: doctor,
  4555. UserName: user_name,
  4556. DoctorAdvice: doctor_advice,
  4557. Remark: remark,
  4558. }
  4559. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4560. if err == nil {
  4561. c.ServeSuccessJSON(map[string]interface{}{
  4562. "msg": "保存成功",
  4563. })
  4564. } else {
  4565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4566. return
  4567. }
  4568. }
  4569. func (c *HisApiController) GetCaseHistoryTemplate() {
  4570. timeLayout := "2006-01-02"
  4571. loc, _ := time.LoadLocation("Local")
  4572. keyword := c.GetString("keyword")
  4573. start_time := c.GetString("start_time")
  4574. end_time := c.GetString("end_time")
  4575. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4576. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4577. admin := c.GetAdminUserInfo()
  4578. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4579. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4580. c.ServeSuccessJSON(map[string]interface{}{
  4581. "template": template,
  4582. //"history": history,
  4583. })
  4584. }
  4585. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4586. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4587. utils.ErrorLog("drug_name")
  4588. return enums.ErrorCodeParamWrong
  4589. }
  4590. adviceName, _ := json["drug_name"].(string)
  4591. if len(adviceName) == 0 {
  4592. utils.ErrorLog("len(advice_name) == 0")
  4593. return enums.ErrorCodeParamWrong
  4594. }
  4595. advice.AdviceName = adviceName
  4596. adviceDesc, _ := json["advice_desc"].(string)
  4597. advice.AdviceDesc = adviceDesc
  4598. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4599. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4600. advice.DrugSpec = drugSpec
  4601. }
  4602. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4603. remark, _ := json["remark"].(string)
  4604. advice.Remark = remark
  4605. }
  4606. if json["id"] == nil {
  4607. advice.DrugId = 0
  4608. } else {
  4609. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4610. drug_id := int64(json["id"].(float64))
  4611. advice.DrugId = drug_id
  4612. }
  4613. }
  4614. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4615. advice_id := int64(json["advice_id"].(float64))
  4616. advice.ID = advice_id
  4617. if advice.ID > 0 {
  4618. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4619. if err == nil {
  4620. if hisAdvice.ID > 0 {
  4621. advice.ExecutionTime = hisAdvice.ExecutionTime
  4622. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4623. advice.ExecutionState = hisAdvice.ExecutionState
  4624. advice.CheckTime = hisAdvice.CheckTime
  4625. advice.Checker = hisAdvice.Checker
  4626. advice.CheckState = hisAdvice.CheckState
  4627. advice.StartTime = hisAdvice.StartTime
  4628. advice.FeedetlSn = hisAdvice.FeedetlSn
  4629. }
  4630. }
  4631. }
  4632. }
  4633. //
  4634. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4635. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4636. // advice.ExecutionTime = execution_time
  4637. //}
  4638. //
  4639. //
  4640. //
  4641. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4642. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4643. // advice.ExecutionStaff = execution_staff
  4644. //}
  4645. //
  4646. //
  4647. //
  4648. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4649. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4650. // advice.ExecutionState = execution_state
  4651. //}
  4652. //
  4653. //
  4654. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4655. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4656. // advice.CheckTime = check_time
  4657. //}
  4658. //
  4659. //
  4660. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4661. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4662. // advice.CheckState = check_state
  4663. //}
  4664. //
  4665. //
  4666. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4667. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4668. // advice.Checker = checker
  4669. //}
  4670. //
  4671. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4672. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4673. // advice.StartTime = start_time
  4674. //}
  4675. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4676. drugSpecUnit, _ := json["min_unit"].(string)
  4677. advice.DrugSpecUnit = drugSpecUnit
  4678. }
  4679. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4680. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4681. advice.SingleDose = singleDose
  4682. }
  4683. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4684. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4685. advice.SingleDoseUnit = singleDoseUnit
  4686. }
  4687. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4688. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4689. advice.PrescribingNumber = prescribingNumber
  4690. }
  4691. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4692. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4693. advice.PrescribingNumberUnit = prescribingNumberUnit
  4694. }
  4695. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4696. deliveryWay, _ := json["delivery_way"].(string)
  4697. advice.DeliveryWay = deliveryWay
  4698. }
  4699. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4700. executionFrequency, _ := json["execution_frequency"].(string)
  4701. advice.ExecutionFrequency = executionFrequency
  4702. }
  4703. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4704. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4705. advice.Price = price
  4706. }
  4707. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4708. med_list_codg, _ := json["medical_insurance_number"].(string)
  4709. advice.MedListCodg = med_list_codg
  4710. }
  4711. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4712. day := int64(json["day"].(float64))
  4713. advice.Day = day
  4714. }
  4715. return 0
  4716. }
  4717. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4718. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4719. id := int64(json["id"].(float64))
  4720. project.ID = id
  4721. historyProject, _ := service.GetHisProjectByID(id)
  4722. project.FeedetlSn = historyProject.FeedetlSn
  4723. }
  4724. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4725. project_id := int64(json["project_id"].(float64))
  4726. project.ProjectId = project_id
  4727. }
  4728. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4729. // price := int64(json["price"].(float64))
  4730. // formatInt_price := strconv.FormatInt(price, 10)
  4731. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4732. // project.Price = float_price
  4733. // }
  4734. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4735. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4736. project.Price = price
  4737. }
  4738. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4739. total, _ := json["total"].(string)
  4740. project.Count = total
  4741. }
  4742. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4743. medical_code, _ := json["medical_code"].(string)
  4744. project.MedListCodg = medical_code
  4745. }
  4746. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4747. single_dose, _ := json["single_dose"].(string)
  4748. project.SingleDose = single_dose
  4749. }
  4750. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4751. delivery_way, _ := json["delivery_way"].(string)
  4752. project.DeliveryWay = delivery_way
  4753. }
  4754. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4755. execution_frequency, _ := json["execution_frequency"].(string)
  4756. project.ExecutionFrequency = execution_frequency
  4757. }
  4758. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4759. remark, _ := json["remark"].(string)
  4760. project.Remark = remark
  4761. }
  4762. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4763. day, _ := json["number_days"].(string)
  4764. project.Day = day
  4765. }
  4766. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4767. unit, _ := json["unit"].(string)
  4768. project.Unit = unit
  4769. }
  4770. return 0
  4771. }
  4772. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4773. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4774. id := int64(json["id"].(float64))
  4775. historyAddtions, _ := service.GetHisAdditionByID(id)
  4776. additionalCharge.ID = id
  4777. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4778. }
  4779. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4780. item_id := int64(json["item_id"].(float64))
  4781. additionalCharge.ItemId = item_id
  4782. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4783. if config.ID > 0 {
  4784. if len(config.Code) > 0 {
  4785. additionalCharge.MedListCodg = config.Code
  4786. }
  4787. }
  4788. }
  4789. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4790. // price := int64(json["price"].(float64))
  4791. // formatInt_price := strconv.FormatInt(price, 10)
  4792. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4793. // additionalCharge.Price = float_price
  4794. // }
  4795. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4796. // price := int64(json["price"].(float64))
  4797. // formatInt_price := strconv.FormatInt(price, 10)
  4798. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4799. // additionalCharge.Price = float_price
  4800. //}
  4801. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4802. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4803. additionalCharge.Price = price
  4804. }
  4805. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4806. count, _ := json["count"].(string)
  4807. counts, _ := strconv.ParseInt(count, 10, 64)
  4808. additionalCharge.Count = counts
  4809. }
  4810. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4811. item_name, _ := json["item_name"].(string)
  4812. additionalCharge.ItemName = item_name
  4813. }
  4814. return 0
  4815. }
  4816. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4817. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4818. utils.ErrorLog("drug_name")
  4819. return enums.ErrorCodeParamWrong
  4820. }
  4821. adviceName, _ := json["drug_name"].(string)
  4822. if len(adviceName) == 0 {
  4823. utils.ErrorLog("len(advice_name) == 0")
  4824. return enums.ErrorCodeParamWrong
  4825. }
  4826. advice.AdviceName = adviceName
  4827. adviceDesc, _ := json["advice_desc"].(string)
  4828. advice.AdviceDesc = adviceDesc
  4829. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4830. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4831. advice.DrugSpec = drugSpec
  4832. }
  4833. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4834. remark, _ := json["remark"].(string)
  4835. advice.Remark = remark
  4836. }
  4837. if json["id"] == nil {
  4838. advice.DrugId = 0
  4839. } else {
  4840. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4841. drug_id := int64(json["id"].(float64))
  4842. advice.DrugId = drug_id
  4843. }
  4844. }
  4845. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4846. groupno := int64(json["groupno"].(float64))
  4847. advice.Groupno = groupno
  4848. }
  4849. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4850. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4851. advice.HospApprFlag = hosp_appr_flag
  4852. }
  4853. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4854. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4855. advice.PrescribingNumber = prescribingNumber
  4856. }
  4857. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4858. // frequency_type := int64(json["frequency_type"].(float64))
  4859. // advice.FrequencyType = frequency_type
  4860. //}
  4861. //
  4862. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4863. // day_count := int64(json["day_count"].(float64))
  4864. // advice.DayCount = day_count
  4865. //}
  4866. //
  4867. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4868. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4869. // week_day, _ := json["week_day"].(string)
  4870. // advice.WeekDay = week_day
  4871. //}
  4872. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4873. drugSpecUnit, _ := json["min_unit"].(string)
  4874. advice.DrugSpecUnit = drugSpecUnit
  4875. }
  4876. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4877. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4878. advice.SingleDose = singleDose
  4879. }
  4880. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4881. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4882. advice.SingleDoseUnit = singleDoseUnit
  4883. }
  4884. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4885. deliveryWay, _ := json["delivery_way"].(string)
  4886. advice.DeliveryWay = deliveryWay
  4887. }
  4888. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4889. executionFrequency, _ := json["execution_frequency"].(string)
  4890. advice.ExecutionFrequency = executionFrequency
  4891. }
  4892. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4893. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4894. advice.Price = price
  4895. }
  4896. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4897. med_list_codg, _ := json["medical_insurance_number"].(string)
  4898. advice.MedListCodg = med_list_codg
  4899. }
  4900. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4901. day := int64(json["day"].(float64))
  4902. advice.Day = day
  4903. }
  4904. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4905. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4906. advice.PrescribingNumberUnit = prescribingNumberUnit
  4907. }
  4908. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4909. advice_id := int64(json["advice_id"].(float64))
  4910. advice.ID = advice_id
  4911. if advice.ID > 0 {
  4912. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4913. if err == nil {
  4914. if hisAdvice.ID > 0 {
  4915. advice.ExecutionTime = hisAdvice.ExecutionTime
  4916. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4917. advice.ExecutionState = hisAdvice.ExecutionState
  4918. advice.CheckTime = hisAdvice.CheckTime
  4919. advice.Checker = hisAdvice.Checker
  4920. advice.CheckState = hisAdvice.CheckState
  4921. advice.StartTime = hisAdvice.StartTime
  4922. advice.HospApprFlag = hisAdvice.HospApprFlag
  4923. advice.IsMedicine = hisAdvice.IsMedicine
  4924. if hisAdvice.UserOrgId == 10028 {
  4925. 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 {
  4926. advice.ExecutionTime = 0
  4927. advice.ExecutionStaff = 0
  4928. advice.ExecutionState = 2
  4929. advice.CheckTime = 0
  4930. advice.Checker = 0
  4931. advice.CheckState = 2
  4932. }
  4933. } else {
  4934. 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 {
  4935. advice.ExecutionTime = 0
  4936. advice.ExecutionStaff = 0
  4937. advice.ExecutionState = 2
  4938. advice.CheckTime = 0
  4939. advice.Checker = 0
  4940. advice.CheckState = 2
  4941. }
  4942. }
  4943. //advice.Groupno = hisAdvice.Groupno
  4944. }
  4945. }
  4946. }
  4947. }
  4948. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4949. //
  4950. //if drugStockConfig.IsOpen == 1 {
  4951. //
  4952. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4953. // if advice.ID == 0 { //医嘱不存在
  4954. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4955. // drug.Total = drug.Total - advice.PrescribingNumber
  4956. // service.UpdateBaseDrugLib(&drug)
  4957. //
  4958. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4959. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4960. // drug.Total = drug.Total - num
  4961. // service.UpdateBaseDrugLib(&drug)
  4962. // }
  4963. //
  4964. // } else if advice.ID > 0 { //医嘱存在
  4965. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4966. // var num float64
  4967. //
  4968. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4969. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4970. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4971. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4972. // drug.Total = drug.Total + num
  4973. // service.UpdateBaseDrugLib(&drug)
  4974. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4975. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4976. // drug.Total = drug.Total - num
  4977. // service.UpdateBaseDrugLib(&drug)
  4978. // }
  4979. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4980. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4981. // if num2 > advice.PrescribingNumber {
  4982. // num = num2 - advice.PrescribingNumber
  4983. // drug.Total = drug.Total + num
  4984. // service.UpdateBaseDrugLib(&drug)
  4985. // } else if num2 < advice.PrescribingNumber {
  4986. // num = advice.PrescribingNumber - num2
  4987. // drug.Total = drug.Total - num
  4988. // service.UpdateBaseDrugLib(&drug)
  4989. // }
  4990. //
  4991. // }
  4992. //
  4993. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4994. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4995. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4996. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4997. // if num1 > num2 {
  4998. // num = num1 - num2
  4999. // drug.Total = drug.Total + num
  5000. // service.UpdateBaseDrugLib(&drug)
  5001. // } else if num1 < num2 {
  5002. // num = num2 - num1
  5003. // drug.Total = drug.Total - num
  5004. // service.UpdateBaseDrugLib(&drug)
  5005. // }
  5006. //
  5007. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5008. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5009. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5010. // if hisAdvice.PrescribingNumber > num2 {
  5011. // num = hisAdvice.PrescribingNumber - num2
  5012. // drug.Total = drug.Total + num
  5013. // service.UpdateBaseDrugLib(&drug)
  5014. // } else if num2 < advice.PrescribingNumber {
  5015. // num = num2 - hisAdvice.PrescribingNumber
  5016. // drug.Total = drug.Total - num
  5017. // service.UpdateBaseDrugLib(&drug)
  5018. // }
  5019. //
  5020. // }
  5021. // }
  5022. // }
  5023. //}
  5024. //
  5025. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5026. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5027. // advice.ExecutionTime = execution_time
  5028. //}
  5029. //
  5030. //
  5031. //
  5032. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5033. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5034. // advice.ExecutionStaff = execution_staff
  5035. //}
  5036. //
  5037. //
  5038. //
  5039. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5040. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5041. // advice.ExecutionState = execution_state
  5042. //}
  5043. //
  5044. //
  5045. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5046. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5047. // advice.CheckTime = check_time
  5048. //}
  5049. //
  5050. //
  5051. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5052. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5053. // advice.CheckState = check_state
  5054. //}
  5055. //
  5056. //
  5057. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5058. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5059. // advice.Checker = checker
  5060. //}
  5061. //
  5062. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5063. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5064. // advice.StartTime = start_time
  5065. //}
  5066. return 0
  5067. }
  5068. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5069. project.ExecutionStaff = 0
  5070. project.ExecutionState = 2
  5071. project.ExecutionTime = 0
  5072. project.Checker = 0
  5073. project.CheckState = 2
  5074. project.CheckTime = 0
  5075. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5076. id := int64(json["id"].(float64))
  5077. project.ID = id
  5078. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5079. project.ExecutionStaff = temp_project.ExecutionStaff
  5080. project.ExecutionState = temp_project.ExecutionState
  5081. project.ExecutionTime = temp_project.ExecutionTime
  5082. project.Checker = temp_project.Checker
  5083. project.CheckState = temp_project.CheckState
  5084. project.CheckTime = temp_project.CheckTime
  5085. project.TeamId = temp_project.TeamId
  5086. }
  5087. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5088. types := int64(json["type"].(float64))
  5089. project.Type = types
  5090. }
  5091. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5092. project_id := int64(json["project_id"].(float64))
  5093. project.ProjectId = project_id
  5094. }
  5095. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5096. team_id := int64(json["team_id"].(float64))
  5097. project.TeamId = team_id
  5098. }
  5099. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5100. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5101. project.Price = price
  5102. }
  5103. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5104. total, _ := json["total"].(string)
  5105. //totals, _ := strconv.ParseInt(total, 10, 64)
  5106. project.Count = total
  5107. }
  5108. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5109. medical_code, _ := json["medical_code"].(string)
  5110. project.MedListCodg = medical_code
  5111. }
  5112. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5113. single_dose, _ := json["single_dose"].(string)
  5114. project.SingleDose = single_dose
  5115. }
  5116. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5117. delivery_way, _ := json["delivery_way"].(string)
  5118. project.DeliveryWay = delivery_way
  5119. }
  5120. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5121. execution_frequency, _ := json["execution_frequency"].(string)
  5122. project.ExecutionFrequency = execution_frequency
  5123. }
  5124. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5125. remark, _ := json["remark"].(string)
  5126. project.Remark = remark
  5127. }
  5128. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5129. day, _ := json["number_days"].(string)
  5130. project.Day = day
  5131. }
  5132. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5133. unit, _ := json["unit"].(string)
  5134. project.Unit = unit
  5135. }
  5136. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5137. // frequency_type := int64(json["frequency_type"].(float64))
  5138. // project.FrequencyType = frequency_type
  5139. //}
  5140. //
  5141. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5142. // day_count := int64(json["day_count"].(float64))
  5143. // project.DayCount = day_count
  5144. //}
  5145. //
  5146. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5147. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5148. // week_day, _ := json["week_day"].(string)
  5149. // project.WeekDay = week_day
  5150. //}
  5151. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5152. //
  5153. //if project.ID == 0 {
  5154. // if stockConfig.IsOpen == 1 {
  5155. // if project.Type == 3 {
  5156. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5157. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5158. // good.Total = good.Total - f_count
  5159. // service.UpdateGoodInfo(&good)
  5160. // }
  5161. // }
  5162. //
  5163. //} else {
  5164. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5165. //
  5166. // if stockConfig.IsOpen == 1 {
  5167. // if project.Type == 3 {
  5168. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5169. // if project.Count < temp_project.Count {
  5170. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5171. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5172. //
  5173. // other_count := f_count_two - f_count_one
  5174. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5175. // good.Total = good.Total + other_count_two
  5176. // service.UpdateGoodInfo(&good)
  5177. // } else if project.Count > temp_project.Count {
  5178. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5179. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5180. //
  5181. // other_count := f_count_one - f_count_two
  5182. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5183. // good.Total = good.Total - other_count_two
  5184. // service.UpdateGoodInfo(&good)
  5185. // }
  5186. //
  5187. // }
  5188. // }
  5189. //
  5190. //}
  5191. return 0
  5192. }
  5193. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5194. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5195. id := int64(json["id"].(float64))
  5196. additionalCharge.ID = id
  5197. }
  5198. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5199. item_id := int64(json["item_id"].(float64))
  5200. additionalCharge.ItemId = item_id
  5201. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5202. if config.ID > 0 {
  5203. if len(config.Code) > 0 {
  5204. additionalCharge.MedListCodg = config.Code
  5205. }
  5206. }
  5207. }
  5208. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5209. // price := int64(json["price"].(float64))
  5210. // formatInt_price := strconv.FormatInt(price, 10)
  5211. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5212. // additionalCharge.Price = float_price
  5213. // }
  5214. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5215. // price := int64(json["price"].(float64))
  5216. // formatInt_price := strconv.FormatInt(price, 10)
  5217. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5218. // additionalCharge.Price = float_price
  5219. //}
  5220. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5221. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5222. additionalCharge.Price = price
  5223. }
  5224. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5225. count, _ := json["count"].(string)
  5226. counts, _ := strconv.ParseInt(count, 10, 64)
  5227. additionalCharge.Count = counts
  5228. }
  5229. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5230. item_name, _ := json["item_name"].(string)
  5231. additionalCharge.ItemName = item_name
  5232. }
  5233. return 0
  5234. }
  5235. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5236. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5237. utils.ErrorLog("drug_name")
  5238. return enums.ErrorCodeParamWrong
  5239. }
  5240. adviceName, _ := json["drug_name"].(string)
  5241. if len(adviceName) == 0 {
  5242. utils.ErrorLog("len(advice_name) == 0")
  5243. return enums.ErrorCodeParamWrong
  5244. }
  5245. advice.AdviceName = adviceName
  5246. adviceDesc, _ := json["advice_desc"].(string)
  5247. advice.AdviceDesc = adviceDesc
  5248. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5249. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5250. advice.DrugSpec = drugSpec
  5251. }
  5252. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5253. remark, _ := json["remark"].(string)
  5254. advice.Remark = remark
  5255. }
  5256. if json["id"] == nil {
  5257. advice.DrugId = 0
  5258. } else {
  5259. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5260. drug_id := int64(json["id"].(float64))
  5261. advice.DrugId = drug_id
  5262. }
  5263. }
  5264. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5265. drugSpecUnit, _ := json["min_unit"].(string)
  5266. advice.DrugSpecUnit = drugSpecUnit
  5267. }
  5268. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5269. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5270. advice.SingleDose = singleDose
  5271. }
  5272. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5273. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5274. advice.SingleDoseUnit = singleDoseUnit
  5275. }
  5276. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5277. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5278. advice.PrescribingNumber = prescribingNumber
  5279. }
  5280. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5281. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5282. advice.PrescribingNumberUnit = prescribingNumberUnit
  5283. }
  5284. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5285. deliveryWay, _ := json["delivery_way"].(string)
  5286. advice.DeliveryWay = deliveryWay
  5287. }
  5288. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5289. executionFrequency, _ := json["execution_frequency"].(string)
  5290. advice.ExecutionFrequency = executionFrequency
  5291. }
  5292. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5293. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5294. advice.Price = price
  5295. }
  5296. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5297. med_list_codg, _ := json["medical_insurance_number"].(string)
  5298. advice.MedListCodg = med_list_codg
  5299. }
  5300. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5301. day := int64(json["day"].(float64))
  5302. advice.Day = day
  5303. }
  5304. advice.FrequencyType = 1
  5305. return 0
  5306. }
  5307. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5308. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5309. types := int64(json["type"].(float64))
  5310. project.Type = types
  5311. }
  5312. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5313. project_id := int64(json["project_id"].(float64))
  5314. project.ProjectId = project_id
  5315. }
  5316. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5317. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5318. project.Price = price
  5319. }
  5320. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5321. total, _ := json["total"].(string)
  5322. //totals, _ := strconv.ParseInt(total, 10, 64)
  5323. project.Count = total
  5324. }
  5325. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5326. medical_code, _ := json["medical_code"].(string)
  5327. project.MedListCodg = medical_code
  5328. }
  5329. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5330. single_dose, _ := json["single_dose"].(string)
  5331. project.SingleDose = single_dose
  5332. }
  5333. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5334. delivery_way, _ := json["delivery_way"].(string)
  5335. project.DeliveryWay = delivery_way
  5336. }
  5337. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5338. execution_frequency, _ := json["execution_frequency"].(string)
  5339. project.ExecutionFrequency = execution_frequency
  5340. }
  5341. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5342. remark, _ := json["remark"].(string)
  5343. project.Remark = remark
  5344. }
  5345. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5346. day, _ := json["number_days"].(string)
  5347. project.Day = day
  5348. }
  5349. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5350. unit, _ := json["unit"].(string)
  5351. project.Unit = unit
  5352. }
  5353. project.FrequencyType = 1
  5354. return 0
  5355. }
  5356. func (c *HisApiController) GetHisOrderList() {
  5357. page, _ := c.GetInt64("page", -1)
  5358. limit, _ := c.GetInt64("limit", -1)
  5359. start_time := c.GetString("start_time")
  5360. end_time := c.GetString("end_time")
  5361. types, _ := c.GetInt64("type", 0)
  5362. keywords := c.GetString("keywords")
  5363. p_type, _ := c.GetInt64("p_type", 0)
  5364. sort_type, _ := c.GetInt64("sort_type", 0)
  5365. charge_type, _ := c.GetInt64("charge_type", 0)
  5366. sch_type, _ := c.GetInt64("sch_type", 0)
  5367. zone_type, _ := c.GetInt64("zone_type", 0)
  5368. timeLayout := "2006-01-02"
  5369. loc, _ := time.LoadLocation("Local")
  5370. var startTime int64
  5371. if len(start_time) > 0 {
  5372. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5373. if err != nil {
  5374. //fmt.Println(err)
  5375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5376. return
  5377. }
  5378. startTime = theTime.Unix()
  5379. }
  5380. var endTime int64
  5381. if len(end_time) > 0 {
  5382. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5383. if err != nil {
  5384. utils.ErrorLog(err.Error())
  5385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5386. return
  5387. }
  5388. endTime = theTime.Unix()
  5389. }
  5390. adminUser := c.GetAdminUserInfo()
  5391. org_id := adminUser.CurrentOrgId
  5392. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type)
  5393. for _, item := range order {
  5394. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5395. item.DoctorName = info.Doctor
  5396. item.DepartmentName = info.XtHisDepartment.Name
  5397. }
  5398. if err == nil {
  5399. c.ServeSuccessJSON(map[string]interface{}{
  5400. "order": order,
  5401. "total": total,
  5402. })
  5403. } else {
  5404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5405. return
  5406. }
  5407. }
  5408. func (c *HisApiController) GetHisOrder() {
  5409. patient_id, _ := c.GetInt64("patient_id", 0)
  5410. number := c.GetString("number")
  5411. adminInfo := c.GetAdminUserInfo()
  5412. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5413. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5414. if err == nil {
  5415. c.ServeSuccessJSON(map[string]interface{}{
  5416. "order": order,
  5417. "prescription": prescriptions,
  5418. })
  5419. } else {
  5420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5421. return
  5422. }
  5423. }
  5424. func (c *HisApiController) GetHisPrescriptionList() {
  5425. record_date := c.GetString("record_date")
  5426. keywords := c.GetString("keywords")
  5427. page, _ := c.GetInt64("page")
  5428. limit, _ := c.GetInt64("limit")
  5429. sch_type, _ := c.GetInt64("sch_type")
  5430. timeLayout := "2006-01-02"
  5431. loc, _ := time.LoadLocation("Local")
  5432. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5433. if err != nil {
  5434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5435. return
  5436. }
  5437. recordDateTime := theTime.Unix()
  5438. adminInfo := c.GetAdminUserInfo()
  5439. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5440. //adminInfo := c.GetAdminUserInfo()
  5441. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5442. //fmt.Println(prescriptionOrder)
  5443. if err == nil {
  5444. c.ServeSuccessJSON(map[string]interface{}{
  5445. "order": prescriptionOrder,
  5446. "total": total,
  5447. })
  5448. } else {
  5449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5450. return
  5451. }
  5452. }
  5453. func (c *HisApiController) GetHisPrescriptionInfo() {
  5454. id, _ := c.GetInt64("id")
  5455. adminInfo := c.GetAdminUserInfo()
  5456. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5457. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5458. if err == nil {
  5459. c.ServeSuccessJSON(map[string]interface{}{
  5460. "order": prescriptionOrder,
  5461. "prescription": prescription,
  5462. })
  5463. } else {
  5464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5465. return
  5466. }
  5467. }
  5468. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5469. adminUser := c.GetAdminUserInfo()
  5470. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5471. c.ServeSuccessJSON(map[string]interface{}{
  5472. "config": config,
  5473. })
  5474. }
  5475. type ResultTwo struct {
  5476. ErrMsg interface{} `json:"err_msg"`
  5477. InfRefmsgid string `json:"inf_refmsgid"`
  5478. Infcode int64 `json:"infcode"`
  5479. Output struct {
  5480. Baseinfo struct {
  5481. Age float64 `json:"age"`
  5482. Brdy string `json:"brdy"`
  5483. Certno string `json:"certno"`
  5484. Gend string `json:"gend"`
  5485. Naty string `json:"naty"`
  5486. PsnCertType string `json:"psn_cert_type"`
  5487. PsnName string `json:"psn_name"`
  5488. PsnNo string `json:"psn_no"`
  5489. } `json:"baseinfo"`
  5490. Idetinfo []interface{} `json:"idetinfo"`
  5491. Iinfo []struct {
  5492. Balc float64 `json:"balc"`
  5493. CvlservFlag string `json:"cvlserv_flag"`
  5494. EmpName string `json:"emp_name"`
  5495. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5496. Insutype string `json:"insutype"`
  5497. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5498. PausInsuDate interface{} `json:"paus_insu_date"`
  5499. PsnInsuDate string `json:"psn_insu_date"`
  5500. PsnInsuStas string `json:"psn_insu_stas"`
  5501. PsnType string `json:"psn_type"`
  5502. } `json:"insuinfo"`
  5503. } `json:"output"`
  5504. RefmsgTime string `json:"refmsg_time"`
  5505. RespondTime string `json:"respond_time"`
  5506. Signtype interface{} `json:"signtype"`
  5507. WarnInfo interface{} `json:"warn_info"`
  5508. }
  5509. type ResultThree struct {
  5510. Cainfo interface{} `json:"cainfo"`
  5511. ErrMsg interface{} `json:"err_msg"`
  5512. InfRefmsgid string `json:"inf_refmsgid"`
  5513. Infcode int64 `json:"infcode"`
  5514. Output struct {
  5515. Data struct {
  5516. IptOtpNo string `json:"ipt_otp_no"`
  5517. MdtrtID string `json:"mdtrt_id"`
  5518. PsnNo string `json:"psn_no"`
  5519. } `json:"data"`
  5520. } `json:"output"`
  5521. RefmsgTime string `json:"refmsg_time"`
  5522. RespondTime string `json:"respond_time"`
  5523. Signtype interface{} `json:"signtype"`
  5524. WarnMsg interface{} `json:"warn_msg"`
  5525. }
  5526. type ResultFour struct {
  5527. Cainfo string `json:"cainfo"`
  5528. ErrMsg string `json:"err_msg"`
  5529. InfRefmsgid string `json:"inf_refmsgid"`
  5530. Infcode int64 `json:"infcode"`
  5531. Output struct {
  5532. Result []struct {
  5533. BasMednFlag string `json:"bas_medn_flag"`
  5534. ChldMedcFlag string `json:"chld_medc_flag"`
  5535. ChrgitmLv string `json:"chrgitm_lv"`
  5536. Cnt float64 `json:"cnt"`
  5537. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5538. DrtReimFlag string `json:"drt_reim_flag"`
  5539. FeedetlSn string `json:"feedetl_sn"`
  5540. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5541. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5542. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5543. ListSpItemFlag string `json:"list_sp_item_flag"`
  5544. LmtUsedFlag string `json:"lmt_used_flag"`
  5545. MedChrgitmType string `json:"med_chrgitm_type"`
  5546. Memo string `json:"memo"`
  5547. OverlmtAmt float64 `json:"overlmt_amt"`
  5548. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5549. Pric float64 `json:"pric"`
  5550. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5551. SelfpayProp float64 `json:"selfpay_prop"`
  5552. } `json:"result"`
  5553. } `json:"output"`
  5554. RefmsgTime string `json:"refmsg_time"`
  5555. RespondTime string `json:"respond_time"`
  5556. Signtype string `json:"signtype"`
  5557. WarnMsg string `json:"warn_msg"`
  5558. }
  5559. type ResultFive struct {
  5560. Insutype string `json:"insutype"`
  5561. }
  5562. type ResultSix struct {
  5563. Cainfo interface{} `json:"cainfo"`
  5564. ErrMsg interface{} `json:"err_msg"`
  5565. InfRefmsgid string `json:"inf_refmsgid"`
  5566. Infcode int64 `json:"infcode"`
  5567. Output struct {
  5568. } `json:"output"`
  5569. RefmsgTime string `json:"refmsg_time"`
  5570. RespondTime string `json:"respond_time"`
  5571. Signtype interface{} `json:"signtype"`
  5572. WarnMsg interface{} `json:"warn_msg"`
  5573. }
  5574. type ResultSeven struct {
  5575. Cainfo string `json:"cainfo"`
  5576. ErrMsg string `json:"err_msg"`
  5577. InfRefmsgid string `json:"inf_refmsgid"`
  5578. Infcode int64 `json:"infcode"`
  5579. Output struct {
  5580. Setldetail []interface{} `json:"setldetail"`
  5581. Setlinfo struct {
  5582. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5583. AcctPay float64 `json:"acct_pay"`
  5584. ActPayDedc float64 `json:"act_pay_dedc"`
  5585. Age float64 `json:"age"`
  5586. Balc float64 `json:"balc"`
  5587. Brdy string `json:"brdy"`
  5588. Certno string `json:"certno"`
  5589. ClrOptins string `json:"clr_optins"`
  5590. ClrType string `json:"clr_type"`
  5591. ClrWay string `json:"clr_way"`
  5592. CvlservFlag string `json:"cvlserv_flag"`
  5593. CvlservPay float64 `json:"cvlserv_pay"`
  5594. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5595. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5596. Gend string `json:"gend"`
  5597. HifesPay float64 `json:"hifes_pay"`
  5598. HifmiPay float64 `json:"hifmi_pay"`
  5599. HifobPay float64 `json:"hifob_pay"`
  5600. HifpPay float64 `json:"hifp_pay"`
  5601. HospPartAmt float64 `json:"hosp_part_amt"`
  5602. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5603. Insutype string `json:"insutype"`
  5604. MafPay float64 `json:"maf_pay"`
  5605. MdtrtCertType string `json:"mdtrt_cert_type"`
  5606. MdtrtID string `json:"mdtrt_id"`
  5607. MedType string `json:"med_type"`
  5608. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5609. MedinsSetlID string `json:"medins_setl_id"`
  5610. Naty string `json:"naty"`
  5611. OthPay float64 `json:"oth_pay"`
  5612. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5613. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5614. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5615. PsnCashPay float64 `json:"psn_cash_pay"`
  5616. PsnCertType string `json:"psn_cert_type"`
  5617. PsnName string `json:"psn_name"`
  5618. PsnNo string `json:"psn_no"`
  5619. PsnPartAmt float64 `json:"psn_part_amt"`
  5620. PsnType string `json:"psn_type"`
  5621. SetlID string `json:"setl_id"`
  5622. SetlTime string `json:"setl_time"`
  5623. } `json:"setlinfo"`
  5624. } `json:"output"`
  5625. RefmsgTime string `json:"refmsg_time"`
  5626. RespondTime string `json:"respond_time"`
  5627. Signtype interface{} `json:"signtype"`
  5628. WarnMsg interface{} `json:"warn_msg"`
  5629. }
  5630. type ResultEight struct {
  5631. Cainfo string `json:"cainfo"`
  5632. ErrMsg string `json:"err_msg"`
  5633. InfRefmsgid string `json:"inf_refmsgid"`
  5634. Infcode int64 `json:"infcode"`
  5635. Output struct {
  5636. Stmtinfo struct {
  5637. SetlOptins string `json:"setl_optins"`
  5638. StmtRslt string `json:"stmt_rslt"`
  5639. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5640. } `json:"stmtinfo"`
  5641. } `json:"output"`
  5642. RefmsgTime string `json:"refmsg_time"`
  5643. RespondTime string `json:"respond_time"`
  5644. Signtype interface{} `json:"signtype"`
  5645. WarnMsg interface{} `json:"warn_msg"`
  5646. }
  5647. type ResultNine struct {
  5648. Cainfo string `json:"cainfo"`
  5649. ErrMsg string `json:"err_msg"`
  5650. InfRefmsgid string `json:"inf_refmsgid"`
  5651. Infcode int64 `json:"infcode"`
  5652. Output struct {
  5653. FileQuryNo string `json:"file_qury_no"`
  5654. } `json:"output"`
  5655. RefmsgTime string `json:"refmsg_time"`
  5656. RespondTime string `json:"respond_time"`
  5657. Signtype interface{} `json:"signtype"`
  5658. WarnMsg interface{} `json:"warn_msg"`
  5659. }
  5660. type ResultTen struct {
  5661. Cainfo string `json:"cainfo"`
  5662. ErrMsg string `json:"err_msg"`
  5663. InfRefmsgid string `json:"inf_refmsgid"`
  5664. Infcode int64 `json:"infcode"`
  5665. Output struct {
  5666. DldEndtime string `json:"dld_endtime"`
  5667. FileQuryNo string `json:"file_qury_no"`
  5668. Filename string `json:"filename"`
  5669. } `json:"output"`
  5670. RefmsgTime string `json:"refmsg_time"`
  5671. RespondTime string `json:"respond_time"`
  5672. Signtype interface{} `json:"signtype"`
  5673. WarnMsg interface{} `json:"warn_msg"`
  5674. }
  5675. type ResultEleven struct {
  5676. Cainfo string `json:"cainfo"`
  5677. ErrMsg string `json:"err_msg"`
  5678. InfRefmsgid string `json:"inf_refmsgid"`
  5679. Infcode int64 `json:"infcode"`
  5680. Output struct {
  5681. Setlinfo struct {
  5682. FixmedinsName string `json:"fixmedins_name"`
  5683. FixmedinsCode string `json:"fixmedins_code"`
  5684. PsnNo string `json:"psn_no"`
  5685. PsnName string `json:"psn_name"`
  5686. HifobPay float64 `json:"hifob_pay"`
  5687. Gend string `json:"gend"`
  5688. Brdy string `json:"brdy"`
  5689. PsnCertType string `json:"psn_cert_type"`
  5690. PsnType string `json:"psn_type"`
  5691. EmpName string `json:"emp_name"`
  5692. Certno string `json:"certno"`
  5693. Insutype string `json:"insutype"`
  5694. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5695. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5696. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5697. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5698. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5699. ActPayDedc float64 `json:"act_pay_dedc"`
  5700. HifpPay float64 `json:"hifp_pay"`
  5701. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5702. CvlservPay float64 `json:"cvlserv_pay"`
  5703. HifesPay float64 `json:"hifes_pay"`
  5704. HifmiPay float64 `json:"hifmi_pay"`
  5705. MafPay float64 `json:"maf_pay"`
  5706. OthPay float64 `json:"oth_pay"`
  5707. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5708. PsnPay float64 `json:"psn_pay"`
  5709. AcctPay float64 `json:"acct_pay"`
  5710. CashPayamt float64 `json:"cash_payamt"`
  5711. Balc float64 `json:"balc"`
  5712. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5713. MedinsSetlId string `json:"medins_setl_id"`
  5714. RefdSetlFlag string `json:"refd_setl_flag"`
  5715. SetlTime string `json:"setl_time"`
  5716. MedType string `json:"med_type"`
  5717. } `json:"setlinfo"`
  5718. } `json:"output"`
  5719. RefmsgTime string `json:"refmsg_time"`
  5720. RespondTime string `json:"respond_time"`
  5721. Signtype interface{} `json:"signtype"`
  5722. WarnMsg interface{} `json:"warn_msg"`
  5723. }
  5724. type Custom struct {
  5725. DetItemFeeSumamt string
  5726. Cut string
  5727. FeedetlSn string
  5728. Price string
  5729. MedListCodg string
  5730. Type int64
  5731. AdviceId int64
  5732. ProjectId int64
  5733. ItemId int64
  5734. }
  5735. // 获取个人信息----挂号-----上传就诊信息
  5736. func (c *HisApiController) GetRegisterInfo() {
  5737. id, _ := c.GetInt64("id")
  5738. record_time := c.GetString("record_time")
  5739. settlementValue, _ := c.GetInt64("settlement_value")
  5740. medical_insurance_card := c.GetString("medical_insurance_card")
  5741. name := c.GetString("name")
  5742. id_card_type, _ := c.GetInt64("id_card_type")
  5743. certificates, _ := c.GetInt64("certificates")
  5744. medical_care, _ := c.GetInt64("medical_care")
  5745. birthday := c.GetString("birthday")
  5746. age, _ := c.GetInt64("age")
  5747. id_card := c.GetString("id_card")
  5748. register_type, _ := c.GetInt64("register")
  5749. doctor, _ := c.GetInt64("doctor")
  5750. department, _ := c.GetInt64("department")
  5751. gender, _ := c.GetInt64("sex")
  5752. phone := c.GetString("phone")
  5753. registration_fee, _ := c.GetFloat("registration_fee")
  5754. medical_expenses, _ := c.GetFloat("medical_expenses")
  5755. social_type, _ := c.GetInt64("social_type")
  5756. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5757. diagnosis_ids := c.GetString("diagnosis")
  5758. sick_type, _ := c.GetInt64("sick_type")
  5759. reg_type := c.GetString("p_type")
  5760. timeLayout := "2006-01-02"
  5761. loc, _ := time.LoadLocation("Local")
  5762. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5763. birthUnix := birthdays.Unix()
  5764. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5765. if err != nil {
  5766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5767. return
  5768. }
  5769. recordDateTime := theTime.Unix()
  5770. adminInfo := c.GetAdminUserInfo()
  5771. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5772. if tempPatient.ID == 0 {
  5773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5774. return
  5775. }
  5776. var patient service.Patients
  5777. if id == 0 {
  5778. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5779. } else {
  5780. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5781. }
  5782. if patient.ID == 0 {
  5783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5784. return
  5785. }
  5786. if len(patient.IdCardNo) == 0 {
  5787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5788. return
  5789. }
  5790. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5791. if len(his) >= 1 {
  5792. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5793. if len(his) >= 1 && order.ID == 0 {
  5794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5795. return
  5796. }
  5797. }
  5798. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5799. fmt.Println(timeStr)
  5800. timeArr := strings.Split(timeStr, " ")
  5801. fmt.Println(timeArr)
  5802. timeArrTwo := strings.Split(timeArr[0], "-")
  5803. timeArrThree := strings.Split(timeArr[1], ":")
  5804. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5805. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5806. if len(lists) == 0 {
  5807. var hisPatient models.XtHisPatient
  5808. hisPatient = models.XtHisPatient{
  5809. Name: name,
  5810. Age: age,
  5811. Gender: gender,
  5812. Birthday: birthUnix,
  5813. Phone: phone,
  5814. MedicalTreatmentType: medical_care,
  5815. IdType: certificates,
  5816. IdCardNo: id_card,
  5817. BalanceAccountsType: settlementValue,
  5818. SocialType: social_type,
  5819. MedicalInsuranceNumber: medical_insurance_card,
  5820. RegisterType: register_type,
  5821. RegisterCost: registration_fee,
  5822. TreatmentCost: medical_expenses,
  5823. AdminUserId: adminInfo.AdminUser.Id,
  5824. UserOrgId: adminInfo.CurrentOrgId,
  5825. Status: 1,
  5826. RecordDate: recordDateTime,
  5827. IsReturn: 1,
  5828. PatientId: patient.ID,
  5829. Ctime: time.Now().Unix(),
  5830. Mtime: time.Now().Unix(),
  5831. Number: str,
  5832. IdCardType: id_card_type,
  5833. Departments: department,
  5834. Doctor: doctor,
  5835. PType: reg_type,
  5836. Diagnosis: diagnosis_ids,
  5837. SickType: sick_type,
  5838. }
  5839. service.CreateHisPatient(&hisPatient)
  5840. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5841. c.ServeSuccessJSON(map[string]interface{}{
  5842. "his_info": hisPatient,
  5843. })
  5844. } else {
  5845. //chrgBchno := rand.Intn(1000000) + 10000
  5846. var hisPatient models.XtHisPatient
  5847. hisPatient = models.XtHisPatient{
  5848. Name: name,
  5849. Age: age,
  5850. Gender: gender,
  5851. Birthday: birthUnix,
  5852. Phone: phone,
  5853. MedicalTreatmentType: medical_care,
  5854. IdType: certificates,
  5855. IdCardNo: id_card,
  5856. BalanceAccountsType: settlementValue,
  5857. SocialType: social_type,
  5858. MedicalInsuranceNumber: medical_insurance_card,
  5859. RegisterType: register_type,
  5860. RegisterCost: registration_fee,
  5861. TreatmentCost: medical_expenses,
  5862. AdminUserId: adminInfo.AdminUser.Id,
  5863. UserOrgId: adminInfo.CurrentOrgId,
  5864. Status: 1,
  5865. RecordDate: recordDateTime,
  5866. IsReturn: 1,
  5867. PatientId: patient.ID,
  5868. Ctime: time.Now().Unix(),
  5869. Mtime: time.Now().Unix(),
  5870. Number: str,
  5871. IdCardType: id_card_type,
  5872. Departments: department,
  5873. Doctor: doctor,
  5874. PType: reg_type,
  5875. Diagnosis: diagnosis_ids,
  5876. SickType: sick_type,
  5877. }
  5878. service.CreateHisPatient(&hisPatient)
  5879. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5880. c.ServeSuccessJSON(map[string]interface{}{
  5881. "his_info": hisPatient,
  5882. })
  5883. }
  5884. }
  5885. // 上传明细----结算
  5886. func (c *HisApiController) GetUploadInfo() {
  5887. id, _ := c.GetInt64("id")
  5888. record_time := c.GetString("record_time")
  5889. his_patient_id, _ := c.GetInt64("his_patient_id")
  5890. oth_desc := c.GetString("oth_desc")
  5891. pay_way, _ := c.GetInt64("pay_way")
  5892. pay_ways := c.GetString("pay_ways")
  5893. pay_price, _ := c.GetFloat("pay_price")
  5894. pay_card_no := c.GetString("pay_card_no")
  5895. discount_price, _ := c.GetFloat("discount_price")
  5896. preferential_price, _ := c.GetFloat("preferential_price")
  5897. reality_price, _ := c.GetFloat("reality_price")
  5898. found_price, _ := c.GetFloat("found_price")
  5899. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5900. private_price, _ := c.GetFloat("private_price")
  5901. timeLayout := "2006-01-02"
  5902. loc, _ := time.LoadLocation("Local")
  5903. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5904. fapiao_code := c.GetString("fapiao_code")
  5905. fapiao_number := c.GetString("fapiao_number")
  5906. diagnosis_id := c.GetString("diagnosis")
  5907. sick_type, _ := c.GetInt64("sick_type")
  5908. reg_type, _ := c.GetInt64("p_type")
  5909. order_id, _ := c.GetInt64("order_id")
  5910. cash_pay := c.GetString("cash_pay")
  5911. wechat_pay := c.GetString("wechat_pay")
  5912. ali_pay := c.GetString("ali_pay")
  5913. jifen_pay := c.GetString("jifen_pay")
  5914. band_card_pay := c.GetString("band_card_pay")
  5915. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5916. tmp_decimal := c.GetString("tmp_decimal")
  5917. var decimal float64 //本次使用的押金
  5918. var errmsg error
  5919. tx := service.XTWriteDB().Begin() //开了事务
  5920. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5921. defer func() {
  5922. if errmsg != nil {
  5923. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5924. tx.Rollback()
  5925. } else {
  5926. tx.Commit()
  5927. }
  5928. }()
  5929. fmt.Println("dec_way", dec_way)
  5930. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5931. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5932. return
  5933. }
  5934. if len(tmp_decimal) > 0 {
  5935. if tmp_decimal[0] == 45 {
  5936. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5937. return
  5938. }
  5939. }
  5940. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5941. fmt.Println(errs)
  5942. decimal = tt
  5943. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5944. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5945. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5946. if err != nil {
  5947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5948. return
  5949. }
  5950. recordDateTime := theTime.Unix()
  5951. adminUser := c.GetAdminUserInfo()
  5952. var prescriptions []*models.HisPrescription
  5953. var prescriptionsOne []*models.HisPrescription
  5954. var start_time int64
  5955. var end_time int64
  5956. ids_str := c.GetString("ids")
  5957. ids_arr := strings.Split(ids_str, ",")
  5958. if tempOrder.ID == 0 {
  5959. if settle_accounts_type == 1 { //日结
  5960. fmt.Println(reg_type)
  5961. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5962. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5963. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5964. } else {
  5965. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5966. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5967. }
  5968. } else { //月结
  5969. start_time_str := c.GetString("start_time")
  5970. end_time_str := c.GetString("end_time")
  5971. timeLayout := "2006-01-02"
  5972. loc, _ := time.LoadLocation("Local")
  5973. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5974. if err != nil {
  5975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5976. return
  5977. }
  5978. recordStartTime := theStartTime.Unix()
  5979. start_time = recordStartTime
  5980. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5981. if err != nil {
  5982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5983. return
  5984. }
  5985. recordEndTime := theEndTime.Unix()
  5986. end_time = recordEndTime
  5987. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5988. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5989. }
  5990. var goods []*models.DialysisBeforePrepareGoods
  5991. var newGoods []*models.NewDialysisBeforePrepareGoods
  5992. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5993. var infos []*models.HisDoctorAdviceInfo
  5994. var infoList []*models.HisDoctorAdviceInfo
  5995. var hisAdvice []*models.HisDoctorAdviceInfo
  5996. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5997. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5998. //判断库存不足
  5999. //结算出库开关
  6000. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6001. if settConfig.IsOpen == 1 {
  6002. //判断库存的地方
  6003. for _, info := range prescriptions {
  6004. if info.Type == 1 {
  6005. infos = append(infos, info.HisDoctorAdviceInfo...)
  6006. }
  6007. if info.Type == 2 {
  6008. for _, sumItem := range info.HisPrescriptionProject {
  6009. if sumItem.Type == 3 {
  6010. var good models.DialysisBeforePrepareGoods
  6011. var newGood models.NewDialysisBeforePrepareGoods
  6012. good.GoodId = sumItem.GoodInfo.ID
  6013. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6014. count, _ := strconv.Atoi(sumItem.Count)
  6015. good.Count = int64(count)
  6016. good.StorehouseId = houseConfig.StorehouseOutInfo
  6017. good.ProjectId = sumItem.ID
  6018. goods = append(goods, &good)
  6019. newGood.GoodId = sumItem.GoodInfo.ID
  6020. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6021. count2, _ := strconv.Atoi(sumItem.Count)
  6022. newGood.Count = int64(count2)
  6023. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6024. newGood.ProjectId = sumItem.ID
  6025. newGoods = append(newGoods, &newGood)
  6026. }
  6027. }
  6028. }
  6029. }
  6030. for _, info := range prescriptionsOne {
  6031. if info.Type == 1 {
  6032. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6033. }
  6034. if info.Type == 2 {
  6035. for _, sumItem := range info.HisPrescriptionProject {
  6036. if sumItem.Type == 3 {
  6037. var newGood models.NewDialysisBeforePrepareGoods
  6038. newGood.GoodId = sumItem.GoodInfo.ID
  6039. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6040. count2, _ := strconv.Atoi(sumItem.Count)
  6041. newGood.Count = int64(count2)
  6042. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6043. newGood.ProjectId = sumItem.ID
  6044. newGoodOne = append(newGoodOne, &newGood)
  6045. }
  6046. }
  6047. }
  6048. }
  6049. //判断
  6050. for _, itemOne := range infos {
  6051. for _, itemTwo := range hisAdvice {
  6052. if itemOne.DrugId == itemTwo.DrugId {
  6053. itemTwo.Child = append(itemTwo.Child, itemOne)
  6054. }
  6055. }
  6056. }
  6057. for _, itemTwo := range hisAdvice {
  6058. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6059. var sum_out_count int64
  6060. for _, itemThree := range itemTwo.Child {
  6061. var prescribing_number int64
  6062. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6063. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6064. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6065. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6066. }
  6067. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6068. prescribing_number = parseIntPrescribingNumber
  6069. }
  6070. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6071. prescribing_number = parseIntPrescribingNumber
  6072. }
  6073. sum_out_count += prescribing_number
  6074. }
  6075. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6076. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6077. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6078. if sum_out_count > drugStockOut.FlushCount {
  6079. c.ServeSuccessJSON(map[string]interface{}{
  6080. "msg": "2",
  6081. "drug": medical,
  6082. })
  6083. return
  6084. }
  6085. }
  6086. fmt.Println("newGoods99999988882os", newGoods)
  6087. for _, itemOne := range newGoods {
  6088. for _, item := range newGoodOne {
  6089. if itemOne.GoodId == item.GoodId {
  6090. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6091. }
  6092. }
  6093. }
  6094. for _, item := range newGoodOne {
  6095. var sum_out_count_one int64
  6096. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6097. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6098. sum_out_count_one += itemOne.Count
  6099. }
  6100. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6101. fmt.Println("sum_out_count_one", sum_out_count_one)
  6102. fmt.Println("list.FlushCount", list.FlushCount)
  6103. if sum_out_count_one > list.FlushCount {
  6104. c.ServeSuccessJSON(map[string]interface{}{
  6105. "msg": "3",
  6106. "good": good,
  6107. })
  6108. return
  6109. }
  6110. }
  6111. }
  6112. timestamp := time.Now().Unix()
  6113. tempTime := time.Unix(timestamp, 0)
  6114. timeFormat := tempTime.Format("20060102150405")
  6115. chrgBchno := rand.Intn(100000) + 10000
  6116. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6117. strconv.FormatInt(his.PatientId, 10)
  6118. var ids []int64
  6119. for _, item := range prescriptions {
  6120. ids = append(ids, item.ID)
  6121. }
  6122. var total float64
  6123. for _, item := range prescriptions {
  6124. fmt.Println(item)
  6125. if item.Type == 1 { //药品
  6126. for _, subItem := range item.HisDoctorAdviceInfo {
  6127. total = total + (subItem.Price * subItem.PrescribingNumber)
  6128. }
  6129. }
  6130. if item.Type == 2 { //项目
  6131. for _, subItem := range item.HisPrescriptionProject {
  6132. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6133. total = total + (subItem.Price * cnt)
  6134. }
  6135. }
  6136. for _, subItem := range item.HisAdditionalCharge {
  6137. total = total + (subItem.Price * float64(subItem.Count))
  6138. }
  6139. }
  6140. if reg_type == 1111 || reg_type == 1112 {
  6141. reg_type = 11
  6142. }
  6143. tm := time.Unix(time.Now().Unix(), 0)
  6144. allTotal := fmt.Sprintf("%.4f", total)
  6145. totals, _ := strconv.ParseFloat(allTotal, 64)
  6146. order := &models.HisOrder{
  6147. UserOrgId: adminUser.CurrentOrgId,
  6148. HisPatientId: his.ID,
  6149. PatientId: id,
  6150. SettleAccountsDate: recordDateTime,
  6151. Ctime: time.Now().Unix(),
  6152. Mtime: time.Now().Unix(),
  6153. Status: 1,
  6154. OrderStatus: 2,
  6155. MdtrtId: his.Number,
  6156. Number: chrg_bchno,
  6157. MedfeeSumamt: totals,
  6158. PayWay: pay_way,
  6159. PayWays: pay_ways,
  6160. PayPrice: pay_price,
  6161. MedType: strconv.Itoa(int(reg_type)),
  6162. PayCardNo: pay_card_no,
  6163. DiscountPrice: discount_price,
  6164. PreferentialPrice: preferential_price,
  6165. RealityPrice: reality_price,
  6166. FoundPrice: found_price,
  6167. MedicalInsurancePrice: medical_insurance_price,
  6168. PrivatePrice: private_price,
  6169. SettleEndTime: end_time,
  6170. SettleStartTime: start_time,
  6171. PsnPartAmt: totals,
  6172. PsnCashPay: totals,
  6173. SettleType: settle_accounts_type,
  6174. FaPiaoCode: fapiao_code,
  6175. FaPiaoNumber: fapiao_number,
  6176. Diagnosis: diagnosis_id,
  6177. PType: 2,
  6178. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6179. Decimal: decimal,
  6180. OthDesc: oth_desc,
  6181. CashPay: cash_pay,
  6182. WechatPay: wechat_pay,
  6183. AliPay: ali_pay,
  6184. JifenPay: jifen_pay,
  6185. BandCardPay: band_card_pay,
  6186. }
  6187. err = service.CreateOrderTX(order, tx)
  6188. if err != nil {
  6189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6190. return
  6191. }
  6192. var customs []*Custom
  6193. for _, item := range prescriptions {
  6194. if item.Type == 1 { //药品a
  6195. for _, subItem := range item.HisDoctorAdviceInfo {
  6196. cus := &Custom{
  6197. AdviceId: subItem.ID,
  6198. ProjectId: 0,
  6199. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6200. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6201. FeedetlSn: subItem.FeedetlSn,
  6202. Price: fmt.Sprintf("%.4f", subItem.Price),
  6203. MedListCodg: subItem.MedListCodg,
  6204. Type: 1,
  6205. }
  6206. customs = append(customs, cus)
  6207. }
  6208. }
  6209. if item.Type == 2 { //项目
  6210. for _, subItem := range item.HisPrescriptionProject {
  6211. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6212. cus := &Custom{
  6213. AdviceId: 0,
  6214. ProjectId: subItem.ID,
  6215. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6216. Cut: fmt.Sprintf("%.4f", cnt),
  6217. FeedetlSn: subItem.FeedetlSn,
  6218. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6219. MedListCodg: subItem.MedListCodg,
  6220. Type: 2,
  6221. }
  6222. customs = append(customs, cus)
  6223. }
  6224. }
  6225. for _, item := range item.HisAdditionalCharge {
  6226. cus := &Custom{
  6227. ItemId: item.ID,
  6228. AdviceId: 0,
  6229. ProjectId: 0,
  6230. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6231. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6232. FeedetlSn: item.FeedetlSn,
  6233. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6234. MedListCodg: item.XtHisAddtionConfig.Code,
  6235. Type: 3,
  6236. }
  6237. customs = append(customs, cus)
  6238. }
  6239. }
  6240. for _, item := range customs {
  6241. var advice_id int64 = 0
  6242. var project_id int64 = 0
  6243. var item_id int64 = 0
  6244. var types int64 = 0
  6245. if item.Type == 1 {
  6246. advice_id = item.AdviceId
  6247. project_id = 0
  6248. item_id = 0
  6249. } else if item.Type == 2 {
  6250. advice_id = 0
  6251. item_id = 0
  6252. project_id = item.ProjectId
  6253. } else if item.Type == 3 {
  6254. advice_id = 0
  6255. item_id = item.ItemId
  6256. project_id = 0
  6257. }
  6258. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6259. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6260. pric, _ := strconv.ParseFloat(item.Price, 32)
  6261. info := &models.HisOrderInfo{
  6262. OrderNumber: order.Number,
  6263. UploadDate: time.Now().Unix(),
  6264. AdviceId: advice_id,
  6265. DetItemFeeSumamt: detItemFeeSumamt,
  6266. Cnt: cut,
  6267. Pric: pric,
  6268. PatientId: id,
  6269. Status: 1,
  6270. Mtime: time.Now().Unix(),
  6271. Ctime: time.Now().Unix(),
  6272. UserOrgId: adminUser.CurrentOrgId,
  6273. HisPatientId: his.ID,
  6274. OrderId: order.ID,
  6275. ProjectId: project_id,
  6276. Type: types,
  6277. ItemId: item_id,
  6278. }
  6279. service.CreateOrderInfoTX(info, tx)
  6280. }
  6281. his.Diagnosis = diagnosis_id
  6282. his.SickType = sick_type
  6283. his.RegisterType = reg_type
  6284. his.MedicalTreatmentType = reg_type
  6285. service.UpdataHisPateintTX(&his, tx)
  6286. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6287. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6288. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6289. //判断是否使用了押金
  6290. if dec_way == "true" {
  6291. tmpstring := strconv.FormatInt(order.ID, 10)
  6292. //扣押金
  6293. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6294. order.Decimal = decimal
  6295. service.UpDateOrderTwo(order, tx)
  6296. if errmsg != nil {
  6297. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6298. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6299. return
  6300. }
  6301. }
  6302. if err == nil {
  6303. for _, info := range prescriptions {
  6304. if info.Type == 1 {
  6305. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6306. }
  6307. if info.Type == 2 {
  6308. for _, sumItem := range info.HisPrescriptionProject {
  6309. if sumItem.Type == 3 {
  6310. var good models.DialysisBeforePrepareGoods
  6311. var newGood models.NewDialysisBeforePrepareGoods
  6312. var oldGood models.OldDialysisBeforePrepareGoods
  6313. good.GoodId = sumItem.GoodInfo.ID
  6314. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6315. count, _ := strconv.Atoi(sumItem.Count)
  6316. good.Count = int64(count)
  6317. good.StorehouseId = houseConfig.StorehouseOutInfo
  6318. good.ProjectId = sumItem.ID
  6319. good.PatientId = sumItem.PatientId
  6320. goods = append(goods, &good)
  6321. newGood.GoodId = sumItem.GoodInfo.ID
  6322. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6323. count2, _ := strconv.Atoi(sumItem.Count)
  6324. newGood.Count = int64(count2)
  6325. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6326. newGood.ProjectId = sumItem.ID
  6327. newGood.PatientId = sumItem.HisPatientId
  6328. newGoods = append(newGoods, &newGood)
  6329. oldGood.GoodId = sumItem.GoodInfo.ID
  6330. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6331. count3, _ := strconv.Atoi(sumItem.Count)
  6332. oldGood.Count = int64(count3)
  6333. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6334. oldGood.ProjectId = sumItem.ID
  6335. oldGood.RecordDate = sumItem.RecordDate
  6336. oldGood.PatientId = sumItem.HisPatientId
  6337. oldGoods = append(oldGoods, &oldGood)
  6338. }
  6339. }
  6340. }
  6341. }
  6342. if settConfig.IsOpen == 1 {
  6343. for _, item := range infoList {
  6344. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6345. if medical.IsUse == 2 {
  6346. //药品出库
  6347. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6348. //查询默认仓库
  6349. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6350. //查询默认仓库剩余多少库存
  6351. var sum_count int64
  6352. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6353. for _, its := range stockInfo {
  6354. if its.MaxUnit == medical.MaxUnit {
  6355. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6356. }
  6357. sum_count += its.StockMaxNumber + its.StockMinNumber
  6358. }
  6359. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6360. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6361. }
  6362. }
  6363. orgId := c.GetAdminUserInfo().CurrentOrgId
  6364. if len(oldGoods) > 0 {
  6365. timeStr := time.Now().Format("2006-01-02")
  6366. timeArr := strings.Split(timeStr, "-")
  6367. total, _ := service.FindAllWarehouseOut(orgId)
  6368. total = total + 1
  6369. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6370. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6371. number = number + total
  6372. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6373. operation_time := time.Now().Unix()
  6374. creater := c.GetAdminUserInfo().AdminUser.Id
  6375. //查询默认出库仓库库存
  6376. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6377. recordDateStr := time.Now().Format("2006-01-02")
  6378. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6379. nowtime := recordDate.Unix()
  6380. warehouseOut := models.WarehouseOut{
  6381. WarehouseOutOrderNumber: warehousing_out_order,
  6382. OperationTime: operation_time,
  6383. OrgId: orgId,
  6384. Creater: creater,
  6385. Ctime: time.Now().Unix(),
  6386. Status: 1,
  6387. WarehouseOutTime: nowtime,
  6388. Type: 1,
  6389. StorehouseId: storeConfig.StorehouseOutInfo,
  6390. IsCheck: 1,
  6391. OrderId: order.ID,
  6392. IsSys: 5,
  6393. }
  6394. //查询是否生成出库单
  6395. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6396. if out.ID == 0 {
  6397. service.AddSigleWarehouseOut(&warehouseOut)
  6398. }
  6399. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6400. for _, item := range oldGoods {
  6401. dialyPrepareOne := models.DialysisBeforePrepare{
  6402. GoodTypeId: item.GoodTypeId,
  6403. GoodId: item.GoodId,
  6404. PatientId: his.PatientId,
  6405. RecordDate: item.RecordDate,
  6406. UserOrgId: adminUser.CurrentOrgId,
  6407. Count: item.Count,
  6408. Ctime: time.Now().Unix(),
  6409. Creater: adminUser.AdminUser.Id,
  6410. CommdityCode: item.CommdityCode,
  6411. Status: 1,
  6412. StorehouseId: houseConfig.StorehouseOutInfo,
  6413. }
  6414. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6415. //非零用
  6416. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6417. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6418. //查询剩余库存
  6419. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6420. var sum_count int64
  6421. for _, item := range goodList {
  6422. sum_count += item.StockCount
  6423. }
  6424. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6425. //耗材
  6426. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6427. }
  6428. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6429. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6430. //查询剩余库存
  6431. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6432. var sum_count int64
  6433. for _, item := range goodList {
  6434. sum_count += item.StockCount
  6435. }
  6436. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6437. //耗材
  6438. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6439. }
  6440. }
  6441. }
  6442. }
  6443. c.ServeSuccessJSON(map[string]interface{}{
  6444. "msg": "结算成功",
  6445. })
  6446. }
  6447. }
  6448. }
  6449. // 退款
  6450. func (c *HisApiController) Refund() {
  6451. order_id, _ := c.GetInt64("order_id")
  6452. order, _ := service.GetHisOrderByID(order_id)
  6453. adminUser := c.GetAdminUserInfo()
  6454. orgid := c.GetAdminUserInfo().CurrentOrgId
  6455. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6456. if err != nil {
  6457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6458. return
  6459. }
  6460. tmp := strconv.FormatInt(order.ID, 10)
  6461. //当押金不为零时产生退费记录
  6462. if order.Decimal != 0 {
  6463. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6464. if err != nil {
  6465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6466. return
  6467. }
  6468. }
  6469. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6470. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6471. var goods []*models.DialysisBeforePrepareGoods
  6472. var newGoods []*models.NewDialysisBeforePrepareGoods
  6473. var infos []*models.HisDoctorAdviceInfo
  6474. for _, info := range orders {
  6475. if info.AdviceId > 0 && info.ProjectId == 0 {
  6476. infos = append(infos, &info.HisDoctorAdviceInfo)
  6477. }
  6478. if info.ProjectId > 0 && info.AdviceId == 0 {
  6479. if info.HisPrescriptionProject.Type == 3 {
  6480. var good models.DialysisBeforePrepareGoods
  6481. var newGood models.NewDialysisBeforePrepareGoods
  6482. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6483. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6484. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6485. good.Count = int64(count)
  6486. good.StorehouseId = houseConfig.StorehouseOutInfo
  6487. good.ProjectId = info.HisPrescriptionProject.ID
  6488. good.PatientId = info.PatientId
  6489. good.OrderId = order_id
  6490. goods = append(goods, &good)
  6491. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6492. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6493. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6494. newGood.Count = int64(count2)
  6495. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6496. newGood.ProjectId = info.HisPrescriptionProject.ID
  6497. newGood.RecordDate = order.SettleAccountsDate
  6498. newGood.UserOrgId = order.UserOrgId
  6499. newGood.PatientId = info.PatientId
  6500. newGood.OrderId = order_id
  6501. newGoods = append(newGoods, &newGood)
  6502. }
  6503. }
  6504. }
  6505. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6506. if settConfig.IsOpen == 1 {
  6507. for _, item := range infos {
  6508. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6509. }
  6510. for _, item := range newGoods {
  6511. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6512. }
  6513. }
  6514. c.ServeSuccessJSON(map[string]interface{}{
  6515. "msg": "退费成功",
  6516. })
  6517. }
  6518. func (c *HisApiController) RefundNumber() {
  6519. his_patient_id, _ := c.GetInt64("id")
  6520. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6521. info.Status = 0
  6522. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6523. if count > 0 {
  6524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6525. return
  6526. }
  6527. err := service.SaveHisPatient(info)
  6528. if err == nil {
  6529. c.ServeSuccessJSON(map[string]interface{}{
  6530. "msg": "退号成功",
  6531. })
  6532. } else {
  6533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6534. return
  6535. }
  6536. }
  6537. func (this *HisApiController) AdditionalCharge() {
  6538. dataBody := make(map[string]interface{}, 0)
  6539. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6540. fmt.Println(err)
  6541. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6542. patient_id := int64(dataBody["patient_id"].(float64))
  6543. medicineData, _ := dataBody["medicineData"].([]interface{})
  6544. adminUserInfo := this.GetAdminUserInfo()
  6545. orgId := adminUserInfo.CurrentOrgId
  6546. admin_user_id := adminUserInfo.AdminUser.Id
  6547. timeStr := time.Now().Format("2006-01-02")
  6548. timeLayout := "2006-01-02 15:04:05"
  6549. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6550. timenow := timeStringToTime.Unix()
  6551. var additionalCharges []*models.HisAdditionalCharge
  6552. for _, item := range medicineData {
  6553. var randNum int
  6554. randNum = rand.Intn(10000) + 1000
  6555. timestamp := time.Now().Unix()
  6556. tempTime := time.Unix(timestamp, 0)
  6557. timeFormat := tempTime.Format("20060102150405")
  6558. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6559. items := item.(map[string]interface{})
  6560. money := items["price"].(string)
  6561. item_id_str := items["item_id"].(string)
  6562. name := items["name"].(string)
  6563. id_str := items["id"].(string)
  6564. moneys, _ := strconv.ParseInt(money, 10, 64)
  6565. monStr := strconv.FormatInt(moneys, 10)
  6566. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6567. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6568. id, _ := strconv.ParseInt(id_str, 10, 64)
  6569. additionalCharge := &models.HisAdditionalCharge{
  6570. ID: id,
  6571. HisPatientId: his_patient_id,
  6572. UserOrgId: orgId,
  6573. PatientId: patient_id,
  6574. RecordDate: timenow,
  6575. Price: monneyStr,
  6576. Status: 1,
  6577. ItemName: name,
  6578. ItemId: item_id,
  6579. AdminUserId: admin_user_id,
  6580. CreatedTime: time.Now().Unix(),
  6581. OrderStatus: 0,
  6582. PrescriptionNumber: "",
  6583. BatchNumber: "",
  6584. FeedetlSn: p_number,
  6585. }
  6586. service.CreateAdditionalCharge(additionalCharge)
  6587. additionalCharges = append(additionalCharges, additionalCharge)
  6588. }
  6589. this.ServeSuccessJSON(map[string]interface{}{
  6590. "msg": "添加成功",
  6591. "additional_charges": additionalCharges,
  6592. })
  6593. }
  6594. func (this *HisApiController) DeleteAddition() {
  6595. id, _ := this.GetInt64("id")
  6596. //TODO 需要判断是否已经结算
  6597. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6598. if err == nil {
  6599. this.ServeSuccessJSON(map[string]interface{}{
  6600. "msg": "删除成功",
  6601. })
  6602. return
  6603. } else {
  6604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6605. return
  6606. }
  6607. }
  6608. func (this *HisApiController) GetAdminUsers() {
  6609. adminUser := this.GetAdminUserInfo()
  6610. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6611. this.ServeSuccessJSON(map[string]interface{}{
  6612. "doctors": doctors,
  6613. })
  6614. }
  6615. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6616. change_type, _ := this.GetInt64("type", 0)
  6617. record_date := this.GetString("record_time")
  6618. patient_id, _ := this.GetInt64("patient_id", 0)
  6619. p_type, _ := this.GetInt64("p_type", 0)
  6620. timeLayout := "2006-01-02"
  6621. loc, _ := time.LoadLocation("Local")
  6622. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6623. record_time := theAdviceRecordTime.Unix()
  6624. adminUserInfo := this.GetAdminUserInfo()
  6625. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6626. if err == nil {
  6627. if len(prescriptions) == 0 {
  6628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6629. return
  6630. } else {
  6631. this.ServeSuccessJSON(map[string]interface{}{
  6632. "prescriptions": prescriptions,
  6633. })
  6634. return
  6635. }
  6636. } else {
  6637. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6638. return
  6639. }
  6640. }
  6641. func (this *HisApiController) GetCallHisPrescription() {
  6642. patient_id, _ := this.GetInt64("patient_id", 0)
  6643. timeLayout := "2006-01-02"
  6644. loc, _ := time.LoadLocation("Local")
  6645. start_time := this.GetString("start_time")
  6646. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6647. end_time := this.GetString("end_time")
  6648. p_type, _ := this.GetInt64("p_type")
  6649. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6650. adminUserInfo := this.GetAdminUserInfo()
  6651. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6652. if err == nil {
  6653. this.ServeSuccessJSON(map[string]interface{}{
  6654. "prescriptions": prescriptions,
  6655. })
  6656. return
  6657. } else {
  6658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6659. return
  6660. }
  6661. }
  6662. func (this *HisApiController) GetHisDayPrescription() {
  6663. timeLayout := "2006-01-02"
  6664. loc, _ := time.LoadLocation("Local")
  6665. start_time := this.GetString("start_time")
  6666. patient_id, _ := this.GetInt64("patient_id", 0)
  6667. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6668. end_time := this.GetString("end_time")
  6669. p_type, _ := this.GetInt64("p_type")
  6670. order_status, _ := this.GetInt64("type")
  6671. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6672. adminUserInfo := this.GetAdminUserInfo()
  6673. var dayHisPrescription []*models.HisPrescription
  6674. var err error
  6675. if order_status == 1 || order_status == 0 {
  6676. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6677. } else if order_status == 2 {
  6678. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6679. }
  6680. var settle_total float64
  6681. for _, item := range dayHisPrescription {
  6682. if len(item.HisPrescriptionProject) > 0 {
  6683. for _, subItem := range item.HisPrescriptionProject {
  6684. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6685. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6686. settle_total = settle_total + total
  6687. }
  6688. }
  6689. if len(item.HisDoctorAdviceInfo) > 0 {
  6690. for _, subItem := range item.HisDoctorAdviceInfo {
  6691. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6692. settle_total = settle_total + total
  6693. }
  6694. }
  6695. }
  6696. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6697. if err == nil {
  6698. this.ServeSuccessJSON(map[string]interface{}{
  6699. "day_prescription": dayHisPrescription,
  6700. "settle_total": settle_total,
  6701. })
  6702. return
  6703. } else {
  6704. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6705. return
  6706. }
  6707. }
  6708. func (c *HisApiController) GetHisChargePatientList() {
  6709. record_date := c.GetString("record_date")
  6710. order_status, _ := c.GetInt64("type")
  6711. timeLayout := "2006-01-02"
  6712. loc, _ := time.LoadLocation("Local")
  6713. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6714. if err != nil {
  6715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6716. return
  6717. }
  6718. recordDateTime := theTime.Unix()
  6719. adminInfo := c.GetAdminUserInfo()
  6720. var tempPatients []*service.NewTempPatients
  6721. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6722. if order_status != 2 {
  6723. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6724. } else {
  6725. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6726. }
  6727. var patients []*service.NewTempPatients
  6728. var patients_two []*service.NewTempPatients
  6729. for _, item := range tempPatients {
  6730. //过滤掉没挂号的和没开处方的
  6731. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6732. patients = append(patients, item)
  6733. }
  6734. //过滤掉没挂号的
  6735. if len(item.HisPatient) > 0 {
  6736. patients_two = append(patients_two, item)
  6737. }
  6738. }
  6739. c.ServeSuccessJSON(map[string]interface{}{
  6740. "list": patients,
  6741. "list_two": patients_two,
  6742. })
  6743. }
  6744. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6745. record_date := c.GetString("record_date")
  6746. timeLayout := "2006-01-02"
  6747. loc, _ := time.LoadLocation("Local")
  6748. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6749. if err != nil {
  6750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6751. return
  6752. }
  6753. recordDateTime := theTime.Unix()
  6754. adminUser := c.GetAdminUserInfo()
  6755. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6756. var patients []*service.Patients
  6757. for _, item := range tempPatients {
  6758. if item.HisPatient.ID == 0 {
  6759. patients = append(patients, item)
  6760. }
  6761. }
  6762. c.ServeSuccessJSON(map[string]interface{}{
  6763. "list": patients,
  6764. //"list_two": patients_two,
  6765. })
  6766. }
  6767. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6768. newArr = make([]*service.Patients, 0)
  6769. for i := 0; i < len(patient); i++ {
  6770. repeat := false
  6771. for j := i + 1; j < len(patient); j++ {
  6772. if patient[i].ID == patient[j].ID {
  6773. repeat = true
  6774. break
  6775. }
  6776. }
  6777. if !repeat {
  6778. newArr = append(newArr, patient[i])
  6779. }
  6780. }
  6781. return
  6782. }
  6783. func (c *HisApiController) GetHisChargePatientInfo() {
  6784. patient_id, _ := c.GetInt64("patient_id")
  6785. his_patient_id, _ := c.GetInt64("his_patient_id")
  6786. record_date := c.GetString("record_date")
  6787. //start_time := c.GetString("start_time")
  6788. //end_time := c.GetString("end_time")
  6789. order_status, _ := c.GetInt64("type", 0)
  6790. p_type, _ := c.GetInt64("p_type", 0)
  6791. order_id, _ := c.GetInt64("order_id", 0)
  6792. timeLayout := "2006-01-02"
  6793. loc, _ := time.LoadLocation("Local")
  6794. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6795. if err != nil {
  6796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6797. return
  6798. }
  6799. recordDateTime := theTime.Unix()
  6800. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6801. //if err != nil {
  6802. //
  6803. //}
  6804. //startRecordDateTime := startTime.Unix()
  6805. //
  6806. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6807. //if err != nil {
  6808. //
  6809. //}
  6810. //endRecordDateTime := endTime.Unix()
  6811. admin := c.GetAdminUserInfo()
  6812. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6813. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6814. var prescriptions []*models.HisPrescription
  6815. //var unChargeMonthPrescriptions []*models.HisPrescription
  6816. order, _ := service.GetHisOrderByID(order_id)
  6817. if order_status == 1 || order_status == 0 {
  6818. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6819. } else if order_status == 2 {
  6820. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6821. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6822. }
  6823. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6824. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6825. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6826. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6827. //获取所有科室信息
  6828. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6829. c.ServeSuccessJSON(map[string]interface{}{
  6830. "his_info": his_patient_info,
  6831. "xt_info": xt_patient_info,
  6832. "prescription": prescriptions,
  6833. "case_history": case_history,
  6834. "info": patientPrescriptionInfo,
  6835. "last_info": lastPatientPrescriptionInfo,
  6836. "order": order,
  6837. "doctors": doctors,
  6838. "department": department,
  6839. })
  6840. return
  6841. }
  6842. func (c *HisApiController) GetAllOrderDetail() {
  6843. order_id, _ := c.GetInt64("id", 0)
  6844. order, _ := service.GetHisOrderByID(order_id)
  6845. if order.ID == 0 {
  6846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6847. return
  6848. }
  6849. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6850. org_id := c.GetAdminUserInfo().CurrentOrgId
  6851. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6852. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6853. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6854. c.ServeSuccessJSON(map[string]interface{}{
  6855. "order": order,
  6856. "order_info": order_info,
  6857. "patient": patient,
  6858. "admin_info": adminInfo,
  6859. "hospital_record": record,
  6860. })
  6861. return
  6862. }
  6863. func (c *HisApiController) GetAllOrderDetailCollect() {
  6864. order_id, _ := c.GetInt64("id", 0)
  6865. order, _ := service.GetHisOrderByID(order_id)
  6866. if order.ID == 0 {
  6867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6868. return
  6869. }
  6870. org_id := c.GetAdminUserInfo().CurrentOrgId
  6871. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6872. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6873. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6874. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6875. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6876. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6877. var bedCostTotal float64 = 0 //床位总费
  6878. //var bedCostSelfTotal float64 = 0 //床位自费
  6879. var operationCostTotal float64 = 0 //手术费
  6880. //var operationCostSelfTotal float64 = 0 //手术费
  6881. var otherCostTotal float64 = 0 //其他费用
  6882. //var otherCostSelfTotal float64 = 0 //其他费用
  6883. var materialCostTotal float64 = 0 //材料费
  6884. //var materialCostSelfTotal float64 = 0 //材料费
  6885. var westernMedicineCostTotal float64 = 0 //西药费
  6886. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6887. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6888. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6889. var checkCostTotal float64 = 0 //检查费
  6890. //var checkCostSelfTotal float64 = 0 //检查费
  6891. var laboratoryCostTotal float64 = 0 //化验费
  6892. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6893. var treatCostTotal float64 = 0 //治疗费用
  6894. //var treatCostSelfTotal float64 = 0 //治疗费用
  6895. var zhenChaCostTotal float64 = 0 //其他费用
  6896. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6897. decimal.DivisionPrecision = 2
  6898. var BalanceAccountsType int64
  6899. if his.ID > 0 {
  6900. BalanceAccountsType = his.BalanceAccountsType
  6901. } else {
  6902. BalanceAccountsType = record.BalanceAccountsType
  6903. }
  6904. if BalanceAccountsType != 2 {
  6905. for _, item := range order_info {
  6906. if org_id == 10215 {
  6907. if item.MedChrgitmType == "01" { //床位费
  6908. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6909. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6910. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6911. }
  6912. if item.MedChrgitmType == "02" { //诊察费
  6913. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6914. //zhenChaCostSelfTotal = zhenChaCostTotal
  6915. }
  6916. if item.MedChrgitmType == "03" { //检查费
  6917. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6918. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6919. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6920. }
  6921. //if item.MedChrgitmType == "02" { //检查费
  6922. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6923. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6924. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6925. //}
  6926. if item.MedChrgitmType == "04" { //化验费
  6927. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6928. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6929. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6930. }
  6931. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6932. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6933. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6934. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6935. }
  6936. if item.MedChrgitmType == "06" { //手术费
  6937. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6938. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6939. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6940. }
  6941. if item.MedChrgitmType == "08" { //材料费
  6942. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6943. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6944. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6945. }
  6946. if item.MedChrgitmType == "09" { //西药费
  6947. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6948. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6949. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6950. }
  6951. if item.MedChrgitmType == "11" { //中成费
  6952. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6953. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6954. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6955. }
  6956. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6957. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6958. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6959. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6960. }
  6961. } else if org_id == 10188 || org_id == 10217 {
  6962. if item.MedChrgitmType == "01" { //床位费
  6963. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6964. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6965. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6966. }
  6967. if item.MedChrgitmType == "02" { //诊察费
  6968. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6969. //zhenChaCostSelfTotal = zhenChaCostTotal
  6970. }
  6971. if item.MedChrgitmType == "03" { //检查费
  6972. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6973. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6974. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6975. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6976. }
  6977. //if item.MedChrgitmType == "02" { //检查费
  6978. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6979. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6980. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6981. //}
  6982. if item.MedChrgitmType == "04" { //化验费
  6983. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6984. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6985. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6986. }
  6987. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6988. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6989. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6990. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6991. }
  6992. if item.MedChrgitmType == "06" { //手术费
  6993. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6994. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6995. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6996. }
  6997. if item.MedChrgitmType == "08" { //材料费
  6998. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6999. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7000. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7001. }
  7002. if item.MedChrgitmType == "09" { //西药费
  7003. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7004. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7005. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7006. }
  7007. if item.MedChrgitmType == "11" { //中成费
  7008. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7009. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7010. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7011. }
  7012. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7013. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7014. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7015. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7016. }
  7017. } else {
  7018. if item.MedChrgitmType == "01" { //床位费
  7019. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7020. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7021. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7022. }
  7023. //if item.MedChrgitmType == "02" { //诊察费
  7024. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7025. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7026. //}
  7027. if item.MedChrgitmType == "03" { //检查费
  7028. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7029. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7030. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7031. }
  7032. //if item.MedChrgitmType == "02" { //检查费
  7033. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7034. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7035. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7036. //}
  7037. if item.MedChrgitmType == "04" { //化验费
  7038. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7039. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7040. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7041. }
  7042. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7043. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7044. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7045. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7046. }
  7047. if item.MedChrgitmType == "06" { //手术费
  7048. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7049. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7050. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7051. }
  7052. if item.MedChrgitmType == "08" { //材料费
  7053. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7054. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7055. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7056. }
  7057. if item.MedChrgitmType == "09" { //西药费
  7058. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7059. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7060. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7061. }
  7062. if item.MedChrgitmType == "11" { //中成费
  7063. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7064. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7065. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7066. }
  7067. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7068. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7069. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7070. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7071. }
  7072. }
  7073. }
  7074. c.ServeSuccessJSON(map[string]interface{}{
  7075. "order": order,
  7076. "order_info": order_info,
  7077. "patient": patient,
  7078. "admin_info": adminInfo,
  7079. "his_hospital": record,
  7080. "bedCostTotal": bedCostTotal,
  7081. "operationCostTotal": operationCostTotal,
  7082. "otherCostTotal": otherCostTotal,
  7083. "materialCostTotal": materialCostTotal,
  7084. "westernMedicineCostTotal": westernMedicineCostTotal,
  7085. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7086. "checkCostTotal": checkCostTotal,
  7087. "zhenChaCostTotal": zhenChaCostTotal,
  7088. "laboratoryCostTotal": laboratoryCostTotal,
  7089. "treatCostTotal": treatCostTotal,
  7090. })
  7091. } else {
  7092. for _, item := range order_info {
  7093. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7094. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7095. item.MedChrgitmType = "09"
  7096. }
  7097. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7098. if item.HisPrescriptionProject.Type == 2 {
  7099. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7100. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7101. case 0:
  7102. item.MedChrgitmType = "0"
  7103. break
  7104. case 1:
  7105. item.MedChrgitmType = "14"
  7106. break
  7107. case 2:
  7108. item.MedChrgitmType = "05"
  7109. break
  7110. case 3:
  7111. item.MedChrgitmType = "03"
  7112. break
  7113. case 4:
  7114. item.MedChrgitmType = "03"
  7115. break
  7116. case 5:
  7117. item.MedChrgitmType = "08"
  7118. break
  7119. case 6:
  7120. item.MedChrgitmType = "14"
  7121. break
  7122. case 7:
  7123. item.MedChrgitmType = "14"
  7124. break
  7125. case 8:
  7126. item.MedChrgitmType = "03"
  7127. break
  7128. case 9:
  7129. item.MedChrgitmType = "14"
  7130. break
  7131. case 10:
  7132. item.MedChrgitmType = "14"
  7133. break
  7134. case 11:
  7135. item.MedChrgitmType = "06"
  7136. break
  7137. case 12:
  7138. item.MedChrgitmType = "12"
  7139. break
  7140. case 13:
  7141. item.MedChrgitmType = "01"
  7142. break
  7143. case 14:
  7144. item.MedChrgitmType = "04"
  7145. break
  7146. case 15:
  7147. item.MedChrgitmType = "14"
  7148. break
  7149. }
  7150. } else {
  7151. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7152. case 1:
  7153. item.MedChrgitmType = "14"
  7154. break
  7155. case 2:
  7156. item.MedChrgitmType = "05"
  7157. break
  7158. case 3:
  7159. item.MedChrgitmType = "04"
  7160. break
  7161. case 4:
  7162. item.MedChrgitmType = "14"
  7163. break
  7164. case 5:
  7165. item.MedChrgitmType = "08"
  7166. break
  7167. case 6:
  7168. item.MedChrgitmType = "14"
  7169. break
  7170. case 7:
  7171. item.MedChrgitmType = "14"
  7172. break
  7173. case 8:
  7174. item.MedChrgitmType = "03"
  7175. break
  7176. case 9:
  7177. item.MedChrgitmType = "14"
  7178. break
  7179. }
  7180. }
  7181. } else if item.HisPrescriptionProject.Type == 3 {
  7182. item.MedChrgitmType = "08"
  7183. }
  7184. }
  7185. }
  7186. for _, item := range order_info {
  7187. if org_id == 10215 {
  7188. if item.MedChrgitmType == "01" { //床位费
  7189. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7190. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7191. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7192. }
  7193. if item.MedChrgitmType == "02" { //诊察费
  7194. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7195. //zhenChaCostSelfTotal = zhenChaCostTotal
  7196. }
  7197. if item.MedChrgitmType == "03" { //检查费
  7198. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7199. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7200. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7201. }
  7202. //if item.MedChrgitmType == "02" { //检查费
  7203. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7204. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7205. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7206. //}
  7207. if item.MedChrgitmType == "04" { //化验费
  7208. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7209. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7210. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7211. }
  7212. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7213. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7214. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7215. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7216. }
  7217. if item.MedChrgitmType == "06" { //手术费
  7218. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7219. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7220. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7221. }
  7222. if item.MedChrgitmType == "08" { //材料费
  7223. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7224. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7225. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7226. }
  7227. if item.MedChrgitmType == "09" { //西药费
  7228. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7229. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7230. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7231. }
  7232. if item.MedChrgitmType == "11" { //中成费
  7233. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7234. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7235. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7236. }
  7237. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7238. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7239. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7240. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7241. }
  7242. } else {
  7243. if item.MedChrgitmType == "01" { //床位费
  7244. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7245. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7246. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7247. }
  7248. //if item.MedChrgitmType == "02" { //诊察费
  7249. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7250. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7251. //}
  7252. if item.MedChrgitmType == "03" { //检查费
  7253. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7254. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7255. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7256. }
  7257. //if item.MedChrgitmType == "02" { //检查费
  7258. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7259. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7260. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7261. //}
  7262. if item.MedChrgitmType == "04" { //化验费
  7263. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7264. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7265. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7266. }
  7267. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7268. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7269. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7270. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7271. }
  7272. if item.MedChrgitmType == "06" { //手术费
  7273. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7274. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7275. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7276. }
  7277. if item.MedChrgitmType == "08" { //材料费
  7278. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7279. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7280. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7281. }
  7282. if item.MedChrgitmType == "09" { //西药费
  7283. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7284. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7285. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7286. }
  7287. if item.MedChrgitmType == "11" { //中成费
  7288. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7289. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7290. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7291. }
  7292. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7293. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7294. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7295. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7296. }
  7297. }
  7298. }
  7299. c.ServeSuccessJSON(map[string]interface{}{
  7300. "order": order,
  7301. "order_info": order_info,
  7302. "patient": patient,
  7303. "admin_info": adminInfo,
  7304. "his_hospital": record,
  7305. "bedCostTotal": bedCostTotal,
  7306. "operationCostTotal": operationCostTotal,
  7307. "otherCostTotal": otherCostTotal,
  7308. "materialCostTotal": materialCostTotal,
  7309. "westernMedicineCostTotal": westernMedicineCostTotal,
  7310. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7311. "checkCostTotal": checkCostTotal,
  7312. "zhenChaCostTotal": zhenChaCostTotal,
  7313. "laboratoryCostTotal": laboratoryCostTotal,
  7314. "treatCostTotal": treatCostTotal,
  7315. })
  7316. }
  7317. }
  7318. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7319. page, _ := c.GetInt64("page")
  7320. limit, _ := c.GetInt64("limit")
  7321. keywords := c.GetString("keywords")
  7322. start_time := c.GetString("start_time")
  7323. end_time := c.GetString("end_time")
  7324. //clr_type := c.GetString("clr_type")
  7325. insutype := c.GetString("insutype")
  7326. timeLayout := "2006-01-02"
  7327. loc, _ := time.LoadLocation("Local")
  7328. var theStartTIme int64
  7329. if len(start_time) > 0 {
  7330. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7331. theStartTIme = theTime.Unix()
  7332. }
  7333. var theEndtTIme int64
  7334. if len(end_time) > 0 {
  7335. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7336. theEndtTIme = theTime.Unix()
  7337. }
  7338. if page <= 0 {
  7339. page = 1
  7340. }
  7341. if limit <= 0 {
  7342. limit = 10
  7343. }
  7344. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7345. c.ServeSuccessJSON(map[string]interface{}{
  7346. "total": total,
  7347. "list": list,
  7348. })
  7349. return
  7350. }
  7351. func (c *HisApiController) GetPutOnRecordList() {
  7352. page, _ := c.GetInt64("page")
  7353. limit, _ := c.GetInt64("limit")
  7354. keywords := c.GetString("keywords")
  7355. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7356. if page <= 0 {
  7357. page = 1
  7358. }
  7359. if limit <= 0 {
  7360. limit = 10
  7361. }
  7362. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7363. c.ServeSuccessJSON(map[string]interface{}{
  7364. "total": total,
  7365. "list": list,
  7366. })
  7367. return
  7368. }
  7369. func (c *HisApiController) GetCompareData() {
  7370. start_time := c.GetString("start_time")
  7371. end_time := c.GetString("end_time")
  7372. insutype := c.GetString("insutype")
  7373. clr_type := c.GetString("clr_type")
  7374. timeLayout := "2006-01-02"
  7375. loc, _ := time.LoadLocation("Local")
  7376. var theStartTIme int64
  7377. if len(start_time) > 0 {
  7378. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7379. if err != nil {
  7380. theStartTIme = 0
  7381. }
  7382. theStartTIme = theTime.Unix()
  7383. }
  7384. var theEndtTIme int64
  7385. if len(end_time) > 0 {
  7386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7387. if err != nil {
  7388. theEndtTIme = 0
  7389. }
  7390. theEndtTIme = theTime.Unix()
  7391. }
  7392. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7393. fmt.Println(err)
  7394. if err == nil {
  7395. c.ServeSuccessJSON(map[string]interface{}{
  7396. "list": formData,
  7397. })
  7398. } else {
  7399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7400. return
  7401. }
  7402. }
  7403. func (c *HisApiController) GetFaPiaoData() {
  7404. order_id, _ := c.GetInt64("order_id")
  7405. patient_id, _ := c.GetInt64("patient_id")
  7406. number := c.GetString("number")
  7407. adminUser := c.GetAdminUserInfo()
  7408. order, _ := service.GetHisOrderByID(order_id)
  7409. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7410. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7411. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7412. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7413. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7414. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7415. var bedCostTotal float64 = 0 //床位总费
  7416. var bedCostSelfTotal float64 = 0 //床位自费
  7417. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7418. var operationCostTotal float64 = 0 //手术费
  7419. var operationCostSelfTotal float64 = 0 //手术费
  7420. var operationCostPartSelfTotal float64 = 0 //手术费
  7421. var otherCostTotal float64 = 0 //其他费用
  7422. var otherCostSelfTotal float64 = 0 //其他费用
  7423. var otherCostPartSelfTotal float64 = 0 //其他费用
  7424. var materialCostTotal float64 = 0 //材料费
  7425. var materialCostSelfTotal float64 = 0 //材料费
  7426. var materialCostPartSelfTotal float64 = 0 //材料费
  7427. var westernMedicineCostTotal float64 = 0 //西药费
  7428. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7429. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7430. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7431. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7432. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7433. var checkCostTotal float64 = 0 //检查费
  7434. var checkCostSelfTotal float64 = 0 //检查费
  7435. var checkCostPartSelfTotal float64 = 0 //检查费
  7436. var laboratoryCostTotal float64 = 0 //化验费
  7437. var laboratoryCostSelfTotal float64 = 0 //化验费
  7438. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7439. var treatCostTotal float64 = 0 //治疗费用
  7440. var treatCostSelfTotal float64 = 0 //治疗费用
  7441. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7442. var zhenChaCostTotal float64 = 0 //其他费用
  7443. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7444. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7445. decimal.DivisionPrecision = 2
  7446. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7447. var balanceAccountsType int64
  7448. if his.ID > 0 {
  7449. balanceAccountsType = his.BalanceAccountsType
  7450. } else {
  7451. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7452. }
  7453. if balanceAccountsType == 2 {
  7454. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7455. for _, item := range orderInfos_two {
  7456. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7457. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7458. item.MedChrgitmType = "09"
  7459. }
  7460. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7461. if item.HisPrescriptionProject.Type == 2 {
  7462. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7463. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7464. case 0:
  7465. item.MedChrgitmType = "0"
  7466. break
  7467. case 1:
  7468. item.MedChrgitmType = "14"
  7469. break
  7470. case 2:
  7471. item.MedChrgitmType = "05"
  7472. break
  7473. case 3:
  7474. item.MedChrgitmType = "03"
  7475. break
  7476. case 4:
  7477. item.MedChrgitmType = "03"
  7478. break
  7479. case 5:
  7480. item.MedChrgitmType = "08"
  7481. break
  7482. case 6:
  7483. item.MedChrgitmType = "14"
  7484. break
  7485. case 7:
  7486. item.MedChrgitmType = "14"
  7487. break
  7488. case 8:
  7489. item.MedChrgitmType = "03"
  7490. break
  7491. case 9:
  7492. item.MedChrgitmType = "14"
  7493. break
  7494. case 10:
  7495. item.MedChrgitmType = "14"
  7496. break
  7497. case 11:
  7498. item.MedChrgitmType = "06"
  7499. break
  7500. case 12:
  7501. item.MedChrgitmType = "12"
  7502. break
  7503. case 13:
  7504. item.MedChrgitmType = "01"
  7505. break
  7506. case 14:
  7507. item.MedChrgitmType = "04"
  7508. break
  7509. case 15:
  7510. item.MedChrgitmType = "02"
  7511. break
  7512. }
  7513. } else {
  7514. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7515. case 1:
  7516. item.MedChrgitmType = "14"
  7517. break
  7518. case 2:
  7519. item.MedChrgitmType = "05"
  7520. break
  7521. case 3:
  7522. item.MedChrgitmType = "03"
  7523. break
  7524. case 4:
  7525. item.MedChrgitmType = "03"
  7526. break
  7527. case 5:
  7528. item.MedChrgitmType = "08"
  7529. break
  7530. case 6:
  7531. item.MedChrgitmType = "14"
  7532. break
  7533. case 7:
  7534. item.MedChrgitmType = "14"
  7535. break
  7536. case 8:
  7537. item.MedChrgitmType = "03"
  7538. break
  7539. case 9:
  7540. item.MedChrgitmType = "14"
  7541. break
  7542. }
  7543. }
  7544. } else if item.HisPrescriptionProject.Type == 3 {
  7545. item.MedChrgitmType = "08"
  7546. }
  7547. }
  7548. }
  7549. for _, item := range orderInfos_two {
  7550. fmt.Println(item.MedChrgitmType)
  7551. if item.MedChrgitmType == "01" { //床位费
  7552. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7553. bedCostSelfTotal = bedCostTotal
  7554. }
  7555. if item.MedChrgitmType == "02" { //诊察费
  7556. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7557. zhenChaCostSelfTotal = zhenChaCostTotal
  7558. }
  7559. if item.MedChrgitmType == "03" { //检查费
  7560. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7561. checkCostSelfTotal = checkCostTotal
  7562. }
  7563. if item.MedChrgitmType == "04" { //化验费
  7564. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7565. laboratoryCostSelfTotal = laboratoryCostTotal
  7566. }
  7567. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7568. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7569. treatCostSelfTotal = treatCostTotal
  7570. }
  7571. if item.MedChrgitmType == "06" { //手术费
  7572. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7573. operationCostSelfTotal = treatCostTotal
  7574. }
  7575. if item.MedChrgitmType == "08" { //材料费
  7576. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7577. materialCostSelfTotal = materialCostTotal
  7578. }
  7579. if item.MedChrgitmType == "09" { //西药费
  7580. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7581. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7582. }
  7583. if item.MedChrgitmType == "11" { //中成费
  7584. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7585. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7586. }
  7587. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7588. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7589. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7590. otherCostSelfTotal = otherCostTotal
  7591. }
  7592. } else {
  7593. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7594. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7595. otherCostSelfTotal = otherCostTotal
  7596. }
  7597. }
  7598. }
  7599. } else {
  7600. for _, item := range orderInfos {
  7601. if item.MedChrgitmType == "01" { //床位费
  7602. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7603. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7604. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7605. }
  7606. if item.MedChrgitmType == "02" { //诊察费
  7607. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7608. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7609. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7610. }
  7611. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7612. if item.MedChrgitmType == "03" { //检查费
  7613. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7614. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7615. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7616. }
  7617. } else {
  7618. if item.MedChrgitmType == "03" { //检查费
  7619. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7620. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7621. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7622. }
  7623. }
  7624. if item.MedChrgitmType == "04" { //化验费
  7625. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7626. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7627. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7628. }
  7629. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7630. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7631. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7632. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7633. }
  7634. if item.MedChrgitmType == "06" { //手术费
  7635. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7636. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7637. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7638. }
  7639. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7640. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7641. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7642. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7643. }
  7644. if item.MedChrgitmType == "09" { //西药费
  7645. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7646. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7647. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7648. }
  7649. if item.MedChrgitmType == "11" { //中成费
  7650. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7651. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7652. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7653. }
  7654. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7655. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7656. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7657. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7658. }
  7659. }
  7660. }
  7661. timeLayout := "2006-01-02"
  7662. loc, _ := time.LoadLocation("Local")
  7663. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7664. if err != nil {
  7665. }
  7666. startRecordDateTime := startTime.Unix()
  7667. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7668. if err != nil {
  7669. }
  7670. endRecordDateTime := endTime.Unix()
  7671. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7672. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7673. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7674. c.ServeSuccessJSON(map[string]interface{}{
  7675. "order_number": order.Number, //业务流水号
  7676. "id_card_no": his.IdCardNo, //社会保障号
  7677. "department_name": department.Name, //科室
  7678. "number": his.Number, //门诊号
  7679. "date": order.SettleAccountsDate, //结算日期
  7680. "name": order.PsnName, //姓名
  7681. "gender": patient.Gender, //性别
  7682. "psn_cash_money": order.PsnCashPay, //个人支付
  7683. "pay_way": "门诊", //结算方式
  7684. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7685. "admin_user_name": admin.UserName, //收款员
  7686. "order": order,
  7687. "order_info": orderInfos_two,
  7688. "his": his,
  7689. "bedCostTotal": bedCostTotal,
  7690. "bedCostSelfTotal": bedCostSelfTotal,
  7691. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7692. "operationCostTotal": operationCostTotal,
  7693. "operationCostSelfTotal": operationCostSelfTotal,
  7694. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7695. "otherCostTotal": otherCostTotal,
  7696. "otherCostSelfTotal": otherCostSelfTotal,
  7697. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7698. "materialCostTotal": materialCostTotal,
  7699. "materialCostSelfTotal": materialCostSelfTotal,
  7700. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7701. "westernMedicineCostTotal": westernMedicineCostTotal,
  7702. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7703. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7704. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7705. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7706. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7707. "checkCostTotal": checkCostTotal,
  7708. "checkCostSelfTotal": checkCostSelfTotal,
  7709. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7710. "laboratoryCostTotal": laboratoryCostTotal,
  7711. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7712. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7713. "treatCostTotal": treatCostTotal,
  7714. "treatCostSelfTotal": treatCostSelfTotal,
  7715. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7716. "zhenChaCostTotal": zhenChaCostTotal,
  7717. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7718. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7719. "his_hospital_record": his_hospital_record,
  7720. "pre_pay_money": pre_pay_money,
  7721. "refund_sum": sum,
  7722. })
  7723. }
  7724. func (this *HisApiController) GetIncomeStatisticsData() {
  7725. start_time := this.GetString("start_time")
  7726. end_time := this.GetString("end_time")
  7727. key_words := this.GetString("key_words")
  7728. limit, _ := this.GetInt64("limit")
  7729. page, _ := this.GetInt64("page")
  7730. if page <= 0 {
  7731. page = 1
  7732. }
  7733. if limit <= 0 {
  7734. limit = 10
  7735. }
  7736. statistics_type, _ := this.GetInt64("statistics_type")
  7737. admin := this.GetAdminUserInfo()
  7738. timeLayout := "2006-01-02"
  7739. loc, _ := time.LoadLocation("Local")
  7740. var theStartTIme int64
  7741. if len(start_time) > 0 {
  7742. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7743. if err != nil {
  7744. theStartTIme = 0
  7745. }
  7746. theStartTIme = theTime.Unix()
  7747. }
  7748. var theEndtTIme int64
  7749. if len(end_time) > 0 {
  7750. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7751. if err != nil {
  7752. theEndtTIme = 0
  7753. }
  7754. theEndtTIme = theTime.Unix()
  7755. }
  7756. if statistics_type == 1 {
  7757. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7758. this.ServeSuccessJSON(map[string]interface{}{
  7759. "list": list,
  7760. "total": total,
  7761. })
  7762. } else {
  7763. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7764. this.ServeSuccessJSON(map[string]interface{}{
  7765. "list": list,
  7766. "total": total,
  7767. })
  7768. }
  7769. }
  7770. func (c *HisApiController) PostProjectInformation() {
  7771. adminUser := c.GetAdminUserInfo()
  7772. orgId := adminUser.CurrentOrgId
  7773. dataBody := make(map[string]interface{}, 0)
  7774. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7775. if err != nil {
  7776. utils.ErrorLog(err.Error())
  7777. return
  7778. }
  7779. utils.ErrorLog("%v", dataBody)
  7780. var projectList []*models.HisProject
  7781. var total_goods []interface{}
  7782. tempProjects := dataBody["projects"].([]interface{})
  7783. total_goods = tempProjects
  7784. for index, projectMap := range tempProjects {
  7785. projectM := projectMap.(map[string]interface{})
  7786. var project models.HisProject
  7787. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7788. utils.ErrorLog("project_name")
  7789. return
  7790. }
  7791. project_name, _ := projectM["project_name"].(string)
  7792. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7793. err_log := models.ExportErrLog{
  7794. LogType: 6,
  7795. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7796. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7797. Status: 1,
  7798. CreateTime: time.Now().Unix(),
  7799. UpdateTime: time.Now().Unix(),
  7800. ExportTime: time.Now().Unix(),
  7801. }
  7802. service.CreateExportErrLog(&err_log)
  7803. continue
  7804. }
  7805. project.ProjectName = project_name
  7806. prices := projectM["price"].(string)
  7807. price, _ := strconv.ParseFloat(prices, 64)
  7808. if price <= 0 { //名字为空则生成一条导入错误日志
  7809. err_log := models.ExportErrLog{
  7810. LogType: 6,
  7811. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7812. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7813. Status: 1,
  7814. CreateTime: time.Now().Unix(),
  7815. UpdateTime: time.Now().Unix(),
  7816. ExportTime: time.Now().Unix(),
  7817. }
  7818. service.CreateExportErrLog(&err_log)
  7819. continue
  7820. }
  7821. project.Price = price
  7822. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7823. utils.ErrorLog("unit_id")
  7824. return
  7825. }
  7826. unit := projectM["unit"].(string)
  7827. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7828. err_log := models.ExportErrLog{
  7829. LogType: 6,
  7830. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7831. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7832. Status: 1,
  7833. CreateTime: time.Now().Unix(),
  7834. UpdateTime: time.Now().Unix(),
  7835. ExportTime: time.Now().Unix(),
  7836. }
  7837. service.CreateExportErrLog(&err_log)
  7838. continue
  7839. }
  7840. project.Unit = unit
  7841. cost_classify := projectM["cost_classify"].(string)
  7842. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7843. err_log := models.ExportErrLog{
  7844. LogType: 6,
  7845. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7846. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7847. Status: 1,
  7848. CreateTime: time.Now().Unix(),
  7849. UpdateTime: time.Now().Unix(),
  7850. ExportTime: time.Now().Unix(),
  7851. }
  7852. service.CreateExportErrLog(&err_log)
  7853. continue
  7854. }
  7855. var costClassify = "费用类别"
  7856. var cost_classify_id int64
  7857. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7858. if len(cost_classify) != 0 {
  7859. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7860. if errcode == gorm.ErrRecordNotFound {
  7861. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7862. dataconfig := models.DictDataconfig{
  7863. ParentId: costClassifyConfig.ID,
  7864. Module: "system",
  7865. OrgId: orgId,
  7866. Name: cost_classify,
  7867. FieldName: "",
  7868. Value: costConfig.Value + 1,
  7869. CreatedTime: "",
  7870. UpdatedTime: "",
  7871. CreateUserId: adminUser.AdminUser.Id,
  7872. Status: 1,
  7873. Remark: "",
  7874. DeleteIdSystem: 0,
  7875. Title: "",
  7876. Content: "",
  7877. Order: 0,
  7878. Code: "",
  7879. }
  7880. service.CreatedDicConfig(&dataconfig)
  7881. }
  7882. }
  7883. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7884. for _, it := range costClassList {
  7885. if cost_classify == it.Name {
  7886. cost_classify_id = int64(it.Value)
  7887. }
  7888. }
  7889. project.CostClassify = cost_classify_id
  7890. executive_section := projectM["executive_section"].(string)
  7891. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7892. err_log := models.ExportErrLog{
  7893. LogType: 6,
  7894. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7895. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7896. Status: 1,
  7897. CreateTime: time.Now().Unix(),
  7898. UpdateTime: time.Now().Unix(),
  7899. ExportTime: time.Now().Unix(),
  7900. }
  7901. service.CreateExportErrLog(&err_log)
  7902. continue
  7903. }
  7904. if len(executive_section) != 0 {
  7905. //查找科室是否有内容
  7906. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7907. if errcodedepart == gorm.ErrRecordNotFound {
  7908. department := models.XtHisDepartment{
  7909. Name: executive_section,
  7910. Status: 1,
  7911. UserOrgId: adminUser.CurrentOrgId,
  7912. CreatedTime: time.Now().Unix(),
  7913. }
  7914. service.CreateDePartment(&department)
  7915. }
  7916. }
  7917. var executive_section_id int64
  7918. departMentList, _ := service.GetAllDepartMent(orgId)
  7919. for _, it := range departMentList {
  7920. if executive_section == it.Name {
  7921. executive_section_id = it.ID
  7922. }
  7923. }
  7924. project.ExecutiveSection = executive_section_id
  7925. medical_coverage := projectM["medical_coverage"].(string)
  7926. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7927. err_log := models.ExportErrLog{
  7928. LogType: 6,
  7929. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7930. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7931. Status: 1,
  7932. CreateTime: time.Now().Unix(),
  7933. UpdateTime: time.Now().Unix(),
  7934. ExportTime: time.Now().Unix(),
  7935. }
  7936. service.CreateExportErrLog(&err_log)
  7937. continue
  7938. }
  7939. var medicalCoverage = "医保等级"
  7940. var medical_coverage_id int64
  7941. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7942. if len(medical_coverage) != 0 {
  7943. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7944. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7945. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7946. dataconfig := models.DictDataconfig{
  7947. ParentId: medicalCoverageConfig.ID,
  7948. Module: "system",
  7949. OrgId: orgId,
  7950. Name: medical_coverage,
  7951. FieldName: "",
  7952. Value: medicalCoverageConfig.Value + 1,
  7953. CreatedTime: "",
  7954. UpdatedTime: "",
  7955. CreateUserId: adminUser.AdminUser.Id,
  7956. Status: 1,
  7957. Remark: "",
  7958. DeleteIdSystem: 0,
  7959. Title: "",
  7960. Content: "",
  7961. Order: 0,
  7962. Code: "",
  7963. }
  7964. service.CreatedDicConfig(&dataconfig)
  7965. }
  7966. }
  7967. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7968. for _, it := range medicalCoverageList {
  7969. if medical_coverage == it.Name {
  7970. medical_coverage_id = int64(it.Value)
  7971. }
  7972. }
  7973. project.MedicalCoverage = medical_coverage_id
  7974. pinyin := projectM["pinyin"].(string)
  7975. project.Pinyin = pinyin
  7976. wubi := projectM["wubi"].(string)
  7977. project.Wubi = wubi
  7978. statistical_classification := projectM["statistical_classification"].(string)
  7979. var statisticalClassification = "统计分类"
  7980. var statistical_classification_id int64
  7981. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7982. if len(statistical_classification) != 0 {
  7983. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7984. if classificationerrcodes == gorm.ErrRecordNotFound {
  7985. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7986. dataconfig := models.DictDataconfig{
  7987. ParentId: classiFication.ID,
  7988. Module: "system",
  7989. OrgId: orgId,
  7990. Name: statistical_classification,
  7991. FieldName: "",
  7992. Value: classiFicationConfig.Value + 1,
  7993. CreatedTime: "",
  7994. UpdatedTime: "",
  7995. CreateUserId: adminUser.AdminUser.Id,
  7996. Status: 1,
  7997. Remark: "",
  7998. DeleteIdSystem: 0,
  7999. Title: "",
  8000. Content: "",
  8001. Order: 0,
  8002. Code: "",
  8003. }
  8004. service.CreatedDicConfig(&dataconfig)
  8005. }
  8006. }
  8007. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8008. for _, it := range classiFicationList {
  8009. if statistical_classification == it.Name {
  8010. statistical_classification_id = int64(it.Value)
  8011. }
  8012. }
  8013. project.StatisticalClassification = statistical_classification_id
  8014. disease_directory := int64(projectM["disease_directory"].(float64))
  8015. project.DiseaseDirectory = disease_directory
  8016. is_record := int64(projectM["is_record"].(float64))
  8017. project.IsRecord = is_record
  8018. medical_code := projectM["medical_code"].(string)
  8019. project.MedicalCode = medical_code
  8020. tube_color := projectM["tube_color"].(string)
  8021. var tubeColor = "试管颜色"
  8022. var tube_color_id int64
  8023. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8024. if len(tube_color) != 0 {
  8025. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8026. if errcodetube == gorm.ErrRecordNotFound {
  8027. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8028. dataconfig := models.DictDataconfig{
  8029. ParentId: tubeColorConfig.ID,
  8030. Module: "system",
  8031. OrgId: orgId,
  8032. Name: tube_color,
  8033. FieldName: "",
  8034. Value: tubeConfig.Value + 1,
  8035. CreatedTime: "",
  8036. UpdatedTime: "",
  8037. CreateUserId: adminUser.AdminUser.Id,
  8038. Status: 1,
  8039. Remark: "",
  8040. DeleteIdSystem: 0,
  8041. Title: "",
  8042. Content: "",
  8043. Order: 0,
  8044. Code: "",
  8045. }
  8046. service.CreatedDicConfig(&dataconfig)
  8047. }
  8048. }
  8049. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8050. for _, it := range tubeColorList {
  8051. if tube_color == it.Name {
  8052. tube_color_id = int64(it.Value)
  8053. }
  8054. }
  8055. project.TubeColor = tube_color_id
  8056. single_dose := projectM["single_dose"].(string)
  8057. project.SingleDose = single_dose
  8058. execution_frequency := projectM["execution_frequency"].(string)
  8059. project.ExecutionFrequency = execution_frequency
  8060. delivery_way := projectM["delivery_way"].(string)
  8061. project.DeliveryWay = delivery_way
  8062. number_days := projectM["number_days"].(string)
  8063. project.NumberDays = number_days
  8064. total := projectM["total"].(string)
  8065. project.Total = total
  8066. medical_status := int64(projectM["medical_status"].(float64))
  8067. project.MedicalStatus = medical_status
  8068. category := int64(projectM["category"].(float64))
  8069. project.Category = category
  8070. specail_project := int64(projectM["specail_project"].(float64))
  8071. project.SpecailProject = specail_project
  8072. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8073. project.SocialSecurityDirectoryCode = social_security_directory_code
  8074. remark := projectM["remark"].(string)
  8075. project.Remark = remark
  8076. record_date := projectM["record_date"].(string)
  8077. timeLayout := "2006-01-02"
  8078. loc, _ := time.LoadLocation("Local")
  8079. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8080. project.RecordDate = theTime.Unix()
  8081. projectList = append(projectList, &project)
  8082. }
  8083. export_time := time.Now().Unix()
  8084. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8085. if len(projectList) > 0 {
  8086. for _, item := range projectList {
  8087. project := models.HisProject{
  8088. ProjectName: item.ProjectName,
  8089. Price: item.Price,
  8090. Unit: item.Unit,
  8091. CostClassify: item.CostClassify,
  8092. ExecutiveSection: item.ExecutiveSection,
  8093. MedicalCoverage: item.MedicalCoverage,
  8094. UserOrgId: orgId,
  8095. Status: 1,
  8096. CreatedTime: time.Now().Unix(),
  8097. Pinyin: item.Pinyin,
  8098. Wubi: item.Wubi,
  8099. StatisticalClassification: item.StatisticalClassification,
  8100. DiseaseDirectory: item.DiseaseDirectory,
  8101. IsRecord: item.IsRecord,
  8102. MedicalCode: item.MedicalCode,
  8103. TubeColor: item.TubeColor,
  8104. SingleDose: item.SingleDose,
  8105. DeliveryWay: item.DeliveryWay,
  8106. NumberDays: item.NumberDays,
  8107. Total: item.Total,
  8108. Category: item.Category,
  8109. MedicalStatus: item.MedicalStatus,
  8110. SpecailProject: item.SpecailProject,
  8111. RecordDate: item.RecordDate,
  8112. Remark: item.Remark,
  8113. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8114. ExecutionFrequency: item.ExecutionFrequency,
  8115. }
  8116. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8117. if errcodeproject == gorm.ErrRecordNotFound {
  8118. service.CreateProjectInfomation(&project)
  8119. } else if errcodeproject == nil {
  8120. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8121. }
  8122. log := models.ExportLog{
  8123. LogType: 6,
  8124. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8125. TotalNum: int64(len(total_goods)),
  8126. FailNum: int64(len(errLogs)),
  8127. SuccessNum: int64(len(projectList)),
  8128. CreateTime: time.Now().Unix(),
  8129. UpdateTime: time.Now().Unix(),
  8130. ExportTime: export_time,
  8131. Status: 1,
  8132. }
  8133. service.CreateExportLog(&log)
  8134. c.ServeSuccessJSON(map[string]interface{}{
  8135. "msg": "导入成功",
  8136. "total_num": len(total_goods),
  8137. "success_num": len(projectList),
  8138. "fail_num": int64(len(errLogs)),
  8139. })
  8140. }
  8141. } else {
  8142. log := models.ExportLog{
  8143. LogType: 6,
  8144. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8145. TotalNum: int64(len(total_goods)),
  8146. FailNum: int64(len(errLogs)),
  8147. SuccessNum: int64(len(projectList)),
  8148. CreateTime: time.Now().Unix(),
  8149. UpdateTime: time.Now().Unix(),
  8150. ExportTime: export_time,
  8151. Status: 1,
  8152. }
  8153. service.CreateExportLog(&log)
  8154. c.ServeSuccessJSON(map[string]interface{}{
  8155. "msg": "导入成功",
  8156. "total_num": len(total_goods),
  8157. "success_num": len(projectList),
  8158. "fail_num": int64(len(errLogs)),
  8159. })
  8160. }
  8161. }
  8162. //func (this *HisApiController) EditProjectInformation(){
  8163. //
  8164. // id, _ := this.GetInt64("id")
  8165. // project_team := this.GetString("project_team")
  8166. // price := this.GetString("price")
  8167. // price_float, _ := strconv.ParseFloat(price, 64)
  8168. // pinyin := this.GetString("pinyin")
  8169. // wubi := this.GetString("wubi")
  8170. // tube_color, _ := this.GetInt64("tube_color")
  8171. // team_type, _ := this.GetInt64("team_type")
  8172. // remark := this.GetString("remark")
  8173. // ids := this.GetString("ids")
  8174. // item_id := this.GetString("item_id")
  8175. // projectTeam := models.XtHisProjectTeam{
  8176. // ProjectTeam: project_team,
  8177. // Price: price_float,
  8178. // Pinyin: pinyin,
  8179. // Wubi: wubi,
  8180. // TubeColor: tube_color,
  8181. // TeamType: team_type,
  8182. // Remark: remark,
  8183. // ProjectId: ids,
  8184. // ItemId: item_id,
  8185. // }
  8186. //
  8187. //
  8188. // dataBody := make(map[string]interface{}, 0)
  8189. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8190. // if err != nil {
  8191. // utils.ErrorLog(err.Error())
  8192. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8193. // return
  8194. // }
  8195. //
  8196. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8197. //
  8198. //
  8199. // if err != nil {
  8200. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8201. // return
  8202. // }
  8203. //
  8204. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8205. // infos, _ := dataBody["info"].([]interface{})
  8206. // if len(infos) > 0 {
  8207. // var ids []string
  8208. //
  8209. // for _, item := range infos {
  8210. // items := item.(map[string]interface{})
  8211. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8212. // utils.ErrorLog("id")
  8213. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8214. // return
  8215. // }
  8216. // id := int64(items["id"].(float64))
  8217. //
  8218. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8219. // utils.ErrorLog("type")
  8220. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8221. // return
  8222. // }
  8223. // types := int64(items["type"].(float64))
  8224. //
  8225. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8226. // utils.ErrorLog("number")
  8227. // }
  8228. //
  8229. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8230. //
  8231. // projectList := models.XtHisProjectList{
  8232. // Number: number,
  8233. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8234. // ProjectId: id,
  8235. // Status: 1,
  8236. // CreatedTime: time.Now().Unix(),
  8237. // UpdatedTime: time.Now().Unix(),
  8238. // TeamId: projectTeam.ID,
  8239. // Type: types,
  8240. // }
  8241. // list := projectList
  8242. //
  8243. // service.CreateProjectList(&list)
  8244. //
  8245. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8246. //
  8247. // }
  8248. // ids_str := strings.Join(ids, ",")
  8249. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8250. // service.SaveProjectTeam(&projectTeam)
  8251. // this.ServeSuccessJSON(map[string]interface{}{
  8252. // "projectTeam": projectTeam,
  8253. // })
  8254. // }
  8255. // }
  8256. //}
  8257. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8258. name := c.GetString("name")
  8259. mode_id, _ := c.GetInt64("mode", 0)
  8260. types, _ := c.GetInt64("type", 0)
  8261. patient_id, _ := c.GetInt64("patient_id", 0)
  8262. types = 1
  8263. adminInfo := c.GetAdminUserInfo()
  8264. template := &models.HisPrescriptionTemplate{
  8265. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8266. PatientId: patient_id,
  8267. Type: types,
  8268. Status: 1,
  8269. Ctime: time.Now().Unix(),
  8270. Mtime: time.Now().Unix(),
  8271. Name: name,
  8272. Mode: mode_id,
  8273. }
  8274. dataBody := make(map[string]interface{}, 0)
  8275. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8276. if err != nil {
  8277. utils.ErrorLog(err.Error())
  8278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8279. return
  8280. }
  8281. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8282. //如果已经存在记录则删除处方
  8283. if template_one.ID > 0 {
  8284. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8285. for _, item := range ps {
  8286. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8287. }
  8288. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8289. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8290. if len(prescriptions) > 0 {
  8291. for _, item := range prescriptions {
  8292. items := item.(map[string]interface{})
  8293. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8294. utils.ErrorLog("type")
  8295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8296. return
  8297. }
  8298. types := int64(items["type"].(float64))
  8299. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8300. utils.ErrorLog("med_type")
  8301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8302. return
  8303. }
  8304. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8305. ctime := time.Now().Unix()
  8306. prescription := &models.HisPrescriptionInfoTemplate{
  8307. PatientId: patient_id,
  8308. UserOrgId: adminInfo.CurrentOrgId,
  8309. Ctime: ctime,
  8310. Mtime: ctime,
  8311. Type: types,
  8312. Modifier: adminInfo.AdminUser.Id,
  8313. Creator: adminInfo.AdminUser.Id,
  8314. Status: 1,
  8315. PTemplateId: template_one.ID,
  8316. MedType: med_type,
  8317. }
  8318. service.CreateHisPrescriptionInfoTemplate(prescription)
  8319. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8320. advices := items["advices"].([]interface{})
  8321. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8322. ctime := time.Now().Unix()
  8323. mtime := ctime
  8324. if len(advices) > 0 {
  8325. for _, advice := range advices {
  8326. var s models.HisPrescriptionAdviceTemplate
  8327. s.PrescriptionId = prescription.ID
  8328. s.AdviceType = 2
  8329. s.StopState = 2
  8330. s.ExecutionState = 2
  8331. s.Status = 1
  8332. s.UserOrgId = adminInfo.CurrentOrgId
  8333. s.CreatedTime = ctime
  8334. s.UpdatedTime = mtime
  8335. s.PatientId = patient_id
  8336. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8337. if errcode > 0 {
  8338. c.ServeFailJSONWithSGJErrorCode(errcode)
  8339. return
  8340. }
  8341. service.CreateHisPrescriptionAdviceTemplate(&s)
  8342. }
  8343. }
  8344. }
  8345. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8346. projects := items["project"].([]interface{})
  8347. if len(projects) > 0 {
  8348. for _, project := range projects {
  8349. var p models.HisPrescriptionProjectTemplate
  8350. p.PrescriptionId = prescription.ID
  8351. p.Ctime = time.Now().Unix()
  8352. p.Mtime = time.Now().Unix()
  8353. p.PatientId = patient_id
  8354. p.UserOrgId = adminInfo.CurrentOrgId
  8355. p.Status = 1
  8356. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8357. if errcode > 0 {
  8358. c.ServeFailJSONWithSGJErrorCode(errcode)
  8359. return
  8360. }
  8361. service.CreateHisPrescriptionProjectTemplate(&p)
  8362. }
  8363. }
  8364. }
  8365. }
  8366. c.ServeSuccessJSON(map[string]interface{}{
  8367. "msg": "创建成功",
  8368. })
  8369. }
  8370. }
  8371. } else {
  8372. err = service.CreateHisPrescriptionTemplate(template)
  8373. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8374. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8375. if len(prescriptions) > 0 {
  8376. for _, item := range prescriptions {
  8377. items := item.(map[string]interface{})
  8378. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8379. utils.ErrorLog("type")
  8380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8381. return
  8382. }
  8383. types := int64(items["type"].(float64))
  8384. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8385. utils.ErrorLog("med_type")
  8386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8387. return
  8388. }
  8389. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8390. ctime := time.Now().Unix()
  8391. prescription := &models.HisPrescriptionInfoTemplate{
  8392. PatientId: patient_id,
  8393. UserOrgId: adminInfo.CurrentOrgId,
  8394. Ctime: ctime,
  8395. Mtime: ctime,
  8396. Type: types,
  8397. Modifier: adminInfo.AdminUser.Id,
  8398. Creator: adminInfo.AdminUser.Id,
  8399. Status: 1,
  8400. PTemplateId: template.ID,
  8401. MedType: med_type,
  8402. }
  8403. service.CreateHisPrescriptionInfoTemplate(prescription)
  8404. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8405. advices := items["advices"].([]interface{})
  8406. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8407. ctime := time.Now().Unix()
  8408. mtime := ctime
  8409. if len(advices) > 0 {
  8410. for _, advice := range advices {
  8411. var s models.HisPrescriptionAdviceTemplate
  8412. s.PrescriptionId = prescription.ID
  8413. s.AdviceType = 2
  8414. s.StopState = 2
  8415. s.ExecutionState = 2
  8416. s.Status = 1
  8417. s.UserOrgId = adminInfo.CurrentOrgId
  8418. s.CreatedTime = ctime
  8419. s.UpdatedTime = mtime
  8420. s.PatientId = patient_id
  8421. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8422. if errcode > 0 {
  8423. c.ServeFailJSONWithSGJErrorCode(errcode)
  8424. return
  8425. }
  8426. service.CreateHisPrescriptionAdviceTemplate(&s)
  8427. }
  8428. }
  8429. }
  8430. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8431. projects := items["project"].([]interface{})
  8432. if len(projects) > 0 {
  8433. for _, project := range projects {
  8434. var p models.HisPrescriptionProjectTemplate
  8435. p.PrescriptionId = prescription.ID
  8436. p.Ctime = time.Now().Unix()
  8437. p.Mtime = time.Now().Unix()
  8438. p.PatientId = patient_id
  8439. p.UserOrgId = adminInfo.CurrentOrgId
  8440. p.Status = 1
  8441. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8442. if errcode > 0 {
  8443. c.ServeFailJSONWithSGJErrorCode(errcode)
  8444. return
  8445. }
  8446. service.CreateHisPrescriptionProjectTemplate(&p)
  8447. }
  8448. }
  8449. }
  8450. }
  8451. c.ServeSuccessJSON(map[string]interface{}{
  8452. "msg": "创建成功",
  8453. })
  8454. }
  8455. }
  8456. }
  8457. }
  8458. func (c *HisApiController) PreSettle() {
  8459. id, _ := c.GetInt64("id")
  8460. record_time := c.GetString("record_time")
  8461. his_patient_id, _ := c.GetInt64("his_patient_id")
  8462. timeLayout := "2006-01-02"
  8463. loc, _ := time.LoadLocation("Local")
  8464. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8465. diagnosis_id := c.GetString("diagnosis")
  8466. sick_type, _ := c.GetInt64("sick_type")
  8467. reg_type, _ := c.GetInt64("p_type")
  8468. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8469. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8470. if err != nil {
  8471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8472. return
  8473. }
  8474. recordDateTime := theTime.Unix()
  8475. adminUser := c.GetAdminUserInfo()
  8476. var prescriptions []*models.HisPrescription
  8477. var start_time int64
  8478. var end_time int64
  8479. ids_str := c.GetString("ids")
  8480. ids_arr := strings.Split(ids_str, ",")
  8481. fmt.Println(reg_type)
  8482. if settle_accounts_type == 1 { //日结
  8483. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8484. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8485. } else {
  8486. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8487. }
  8488. fmt.Println(prescriptions)
  8489. } else { //月结
  8490. start_time_str := c.GetString("start_time")
  8491. end_time_str := c.GetString("end_time")
  8492. timeLayout := "2006-01-02"
  8493. loc, _ := time.LoadLocation("Local")
  8494. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8495. if err != nil {
  8496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8497. return
  8498. }
  8499. recordStartTime := theStartTime.Unix()
  8500. start_time = recordStartTime
  8501. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8502. if err != nil {
  8503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8504. return
  8505. }
  8506. recordEndTime := theEndTime.Unix()
  8507. end_time = recordEndTime
  8508. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8509. }
  8510. if reg_type == 1111 || reg_type == 1112 {
  8511. reg_type = 11
  8512. }
  8513. timestamp := time.Now().Unix()
  8514. tempTime := time.Unix(timestamp, 0)
  8515. timeFormat := tempTime.Format("20060102150405")
  8516. chrgBchno := rand.Intn(100000) + 10000
  8517. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8518. strconv.FormatInt(his.PatientId, 10)
  8519. var ids []int64
  8520. for _, item := range prescriptions {
  8521. ids = append(ids, item.ID)
  8522. }
  8523. fmt.Println(ids)
  8524. var total float64
  8525. for _, item := range prescriptions {
  8526. fmt.Println(item)
  8527. if item.Type == 1 { //药品
  8528. for _, subItem := range item.HisDoctorAdviceInfo {
  8529. total = total + (subItem.Price * subItem.PrescribingNumber)
  8530. }
  8531. }
  8532. if item.Type == 2 { //项目
  8533. for _, subItem := range item.HisPrescriptionProject {
  8534. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8535. total = total + (subItem.Price * cnt)
  8536. }
  8537. }
  8538. for _, subItem := range item.HisAdditionalCharge {
  8539. total = total + (subItem.Price * float64(subItem.Count))
  8540. }
  8541. }
  8542. allTotal := fmt.Sprintf("%.2f", total)
  8543. totals, _ := strconv.ParseFloat(allTotal, 64)
  8544. order := &models.HisOrder{
  8545. UserOrgId: adminUser.CurrentOrgId,
  8546. HisPatientId: his.ID,
  8547. PatientId: id,
  8548. SettleAccountsDate: recordDateTime,
  8549. Ctime: time.Now().Unix(),
  8550. Mtime: time.Now().Unix(),
  8551. Status: 1,
  8552. OrderStatus: 1,
  8553. MdtrtId: his.Number,
  8554. Number: chrg_bchno,
  8555. MedfeeSumamt: totals,
  8556. SettleEndTime: end_time,
  8557. SettleStartTime: start_time,
  8558. SettleType: settle_accounts_type,
  8559. PsnPartAmt: totals,
  8560. PsnCashPay: totals,
  8561. PType: 2,
  8562. IsPre: 1,
  8563. MedType: strconv.Itoa(int(reg_type)),
  8564. Diagnosis: diagnosis_id,
  8565. }
  8566. err = service.CreateOrder(order)
  8567. if err != nil {
  8568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8569. return
  8570. }
  8571. var customs []*Custom
  8572. for _, item := range prescriptions {
  8573. fmt.Println(item.Type)
  8574. if item.Type == 1 { //药品
  8575. for _, subItem := range item.HisDoctorAdviceInfo {
  8576. cus := &Custom{
  8577. AdviceId: subItem.ID,
  8578. ProjectId: 0,
  8579. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8580. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8581. FeedetlSn: subItem.FeedetlSn,
  8582. Price: fmt.Sprintf("%.2f", subItem.Price),
  8583. MedListCodg: subItem.MedListCodg,
  8584. Type: 1,
  8585. }
  8586. customs = append(customs, cus)
  8587. }
  8588. }
  8589. if item.Type == 2 { //项目
  8590. for _, subItem := range item.HisPrescriptionProject {
  8591. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8592. cus := &Custom{
  8593. AdviceId: 0,
  8594. ProjectId: subItem.ID,
  8595. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8596. Cut: fmt.Sprintf("%.2f", cnt),
  8597. FeedetlSn: subItem.FeedetlSn,
  8598. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8599. MedListCodg: subItem.MedListCodg,
  8600. Type: 2,
  8601. }
  8602. customs = append(customs, cus)
  8603. }
  8604. }
  8605. for _, item := range item.HisAdditionalCharge {
  8606. cus := &Custom{
  8607. ItemId: item.ID,
  8608. AdviceId: 0,
  8609. ProjectId: 0,
  8610. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8611. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8612. FeedetlSn: item.FeedetlSn,
  8613. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8614. MedListCodg: item.XtHisAddtionConfig.Code,
  8615. Type: 3,
  8616. }
  8617. customs = append(customs, cus)
  8618. }
  8619. }
  8620. fmt.Println(customs)
  8621. for _, item := range customs {
  8622. var advice_id int64 = 0
  8623. var project_id int64 = 0
  8624. var item_id int64 = 0
  8625. var types int64 = 0
  8626. if item.Type == 1 {
  8627. advice_id = item.AdviceId
  8628. project_id = 0
  8629. item_id = 0
  8630. } else if item.Type == 2 {
  8631. advice_id = 0
  8632. item_id = 0
  8633. project_id = item.ProjectId
  8634. } else if item.Type == 3 {
  8635. advice_id = 0
  8636. item_id = item.ItemId
  8637. project_id = 0
  8638. }
  8639. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8640. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8641. pric, _ := strconv.ParseFloat(item.Price, 32)
  8642. info := &models.HisOrderInfo{
  8643. OrderNumber: order.Number,
  8644. UploadDate: time.Now().Unix(),
  8645. AdviceId: advice_id,
  8646. DetItemFeeSumamt: detItemFeeSumamt,
  8647. Cnt: cut,
  8648. Pric: pric,
  8649. PatientId: id,
  8650. Status: 1,
  8651. Mtime: time.Now().Unix(),
  8652. Ctime: time.Now().Unix(),
  8653. UserOrgId: adminUser.CurrentOrgId,
  8654. HisPatientId: his.ID,
  8655. OrderId: order.ID,
  8656. ProjectId: project_id,
  8657. Type: types,
  8658. ItemId: item_id,
  8659. }
  8660. service.CreateOrderInfo(info)
  8661. }
  8662. his.SickType = sick_type
  8663. service.UpdataHisPateint(&his)
  8664. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8665. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8666. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8667. if err == nil {
  8668. c.ServeSuccessJSON(map[string]interface{}{
  8669. "msg": "结算成功",
  8670. })
  8671. }
  8672. }
  8673. type CustomOrderInfo struct {
  8674. Name string
  8675. Spec string
  8676. Unit string
  8677. Count float64
  8678. Price float64
  8679. Total float64
  8680. }
  8681. func (c *HisApiController) GetPrivateExpensesInfo() {
  8682. order_id, _ := c.GetInt64("id", 0)
  8683. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8684. order, _ := service.GetHisOrderByID(order_id)
  8685. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8686. if order.ID == 0 {
  8687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8688. return
  8689. }
  8690. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8691. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8692. org_id := c.GetAdminUserInfo().CurrentOrgId
  8693. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8694. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8695. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8696. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8697. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8698. var orderInfos_four []*models.HisOrderInfoTwo
  8699. for _, item := range orderInfos_three {
  8700. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8701. item.HisPrescriptionProject.IsCheckTeam = 1
  8702. orderInfos_four = append(orderInfos_four, item)
  8703. }
  8704. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8705. item.HisPrescriptionProject.IsCheckTeam = 2
  8706. orderInfos_two = append(orderInfos_two, item)
  8707. }
  8708. }
  8709. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8710. var cus_slice []CustomOrderInfo
  8711. //for _, item := range new_order_info {
  8712. // var cus CustomOrderInfo
  8713. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8714. // cus.Unit = ""
  8715. // cus.Spec = ""
  8716. // var total float64
  8717. // for _, subItem := range orderInfos_four {
  8718. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8719. // total = total + subItem.DetItemFeeSumamt
  8720. // fmt.Println(subItem.DetItemFeeSumamt)
  8721. // }
  8722. // }
  8723. // cus.Count = 1
  8724. // cus.Total = total
  8725. // cus_slice = append(cus_slice, cus)
  8726. //}
  8727. orderInfos = append(orderInfos, orderInfos_two...)
  8728. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8729. orderInfos = append(orderInfos, orderInfos_three...)
  8730. //}/**/
  8731. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8732. c.ServeSuccessJSON(map[string]interface{}{
  8733. "order": order,
  8734. "order_info": orderInfos,
  8735. "patient": patient,
  8736. "admin_info": adminInfo,
  8737. "his": his,
  8738. "current_admin": role,
  8739. "org_config": miConfig,
  8740. "new_order_info": cus_slice,
  8741. })
  8742. }
  8743. func (this *HisApiController) ChangeMedType() {
  8744. med_type := this.GetString("med_type")
  8745. old_med_type := this.GetString("old_med_type")
  8746. ids := this.GetString("ids")
  8747. settle_type, _ := this.GetInt64("settle_type")
  8748. start_time := this.GetString("start_time")
  8749. end_time := this.GetString("end_time")
  8750. ids_arr := strings.Split(ids, ",")
  8751. if settle_type == 1 { //日结
  8752. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8753. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8754. prescription.MedType = med_type
  8755. err := service.SaveHisPrescription(&prescription)
  8756. if err == nil {
  8757. this.ServeSuccessJSON(map[string]interface{}{
  8758. "msg": "修改成功",
  8759. })
  8760. } else {
  8761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8762. return
  8763. }
  8764. } else if settle_type == 2 {
  8765. timeLayout := "2006-01-02"
  8766. loc, _ := time.LoadLocation("Local")
  8767. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8768. if err != nil {
  8769. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8770. return
  8771. }
  8772. recordStartTime := theStartTime.Unix()
  8773. start_time_timestamp := recordStartTime
  8774. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8775. if err != nil {
  8776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8777. return
  8778. }
  8779. recordEndTime := theEndTime.Unix()
  8780. end_time_timestamp := recordEndTime
  8781. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8782. if updateErr == nil {
  8783. this.ServeSuccessJSON(map[string]interface{}{
  8784. "msg": "修改成功",
  8785. })
  8786. } else {
  8787. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8788. return
  8789. }
  8790. }
  8791. }
  8792. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8793. patient_id, _ := c.GetInt64("patient_id")
  8794. his_patient_id, _ := c.GetInt64("his_patient_id")
  8795. record_date := c.GetString("record_date")
  8796. start_time := c.GetString("start_time")
  8797. end_time := c.GetString("end_time")
  8798. order_status, _ := c.GetInt64("type", 0)
  8799. p_type, _ := c.GetInt64("p_type", 0)
  8800. order_id, _ := c.GetInt64("order_id", 0)
  8801. timeLayout := "2006-01-02"
  8802. loc, _ := time.LoadLocation("Local")
  8803. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8804. if err != nil {
  8805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8806. return
  8807. }
  8808. recordDateTime := theTime.Unix()
  8809. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8810. if err != nil {
  8811. }
  8812. startRecordDateTime := startTime.Unix()
  8813. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8814. if err != nil {
  8815. }
  8816. endRecordDateTime := endTime.Unix()
  8817. admin := c.GetAdminUserInfo()
  8818. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8819. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8820. order, _ := service.GetHisOrderByID(order_id)
  8821. var monthPrescriptions []*models.HisPrescription
  8822. if order_status == 1 || order_status == 0 {
  8823. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8824. } else if order_status == 2 {
  8825. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8826. }
  8827. var settle_total float64
  8828. for _, item := range monthPrescriptions {
  8829. if len(item.HisPrescriptionProject) > 0 {
  8830. for _, subItem := range item.HisPrescriptionProject {
  8831. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8832. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8833. settle_total = settle_total + total
  8834. }
  8835. }
  8836. if len(item.HisDoctorAdviceInfo) > 0 {
  8837. for _, subItem := range item.HisDoctorAdviceInfo {
  8838. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8839. settle_total = settle_total + total
  8840. }
  8841. }
  8842. }
  8843. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8844. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8845. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8846. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8847. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8848. //获取所有科室信息
  8849. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8850. c.ServeSuccessJSON(map[string]interface{}{
  8851. "his_info": his_patient_info,
  8852. "xt_info": xt_patient_info,
  8853. "case_history": case_history,
  8854. "info": patientPrescriptionInfo,
  8855. "last_info": lastPatientPrescriptionInfo,
  8856. "month_prescriptions": monthPrescriptions,
  8857. "order": order,
  8858. "doctors": doctors,
  8859. "department": department,
  8860. "settle_total": settle_total,
  8861. })
  8862. return
  8863. }
  8864. func (c *HisApiController) GetHisMonthPatientInfo() {
  8865. patient_id, _ := c.GetInt64("patient_id")
  8866. his_patient_id, _ := c.GetInt64("his_patient_id")
  8867. record_date := c.GetString("record_date")
  8868. number := c.GetString("number")
  8869. start_time := c.GetString("start_time")
  8870. end_time := c.GetString("end_time")
  8871. p_type, _ := c.GetInt64("p_type")
  8872. timeLayout := "2006-01-02"
  8873. loc, _ := time.LoadLocation("Local")
  8874. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8875. if err != nil {
  8876. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8877. return
  8878. }
  8879. recordDateTime := theTime.Unix()
  8880. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8881. if err != nil {
  8882. }
  8883. startRecordDateTime := startTime.Unix()
  8884. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8885. if err != nil {
  8886. }
  8887. endRecordDateTime := endTime.Unix()
  8888. admin := c.GetAdminUserInfo()
  8889. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8890. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8891. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8892. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8893. var settle_total float64
  8894. for _, item := range monthPrescriptions {
  8895. if len(item.HisPrescriptionProject) > 0 {
  8896. for _, subItem := range item.HisPrescriptionProject {
  8897. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8898. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8899. settle_total = settle_total + total
  8900. }
  8901. }
  8902. if len(item.HisDoctorAdviceInfo) > 0 {
  8903. for _, subItem := range item.HisDoctorAdviceInfo {
  8904. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8905. settle_total = settle_total + total
  8906. }
  8907. }
  8908. }
  8909. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8910. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8911. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8912. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8913. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8914. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8915. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8916. //获取所有科室信息
  8917. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8918. c.ServeSuccessJSON(map[string]interface{}{
  8919. "his_info": his_patient_info,
  8920. "xt_info": xt_patient_info,
  8921. "case_history": case_history,
  8922. "info": patientPrescriptionInfo,
  8923. "month_prescriptions": monthPrescriptions,
  8924. "order": order,
  8925. "doctors": doctors,
  8926. "department": department,
  8927. "count": count,
  8928. "drugStockConfig": drugStockConfig,
  8929. "last_info": lastPatientPrescriptionInfo,
  8930. "settle_total": settle_total,
  8931. })
  8932. return
  8933. }
  8934. func (c *HisApiController) GetAllOrder() {
  8935. org_id := c.GetAdminUserInfo().CurrentOrgId
  8936. orders, _ := service.GetNewHisOrderList(org_id)
  8937. c.ServeSuccessJSON(map[string]interface{}{
  8938. "order": orders,
  8939. })
  8940. return
  8941. }
  8942. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8943. newArr = make([]*models.HisOrderInfoTwo, 0)
  8944. for i := 0; i < len(arr); i++ {
  8945. repeat := false
  8946. for j := i + 1; j < len(arr); j++ {
  8947. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8948. repeat = true
  8949. break
  8950. }
  8951. }
  8952. if !repeat {
  8953. newArr = append(newArr, arr[i])
  8954. }
  8955. }
  8956. return
  8957. }
  8958. // 修改处方退库操作 参数传修改之前的处方数据
  8959. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8960. if advice.ExecutionState == 1 {
  8961. //查询该病人该药品是否有库存记录
  8962. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8963. if errcode == gorm.ErrRecordNotFound {
  8964. } else {
  8965. //退库
  8966. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8967. if advice.PrescribingNumberUnit == drug.MinUnit {
  8968. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8969. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8970. //退库
  8971. warehouseInfo := models.DrugWarehouseInfo{
  8972. StockMinNumber: prescribingNumber,
  8973. }
  8974. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8975. operation_time := time.Now().Unix()
  8976. creater := advice.AdviceDoctor
  8977. ctime := time.Now().Unix()
  8978. timeStr := time.Now().Format("2006-01-02")
  8979. timeArr := strings.Split(timeStr, "-")
  8980. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8981. total = total + 1
  8982. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8983. cancelStock := models.DrugCancelStock{
  8984. OrderNumber: orderNumber,
  8985. OperaTime: operation_time,
  8986. OrgId: advice.UserOrgId,
  8987. Creater: creater,
  8988. Ctime: ctime,
  8989. Status: 1,
  8990. ReturnTime: advice.AdviceDate,
  8991. Dealer: info.Dealer,
  8992. Manufacturer: info.Manufacturer,
  8993. Type: 1,
  8994. }
  8995. service.AddSigleDrugCancelStock(&cancelStock)
  8996. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8997. dealer, _ := service.GetDealerById(info.Dealer)
  8998. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8999. cancelStockInfo := models.DrugCancelStockInfo{
  9000. OrderNumber: cancelInfo.OrderNumber,
  9001. CancelStockId: cancelInfo.ID,
  9002. DrugId: info.DrugId,
  9003. Count: info.Count,
  9004. Status: 1,
  9005. Ctime: ctime,
  9006. OrgId: advice.UserOrgId,
  9007. Type: 1,
  9008. Manufacturer: manufactureName.ManufacturerName,
  9009. Dealer: dealer.DealerName,
  9010. Total: 0,
  9011. RetailPrice: info.RetailPrice,
  9012. RetailTotalPrice: info.RetailTotalPrice,
  9013. Price: info.Price,
  9014. RegisterAccount: "",
  9015. Remark: info.Remark,
  9016. BatchNumber: info.BatchNumber,
  9017. MaxUnit: info.CountUnit,
  9018. ProductDate: info.ProductDate,
  9019. ExpiryDate: info.ExpiryDate,
  9020. BatchNumberId: info.WarehouseInfoId,
  9021. }
  9022. flow := models.DrugFlow{
  9023. WarehousingId: 0,
  9024. DrugId: info.DrugId,
  9025. Number: "",
  9026. BatchNumber: info.BatchNumber,
  9027. Count: info.Count,
  9028. UserOrgId: advice.UserOrgId,
  9029. PatientId: 0,
  9030. SystemTime: ctime,
  9031. ConsumableType: 4,
  9032. IsSys: 0,
  9033. WarehousingOrder: "",
  9034. WarehouseOutId: 0,
  9035. WarehouseOutOrderNumber: "",
  9036. IsEdit: 0,
  9037. CancelStockId: cancelStock.ID,
  9038. CancelOrderNumber: cancelStock.OrderNumber,
  9039. Manufacturer: info.Manufacturer,
  9040. Dealer: info.Dealer,
  9041. Creator: advice.UserOrgId,
  9042. UpdateCreator: 0,
  9043. Status: 1,
  9044. Ctime: time.Now().Unix(),
  9045. Mtime: 0,
  9046. Price: info.Price,
  9047. WarehousingDetailId: 0,
  9048. WarehouseOutDetailId: 0,
  9049. CancelOutDetailId: 0,
  9050. ExpireDate: info.ExpiryDate,
  9051. ProductDate: info.ProductDate,
  9052. MaxUnit: info.CountUnit,
  9053. MinUnit: "",
  9054. }
  9055. service.CreatedCancelStock(cancelStockInfo)
  9056. service.CreateDrugFlowOne(flow)
  9057. } else {
  9058. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9059. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9060. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9061. warehouseInfo := models.DrugWarehouseInfo{
  9062. StockMinNumber: prescribingNumber,
  9063. }
  9064. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9065. }
  9066. operation_time := time.Now().Unix()
  9067. creater := advice.AdviceDoctor
  9068. ctime := time.Now().Unix()
  9069. timeStr := time.Now().Format("2006-01-02")
  9070. timeArr := strings.Split(timeStr, "-")
  9071. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9072. total = total + 1
  9073. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9074. cancelStock := models.DrugCancelStock{
  9075. OrderNumber: orderNumber,
  9076. OperaTime: operation_time,
  9077. OrgId: advice.UserOrgId,
  9078. Creater: creater,
  9079. Ctime: ctime,
  9080. Status: 1,
  9081. ReturnTime: advice.AdviceDate,
  9082. Dealer: info.Dealer,
  9083. Manufacturer: info.Manufacturer,
  9084. Type: 1,
  9085. }
  9086. service.AddSigleDrugCancelStock(&cancelStock)
  9087. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9088. dealer, _ := service.GetDealerById(info.Dealer)
  9089. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9090. cancelStockInfo := models.DrugCancelStockInfo{
  9091. OrderNumber: cancelInfo.OrderNumber,
  9092. CancelStockId: cancelInfo.ID,
  9093. DrugId: info.DrugId,
  9094. Count: info.Count,
  9095. Status: 1,
  9096. Ctime: ctime,
  9097. OrgId: advice.UserOrgId,
  9098. Type: 1,
  9099. Manufacturer: manufactureName.ManufacturerName,
  9100. Dealer: dealer.DealerName,
  9101. Total: 0,
  9102. RetailPrice: info.RetailPrice,
  9103. RetailTotalPrice: info.RetailTotalPrice,
  9104. Price: info.Price,
  9105. RegisterAccount: "",
  9106. Remark: info.Remark,
  9107. BatchNumber: info.BatchNumber,
  9108. MaxUnit: info.CountUnit,
  9109. ProductDate: info.ProductDate,
  9110. ExpiryDate: info.ExpiryDate,
  9111. BatchNumberId: info.WarehouseInfoId,
  9112. }
  9113. flow := models.DrugFlow{
  9114. WarehousingId: 0,
  9115. DrugId: info.DrugId,
  9116. Number: "",
  9117. BatchNumber: info.BatchNumber,
  9118. Count: info.Count,
  9119. UserOrgId: advice.UserOrgId,
  9120. PatientId: 0,
  9121. SystemTime: ctime,
  9122. ConsumableType: 4,
  9123. IsSys: 0,
  9124. WarehousingOrder: "",
  9125. WarehouseOutId: 0,
  9126. WarehouseOutOrderNumber: "",
  9127. IsEdit: 0,
  9128. CancelStockId: cancelStock.ID,
  9129. CancelOrderNumber: cancelStock.OrderNumber,
  9130. Manufacturer: info.Manufacturer,
  9131. Dealer: info.Dealer,
  9132. Creator: advice.AdviceDoctor,
  9133. UpdateCreator: 0,
  9134. Status: 1,
  9135. Ctime: time.Now().Unix(),
  9136. Mtime: 0,
  9137. Price: info.Price,
  9138. WarehousingDetailId: 0,
  9139. WarehouseOutDetailId: 0,
  9140. CancelOutDetailId: 0,
  9141. ExpireDate: info.ExpiryDate,
  9142. ProductDate: info.ProductDate,
  9143. MaxUnit: info.CountUnit,
  9144. MinUnit: "",
  9145. }
  9146. service.CreatedCancelStock(cancelStockInfo)
  9147. service.CreateDrugFlowOne(flow)
  9148. }
  9149. }
  9150. }
  9151. return err
  9152. }
  9153. func (this *HisApiController) DeleteNCDS() {
  9154. id, _ := this.GetInt64("id", 0)
  9155. if id > 0 {
  9156. service.DeletePsnNCDSRecordById(id)
  9157. this.ServeSuccessJSON(map[string]interface{}{
  9158. "msg": "删除成功",
  9159. })
  9160. } else {
  9161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9162. return
  9163. }
  9164. }
  9165. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9166. id, _ := c.GetInt64("id")
  9167. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9168. c.ServeSuccessJSON(map[string]interface{}{
  9169. "advice": advice,
  9170. })
  9171. return
  9172. }
  9173. func (c *HisApiController) GetHisMonthChargePatientList() {
  9174. record_date := c.GetString("record_date")
  9175. start_time := c.GetString("start_time")
  9176. end_time := c.GetString("end_time")
  9177. timeLayout := "2006-01-02"
  9178. loc, _ := time.LoadLocation("Local")
  9179. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9180. if err != nil {
  9181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9182. return
  9183. }
  9184. if err != nil {
  9185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9186. return
  9187. }
  9188. recordDateTime := theTime.Unix()
  9189. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9190. if err != nil {
  9191. }
  9192. startRecordDateTime := startTime.Unix()
  9193. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9194. if err != nil {
  9195. }
  9196. endRecordDateTime := endTime.Unix()
  9197. adminInfo := c.GetAdminUserInfo()
  9198. var tempMonthChargePatients []*service.MonthChargePatients
  9199. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9200. for _, item := range tempPatients {
  9201. //过滤没有处方的
  9202. if len(item.HisPrescription) == 0 {
  9203. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9204. }
  9205. }
  9206. c.ServeSuccessJSON(map[string]interface{}{
  9207. "list": tempMonthChargePatients,
  9208. })
  9209. }