his_api_controller.go 440KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. //beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. //beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. }
  90. //func (c *HisApiController) CheckHisPatient() {
  91. // record_date := c.GetString("record_date")
  92. // patient_id, _ := c.GetInt64("patient_id")
  93. //
  94. // timeLayout := "2006-01-02"
  95. // loc, _ := time.LoadLocation("Local")
  96. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. // if err != nil {
  98. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. // return
  100. // }
  101. // recordDateTime := theTime.Unix()
  102. // adminInfo := c.GetAdminUserInfo()
  103. // patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. // if len(patients) > 1 {
  105. // ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. // if len(ps) > 0 {
  107. // c.ServeSuccessJSON(map[string]interface{}{
  108. // "status": 1,
  109. // "msg": "关联",
  110. // "ps": ps,
  111. // })
  112. // } else {
  113. // c.ServeSuccessJSON(map[string]interface{}{
  114. // "status": 0,
  115. // "msg": "无需关联",
  116. // })
  117. // }
  118. // } else {
  119. // c.ServeSuccessJSON(map[string]interface{}{
  120. // "status": 0,
  121. // "msg": "无需关联",
  122. // })
  123. // return
  124. // }
  125. //}
  126. //func (c *HisApiController) AssociationHisPrescription() {
  127. // record_date, _ := c.GetInt64("record_date")
  128. // his_patient_id, _ := c.GetInt64("his_patient_id")
  129. // patient_id, _ := c.GetInt64("patient_id")
  130. // p_ids := c.GetString("p_ids")
  131. // p_ids_arr := strings.Split(p_ids, ",")
  132. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  133. // if his_patient_id == 0 || his_patient.ID == 0 {
  134. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  135. // return
  136. // }
  137. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  138. // if err == nil {
  139. // c.ServeSuccessJSON(map[string]interface{}{
  140. // "msg": "关联处方成功",
  141. // })
  142. // return
  143. // } else {
  144. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  145. // return
  146. // }
  147. //}
  148. //func (c *HisApiController) AssociationHisPrescription() {
  149. // record_date, _ := c.GetInt64("record_date")
  150. // his_patient_id, _ := c.GetInt64("his_patient_id")
  151. // patient_id, _ := c.GetInt64("patient_id")
  152. // p_ids := c.GetString("p_ids")
  153. // p_ids_arr := strings.Split(p_ids, ",")
  154. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  155. // if his_patient_id == 0 || his_patient.ID == 0 {
  156. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  157. // return
  158. // }
  159. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  160. // if err == nil {
  161. // c.ServeSuccessJSON(map[string]interface{}{
  162. // "msg": "关联处方成功",
  163. // })
  164. // return
  165. // } else {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  167. // return
  168. // }
  169. //}
  170. func (c *HisApiController) GetFaPiaoNumber() {
  171. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  172. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  173. fmt.Println(count)
  174. var zero string
  175. number := count + 1
  176. if number >= 1000 {
  177. zero = "0000" + strconv.FormatInt(number, 10)
  178. } else if number >= 10000 {
  179. zero = "000" + strconv.FormatInt(number, 10)
  180. } else if number >= 100000 {
  181. zero = "00" + strconv.FormatInt(number, 10)
  182. } else if number >= 1000000 {
  183. zero = "0" + strconv.FormatInt(number, 10)
  184. } else {
  185. zero = strconv.FormatInt(number, 10)
  186. }
  187. c.ServeSuccessJSON(map[string]interface{}{
  188. "fapiao_number": zero,
  189. })
  190. return
  191. }
  192. func (c *HisApiController) ChangeOrderDesc() {
  193. id, _ := c.GetInt64("id")
  194. desc := c.GetString("desc")
  195. change_type := c.GetString("change_type")
  196. order, _ := service.GetHisOrderByID(id)
  197. if order.ID == 0 {
  198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  199. return
  200. }
  201. switch change_type {
  202. case "oth_desc":
  203. order.OthDesc = desc
  204. break
  205. case "cash_pay":
  206. order.CashPay = desc
  207. break
  208. case "jifen_pay":
  209. order.JifenPay = desc
  210. break
  211. case "band_card_pay":
  212. order.BandCardPay = desc
  213. break
  214. case "ali_pay":
  215. order.AliPay = desc
  216. break
  217. case "wechat_pay":
  218. order.WechatPay = desc
  219. break
  220. case "fa_piao_number":
  221. order.FaPiaoNumber = desc
  222. break
  223. case "fa_piao_code":
  224. order.FaPiaoCode = desc
  225. break
  226. }
  227. err := service.SaveHisOrder(&order)
  228. if err == nil {
  229. c.ServeSuccessJSON(map[string]interface{}{
  230. "msg": "修改成功",
  231. })
  232. return
  233. } else {
  234. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  235. return
  236. }
  237. }
  238. func (c *HisApiController) GetMonthHisPatient() {
  239. record_date := c.GetString("record_date")
  240. //order_status, _ := c.GetInt64("type")
  241. timeLayout := "2006-01-02"
  242. loc, _ := time.LoadLocation("Local")
  243. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  244. if err != nil {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  246. return
  247. }
  248. recordDateTime := theTime.Unix()
  249. adminInfo := c.GetAdminUserInfo()
  250. var tempPatients []service.NewTempPatients
  251. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  252. // 获取当前时间
  253. now := time.Now()
  254. // 获取本月的第一天
  255. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  256. // 获取下个月的第一天
  257. nextMonth := firstDay.AddDate(0, 1, 0)
  258. // 获取本月的最后一天
  259. lastDay := nextMonth.Add(-time.Nanosecond)
  260. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  261. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  262. var patients []service.NewTempPatients
  263. var patients_two []service.NewTempPatients
  264. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  265. for _, item := range tempPatients {
  266. //过滤掉没挂号的和没开处方的
  267. if len(item.HisPrescription) > 0 {
  268. patients = append(patients, item)
  269. patients_two = append(patients_two, item)
  270. }
  271. ////过滤掉没挂号的
  272. //if len(item.HisPatient) > 0 {
  273. //}
  274. }
  275. } else {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. // patients_two = append(patients_two, item)
  284. //}
  285. }
  286. }
  287. c.ServeSuccessJSON(map[string]interface{}{
  288. "list": patients,
  289. "list_two": patients_two,
  290. "chargePatients": chargePatients,
  291. })
  292. }
  293. func (c *HisApiController) GetBatchSettleAccounts() {
  294. order_ids := c.GetString("order_ids")
  295. admin_user_id, _ := c.GetInt64("admin_user_id")
  296. adminUser := c.GetAdminUserInfo()
  297. orders := strings.Split(order_ids, ",")
  298. var newOrders []models.Orders
  299. for _, item := range orders {
  300. order, _ := service.GetHisOrderByIDTenOne(item)
  301. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  302. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  303. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  304. orderInfos = append(orderInfos, orderInfos_two...)
  305. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  306. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  307. var diagnosis_ids []string
  308. if his.ID > 0 {
  309. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  310. } else {
  311. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  312. }
  313. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  314. var dia_config []*models.HisXtDiagnoseConfig
  315. var name string
  316. for _, item := range diagnosis_ids {
  317. id, _ := strconv.ParseInt(item, 10, 64)
  318. diagnosisConfig, _ := service.FindDiagnoseById(id)
  319. dia_config = append(dia_config, diagnosisConfig)
  320. if len(name) == 0 {
  321. name = diagnosisConfig.ClassName
  322. } else {
  323. name = name + "," + diagnosisConfig.ClassName
  324. }
  325. }
  326. var bedCostTotal float64 = 0 //床位总费
  327. var bedCostSelfTotal float64 = 0 //床位自费
  328. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  329. var bedSelfTotal float64 = 0 //床位部分项目自费
  330. var bedInscpTotal float64 = 0 //床位部分项目自费
  331. var operationCostTotal float64 = 0 //手术费
  332. var operationCostSelfTotal float64 = 0 //手术费
  333. var operationCostPartSelfTotal float64 = 0 //手术费
  334. var operationSelfTotal float64 = 0 //床位部分项目自费
  335. var operationInscpTotal float64 = 0 //床位部分项目自费
  336. var otherCostTotal float64 = 0 //其他费用
  337. var otherCostSelfTotal float64 = 0 //其他费用
  338. var otherCostPartSelfTotal float64 = 0 //其他费用
  339. var otherSelfTotal float64 = 0 //床位部分项目自费
  340. var otherInscpTotal float64 = 0 //床位部分项目自费
  341. var materialCostTotal float64 = 0 //材料费
  342. var materialCostSelfTotal float64 = 0 //材料费
  343. var materialCostPartSelfTotal float64 = 0 //材料费
  344. var materialSelfTotal float64 = 0 //床位部分项目自费
  345. var materialInscpTotal float64 = 0 //床位部分项目自费
  346. var westernMedicineCostTotal float64 = 0 //西药费
  347. var westernMedicineCostSelfTotal float64 = 0 //西药费
  348. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  349. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  350. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  351. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  352. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  353. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  354. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  355. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  356. var checkCostTotal float64 = 0 //检查费
  357. var checkCostSelfTotal float64 = 0 //检查费
  358. var checkCostPartSelfTotal float64 = 0 //检查费
  359. var checkSelfTotal float64 = 0 //床位部分项目自费
  360. var checkInscpTotal float64 = 0 //床位部分项目自费
  361. var laboratoryCostTotal float64 = 0 //化验费
  362. var laboratoryCostSelfTotal float64 = 0 //化验费
  363. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  364. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  365. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  366. var treatCostTotal float64 = 0 //治疗费用
  367. var treatCostSelfTotal float64 = 0 //治疗费用
  368. var treatCostPartSelfTotal float64 = 0 //治疗费用
  369. var treatSelfTotal float64 = 0 //床位部分项目自费
  370. var treatInscpTotal float64 = 0 //床位部分项目自费
  371. decimal.DivisionPrecision = 2
  372. for _, item := range orderInfos {
  373. if item.MedChrgitmType == "01" { //床位费
  374. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  375. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  376. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  377. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  378. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  379. }
  380. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  381. if item.MedChrgitmType == "03" { //检查费
  382. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  383. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  384. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  385. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  386. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  387. }
  388. } else {
  389. if item.MedChrgitmType == "03" { //检查费
  390. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  391. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  392. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  393. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  394. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  395. }
  396. }
  397. if item.MedChrgitmType == "04" { //化验费
  398. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  399. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  400. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  401. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  402. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  403. }
  404. if item.MedChrgitmType == "05" { //治疗费
  405. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  406. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  407. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  408. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  409. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  410. }
  411. if item.MedChrgitmType == "06" { //手术费
  412. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  413. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  414. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  415. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  416. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  417. }
  418. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  419. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  420. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  421. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  422. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  423. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  424. }
  425. if item.MedChrgitmType == "09" { //西药费
  426. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  427. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  428. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  429. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  430. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  431. }
  432. if item.MedChrgitmType == "11" { //中成费
  433. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  434. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  435. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  436. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  437. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  438. }
  439. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  440. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  441. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  442. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  443. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  444. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  445. }
  446. }
  447. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  448. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  449. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  450. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  451. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  452. var doctor_name string
  453. if roles.ID == 0 {
  454. doctor_name = "管理员"
  455. } else {
  456. doctor_name = roles.UserName
  457. }
  458. yiliao_leibie := ""
  459. switch order.MedType {
  460. case "11":
  461. yiliao_leibie = "普通门诊"
  462. break
  463. case "12":
  464. yiliao_leibie = "门诊挂号"
  465. break
  466. case "13":
  467. yiliao_leibie = "急诊"
  468. break
  469. case "14":
  470. yiliao_leibie = "门诊特殊病"
  471. break
  472. case "15":
  473. yiliao_leibie = "门诊统筹"
  474. break
  475. case "16":
  476. yiliao_leibie = "门诊慢性病"
  477. break
  478. case "21":
  479. yiliao_leibie = "普通住院"
  480. break
  481. }
  482. var newOrder models.Orders
  483. newOrder.Diagnosis = name
  484. newOrder.OrderInfos = orderInfos
  485. newOrder.Number = order.MdtrtId
  486. newOrder.Date = order.SettleAccountsDate
  487. newOrder.ChargeAdmin = charge_admin
  488. newOrder.PrintorAdmin = printor_admin
  489. newOrder.Order = order
  490. newOrder.BedCostTotal = bedCostTotal
  491. newOrder.BedCostSelfTotal = bedCostSelfTotal
  492. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  493. newOrder.BedSelfTotal = bedSelfTotal
  494. newOrder.BedInscpTotal = bedInscpTotal
  495. newOrder.OperationCostTotal = operationCostTotal
  496. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  497. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  498. newOrder.OperationSelfTotal = operationSelfTotal
  499. newOrder.OperationInscpTotal = operationInscpTotal
  500. newOrder.OtherCostTotal = otherCostTotal
  501. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  502. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  503. newOrder.OtherSelfTotal = otherSelfTotal
  504. newOrder.OtherInscpTotal = otherInscpTotal
  505. newOrder.MaterialCostTotal = materialCostTotal
  506. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  507. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  508. newOrder.MaterialSelfTotal = materialSelfTotal
  509. newOrder.MaterialInscpTotal = materialInscpTotal
  510. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  511. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  512. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  513. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  514. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  515. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  516. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  517. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  518. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  519. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  520. newOrder.CheckCostTotal = checkCostTotal
  521. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  522. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  523. newOrder.CheckSelfTotal = checkSelfTotal
  524. newOrder.CheckInscpTotal = checkInscpTotal
  525. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  526. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  527. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  528. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  529. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  530. newOrder.TreatCostTotal = treatCostTotal
  531. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  532. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  533. newOrder.TreatSelfTotal = treatSelfTotal
  534. newOrder.TreatInscpTotal = treatInscpTotal
  535. newOrder.DoctorInfo = doctor_info
  536. newOrder.DoctorName = doctor_name
  537. newOrder.HealthCardNo = order.PsnNo
  538. newOrder.YiliaoLeibie = yiliao_leibie
  539. newOrder.Patient = patient
  540. newOrder.OrgName = miConfig.OrgName
  541. newOrder.OrgCode = miConfig.Code
  542. newOrder.OrderNumber = order.Number
  543. newOrder.HisPatient = his
  544. newOrder.DiaConfig = dia_config
  545. newOrders = append(newOrders, newOrder)
  546. }
  547. c.ServeSuccessJSON(map[string]interface{}{
  548. "orders": newOrders,
  549. })
  550. }
  551. func (c *HisApiController) GetTestOrder() {
  552. order_id, _ := c.GetInt64("order_id")
  553. admin_user_id, _ := c.GetInt64("admin_user_id")
  554. adminUser := c.GetAdminUserInfo()
  555. order, _ := service.GetHisOrderByID(order_id)
  556. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  557. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  558. orderInfos = append(orderInfos, orderInfos_two...)
  559. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  560. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  561. var dia_config []*models.HisXtDiagnoseConfig
  562. var name string
  563. var bedCostTotal float64 = 0 //床位总费
  564. var bedCostSelfTotal float64 = 0 //床位自费
  565. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  566. var bedSelfTotal float64 = 0 //床位部分项目自费
  567. var bedInscpTotal float64 = 0 //床位部分项目自费
  568. var operationCostTotal float64 = 0 //手术费
  569. var operationCostSelfTotal float64 = 0 //手术费
  570. var operationCostPartSelfTotal float64 = 0 //手术费
  571. var operationSelfTotal float64 = 0 //床位部分项目自费
  572. var operationInscpTotal float64 = 0 //床位部分项目自费
  573. var otherCostTotal float64 = 0 //其他费用
  574. var otherCostSelfTotal float64 = 0 //其他费用
  575. var otherCostPartSelfTotal float64 = 0 //其他费用
  576. var otherSelfTotal float64 = 0 //床位部分项目自费
  577. var otherInscpTotal float64 = 0 //床位部分项目自费
  578. var materialCostTotal float64 = 0 //材料费
  579. var materialCostSelfTotal float64 = 0 //材料费
  580. var materialCostPartSelfTotal float64 = 0 //材料费
  581. var materialSelfTotal float64 = 0 //床位部分项目自费
  582. var materialInscpTotal float64 = 0 //床位部分项目自费
  583. var westernMedicineCostTotal float64 = 0 //西药费
  584. var westernMedicineCostSelfTotal float64 = 0 //西药费
  585. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  586. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  587. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  588. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  589. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  590. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  591. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  592. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  593. var checkCostTotal float64 = 0 //检查费
  594. var checkCostSelfTotal float64 = 0 //检查费
  595. var checkCostPartSelfTotal float64 = 0 //检查费
  596. var checkSelfTotal float64 = 0 //床位部分项目自费
  597. var checkInscpTotal float64 = 0 //床位部分项目自费
  598. var laboratoryCostTotal float64 = 0 //化验费
  599. var laboratoryCostSelfTotal float64 = 0 //化验费
  600. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  601. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  602. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  603. var treatCostTotal float64 = 0 //治疗费用
  604. var treatCostSelfTotal float64 = 0 //治疗费用
  605. var treatCostPartSelfTotal float64 = 0 //治疗费用
  606. var treatSelfTotal float64 = 0 //床位部分项目自费
  607. var treatInscpTotal float64 = 0 //床位部分项目自费
  608. decimal.DivisionPrecision = 2
  609. for _, item := range orderInfos {
  610. if item.MedChrgitmType == "01" { //床位费
  611. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  612. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  613. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  614. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  615. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  616. }
  617. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  618. if item.MedChrgitmType == "03" { //检查费
  619. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  620. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  621. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  622. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  623. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  624. }
  625. } else {
  626. if item.MedChrgitmType == "03" { //检查费
  627. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  628. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  629. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  630. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  631. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  632. }
  633. }
  634. if item.MedChrgitmType == "04" { //化验费
  635. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  636. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  637. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  638. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  639. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  640. }
  641. if item.MedChrgitmType == "05" { //治疗费
  642. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  643. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  644. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  645. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  646. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  647. }
  648. if item.MedChrgitmType == "06" { //手术费
  649. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  650. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  651. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  652. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  653. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  654. }
  655. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  656. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  657. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  658. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  659. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  660. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  661. }
  662. if item.MedChrgitmType == "09" { //西药费
  663. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  664. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  665. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  666. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  667. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  668. }
  669. if item.MedChrgitmType == "11" { //中成费
  670. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  671. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  672. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  673. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  674. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  675. }
  676. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  677. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  678. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  679. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  680. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  681. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  682. }
  683. }
  684. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  685. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  686. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  687. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  688. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  689. var doctor_name string
  690. if roles.ID == 0 {
  691. doctor_name = "管理员"
  692. } else {
  693. doctor_name = roles.UserName
  694. }
  695. yiliao_leibie := ""
  696. switch order.MedType {
  697. case "11":
  698. yiliao_leibie = "普通门诊"
  699. break
  700. case "12":
  701. yiliao_leibie = "门诊挂号"
  702. break
  703. case "13":
  704. yiliao_leibie = "急诊"
  705. break
  706. case "14":
  707. yiliao_leibie = "门诊特殊病"
  708. break
  709. case "15":
  710. yiliao_leibie = "门诊统筹"
  711. break
  712. case "16":
  713. yiliao_leibie = "门诊慢性病"
  714. break
  715. case "21":
  716. yiliao_leibie = "普通住院"
  717. break
  718. }
  719. c.ServeSuccessJSON(map[string]interface{}{
  720. "diagnosis": name,
  721. "order_infos": orderInfos,
  722. "number": order.MdtrtId,
  723. "date": order.SettleAccountsDate,
  724. "charge_admin": charge_admin,
  725. "printor_admin": printor_admin,
  726. "info": order,
  727. "order": order,
  728. "bedCostTotal": bedCostTotal,
  729. "bedCostSelfTotal": bedCostSelfTotal,
  730. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  731. "bedSelfTotal": bedSelfTotal,
  732. "bedInscpTotal": bedInscpTotal,
  733. "operationCostTotal": operationCostTotal,
  734. "operationCostSelfTotal": operationCostSelfTotal,
  735. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  736. "operationSelfTotal": operationSelfTotal,
  737. "operationInscpTotal": operationInscpTotal,
  738. "otherCostTotal": otherCostTotal,
  739. "otherCostSelfTotal": otherCostSelfTotal,
  740. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  741. "otherSelfTotal": otherSelfTotal,
  742. "otherInscpTotal": otherInscpTotal,
  743. "materialCostTotal": materialCostTotal,
  744. "materialCostSelfTotal": materialCostSelfTotal,
  745. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  746. "materialSelfTotal": materialSelfTotal,
  747. "materialInscpTotal": materialInscpTotal,
  748. "westernMedicineCostTotal": westernMedicineCostTotal,
  749. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  750. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  751. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  752. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  753. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  754. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  755. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  756. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  757. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  758. "checkCostTotal": checkCostTotal,
  759. "checkCostSelfTotal": checkCostSelfTotal,
  760. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  761. "checkSelfTotal": checkSelfTotal,
  762. "checkInscpTotal": checkInscpTotal,
  763. "laboratoryCostTotal": laboratoryCostTotal,
  764. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  765. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  766. "laboratorySelfTotal": laboratorySelfTotal,
  767. "laboratoryInscpTotal": laboratoryInscpTotal,
  768. "treatCostTotal": treatCostTotal,
  769. "treatCostSelfTotal": treatCostSelfTotal,
  770. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  771. "treatSelfTotal": treatSelfTotal,
  772. "treatInscpTotal": treatInscpTotal,
  773. "doctor_info": doctor_info,
  774. "doctor_name": doctor_name,
  775. "health_card_no": order.PsnNo,
  776. "yiliao_leibie": yiliao_leibie,
  777. "patient": patient,
  778. "org_name": miConfig.OrgName,
  779. "org_code": miConfig.Code,
  780. "order_number": order.Number,
  781. "his_hospital": his_hospital,
  782. "dia_config": dia_config,
  783. })
  784. }
  785. func (c *PublicApiController) GetBaiLinExportData() {
  786. data := service.GetBaiLinOrderData()
  787. fmt.Println(len(data))
  788. var new_data []*models.NewCustomHisOrder
  789. for _, item := range data {
  790. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  791. new_data = append(new_data, item)
  792. }
  793. }
  794. fmt.Println(len(new_data))
  795. c.ServeSuccessJSON(map[string]interface{}{
  796. "list": new_data,
  797. })
  798. }
  799. func (c *HisApiController) GetHisUnChargePatientList() {
  800. record_date := c.GetString("record_date")
  801. sch_type, _ := c.GetInt64("sch_type")
  802. timeLayout := "2006-01-02"
  803. loc, _ := time.LoadLocation("Local")
  804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  805. if err != nil {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  807. return
  808. }
  809. recordDateTime := theTime.Unix()
  810. adminInfo := c.GetAdminUserInfo()
  811. var tempPatients []*service.NewTempPatients
  812. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  813. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  814. var patients []*service.NewTempPatients
  815. var patients_two []*service.NewTempPatients
  816. for _, item := range tempPatients {
  817. //过滤掉没挂号的和没开处方的
  818. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  819. patients = append(patients, item)
  820. }
  821. //过滤掉没挂号的
  822. if len(item.HisPatient) > 0 {
  823. patients_two = append(patients_two, item)
  824. }
  825. }
  826. c.ServeSuccessJSON(map[string]interface{}{
  827. "list": patients,
  828. "list_two": patients_two,
  829. })
  830. }
  831. func (c *HisApiController) GetPrivateExpensesOrder() {
  832. //id, _ := c.GetInt64("id")
  833. //record_time := c.GetString("record_time")
  834. order_id, _ := c.GetInt64("order_id")
  835. admin_user_id, _ := c.GetInt64("admin_user_id")
  836. //timeLayout := "2006-01-02"
  837. //loc, _ := time.LoadLocation("Local")
  838. //
  839. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  840. //if err != nil {
  841. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  842. // return
  843. //}
  844. //recordDateTime := theTime.Unix()
  845. adminUser := c.GetAdminUserInfo()
  846. order, _ := service.GetHisOrderByID(order_id)
  847. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  848. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  849. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  850. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  851. //var config []*models.HisXtDiagnoseConfig
  852. var name string
  853. if order.PType == 1 {
  854. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  855. for _, item := range diagnosis_ids {
  856. id, _ := strconv.ParseInt(item, 10, 64)
  857. diagnosisConfig, _ := service.FindDiagnoseById(id)
  858. if len(name) == 0 {
  859. name = diagnosisConfig.ClassName
  860. } else {
  861. name = name + "," + diagnosisConfig.ClassName
  862. }
  863. }
  864. } else {
  865. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  866. for _, item := range diagnosis_ids {
  867. id, _ := strconv.ParseInt(item, 10, 64)
  868. diagnosisConfig, _ := service.FindDiagnoseById(id)
  869. if len(name) == 0 {
  870. name = diagnosisConfig.ClassName
  871. } else {
  872. name = name + "," + diagnosisConfig.ClassName
  873. }
  874. }
  875. }
  876. var bedCostTotal float64 = 0 //床位总费
  877. //var bedCostSelfTotal float64 = 0 //床位自费
  878. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  879. var operationCostTotal float64 = 0 //手术费
  880. //var operationCostSelfTotal float64 = 0 //手术费
  881. var operationCostPartSelfTotal float64 = 0 //手术费
  882. var otherCostTotal float64 = 0 //其他费用
  883. //var otherCostSelfTotal float64 = 0 //其他费用
  884. var otherCostPartSelfTotal float64 = 0 //其他费用
  885. var materialCostTotal float64 = 0 //材料费
  886. //var materialCostSelfTotal float64 = 0 //材料费
  887. var materialCostPartSelfTotal float64 = 0 //材料费
  888. var westernMedicineCostTotal float64 = 0 //西药费
  889. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  890. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  891. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  892. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  893. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  894. var checkCostTotal float64 = 0 //检查费
  895. //var checkCostSelfTotal float64 = 0 //检查费
  896. var checkCostPartSelfTotal float64 = 0 //检查费
  897. var laboratoryCostTotal float64 = 0 //化验费
  898. //var laboratoryCostSelfTotal float64 = 0 //化验费
  899. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  900. var treatCostTotal float64 = 0 //治疗费用
  901. //var treatCostSelfTotal float64 = 0 //治疗费用
  902. var treatCostPartSelfTotal float64 = 0 //治疗费用
  903. var zhenChaCostTotal float64 = 0 //其他费用
  904. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  905. decimal.DivisionPrecision = 2
  906. for _, item := range orderInfos {
  907. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  908. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  909. item.MedChrgitmType = "09"
  910. }
  911. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  912. if item.HisPrescriptionProject.Type == 2 {
  913. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  914. fmt.Println("CostClassify")
  915. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  916. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  917. case 0:
  918. item.MedChrgitmType = "0"
  919. break
  920. case 1:
  921. item.MedChrgitmType = "14"
  922. break
  923. case 2:
  924. item.MedChrgitmType = "05"
  925. break
  926. case 3:
  927. item.MedChrgitmType = "03"
  928. break
  929. case 4:
  930. item.MedChrgitmType = "03"
  931. break
  932. case 5:
  933. item.MedChrgitmType = "08"
  934. break
  935. case 6:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 7:
  939. item.MedChrgitmType = "14"
  940. break
  941. case 8:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 9:
  945. item.MedChrgitmType = "14"
  946. break
  947. case 10:
  948. item.MedChrgitmType = "14"
  949. break
  950. case 11:
  951. item.MedChrgitmType = "06"
  952. break
  953. case 12:
  954. item.MedChrgitmType = "12"
  955. break
  956. case 13:
  957. item.MedChrgitmType = "01"
  958. break
  959. case 14:
  960. item.MedChrgitmType = "04"
  961. break
  962. case 15:
  963. item.MedChrgitmType = "14"
  964. break
  965. }
  966. } else {
  967. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  968. case 1:
  969. item.MedChrgitmType = "14"
  970. break
  971. case 2:
  972. item.MedChrgitmType = "05"
  973. break
  974. case 3:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 4:
  978. item.MedChrgitmType = "14"
  979. break
  980. case 5:
  981. item.MedChrgitmType = "08"
  982. break
  983. case 6:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 7:
  987. item.MedChrgitmType = "14"
  988. break
  989. case 8:
  990. item.MedChrgitmType = "03"
  991. break
  992. case 9:
  993. item.MedChrgitmType = "14"
  994. break
  995. default:
  996. item.MedChrgitmType = "14"
  997. break
  998. }
  999. }
  1000. } else if item.HisPrescriptionProject.Type == 3 {
  1001. item.MedChrgitmType = "08"
  1002. }
  1003. }
  1004. }
  1005. order.PsnCashPay = order.MedfeeSumamt
  1006. for _, item := range orderInfos {
  1007. if item.MedChrgitmType == "01" { //床位费
  1008. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1009. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1010. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1011. }
  1012. if item.MedChrgitmType == "02" { //诊察费
  1013. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1014. //zhenChaCostSelfTotal = zhenChaCostTotal
  1015. }
  1016. if item.MedChrgitmType == "03" { //检查费
  1017. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1018. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1019. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1020. }
  1021. if item.MedChrgitmType == "02" { //检查费
  1022. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1023. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1024. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1025. }
  1026. if item.MedChrgitmType == "04" { //化验费
  1027. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1028. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1029. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1030. }
  1031. if item.MedChrgitmType == "05" { //治疗费
  1032. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "06" { //手术费
  1037. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1042. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "09" { //西药费
  1047. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "11" { //中成费
  1052. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1057. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. }
  1062. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1063. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1064. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1065. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1066. c.ServeSuccessJSON(map[string]interface{}{
  1067. "patient": patient,
  1068. "order_infos": orderInfos,
  1069. "diagnosis": name,
  1070. "bedCostTotal": bedCostTotal,
  1071. "bedCostSelfTotal": bedCostTotal,
  1072. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1073. "operationCostTotal": operationCostTotal,
  1074. "operationCostSelfTotal": operationCostTotal,
  1075. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1076. "otherCostTotal": otherCostTotal,
  1077. "otherCostSelfTotal": otherCostTotal,
  1078. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1079. "materialCostTotal": materialCostTotal,
  1080. "materialCostSelfTotal": materialCostTotal,
  1081. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1082. "westernMedicineCostTotal": westernMedicineCostTotal,
  1083. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1084. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1085. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1086. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1087. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1088. "checkCostTotal": checkCostTotal,
  1089. "checkCostSelfTotal": checkCostTotal,
  1090. "zhenChaCostTotal": zhenChaCostTotal,
  1091. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1092. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1093. "laboratoryCostTotal": laboratoryCostTotal,
  1094. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1095. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1096. "treatCostTotal": treatCostTotal,
  1097. "treatCostSelfTotal": treatCostTotal,
  1098. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1099. "charge_admin": charge_admin,
  1100. "printor_admin": printor_admin,
  1101. "org_name": org.OrgName,
  1102. "org_code": miConfig.Code,
  1103. "name": patient.Name,
  1104. "number": order.MdtrtId,
  1105. "date": order.SettleAccountsDate,
  1106. "info": order,
  1107. "his_hospital": his_hospital,
  1108. "his": his,
  1109. })
  1110. }
  1111. func (c *HisApiController) RefudDetail() {
  1112. order_id, _ := c.GetInt64("order_id")
  1113. order, _ := service.GetHisOrderByID(order_id)
  1114. adminUser := c.GetAdminUserInfo()
  1115. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1116. c.ServeSuccessJSON(map[string]interface{}{
  1117. "msg": "撤销成功",
  1118. })
  1119. }
  1120. func (c *HisApiController) Sscard() {
  1121. //r := CardInit()
  1122. //if r == 0 {
  1123. // GetBaseInfo()
  1124. //}
  1125. //c.ServeSuccessJSON(map[string]interface{}{
  1126. // "list": "11",
  1127. //})
  1128. }
  1129. func GetBaseInfo() error {
  1130. //handle := syscall.MustLoadDLL("SSCard.dll")
  1131. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1132. //
  1133. //str := make([]byte, 256)
  1134. //str1 := make([]byte, 256)
  1135. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1136. //if ferr != nil {
  1137. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1138. // return ferr
  1139. //}
  1140. //
  1141. //fmt.Println(string(str))
  1142. //
  1143. //fmt.Println(r)
  1144. return nil
  1145. }
  1146. func CardInit() int {
  1147. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1148. //add := DllTestDef.MustFindProc("Init")
  1149. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1150. //if err != nil {
  1151. // fmt.Println("SSCard的运算结果为:", ret)
  1152. //}
  1153. //result := int(ret)
  1154. return 0
  1155. }
  1156. func IntPtr(n int) uintptr {
  1157. return uintptr(n)
  1158. }
  1159. func StrPtr(s string) uintptr {
  1160. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1161. }
  1162. func (c *HisApiController) GetHisPatientList() {
  1163. //types, _ := c.GetInt64("type", 0)
  1164. record_date := c.GetString("record_date")
  1165. sch_type, _ := c.GetInt64("sch_type")
  1166. timeLayout := "2006-01-02"
  1167. loc, _ := time.LoadLocation("Local")
  1168. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1169. if err != nil {
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. recordDateTime := theTime.Unix()
  1174. adminInfo := c.GetAdminUserInfo()
  1175. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1176. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1177. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1178. //获取当前用户的信息
  1179. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1180. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1181. //获取所有科室信息
  1182. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1183. c.ServeSuccessJSON(map[string]interface{}{
  1184. "list": patients,
  1185. "list_two": patients_two,
  1186. "info": adminUserInfo,
  1187. "doctors": doctors,
  1188. "department": department,
  1189. })
  1190. }
  1191. type CustomTemplate struct {
  1192. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1193. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1194. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1195. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1196. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1197. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1198. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1199. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1200. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1201. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1202. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1203. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1204. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1205. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1206. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1207. }
  1208. func (c *HisApiController) GetHisPatientInfo() {
  1209. patient_id, _ := c.GetInt64("patient_id")
  1210. his_patient_id, _ := c.GetInt64("his_patient_id")
  1211. record_date := c.GetString("record_date")
  1212. number := c.GetString("number")
  1213. //start_time := c.GetString("start_time")
  1214. //end_time := c.GetString("end_time")
  1215. p_type, _ := c.GetInt64("p_type")
  1216. timeLayout := "2006-01-02"
  1217. loc, _ := time.LoadLocation("Local")
  1218. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1219. if err != nil {
  1220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1221. return
  1222. }
  1223. recordDateTime := theTime.Unix()
  1224. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1225. //if err != nil {
  1226. //
  1227. //}
  1228. //startRecordDateTime := startTime.Unix()
  1229. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1230. //if err != nil {
  1231. //
  1232. //}
  1233. //endRecordDateTime := endTime.Unix()
  1234. admin := c.GetAdminUserInfo()
  1235. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1236. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1237. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1238. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1239. var prescriptions []*models.HisPrescription
  1240. var last_prescriptions []*models.HisPrescription
  1241. var sch_prescriptions []CustomTemplate
  1242. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1243. if p_type == 1 { //住院
  1244. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1245. for _, item := range prescriptions {
  1246. for _, subItem := range item.HisDoctorAdviceInfo {
  1247. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1248. if info.RetailPrice > 0 {
  1249. subItem.Drug.MinPrice = info.RetailPrice
  1250. }
  1251. }
  1252. }
  1253. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1254. } else { //门诊
  1255. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1256. for _, item := range prescriptions {
  1257. for _, subItem := range item.HisDoctorAdviceInfo {
  1258. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1259. if info.RetailPrice > 0 {
  1260. subItem.Drug.MinPrice = info.RetailPrice
  1261. }
  1262. }
  1263. }
  1264. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1265. }
  1266. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1267. if sch.ID > 0 {
  1268. var week string
  1269. t := time.Now()
  1270. switch t.Weekday().String() {
  1271. case "Monday":
  1272. week = "周一"
  1273. break
  1274. case "Tuesday":
  1275. week = "周二"
  1276. break
  1277. case "Wednesday":
  1278. week = "周三"
  1279. break
  1280. case "Thursday":
  1281. week = "周四"
  1282. break
  1283. case "Friday":
  1284. week = "周五"
  1285. break
  1286. case "Saturday":
  1287. week = "周六"
  1288. break
  1289. case "Sunday":
  1290. week = "周日"
  1291. break
  1292. }
  1293. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1294. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1295. //根据推送频率组装新的数组
  1296. for _, item := range temp_sch_prescriptions {
  1297. var cus CustomTemplate
  1298. cus.ID = item.ID
  1299. cus.UserOrgId = item.UserOrgId
  1300. cus.PatientId = item.PatientId
  1301. cus.MedType = item.MedType
  1302. cus.RecordDate = item.RecordDate
  1303. cus.Type = item.Type
  1304. cus.PType = item.PType
  1305. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1306. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1307. if subItem.FrequencyType == 1 { //每次必推
  1308. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1309. }
  1310. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1311. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1312. }
  1313. if subItem.FrequencyType == 2 { //按照天数频率
  1314. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1315. now := p.Unix()
  1316. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1317. dayStr2 := "-" + dayStr
  1318. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1319. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1320. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1321. if len(advices) == 0 {
  1322. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1323. }
  1324. }
  1325. }
  1326. }
  1327. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1328. if subItem.Type == 2 {
  1329. if subItem.XtHisProject.MedicalStatus != 1 {
  1330. if subItem.FrequencyType == 1 {
  1331. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1332. }
  1333. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1334. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1335. }
  1336. if subItem.FrequencyType == 2 {
  1337. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1338. now := p.Unix()
  1339. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1340. dayStr2 := "-" + dayStr
  1341. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1342. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1343. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1344. if len(projects) == 0 {
  1345. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1346. }
  1347. }
  1348. }
  1349. } else if subItem.Type == 3 {
  1350. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1351. if subItem.FrequencyType == 1 {
  1352. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1353. }
  1354. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1355. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1356. }
  1357. if subItem.FrequencyType == 2 {
  1358. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1359. now := p.Unix()
  1360. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1361. dayStr2 := "-" + dayStr
  1362. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1363. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1364. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1365. if len(projects) == 0 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. }
  1369. }
  1370. }
  1371. }
  1372. sch_prescriptions = append(sch_prescriptions, cus)
  1373. }
  1374. for _, item := range sch_prescriptions {
  1375. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1376. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1377. }
  1378. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1379. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1380. }
  1381. }
  1382. }
  1383. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1384. if config.ID > 0 && config.IsOpen == 1 {
  1385. for _, item := range sch_prescriptions {
  1386. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1387. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1388. if info.RetailPrice > 0 {
  1389. subItem.Drug.MinPrice = info.RetailPrice
  1390. }
  1391. }
  1392. }
  1393. }
  1394. if config.ID > 0 && config.IsOpen == 1 {
  1395. for _, item := range sch_prescriptions {
  1396. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1397. if subItem.Type == 3 {
  1398. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1399. if info.Price > 0 {
  1400. subItem.GoodInfo.PackingPrice = info.Price
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1407. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1408. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1409. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1410. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1411. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1412. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1413. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1414. //获取所有科室信息
  1415. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1416. c.ServeSuccessJSON(map[string]interface{}{
  1417. "his_info": his_patient_info,
  1418. "xt_info": xt_patient_info,
  1419. "prescription": prescriptions,
  1420. "case_history": case_history,
  1421. "info": patientPrescriptionInfo,
  1422. //"month_prescriptions": monthPrescriptions,
  1423. "order": order,
  1424. "doctors": doctors,
  1425. "department": department,
  1426. "sch_prescriptions": sch_prescriptions,
  1427. "last_prescriptions": last_prescriptions,
  1428. "schedule": sch,
  1429. "count": count,
  1430. "drugStockConfig": drugStockConfig,
  1431. "last_info": lastPatientPrescriptionInfo,
  1432. })
  1433. return
  1434. }
  1435. func (c *HisApiController) GetHisPrescriptionConfig() {
  1436. adminInfo := c.GetAdminUserInfo()
  1437. //获取医嘱模版
  1438. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1439. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1440. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1441. //获取所有基础药
  1442. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1443. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1444. if config.ID > 0 && config.IsOpen == 1 {
  1445. for _, item := range drugs {
  1446. var index = 0
  1447. for _, subItem := range item.OtherDrugWarehouseInfo {
  1448. if index == 0 {
  1449. index = index + 1
  1450. if subItem.RetailPrice > 0 {
  1451. item.MinPrice = subItem.RetailPrice
  1452. }
  1453. }
  1454. }
  1455. }
  1456. }
  1457. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1458. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1459. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1460. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1463. //获取诊断信息
  1464. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1465. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1466. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1467. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1468. //获取是否开启保存耗材出库的开关
  1469. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1470. c.ServeSuccessJSON(map[string]interface{}{
  1471. "drugs": drugs,
  1472. "advices_template": advices,
  1473. "drugways": drugways,
  1474. "efs": efs,
  1475. "doctors": doctors,
  1476. "department": department,
  1477. "sick": sick,
  1478. "additions": additions,
  1479. "diagnose": diagnose,
  1480. "manufacturers": manufacturers,
  1481. "goodOutOpen": goodOutOpen,
  1482. "patientDiagnose": patientDiagnose,
  1483. })
  1484. }
  1485. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1486. //获取所有基础药
  1487. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1488. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1489. if config.ID > 0 && config.IsOpen == 1 {
  1490. for _, item := range drugs {
  1491. var index = 0
  1492. for _, subItem := range item.OtherDrugWarehouseInfo {
  1493. if index == 0 {
  1494. index = index + 1
  1495. if subItem.RetailPrice > 0 {
  1496. item.MinPrice = subItem.RetailPrice
  1497. }
  1498. }
  1499. }
  1500. }
  1501. }
  1502. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1503. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1504. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1505. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1506. //获取所有科室信息
  1507. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1508. //获取诊断信息
  1509. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1510. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1511. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1512. //获取是否开启保存耗材出库的开关
  1513. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1514. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1515. c.ServeSuccessJSON(map[string]interface{}{
  1516. "drugs": drugs,
  1517. "advices_template": advices,
  1518. "drugways": drugways,
  1519. "efs": efs,
  1520. "doctors": doctors,
  1521. "department": department,
  1522. "sick": sick,
  1523. "additions": additions,
  1524. "diagnose": diagnose,
  1525. "manufacturers": manufacturers,
  1526. "goodOutOpen": goodOutOpen,
  1527. "patientDiagnose": patientDiagnose,
  1528. })
  1529. }
  1530. }
  1531. func (c *HisApiController) CreateHisPrescription() {
  1532. record_date := c.GetString("record_date")
  1533. patient_id, _ := c.GetInt64("patient_id")
  1534. reg_type, _ := c.GetInt64("reg_type")
  1535. diagnose := c.GetString("diagnose")
  1536. sick_type, _ := c.GetInt64("sick_type")
  1537. sick_history := c.GetString("sick_history")
  1538. doctor_id, _ := c.GetInt64("doctor", 0)
  1539. department, _ := c.GetInt64("department", 0)
  1540. his_patient_id, _ := c.GetInt64("his_patient_id")
  1541. p_type, _ := c.GetInt64("p_type")
  1542. patient_diagnose := c.GetString("patient_diagnose")
  1543. dataBody := make(map[string]interface{}, 0)
  1544. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1545. if err != nil {
  1546. utils.ErrorLog(err.Error())
  1547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1548. return
  1549. }
  1550. timeLayout := "2006-01-02"
  1551. loc, _ := time.LoadLocation("Local")
  1552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1553. if err != nil {
  1554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1555. return
  1556. }
  1557. adminInfo := c.GetAdminUserInfo()
  1558. recordDateTime := theTime.Unix()
  1559. //查询默认出库仓库库存
  1560. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1561. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1562. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1563. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1564. if len(lists) == 1 {
  1565. his_patient_id = lists[0].ID
  1566. }
  1567. }
  1568. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1569. //保存处方出库
  1570. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1571. //自动出库
  1572. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1573. //耗材保存处方出库
  1574. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1575. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1576. //已发药和已收费限制逻辑
  1577. isMidicine := false
  1578. isCharge := false
  1579. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1580. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1581. if len(prescriptions) > 0 {
  1582. for _, item := range prescriptions {
  1583. items := item.(map[string]interface{})
  1584. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1585. utils.ErrorLog("id")
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1587. return
  1588. }
  1589. id := int64(items["id"].(float64))
  1590. if id > 0 {
  1591. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1592. if err != nil {
  1593. if new_prescription.OrderStatus == 4 {
  1594. isCharge = true
  1595. }
  1596. }
  1597. }
  1598. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1599. advices := items["advices"].([]interface{})
  1600. if len(advices) > 0 {
  1601. for _, advice := range advices {
  1602. var adviceId int64
  1603. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1604. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1605. }
  1606. if adviceId > 0 {
  1607. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1608. if err == nil {
  1609. if his_advice_info.IsMedicine == 1 {
  1610. isMidicine = true
  1611. }
  1612. }
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. }
  1620. if isMidicine == true {
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1622. return
  1623. }
  1624. if isCharge == true {
  1625. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1626. return
  1627. }
  1628. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1629. //药品发药出库
  1630. if pharmacyConfig.IsOpen == 1 {
  1631. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1632. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1633. if len(prescriptions) > 0 {
  1634. for _, item := range prescriptions {
  1635. items := item.(map[string]interface{})
  1636. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1637. advices := items["advices"].([]interface{})
  1638. if len(advices) > 0 {
  1639. for _, advice := range advices {
  1640. var drug_id int64
  1641. var prescribing_number float64
  1642. var prescribingNumberUnit string
  1643. var adviceId int64
  1644. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1645. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1646. }
  1647. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1648. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1649. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1650. }
  1651. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1652. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1653. }
  1654. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1655. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1656. }
  1657. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1658. if drug.ID == 0 {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1660. return
  1661. }
  1662. //查询药品的所有库存
  1663. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1664. var total_count int64
  1665. for _, it := range list {
  1666. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1667. }
  1668. totals := strconv.FormatInt(total_count, 10)
  1669. //查询该药品是否存在开药记录
  1670. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1671. fmt.Println("wooooooooooooo", advicelist.ID)
  1672. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1673. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1674. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1675. //新增处方
  1676. if advicelist.ID == 0 {
  1677. all_count, _ := strconv.ParseFloat(totals, 64)
  1678. if prescribingNumberUnit == drug.MinUnit {
  1679. fmt.Println("prescribing_number", prescribing_number)
  1680. fmt.Println("all_count", all_count)
  1681. if drug.IsUse != 1 {
  1682. if drug.IsProject == 0 || drug.IsProject == 2 {
  1683. if all_count == 0 {
  1684. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1685. return
  1686. }
  1687. if prescribing_number > all_count {
  1688. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1689. return
  1690. }
  1691. }
  1692. }
  1693. }
  1694. if prescribingNumberUnit == drug.MaxUnit {
  1695. num := prescribing_number * float64(drug.MinNumber)
  1696. if drug.IsUse != 1 {
  1697. if drug.IsProject == 0 || drug.IsProject == 2 {
  1698. if all_count == 0 {
  1699. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1700. return
  1701. }
  1702. if num > all_count {
  1703. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1704. return
  1705. }
  1706. }
  1707. }
  1708. }
  1709. }
  1710. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1711. if drugOutConfig.IsOpen != 1 {
  1712. //修改处方
  1713. for _, advice := range advices {
  1714. var drug_id int64
  1715. var prescribing_number float64
  1716. var prescribingNumberUnit string
  1717. var prescribingNumber string
  1718. var adviceId int64
  1719. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1720. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1721. }
  1722. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1723. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1724. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1725. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1726. }
  1727. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1728. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1729. }
  1730. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1731. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1732. }
  1733. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1734. if drug.ID == 0 {
  1735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1736. return
  1737. }
  1738. //查询药品的所有库存
  1739. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1740. var total_count int64
  1741. for _, it := range list {
  1742. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1743. }
  1744. totals := strconv.FormatInt(total_count, 10)
  1745. //查询该药品是否存在开药记录
  1746. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1747. //新增处方
  1748. if advicelist.ID == 0 {
  1749. all_count, _ := strconv.ParseFloat(totals, 64)
  1750. if prescribingNumberUnit == drug.MinUnit {
  1751. if drug.IsUse != 1 {
  1752. if drug.IsProject == 0 || drug.IsProject == 2 {
  1753. if all_count == 0 {
  1754. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1755. return
  1756. }
  1757. if prescribing_number > all_count {
  1758. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1759. return
  1760. }
  1761. }
  1762. }
  1763. } else {
  1764. if prescribingNumberUnit == drug.MaxUnit {
  1765. num := prescribing_number * float64(drug.MinNumber)
  1766. if drug.IsUse != 1 {
  1767. if drug.IsProject == 0 || drug.IsProject == 2 {
  1768. if all_count == 0 {
  1769. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1770. return
  1771. }
  1772. if num > all_count {
  1773. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1774. return
  1775. }
  1776. }
  1777. }
  1778. }
  1779. }
  1780. }
  1781. //修改处方
  1782. if advicelist.ID > 0 {
  1783. var device_number int64
  1784. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1785. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1786. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1787. device_number = prescribingNumberInt * drug.MinNumber
  1788. }
  1789. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1790. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1791. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1792. device_number = prescribingNumberInt
  1793. }
  1794. var number_count int64
  1795. if prescribingNumberUnit == drug.MaxUnit {
  1796. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1797. number_count = prescribingNumberInt * drug.MinNumber
  1798. }
  1799. if prescribingNumberUnit == drug.MinUnit {
  1800. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1801. number_count = prescribingNumberInt
  1802. }
  1803. //如果修改的数量大于之前修改的数量
  1804. if (number_count - device_number) > 0 {
  1805. //如果修改的差数量 大于库存数量
  1806. if drug.IsUse != 1 {
  1807. if (number_count - device_number) > total_count {
  1808. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1809. return
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. }
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. }
  1822. }
  1823. //已发药和已收费限制逻辑
  1824. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1825. //校验库存总量
  1826. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1827. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1828. if len(prescriptions) > 0 {
  1829. for _, item := range prescriptions {
  1830. items := item.(map[string]interface{})
  1831. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1832. advices := items["advices"].([]interface{})
  1833. if len(advices) > 0 {
  1834. for _, advice := range advices {
  1835. var drug_id int64
  1836. var prescribing_number float64
  1837. var prescribingNumberUnit string
  1838. var adviceId int64
  1839. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1840. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1841. }
  1842. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1843. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1844. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1845. }
  1846. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1847. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1848. }
  1849. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1850. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1851. }
  1852. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1853. if drug.ID == 0 {
  1854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1855. return
  1856. }
  1857. //查询药品的所有库存
  1858. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1859. var total_count int64
  1860. for _, it := range list {
  1861. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1862. }
  1863. totals := strconv.FormatInt(total_count, 10)
  1864. //查询该药品是否存在开药记录
  1865. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1866. //查询最新批次库存
  1867. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1868. var batch_number_count int64
  1869. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1870. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1871. //新增处方
  1872. if advicelist.ID == 0 {
  1873. all_count, _ := strconv.ParseFloat(totals, 64)
  1874. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1875. if prescribingNumberUnit == drug.MinUnit {
  1876. if drug.IsUse != 1 {
  1877. if drug.IsProject == 0 || drug.IsProject == 2 {
  1878. if all_count == 0 {
  1879. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1880. return
  1881. }
  1882. if prescribing_number > all_count {
  1883. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1884. return
  1885. }
  1886. }
  1887. if adminInfo.CurrentOrgId == 10215 {
  1888. if prescribing_number > batch_number_all_count {
  1889. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1890. return
  1891. }
  1892. }
  1893. }
  1894. }
  1895. if prescribingNumberUnit == drug.MaxUnit {
  1896. num := prescribing_number * float64(drug.MinNumber)
  1897. if drug.IsUse != 1 {
  1898. if drug.IsProject == 0 || drug.IsProject == 2 {
  1899. if all_count == 0 {
  1900. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1901. return
  1902. }
  1903. if num > all_count {
  1904. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1905. return
  1906. }
  1907. }
  1908. if adminInfo.CurrentOrgId == 10215 {
  1909. if num > batch_number_all_count {
  1910. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1911. return
  1912. }
  1913. }
  1914. }
  1915. }
  1916. }
  1917. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1918. if drugOutConfig.IsOpen != 1 {
  1919. //修改处方
  1920. for _, advice := range advices {
  1921. var drug_id int64
  1922. var prescribing_number float64
  1923. var prescribingNumberUnit string
  1924. var prescribingNumber string
  1925. var adviceId int64
  1926. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1927. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1928. }
  1929. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1930. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1931. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1932. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1933. }
  1934. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1935. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1936. }
  1937. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1938. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1939. }
  1940. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1941. if drug.ID == 0 {
  1942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1943. return
  1944. }
  1945. //查询药品的所有库存
  1946. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1947. var total_count int64
  1948. for _, it := range list {
  1949. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1950. }
  1951. totals := strconv.FormatInt(total_count, 10)
  1952. //查询该药品是否存在开药记录
  1953. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1954. //新增处方
  1955. if advicelist.ID == 0 {
  1956. //查询最新批次库存
  1957. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1958. var batch_number_count int64
  1959. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1960. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1961. all_count, _ := strconv.ParseFloat(totals, 64)
  1962. if prescribingNumberUnit == drug.MinUnit {
  1963. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1964. if drug.IsUse != 1 {
  1965. if drug.IsProject == 0 || drug.IsProject == 2 {
  1966. if all_count == 0 {
  1967. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1968. return
  1969. }
  1970. if prescribing_number > all_count {
  1971. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1972. return
  1973. }
  1974. }
  1975. if adminInfo.CurrentOrgId == 10215 {
  1976. if prescribing_number > batch_number_all_count {
  1977. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1978. return
  1979. }
  1980. }
  1981. }
  1982. } else {
  1983. if prescribingNumberUnit == drug.MaxUnit {
  1984. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1985. num := prescribing_number * float64(drug.MinNumber)
  1986. if drug.IsUse != 1 {
  1987. if drug.IsProject == 0 || drug.IsProject == 2 {
  1988. if all_count == 0 {
  1989. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1990. return
  1991. }
  1992. if num > all_count {
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1994. return
  1995. }
  1996. }
  1997. if adminInfo.CurrentOrgId == 10215 {
  1998. if prescribing_number > batch_number_all_count {
  1999. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2000. return
  2001. }
  2002. }
  2003. }
  2004. }
  2005. }
  2006. }
  2007. //修改处方
  2008. if advicelist.ID > 0 {
  2009. //查询最新批次库存
  2010. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2011. var batch_number_count int64
  2012. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2013. var device_number int64
  2014. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2015. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2016. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2017. device_number = prescribingNumberInt * drug.MinNumber
  2018. }
  2019. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2020. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2021. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2022. device_number = prescribingNumberInt
  2023. }
  2024. var number_count int64
  2025. if prescribingNumberUnit == drug.MaxUnit {
  2026. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2027. number_count = prescribingNumberInt * drug.MinNumber
  2028. }
  2029. if prescribingNumberUnit == drug.MinUnit {
  2030. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2031. number_count = prescribingNumberInt
  2032. }
  2033. //如果修改的数量大于之前修改的数量
  2034. if (number_count - device_number) > 0 {
  2035. //如果修改的差数量 大于库存数量
  2036. if drug.IsUse != 1 {
  2037. if drug.IsProject == 0 || drug.IsProject == 2 {
  2038. if total_count == 0 {
  2039. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2040. return
  2041. }
  2042. if (number_count - device_number) > total_count {
  2043. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2044. return
  2045. }
  2046. if (number_count - device_number) > batch_number_count {
  2047. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2048. return
  2049. }
  2050. }
  2051. if adminInfo.CurrentOrgId == 10215 {
  2052. // 查询该药品最后一次出库记录
  2053. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2054. var out_count int64
  2055. var in_count int64
  2056. var stock_max_number int64
  2057. var stock_min_number int64
  2058. for _, it := range outInfo {
  2059. if it.CountUnit == drug.MaxUnit {
  2060. it.Count = it.Count * drug.MinNumber
  2061. }
  2062. out_count += it.Count
  2063. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2064. stock_max_number = warehouseInfoList.StockMaxNumber
  2065. stock_min_number = warehouseInfoList.StockMinNumber
  2066. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2067. }
  2068. if out_count > 0 {
  2069. if (number_count - device_number) > in_count {
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2071. return
  2072. }
  2073. }
  2074. // 未出库
  2075. if out_count == 0 {
  2076. var sum_in_count int64
  2077. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2078. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2079. fmt.Println("sum_in_count", sum_in_count)
  2080. //如果修改的数量大于有库存的第一个批次
  2081. if number_count > sum_in_count {
  2082. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2083. return
  2084. }
  2085. }
  2086. }
  2087. }
  2088. }
  2089. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2090. if pharmacyConfig.IsOpen != 1 {
  2091. if device_number != number_count {
  2092. // 查询该药品最后一次出库记录
  2093. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2094. //回退库存
  2095. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2096. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2097. }
  2098. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2099. var stock_max_number int64
  2100. var stock_min_number int64
  2101. if number_count >= drug.MinNumber {
  2102. stock_max_number = device_number / drug.MinNumber
  2103. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2104. stock_min_number = device_number % drug.MinNumber
  2105. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2106. } else {
  2107. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2108. }
  2109. }
  2110. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2111. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2112. }
  2113. //删除记录
  2114. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2115. //查询默认仓库剩余多少库存
  2116. var sum_count int64
  2117. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2118. for _, its := range stockInfo {
  2119. if its.MaxUnit == drug.MaxUnit {
  2120. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2121. }
  2122. sum_count += its.StockMaxNumber + its.StockMinNumber
  2123. }
  2124. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. //保存处方开药
  2131. if drugOutConfig.IsOpen == 1 {
  2132. //修改处方
  2133. for _, advice := range advices {
  2134. var drug_id int64
  2135. var prescribing_number float64
  2136. var prescribingNumberUnit string
  2137. var prescribingNumber string
  2138. var adviceId int64
  2139. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2140. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2141. }
  2142. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2143. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2144. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2145. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2146. }
  2147. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2148. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2149. }
  2150. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2151. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2152. }
  2153. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2154. if drug.ID == 0 {
  2155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2156. return
  2157. }
  2158. //查询药品的所有库存
  2159. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2160. var total_count int64
  2161. for _, it := range list {
  2162. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2163. }
  2164. totals := strconv.FormatInt(total_count, 10)
  2165. //查询该药品是否存在开药记录
  2166. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2167. //新增处方
  2168. if advicelist.ID == 0 {
  2169. //查询最新批次库存
  2170. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2171. var batch_number_count int64
  2172. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2173. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2174. all_count, _ := strconv.ParseFloat(totals, 64)
  2175. if prescribingNumberUnit == drug.MinUnit {
  2176. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2177. if drug.IsUse != 1 {
  2178. if drug.IsProject == 0 || drug.IsProject == 2 {
  2179. if all_count == 0 {
  2180. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2181. return
  2182. }
  2183. if prescribing_number > all_count {
  2184. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2185. return
  2186. }
  2187. }
  2188. if adminInfo.CurrentOrgId == 10215 {
  2189. if prescribing_number > batch_number_all_count {
  2190. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2191. return
  2192. }
  2193. }
  2194. }
  2195. } else {
  2196. if prescribingNumberUnit == drug.MaxUnit {
  2197. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2198. num := prescribing_number * float64(drug.MinNumber)
  2199. if drug.IsUse != 1 {
  2200. if drug.IsProject == 0 || drug.IsProject == 2 {
  2201. if all_count == 0 {
  2202. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2203. return
  2204. }
  2205. if num > all_count {
  2206. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2207. return
  2208. }
  2209. }
  2210. if adminInfo.CurrentOrgId == 10215 {
  2211. if prescribing_number > batch_number_all_count {
  2212. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2213. return
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219. }
  2220. //修改处方
  2221. if advicelist.ID > 0 {
  2222. //查询最新批次库存
  2223. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2224. var batch_number_count int64
  2225. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2226. var device_number int64
  2227. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2228. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2229. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2230. device_number = prescribingNumberInt * drug.MinNumber
  2231. }
  2232. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2233. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2234. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2235. device_number = prescribingNumberInt
  2236. }
  2237. var number_count int64
  2238. if prescribingNumberUnit == drug.MaxUnit {
  2239. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2240. number_count = prescribingNumberInt * drug.MinNumber
  2241. }
  2242. if prescribingNumberUnit == drug.MinUnit {
  2243. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2244. number_count = prescribingNumberInt
  2245. }
  2246. //如果修改的数量大于之前修改的数量
  2247. if (number_count - device_number) > 0 {
  2248. //如果修改的差数量 大于库存数量
  2249. if drug.IsUse != 1 {
  2250. if drug.IsProject == 0 || drug.IsProject == 2 {
  2251. if total_count == 0 {
  2252. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2253. return
  2254. }
  2255. if (number_count - device_number) > total_count {
  2256. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2257. return
  2258. }
  2259. }
  2260. if adminInfo.CurrentOrgId == 10215 {
  2261. if (number_count - device_number) > batch_number_count {
  2262. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2263. return
  2264. }
  2265. }
  2266. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2267. //查询历史出库数据总批次
  2268. // 查询该药品最后一次出库记录
  2269. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2270. var out_count int64
  2271. var in_count int64
  2272. var stock_max_number int64
  2273. var stock_min_number int64
  2274. for _, it := range outInfo {
  2275. if it.CountUnit == drug.MaxUnit {
  2276. it.Count = it.Count * drug.MinNumber
  2277. }
  2278. out_count += it.Count
  2279. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2280. stock_max_number = warehouseInfoList.StockMaxNumber
  2281. stock_min_number = warehouseInfoList.StockMinNumber
  2282. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2283. }
  2284. if out_count > 0 {
  2285. if (number_count - device_number) > in_count {
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2287. return
  2288. }
  2289. }
  2290. // 未出库
  2291. if out_count == 0 {
  2292. var sum_in_count int64
  2293. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2294. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2295. if sum_in_count == 0 {
  2296. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2297. return
  2298. }
  2299. //如果修改的数量大于有库存的第一个批次
  2300. if number_count > sum_in_count {
  2301. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2302. return
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. }
  2311. }
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. //校验耗材库存
  2319. if goodOutConfig.IsOpen == 1 {
  2320. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2321. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2322. if len(prescriptions) > 0 {
  2323. for _, item := range prescriptions {
  2324. items := item.(map[string]interface{})
  2325. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2326. projects := items["project"].([]interface{})
  2327. if len(projects) > 0 {
  2328. for _, project := range projects {
  2329. var project_id int64
  2330. var project_type int64
  2331. var totals float64
  2332. var project_name string
  2333. var parsetotal int64
  2334. var id int64
  2335. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2336. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2337. }
  2338. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2339. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2340. }
  2341. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2342. total, _ := project.(map[string]interface{})["total"].(string)
  2343. totals, _ = strconv.ParseFloat(total, 64)
  2344. }
  2345. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2346. project_name = project.(map[string]interface{})["project_name"].(string)
  2347. }
  2348. if project_type == 3 {
  2349. //查找该耗材的出库记录
  2350. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2351. if len(goodWarehouseInfo) == 0 {
  2352. //查询耗材库存
  2353. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2354. var stock_count int64
  2355. for _, it := range list {
  2356. stock_count += it.StockCount
  2357. }
  2358. stock_counts := strconv.FormatInt(stock_count, 10)
  2359. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2360. if stock_total_count == 0 {
  2361. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2362. return
  2363. }
  2364. if totals > stock_total_count {
  2365. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2366. return
  2367. }
  2368. }
  2369. if len(goodWarehouseInfo) > 0 {
  2370. //查询该患者耗材的历史数据
  2371. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2372. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2373. //数量发生改变
  2374. if parsetotal != count {
  2375. //如果现在的数量大于历史数量,就要看库存是否足够
  2376. if parsetotal > count {
  2377. //查询耗材所有库存
  2378. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2379. var stock_count int64
  2380. for _, it := range list {
  2381. stock_count += it.StockCount
  2382. }
  2383. //库存不足
  2384. if stock_count == 0 {
  2385. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2386. return
  2387. }
  2388. if (parsetotal - count) > stock_count {
  2389. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2390. return
  2391. }
  2392. }
  2393. }
  2394. }
  2395. }
  2396. }
  2397. }
  2398. }
  2399. }
  2400. }
  2401. }
  2402. }
  2403. //不使用耗材保存处方出库
  2404. if goodOutConfig.IsOpen != 1 {
  2405. if stockConfig.IsOpen == 1 {
  2406. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2407. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2408. if len(prescriptions) > 0 {
  2409. for _, item := range prescriptions {
  2410. items := item.(map[string]interface{})
  2411. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2412. projects := items["project"].([]interface{})
  2413. if len(projects) > 0 {
  2414. for _, project := range projects {
  2415. var project_id int64
  2416. var project_type int64
  2417. var totals float64
  2418. var project_name string
  2419. var parsetotal int64
  2420. var id int64
  2421. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2422. id = int64(project.(map[string]interface{})["id"].(float64))
  2423. }
  2424. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2425. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2426. }
  2427. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2428. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2429. }
  2430. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2431. total, _ := project.(map[string]interface{})["total"].(string)
  2432. totals, _ = strconv.ParseFloat(total, 64)
  2433. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2434. }
  2435. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2436. project_name = project.(map[string]interface{})["project_name"].(string)
  2437. }
  2438. if project_type == 3 {
  2439. //查找该耗材的出库记录
  2440. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2441. //没有出库记录
  2442. if len(goodWarehouseInfo) == 0 {
  2443. //查询耗材库存
  2444. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2445. var stock_count int64
  2446. for _, it := range list {
  2447. stock_count += it.StockCount
  2448. }
  2449. stock_counts := strconv.FormatInt(stock_count, 10)
  2450. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2451. if stock_total_count == 0 {
  2452. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2453. return
  2454. }
  2455. if totals > stock_total_count {
  2456. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2457. return
  2458. }
  2459. //查找今日该患者已经出库的所有耗材
  2460. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2461. for _, item := range goodList {
  2462. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2463. var flush_count int64
  2464. for _, it := range goodListSix {
  2465. flush_count += it.StockCount
  2466. }
  2467. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2468. creater := adminInfo.AdminUser.Id
  2469. if errs != nil {
  2470. goodErrcode := models.XtGoodErrcode{
  2471. UserOrgId: item.OrgId,
  2472. Errcode: "手动出库更新剩余出库失败",
  2473. GoodId: item.GoodId,
  2474. Status: 1,
  2475. Ctime: time.Now().Unix(),
  2476. Mtime: 0,
  2477. Count: 0,
  2478. StockCount: 0,
  2479. Creater: creater,
  2480. BatchNumberId: 0,
  2481. WarehouseOutId: 0,
  2482. }
  2483. service.CreateGoodErrcode(goodErrcode)
  2484. }
  2485. }
  2486. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2487. }
  2488. //有出库记录
  2489. if len(goodWarehouseInfo) > 0 {
  2490. //查询该患者耗材的历史数据
  2491. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2492. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2493. //数量发生改变
  2494. if parsetotal != count {
  2495. //查找今日该患者已经出库的所有耗材
  2496. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2497. for _, item := range goodList {
  2498. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2499. var flush_count int64
  2500. for _, it := range goodListSix {
  2501. flush_count += it.StockCount
  2502. }
  2503. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2504. //减少出库数量
  2505. creater := adminInfo.AdminUser.Id
  2506. if errs != nil {
  2507. goodErrcode := models.XtGoodErrcode{
  2508. UserOrgId: item.OrgId,
  2509. Errcode: "手动出库更新剩余出库失败",
  2510. GoodId: item.GoodId,
  2511. Status: 1,
  2512. Ctime: time.Now().Unix(),
  2513. Mtime: 0,
  2514. Count: 0,
  2515. StockCount: 0,
  2516. Creater: creater,
  2517. BatchNumberId: 0,
  2518. WarehouseOutId: 0,
  2519. }
  2520. service.CreateGoodErrcode(goodErrcode)
  2521. }
  2522. //查询默认仓库
  2523. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2524. var total_count int64
  2525. for _, it := range stockList {
  2526. total_count += it.StockCount
  2527. }
  2528. //基础库插入数据
  2529. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2530. }
  2531. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2532. }
  2533. }
  2534. }
  2535. }
  2536. }
  2537. }
  2538. }
  2539. }
  2540. }
  2541. }
  2542. }
  2543. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2544. var hpInfo models.HisPrescriptionInfo
  2545. if info.ID == 0 {
  2546. var randNum int
  2547. randNum = rand.Intn(10000) + 1000
  2548. timestamp := time.Now().Unix()
  2549. tempTime := time.Unix(timestamp, 0)
  2550. timeFormat := tempTime.Format("20060102150405")
  2551. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2552. hpInfo = models.HisPrescriptionInfo{
  2553. HisPatientId: his_patient_id,
  2554. UserOrgId: adminInfo.CurrentOrgId,
  2555. RecordDate: theTime.Unix(),
  2556. PatientId: patient_id,
  2557. Status: 1,
  2558. Ctime: time.Now().Unix(),
  2559. Mtime: time.Now().Unix(),
  2560. Creator: adminInfo.AdminUser.Id,
  2561. Modifier: adminInfo.AdminUser.Id,
  2562. Diagnosis: diagnose,
  2563. SickHistory: sick_history,
  2564. Departments: department,
  2565. RegisterType: reg_type,
  2566. PrescriptionNumber: p_number,
  2567. PrescriptionStatus: 1,
  2568. Doctor: role.UserName,
  2569. DoctorId: doctor_id,
  2570. SickType: sick_type,
  2571. PType: p_type,
  2572. PatientDiagnosis: patient_diagnose,
  2573. }
  2574. service.SavePatientPrescriptionInfo(hpInfo)
  2575. //创建步骤表
  2576. finish := models.XtDialysisFinish{
  2577. IsFinish: 1,
  2578. UserOrgId: adminInfo.CurrentOrgId,
  2579. Status: 1,
  2580. Ctime: time.Now().Unix(),
  2581. Mtime: 0,
  2582. Module: 4,
  2583. RecordDate: theTime.Unix(),
  2584. Sourse: 1,
  2585. PatientId: patient_id,
  2586. }
  2587. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2588. if dialysisFinish.ID == 0 {
  2589. service.CreateDialysisFinish(finish)
  2590. }
  2591. redis := service.RedisClient()
  2592. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2593. redis.Set(key, "", time.Second)
  2594. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2595. redis.Set(keyOne, "", time.Second)
  2596. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2597. redis.Set(keySeven, "", time.Second)
  2598. defer redis.Close()
  2599. } else {
  2600. hpInfo = models.HisPrescriptionInfo{
  2601. ID: info.ID,
  2602. UserOrgId: adminInfo.CurrentOrgId,
  2603. RecordDate: info.RecordDate,
  2604. PatientId: info.PatientId,
  2605. Status: 1,
  2606. Ctime: info.Ctime,
  2607. Mtime: time.Now().Unix(),
  2608. Creator: info.Creator,
  2609. Modifier: adminInfo.AdminUser.Id,
  2610. Diagnosis: diagnose,
  2611. SickHistory: sick_history,
  2612. Departments: department,
  2613. RegisterType: reg_type,
  2614. PrescriptionNumber: info.PrescriptionNumber,
  2615. Doctor: role.UserName,
  2616. PrescriptionStatus: info.PrescriptionStatus,
  2617. DoctorId: doctor_id,
  2618. SickType: sick_type,
  2619. PType: info.PType,
  2620. HisPatientId: info.HisPatientId,
  2621. PatientDiagnosis: patient_diagnose,
  2622. }
  2623. service.SavePatientPrescriptionInfo(hpInfo)
  2624. //创建步骤表
  2625. finish := models.XtDialysisFinish{
  2626. IsFinish: 1,
  2627. UserOrgId: adminInfo.CurrentOrgId,
  2628. Status: 1,
  2629. Ctime: time.Now().Unix(),
  2630. Mtime: 0,
  2631. Module: 4,
  2632. RecordDate: info.RecordDate,
  2633. Sourse: 1,
  2634. PatientId: info.PatientId,
  2635. }
  2636. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2637. if dialysisFinish.ID == 0 {
  2638. service.CreateDialysisFinish(finish)
  2639. }
  2640. redis := service.RedisClient()
  2641. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2642. redis.Set(key, "", time.Second)
  2643. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2644. redis.Set(keyOne, "", time.Second)
  2645. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2646. redis.Set(keySeven, "", time.Second)
  2647. defer redis.Close()
  2648. }
  2649. //定义切片
  2650. var adviceList []models.HisDoctorAdviceInfo
  2651. var projectList []models.HisPrescriptionProject
  2652. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2653. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2654. var tempPrescription *models.HisPrescription
  2655. if len(prescriptions) > 0 {
  2656. for _, item := range prescriptions {
  2657. items := item.(map[string]interface{})
  2658. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2659. utils.ErrorLog("id")
  2660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2661. return
  2662. }
  2663. id := int64(items["id"].(float64))
  2664. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2665. tempPrescription = &new_prescription
  2666. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2667. utils.ErrorLog("type")
  2668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2669. return
  2670. }
  2671. types := int64(items["type"].(float64))
  2672. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2673. utils.ErrorLog("med_type")
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2675. return
  2676. }
  2677. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2678. if med_type == "0" {
  2679. med_type = "14"
  2680. }
  2681. //if order_status == 0 {
  2682. // order_status = 1
  2683. //}
  2684. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2685. utils.ErrorLog("pre_time")
  2686. }
  2687. preTime, _ := items["pre_time"].(string)
  2688. timeLayout := "2006-01-02"
  2689. loc, _ := time.LoadLocation("Local")
  2690. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2691. if err != nil {
  2692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2693. return
  2694. }
  2695. pTime := theTime2.Unix()
  2696. ctime := time.Now().Unix()
  2697. if tempPrescription.ID == 0 {
  2698. prescription := &models.HisPrescription{
  2699. ID: 0,
  2700. PatientId: patient_id,
  2701. UserOrgId: adminInfo.CurrentOrgId,
  2702. RecordDate: recordDateTime,
  2703. Ctime: ctime,
  2704. Mtime: ctime,
  2705. Type: types,
  2706. Modifier: adminInfo.AdminUser.Id,
  2707. Creator: adminInfo.AdminUser.Id,
  2708. Status: 1,
  2709. Doctor: role.UserName,
  2710. HisPatientId: his_patient_id,
  2711. OrderStatus: 1,
  2712. BatchNumber: "",
  2713. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2714. PreTime: pTime,
  2715. PType: p_type,
  2716. MedType: med_type,
  2717. }
  2718. tempPrescription = prescription
  2719. service.SaveHisPrescription(tempPrescription)
  2720. redis := service.RedisClient()
  2721. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2722. redis.Set(key, "", time.Second)
  2723. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2724. redis.Set(keyOne, "", time.Second)
  2725. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2726. redis.Set(keySeven, "", time.Second)
  2727. defer redis.Close()
  2728. } else {
  2729. tempPrescription.ID = id
  2730. tempPrescription.Type = types
  2731. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2732. tempPrescription.Mtime = time.Now().Unix()
  2733. tempPrescription.Doctor = role.UserName
  2734. //tempPrescription.OrderStatus = order_status
  2735. tempPrescription.PreTime = pTime
  2736. tempPrescription.MedType = med_type
  2737. service.SaveHisPrescription(tempPrescription)
  2738. redis := service.RedisClient()
  2739. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2740. redis.Set(key, "", time.Second)
  2741. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2742. redis.Set(keyOne, "", time.Second)
  2743. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2744. redis.Set(keySeven, "", time.Second)
  2745. defer redis.Close()
  2746. }
  2747. //service.SaveHisPrescription(prescription)
  2748. //更改患者挂号状态
  2749. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2750. fmt.Println("更改失败", err2)
  2751. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2752. advices := items["advices"].([]interface{})
  2753. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2754. groupNo := int64(0)
  2755. ctime := time.Now().Unix()
  2756. mtime := ctime
  2757. if len(advices) > 0 {
  2758. for _, advice := range advices {
  2759. var s models.HisDoctorAdviceInfo
  2760. s.PrescriptionId = tempPrescription.ID
  2761. s.AdviceType = 2
  2762. s.AdviceDoctor = doctor_id
  2763. s.StopState = 2
  2764. s.ExecutionState = 2
  2765. s.AdviceDate = recordDateTime
  2766. s.Status = 1
  2767. s.UserOrgId = adminInfo.CurrentOrgId
  2768. s.RecordDate = recordDateTime
  2769. s.StartTime = tempPrescription.PreTime
  2770. s.Groupno = groupNo
  2771. s.CreatedTime = ctime
  2772. s.UpdatedTime = mtime
  2773. s.PatientId = patient_id
  2774. s.HisPatientId = his_patient_id
  2775. s.StartTime = pTime
  2776. s.IsSettle = 2
  2777. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2778. if errcode > 0 {
  2779. c.ServeFailJSONWithSGJErrorCode(errcode)
  2780. return
  2781. }
  2782. s.StartTime = pTime
  2783. var total_count int64 //处方总库存
  2784. //查询改药品信息
  2785. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2786. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2787. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2788. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2789. total_count += prescribingNumberSeven * medical.MinNumber
  2790. }
  2791. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2792. total_count += prescribingNumberSeven
  2793. }
  2794. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2795. total_count += prescribingNumberSeven
  2796. }
  2797. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2798. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2799. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2800. if s.Price != lastWarehouse.RetailPrice {
  2801. s.Price = lastWarehouse.RetailPrice
  2802. }
  2803. if s.Price == 0 {
  2804. s.Price = lastWarehouse.RetailPrice
  2805. }
  2806. }
  2807. service.CreateHisDoctorAdvice(&s)
  2808. //记录日志
  2809. byterequest, _ := json.Marshal(s)
  2810. adviceLog := models.XtDoctorAdviceLog{
  2811. UserOrgId: s.UserOrgId,
  2812. PatientId: s.PatientId,
  2813. AdminUserId: adminInfo.AdminUser.Id,
  2814. Module: 1,
  2815. ErrLog: string(byterequest),
  2816. Status: 1,
  2817. Ctime: time.Now().Unix(),
  2818. Mtime: 0,
  2819. Source: "电脑端新建his医嘱",
  2820. RecordDate: s.AdviceDate,
  2821. }
  2822. service.CreateDoctorAdviceLog(adviceLog)
  2823. //存储切片中
  2824. adviceList = append(adviceList, s)
  2825. redis := service.RedisClient()
  2826. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2827. redis.Set(key, "", time.Second)
  2828. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2829. redis.Set(keyOne, "", time.Second)
  2830. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2831. redis.Set(keySeven, "", time.Second)
  2832. var randNum int
  2833. randNum = rand.Intn(10000) + 1000
  2834. timestamp := time.Now().Unix()
  2835. tempTime := time.Unix(timestamp, 0)
  2836. timeFormat := tempTime.Format("20060102150405")
  2837. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2838. service.CreateHisDoctorAdvice(&s)
  2839. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2840. redis.Set(keySix, "", time.Second)
  2841. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2842. redis.Set(keyFive, "", time.Second)
  2843. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2844. redis.Set(keyEight, "", time.Second)
  2845. defer redis.Close()
  2846. }
  2847. }
  2848. }
  2849. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2850. projects := items["project"].([]interface{})
  2851. if len(projects) > 0 {
  2852. for _, project := range projects {
  2853. var p models.HisPrescriptionProject
  2854. p.PrescriptionId = tempPrescription.ID
  2855. p.Ctime = time.Now().Unix()
  2856. p.Mtime = time.Now().Unix()
  2857. p.PatientId = patient_id
  2858. p.RecordDate = recordDateTime
  2859. p.Doctor = doctor_id
  2860. p.UserOrgId = adminInfo.CurrentOrgId
  2861. p.HisPatientId = his_patient_id
  2862. p.Status = 1
  2863. p.StartTime = pTime
  2864. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2865. if errcode > 0 {
  2866. c.ServeFailJSONWithSGJErrorCode(errcode)
  2867. return
  2868. }
  2869. if p.ID == 0 {
  2870. p.IsOut = 2
  2871. }
  2872. if p.ID > 0 {
  2873. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2874. p.IsOut = projectDetail.IsOut
  2875. }
  2876. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2877. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2878. if p.Type == 3 {
  2879. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2880. if p.Price != lastWarehouse.PackingPrice {
  2881. p.Price = lastWarehouse.PackingPrice
  2882. }
  2883. if p.Unit == "" {
  2884. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2885. p.Unit = goodInfoOne.PackingUnit
  2886. }
  2887. }
  2888. }
  2889. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2890. //
  2891. // if p.Type == 3 {
  2892. // //查询该耗材是否停用
  2893. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2894. // //表示该耗材已经停用,不能保存
  2895. // if goodInfoSeven.ID == 0 {
  2896. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2897. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2898. // return
  2899. // }
  2900. // }
  2901. //
  2902. //}
  2903. service.CreateHisProjectTwo(&p)
  2904. //记录日志
  2905. byterequest, _ := json.Marshal(p)
  2906. adviceLog := models.XtDoctorAdviceLog{
  2907. UserOrgId: p.UserOrgId,
  2908. PatientId: p.PatientId,
  2909. AdminUserId: adminInfo.AdminUser.Id,
  2910. Module: 1,
  2911. ErrLog: string(byterequest),
  2912. Status: 1,
  2913. Ctime: time.Now().Unix(),
  2914. Mtime: 0,
  2915. Source: "电脑端新建his项目",
  2916. RecordDate: p.RecordDate,
  2917. }
  2918. service.CreateDoctorAdviceLog(adviceLog)
  2919. projectList = append(projectList, p)
  2920. var randNum int
  2921. randNum = rand.Intn(10000) + 1000
  2922. timestamp := time.Now().Unix()
  2923. tempTime := time.Unix(timestamp, 0)
  2924. timeFormat := tempTime.Format("20060102150405")
  2925. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2926. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2927. //新增或者编辑项目,修改对应的标签数据
  2928. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2929. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2930. var label models.HisLabelPrintInfo
  2931. project, _ := service.GetProjectDetail(p.ProjectId)
  2932. if project.CostClassify == 3 { //类别为检验检查
  2933. if p.TeamId > 0 { //检验检查组套
  2934. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2935. if tempLabel.ID == 0 {
  2936. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2937. label.Number = tempPrescription.PrescriptionNumber
  2938. label.ProjectId = project.ID
  2939. label.Status = 1
  2940. label.IsPrint = 2
  2941. label.DoctorId = info.DoctorId
  2942. label.UserOrgId = p.UserOrgId
  2943. label.PatientId = patient_id
  2944. label.RecordDate = recordDateTime
  2945. label.Ctime = time.Now().Unix()
  2946. label.Mtime = time.Now().Unix()
  2947. label.ItemId = p.TeamId
  2948. label.FeedetlSn = p.FeedetlSn
  2949. label.PProjectId = p.ID
  2950. label.ProjectName = team.ProjectTeam
  2951. label.PatientName = patient.Name
  2952. service.CreateHisLabelRecord(&label)
  2953. }
  2954. } else { //单条检验检查项目
  2955. label.Number = tempPrescription.PrescriptionNumber
  2956. label.ProjectId = project.ID
  2957. label.Status = 1
  2958. label.DoctorId = info.DoctorId
  2959. label.UserOrgId = p.UserOrgId
  2960. label.PatientId = patient_id
  2961. label.RecordDate = recordDateTime
  2962. label.IsPrint = 2
  2963. label.Ctime = time.Now().Unix()
  2964. label.Mtime = time.Now().Unix()
  2965. label.FeedetlSn = p.FeedetlSn
  2966. label.PProjectId = p.ID
  2967. label.ItemId = p.TeamId
  2968. label.ProjectName = project.ProjectName
  2969. label.PatientName = patient.Name
  2970. service.CreateHisLabelRecord(&label)
  2971. }
  2972. }
  2973. }
  2974. }
  2975. service.SaveHisProjectTwo(&p)
  2976. }
  2977. }
  2978. }
  2979. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2980. // addition := items["addition"].([]interface{})
  2981. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2982. // ctime := time.Now().Unix()
  2983. // mtime := ctime
  2984. // if len(addition) > 0 {
  2985. // for _, item := range addition {
  2986. // var s models.HisAdditionalCharge
  2987. // s.PrescriptionId = tempPrescription.ID
  2988. // s.Status = 1
  2989. // s.UserOrgId = adminInfo.CurrentOrgId
  2990. // s.RecordDate = recordDateTime
  2991. // s.CreatedTime = ctime
  2992. // s.UpdatedTime = mtime
  2993. // s.PatientId = patient_id
  2994. // s.HisPatientId = his_patient_id
  2995. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2996. // if errcode > 0 {
  2997. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2998. // return
  2999. // }
  3000. // service.CreateAdditionalCharge(&s)
  3001. // var randNum int
  3002. // randNum = rand.Intn(10000) + 1000
  3003. // timestamp := time.Now().Unix()
  3004. // tempTime := time.Unix(timestamp, 0)
  3005. // timeFormat := tempTime.Format("20060102150405")
  3006. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3007. // service.CreateAdditionalCharge(&s)
  3008. //
  3009. // }
  3010. // }
  3011. //}
  3012. }
  3013. }
  3014. //查询今日该患者开的药品处方
  3015. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3016. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3017. //药品出库
  3018. if drugOutConfig.IsOpen == 1 {
  3019. for _, item := range hisdoctorlist {
  3020. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3021. // 查询该药品最后一次出库记录
  3022. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3023. if len(druginfo) > 0 {
  3024. //回退库存
  3025. for _, it := range druginfo {
  3026. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3027. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3028. }
  3029. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3030. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3031. }
  3032. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3033. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3034. }
  3035. }
  3036. }
  3037. //删除记录
  3038. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3039. //查询最后一次数据
  3040. if drugOutConfig.IsOpen == 1 {
  3041. //出库
  3042. if drug.IsUse == 2 {
  3043. creater := adminInfo.AdminUser.Id
  3044. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3045. }
  3046. //更新字典里面的库存
  3047. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3048. var sum_count int64
  3049. for _, its := range stockInfo {
  3050. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3051. if its.MaxUnit == baseDrug.MaxUnit {
  3052. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3053. }
  3054. sum_count += its.StockMaxNumber + its.StockMinNumber
  3055. }
  3056. //更新基础库存
  3057. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3058. //剩余库存
  3059. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3060. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3061. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3062. }
  3063. }
  3064. }
  3065. //耗材保存处方出库
  3066. if goodOutConfig.IsOpen == 1 {
  3067. //查询今日耗材出库数量
  3068. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3069. for _, item := range hisgoodlist {
  3070. //查询历史出库数据
  3071. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3072. var out_count_five int64
  3073. for _, item := range flowGood {
  3074. out_count_five += item.Count
  3075. }
  3076. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3077. if out_count_five != parseIntCount {
  3078. //查询耗材最后一次出库记录
  3079. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3080. //查询默认出库仓库库存
  3081. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3082. if len(wareOut) > 0 {
  3083. for _, it := range wareOut {
  3084. //回退库存
  3085. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3086. //删除出库记录
  3087. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3088. }
  3089. }
  3090. timeStr := time.Now().Format("2006-01-02")
  3091. timeArr := strings.Split(timeStr, "-")
  3092. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3093. total = total + 1
  3094. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3095. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3096. number = number + total
  3097. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3098. operation_time := time.Now().Unix()
  3099. creater := c.GetAdminUserInfo().AdminUser.Id
  3100. recordDateStr := time.Now().Format("2006-01-02")
  3101. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3102. nowtime := recordDate.Unix()
  3103. warehouseOut := models.WarehouseOut{
  3104. WarehouseOutOrderNumber: warehousing_out_order,
  3105. OperationTime: operation_time,
  3106. OrgId: adminInfo.CurrentOrgId,
  3107. Creater: creater,
  3108. Ctime: time.Now().Unix(),
  3109. Status: 1,
  3110. WarehouseOutTime: nowtime,
  3111. Type: 1,
  3112. StorehouseId: storeConfig.StorehouseOutInfo,
  3113. IsCheck: 1,
  3114. IsSys: 1,
  3115. }
  3116. //查询是否生成出库单
  3117. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3118. if out.ID == 0 {
  3119. service.AddSigleWarehouseOut(&warehouseOut)
  3120. }
  3121. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3122. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3123. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3124. dialyPrepareOne := models.DialysisBeforePrepare{
  3125. GoodTypeId: goodObj.GoodTypeId,
  3126. GoodId: item.ProjectId,
  3127. PatientId: item.PatientId,
  3128. RecordDate: item.RecordDate,
  3129. UserOrgId: adminInfo.CurrentOrgId,
  3130. Count: parseIntCount,
  3131. Ctime: time.Now().Unix(),
  3132. Creater: creater,
  3133. Status: 1,
  3134. StorehouseId: houseConfig.StorehouseOutInfo,
  3135. ProjectId: item.ID,
  3136. }
  3137. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3138. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3139. //查询历史出库数据
  3140. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3141. var out_count int64
  3142. for _, item := range flowGood {
  3143. out_count += item.Count
  3144. }
  3145. //如果历史数和当前数据不想等才进行退库出库
  3146. if out_count != parseIntCount {
  3147. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3148. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3149. detail := models.AutomaticReduceDetail{
  3150. WarehouseOutId: 0,
  3151. WarehouseOutOrderNumber: "",
  3152. PatientId: item.PatientId,
  3153. Ctime: time.Now().Unix(),
  3154. Mtime: 0,
  3155. Status: 1,
  3156. RecordTime: item.RecordDate,
  3157. OrgId: item.UserOrgId,
  3158. GoodId: item.ProjectId,
  3159. GoodTypeId: 0,
  3160. Count: parseIntCount,
  3161. Type: 0,
  3162. ProjectId: item.ID,
  3163. StorehouseId: 0,
  3164. }
  3165. service.CreateAutoDetail(detail)
  3166. //查询剩余库存
  3167. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3168. var sum_count int64
  3169. for _, item := range goodList {
  3170. sum_count += item.StockCount
  3171. }
  3172. //更新剩余库存
  3173. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3174. //耗材
  3175. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3176. }
  3177. }
  3178. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3179. //查询历史出库数据
  3180. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3181. var out_count int64
  3182. for _, item := range flowGood {
  3183. out_count += item.Count
  3184. }
  3185. //如果历史数和当前数据不想等才进行退库出库
  3186. if out_count != parseIntCount {
  3187. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3188. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3189. detail := models.AutomaticReduceDetail{
  3190. WarehouseOutId: 0,
  3191. WarehouseOutOrderNumber: "",
  3192. PatientId: item.PatientId,
  3193. Ctime: time.Now().Unix(),
  3194. Mtime: 0,
  3195. Status: 1,
  3196. RecordTime: item.RecordDate,
  3197. OrgId: item.UserOrgId,
  3198. GoodId: item.ProjectId,
  3199. GoodTypeId: 0,
  3200. Count: parseIntCount,
  3201. Type: 0,
  3202. ProjectId: item.ID,
  3203. StorehouseId: 0,
  3204. }
  3205. service.CreateAutoDetail(detail)
  3206. //查询剩余库存
  3207. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3208. var sum_count int64
  3209. for _, item := range goodList {
  3210. sum_count += item.StockCount
  3211. }
  3212. //更新剩余库存
  3213. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3214. //耗材
  3215. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3216. }
  3217. }
  3218. }
  3219. }
  3220. }
  3221. }
  3222. //redisClient := service.RedisClient()
  3223. //defer redisClient.Close()
  3224. //
  3225. //list := models.HisList{
  3226. // Patient_id: patient_id,
  3227. // Advice_id:0,
  3228. // Record_date: 0,
  3229. // Advice: adviceList,
  3230. // Project: nil,
  3231. //}
  3232. //hisLis = append(hisLis, list)
  3233. //
  3234. //advice_json, _ := json.Marshal(&hisLis)
  3235. //redisClient.RPush("111", advice_json).Result()
  3236. //result, _ := redisClient.RPop("111").Result()
  3237. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3238. //
  3239. //var dat []map[string]interface{}
  3240. //json.Unmarshal([]byte(result), &dat)
  3241. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3242. //
  3243. //for k,v:=range dat{
  3244. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3245. //}
  3246. //project_json, _ := json.Marshal(&projectList)
  3247. //redisClient.LPush("222", project_json).Result()
  3248. if err == nil {
  3249. c.ServeSuccessJSON(map[string]interface{}{
  3250. "msg": "保存成功",
  3251. })
  3252. return
  3253. } else {
  3254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3255. return
  3256. }
  3257. }
  3258. func (c *HisApiController) EditHisPrescription() {
  3259. record_date := c.GetString("record_date")
  3260. patient_id, _ := c.GetInt64("patient_id")
  3261. reg_type, _ := c.GetInt64("reg_type")
  3262. //diagnose, _ := c.GetInt64("diagnose", 0)
  3263. diagnose := c.GetString("diagnose")
  3264. sick_type, _ := c.GetInt64("sick_type")
  3265. sick_history := c.GetString("sick_history")
  3266. doctor_id, _ := c.GetInt64("doctor", 0)
  3267. department, _ := c.GetInt64("department", 0)
  3268. his_patient_id, _ := c.GetInt64("his_patient_id")
  3269. p_type, _ := c.GetInt64("p_type")
  3270. dataBody := make(map[string]interface{}, 0)
  3271. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3272. if err != nil {
  3273. utils.ErrorLog(err.Error())
  3274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3275. return
  3276. }
  3277. timeLayout := "2006-01-02"
  3278. loc, _ := time.LoadLocation("Local")
  3279. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3280. if err != nil {
  3281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3282. return
  3283. }
  3284. adminInfo := c.GetAdminUserInfo()
  3285. recordDateTime := theTime.Unix()
  3286. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3287. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3288. var hpInfo models.HisPrescriptionInfo
  3289. if info.ID == 0 {
  3290. var randNum int
  3291. randNum = rand.Intn(10000) + 1000
  3292. timestamp := time.Now().Unix()
  3293. tempTime := time.Unix(timestamp, 0)
  3294. timeFormat := tempTime.Format("20060102150405")
  3295. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3296. hpInfo = models.HisPrescriptionInfo{
  3297. UserOrgId: adminInfo.CurrentOrgId,
  3298. RecordDate: theTime.Unix(),
  3299. PatientId: patient_id,
  3300. Status: 1,
  3301. Ctime: time.Now().Unix(),
  3302. Mtime: time.Now().Unix(),
  3303. Creator: adminInfo.AdminUser.Id,
  3304. Modifier: adminInfo.AdminUser.Id,
  3305. Diagnosis: diagnose,
  3306. SickHistory: sick_history,
  3307. Departments: department,
  3308. RegisterType: reg_type,
  3309. PrescriptionNumber: p_number,
  3310. PrescriptionStatus: 1,
  3311. Doctor: role.UserName,
  3312. DoctorId: doctor_id,
  3313. SickType: sick_type,
  3314. PType: p_type,
  3315. }
  3316. service.SavePatientPrescriptionInfo(hpInfo)
  3317. } else {
  3318. hpInfo = models.HisPrescriptionInfo{
  3319. ID: info.ID,
  3320. UserOrgId: adminInfo.CurrentOrgId,
  3321. RecordDate: info.RecordDate,
  3322. PatientId: info.PatientId,
  3323. Status: 1,
  3324. Ctime: info.Ctime,
  3325. Mtime: time.Now().Unix(),
  3326. Creator: info.Creator,
  3327. Modifier: adminInfo.AdminUser.Id,
  3328. Diagnosis: diagnose,
  3329. SickHistory: sick_history,
  3330. Departments: department,
  3331. RegisterType: reg_type,
  3332. PrescriptionNumber: info.PrescriptionNumber,
  3333. Doctor: role.UserName,
  3334. PrescriptionStatus: info.PrescriptionStatus,
  3335. DoctorId: doctor_id,
  3336. SickType: sick_type,
  3337. PType: info.PType,
  3338. }
  3339. service.SavePatientPrescriptionInfo(hpInfo)
  3340. }
  3341. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3342. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3343. if len(prescriptions) > 0 {
  3344. for _, item := range prescriptions {
  3345. items := item.(map[string]interface{})
  3346. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3347. utils.ErrorLog("id")
  3348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3349. return
  3350. }
  3351. id := int64(items["id"].(float64))
  3352. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3353. utils.ErrorLog("type")
  3354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3355. return
  3356. }
  3357. types := int64(items["type"].(float64))
  3358. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3359. utils.ErrorLog("med_type")
  3360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3361. return
  3362. }
  3363. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3364. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3365. ctime := time.Now().Unix()
  3366. prescription := &models.HisPrescription{
  3367. ID: id,
  3368. PatientId: patient_id,
  3369. UserOrgId: adminInfo.CurrentOrgId,
  3370. RecordDate: recordDateTime,
  3371. Ctime: ctime,
  3372. Mtime: ctime,
  3373. Type: types,
  3374. Modifier: adminInfo.AdminUser.Id,
  3375. Creator: adminInfo.AdminUser.Id,
  3376. Status: 1,
  3377. Doctor: role.UserName,
  3378. HisPatientId: his_patient_id,
  3379. OrderStatus: 1,
  3380. BatchNumber: "",
  3381. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3382. PType: hpInfo.PType,
  3383. MedType: med_type,
  3384. }
  3385. if historyPrescription.ID > 0 {
  3386. prescription.PreTime = historyPrescription.PreTime
  3387. }
  3388. service.SaveHisPrescription(prescription)
  3389. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3390. advices := items["advices"].([]interface{})
  3391. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3392. groupNo := int64(0)
  3393. ctime := time.Now().Unix()
  3394. mtime := ctime
  3395. if len(advices) > 0 {
  3396. for _, advice := range advices {
  3397. var s models.HisDoctorAdviceInfo
  3398. s.PrescriptionId = prescription.ID
  3399. s.AdviceType = 2
  3400. s.AdviceDoctor = adminInfo.AdminUser.Id
  3401. s.StopState = 2
  3402. s.ExecutionState = 2
  3403. s.AdviceDate = recordDateTime
  3404. s.Status = 1
  3405. s.UserOrgId = adminInfo.CurrentOrgId
  3406. s.RecordDate = recordDateTime
  3407. s.StartTime = prescription.PreTime
  3408. s.Groupno = groupNo
  3409. s.CreatedTime = ctime
  3410. s.UpdatedTime = mtime
  3411. s.PatientId = patient_id
  3412. s.HisPatientId = his_patient_id
  3413. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3414. if errcode > 0 {
  3415. c.ServeFailJSONWithSGJErrorCode(errcode)
  3416. return
  3417. }
  3418. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3419. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3420. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3421. if s.Price == 0 {
  3422. s.Price = lastWarehouse.RetailPrice
  3423. }
  3424. }
  3425. service.CreateHisDoctorAdvice(&s)
  3426. //记录日志
  3427. byterequest, _ := json.Marshal(s)
  3428. adviceLog := models.XtDoctorAdviceLog{
  3429. UserOrgId: s.UserOrgId,
  3430. PatientId: s.PatientId,
  3431. AdminUserId: adminInfo.AdminUser.Id,
  3432. Module: 1,
  3433. ErrLog: string(byterequest),
  3434. Status: 1,
  3435. Ctime: time.Now().Unix(),
  3436. Mtime: 0,
  3437. Source: "电脑端his医嘱修改",
  3438. RecordDate: s.AdviceDate,
  3439. }
  3440. service.CreateDoctorAdviceLog(adviceLog)
  3441. redis := service.RedisClient()
  3442. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3443. redis.Set(key, "", time.Second)
  3444. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3445. fmt.Println("keyOne", keyOne)
  3446. redis.Set(keyOne, "", time.Second)
  3447. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3448. redis.Set(keySeven, "", time.Second)
  3449. redis.Close()
  3450. }
  3451. }
  3452. }
  3453. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3454. projects := items["project"].([]interface{})
  3455. if len(projects) > 0 {
  3456. for _, project := range projects {
  3457. var p models.HisPrescriptionProject
  3458. p.PrescriptionId = prescription.ID
  3459. p.Ctime = time.Now().Unix()
  3460. p.Mtime = time.Now().Unix()
  3461. p.PatientId = patient_id
  3462. p.RecordDate = recordDateTime
  3463. p.UserOrgId = adminInfo.CurrentOrgId
  3464. p.HisPatientId = his_patient_id
  3465. p.Status = 1
  3466. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3467. if errcode > 0 {
  3468. c.ServeFailJSONWithSGJErrorCode(errcode)
  3469. return
  3470. }
  3471. service.CreateHisProjectTwo(&p)
  3472. //记录日志
  3473. byterequest, _ := json.Marshal(p)
  3474. adviceLog := models.XtDoctorAdviceLog{
  3475. UserOrgId: p.UserOrgId,
  3476. PatientId: p.PatientId,
  3477. AdminUserId: adminInfo.AdminUser.Id,
  3478. Module: 1,
  3479. ErrLog: string(byterequest),
  3480. Status: 1,
  3481. Ctime: time.Now().Unix(),
  3482. Mtime: 0,
  3483. Source: "电脑端his项目修改",
  3484. RecordDate: p.RecordDate,
  3485. }
  3486. service.CreateDoctorAdviceLog(adviceLog)
  3487. }
  3488. }
  3489. }
  3490. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3491. addition := items["addition"].([]interface{})
  3492. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3493. ctime := time.Now().Unix()
  3494. mtime := ctime
  3495. if len(addition) > 0 {
  3496. for _, item := range addition {
  3497. var s models.HisAdditionalCharge
  3498. s.PrescriptionId = prescription.ID
  3499. s.Status = 1
  3500. s.UserOrgId = adminInfo.CurrentOrgId
  3501. s.RecordDate = recordDateTime
  3502. s.CreatedTime = ctime
  3503. s.UpdatedTime = mtime
  3504. s.PatientId = patient_id
  3505. s.HisPatientId = his_patient_id
  3506. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3507. if errcode > 0 {
  3508. c.ServeFailJSONWithSGJErrorCode(errcode)
  3509. return
  3510. }
  3511. service.CreateAdditionalCharge(&s)
  3512. }
  3513. }
  3514. }
  3515. }
  3516. }
  3517. }
  3518. if err == nil {
  3519. c.ServeSuccessJSON(map[string]interface{}{
  3520. "msg": "保存成功",
  3521. })
  3522. return
  3523. } else {
  3524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3525. return
  3526. }
  3527. }
  3528. func (c *HisApiController) DeletePrescription() {
  3529. prescription_id, _ := c.GetInt64("id")
  3530. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3531. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3532. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3533. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3534. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3535. //耗材保存处方出库
  3536. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3537. //已收费和已发药限制逻辑
  3538. isCharge := false
  3539. isMedicine := false
  3540. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3541. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3542. for _, item := range new_prescriptions {
  3543. if item.IsMedicine == 1 {
  3544. isMedicine = true
  3545. }
  3546. }
  3547. for _, item := range new_prescriptions {
  3548. if item.OrderStatus == 4 {
  3549. isCharge = true
  3550. }
  3551. }
  3552. if p_err != nil {
  3553. if new_prescription.ID > 0 {
  3554. if new_prescription.OrderStatus == 2 {
  3555. isCharge = true
  3556. }
  3557. }
  3558. }
  3559. for _, item := range advices {
  3560. if item.IsMedicine == 1 {
  3561. isMedicine = true
  3562. }
  3563. }
  3564. if isCharge {
  3565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3566. return
  3567. }
  3568. if isMedicine {
  3569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3570. return
  3571. }
  3572. //已收费和已发药限制逻辑
  3573. if len(projects) > 0 {
  3574. for _, item := range projects {
  3575. service.DeletePrintInfo(item.ID) //删除打印信息
  3576. if goodOutConfig.IsOpen != 1 {
  3577. if stockConfig.IsOpen == 1 {
  3578. if item.Type == 3 && item.IsOut == 1 {
  3579. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3580. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3581. good.Total = good.Total + f_count
  3582. service.UpdateGoodInfo(&good)
  3583. operation_time := time.Now().Unix()
  3584. creater := c.GetAdminUserInfo().AdminUser.Id
  3585. //创建退库单
  3586. timeStr := time.Now().Format("2006-01-02")
  3587. timeArr := strings.Split(timeStr, "-")
  3588. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3589. total = total + 1
  3590. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3591. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3592. cancelStock := models.CancelStock{
  3593. OrderNumber: orderNumber,
  3594. OperaTime: operation_time,
  3595. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3596. Creater: creater,
  3597. Ctime: time.Now().Unix(),
  3598. Status: 1,
  3599. ReturnTime: item.RecordDate,
  3600. Type: 1,
  3601. StorehouseId: houseConfig.StorehouseOutInfo,
  3602. IsCheck: 1,
  3603. }
  3604. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3605. if msgerrkonde == gorm.ErrRecordNotFound {
  3606. service.AddSigleCancelStock(&cancelStock)
  3607. }
  3608. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3609. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3610. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3611. //查询该耗材是否出库
  3612. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3613. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3614. deaerler, _ := service.GetDealerById(info.Dealer)
  3615. var total_count int64
  3616. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3617. total_count += count
  3618. if info.ID > 0 {
  3619. if info.Count >= total_count {
  3620. //回退库存
  3621. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3622. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3623. var flush_count int64
  3624. for _, it := range goodList {
  3625. flush_count += it.StockCount
  3626. }
  3627. cancelStockInfo := models.CancelStockInfo{
  3628. GoodId: item.ProjectId,
  3629. CancelStockId: cancel.ID,
  3630. GoodTypeId: good.GoodTypeId,
  3631. Count: prescribingNumber,
  3632. Price: info.Price,
  3633. Total: 0,
  3634. ProductDate: info.ProductDate,
  3635. ExpiryDate: info.ExpiryDate,
  3636. Ctime: time.Now().Unix(),
  3637. Status: 1,
  3638. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3639. OrderNumber: cancel.OrderNumber,
  3640. Type: 0,
  3641. Dealer: deaerler.DealerName,
  3642. Manufacturer: manufacturer.ManufacturerName,
  3643. Number: info.Number,
  3644. RegisterAccount: "",
  3645. Remark: "",
  3646. WarehouseInfoId: info.WarehouseInfotId,
  3647. PatientId: info.PatientId,
  3648. RecordDate: info.SysRecordTime,
  3649. StorehouseId: houseConfig.StorehouseOutInfo,
  3650. IsCheck: 1,
  3651. }
  3652. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3653. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3654. flow := models.VmStockFlow{
  3655. WarehousingId: info.WarehouseInfotId,
  3656. GoodId: item.ProjectId,
  3657. Number: info.Number,
  3658. LicenseNumber: info.LicenseNumber,
  3659. Count: prescribingNumber,
  3660. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3661. PatientId: item.PatientId,
  3662. SystemTime: info.SysRecordTime,
  3663. ConsumableType: 7,
  3664. IsSys: 0,
  3665. WarehousingOrder: "",
  3666. WarehouseOutId: info.WarehouseOutId,
  3667. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3668. IsEdit: 0,
  3669. CancelStockId: cancel.ID,
  3670. CancelOrderNumber: cancel.OrderNumber,
  3671. Manufacturer: manufacturer.ID,
  3672. Dealer: 0,
  3673. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3674. UpdateCreator: 0,
  3675. Status: 1,
  3676. Ctime: time.Now().Unix(),
  3677. Mtime: 0,
  3678. Price: info.Price,
  3679. WarehousingDetailId: info.WarehouseInfotId,
  3680. WarehouseOutDetailId: info.ID,
  3681. CancelOutDetailId: cancelInfo.ID,
  3682. ProductDate: info.ProductDate,
  3683. ExpireDate: info.ExpiryDate,
  3684. StorehouseId: houseConfig.StorehouseOutInfo,
  3685. OverCount: flush_count,
  3686. }
  3687. service.CreateStockFlowOne(flow)
  3688. //退库数量增加
  3689. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3690. //出库数量减少
  3691. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3692. }
  3693. if info.Count < total_count {
  3694. //回退库存
  3695. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3696. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3697. var flush_count int64
  3698. for _, it := range goodList {
  3699. flush_count += it.StockCount
  3700. }
  3701. cancelStockInfo := models.CancelStockInfo{
  3702. GoodId: item.ProjectId,
  3703. CancelStockId: cancel.ID,
  3704. GoodTypeId: good.GoodTypeId,
  3705. Count: info.Count,
  3706. Price: info.Price,
  3707. Total: 0,
  3708. ProductDate: info.ProductDate,
  3709. ExpiryDate: info.ExpiryDate,
  3710. Ctime: time.Now().Unix(),
  3711. Status: 1,
  3712. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3713. OrderNumber: cancel.OrderNumber,
  3714. Type: 0,
  3715. Dealer: deaerler.DealerName,
  3716. Manufacturer: manufacturer.ManufacturerName,
  3717. Number: info.Number,
  3718. RegisterAccount: "",
  3719. Remark: "",
  3720. WarehouseInfoId: info.WarehouseInfotId,
  3721. PatientId: info.PatientId,
  3722. RecordDate: info.SysRecordTime,
  3723. StorehouseId: houseConfig.StorehouseOutInfo,
  3724. IsCheck: 1,
  3725. }
  3726. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3727. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3728. flow := models.VmStockFlow{
  3729. WarehousingId: info.WarehouseInfotId,
  3730. GoodId: item.ProjectId,
  3731. Number: info.Number,
  3732. LicenseNumber: info.LicenseNumber,
  3733. Count: info.Count,
  3734. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3735. PatientId: item.PatientId,
  3736. SystemTime: info.SysRecordTime,
  3737. ConsumableType: 7,
  3738. IsSys: 0,
  3739. WarehousingOrder: "",
  3740. WarehouseOutId: info.WarehouseOutId,
  3741. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3742. IsEdit: 0,
  3743. CancelStockId: cancel.ID,
  3744. CancelOrderNumber: cancel.OrderNumber,
  3745. Manufacturer: manufacturer.ID,
  3746. Dealer: 0,
  3747. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3748. UpdateCreator: 0,
  3749. Status: 1,
  3750. Ctime: time.Now().Unix(),
  3751. Mtime: 0,
  3752. Price: info.Price,
  3753. WarehousingDetailId: info.WarehouseInfotId,
  3754. WarehouseOutDetailId: info.ID,
  3755. CancelOutDetailId: cancelInfo.ID,
  3756. ProductDate: info.ProductDate,
  3757. ExpireDate: info.ExpiryDate,
  3758. StorehouseId: houseConfig.StorehouseOutInfo,
  3759. OverCount: flush_count,
  3760. }
  3761. service.CreateStockFlowOne(flow)
  3762. //退库数量增加
  3763. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3764. //出库数量减少
  3765. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3766. }
  3767. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3768. var flush_count int64
  3769. for _, it := range goodList {
  3770. flush_count += it.StockCount
  3771. }
  3772. //查询已出库数量
  3773. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3774. if prescribingNumber < dialysisInfo.Count {
  3775. //改变数量
  3776. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3777. }
  3778. if prescribingNumber >= dialysisInfo.Count {
  3779. //删除出库表
  3780. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3781. }
  3782. //更新库存
  3783. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3784. //更新基础库库存
  3785. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3786. }
  3787. }
  3788. }
  3789. }
  3790. //保存耗材出库
  3791. if goodOutConfig.IsOpen == 1 {
  3792. if item.Type == 3 {
  3793. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3794. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3795. good.Total = good.Total + f_count
  3796. service.UpdateGoodInfo(&good)
  3797. operation_time := time.Now().Unix()
  3798. creater := c.GetAdminUserInfo().AdminUser.Id
  3799. //创建退库单
  3800. timeStr := time.Now().Format("2006-01-02")
  3801. timeArr := strings.Split(timeStr, "-")
  3802. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3803. total = total + 1
  3804. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3805. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3806. cancelStock := models.CancelStock{
  3807. OrderNumber: orderNumber,
  3808. OperaTime: operation_time,
  3809. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3810. Creater: creater,
  3811. Ctime: time.Now().Unix(),
  3812. Status: 1,
  3813. ReturnTime: item.RecordDate,
  3814. Type: 1,
  3815. StorehouseId: houseConfig.StorehouseOutInfo,
  3816. IsCheck: 1,
  3817. }
  3818. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3819. if msgerrkonde == gorm.ErrRecordNotFound {
  3820. service.AddSigleCancelStock(&cancelStock)
  3821. }
  3822. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3823. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3824. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3825. //查询该耗材是否出库
  3826. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3827. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3828. deaerler, _ := service.GetDealerById(info.Dealer)
  3829. var total_count int64
  3830. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3831. total_count += count
  3832. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3833. var flush_count int64
  3834. for _, it := range goodList {
  3835. flush_count += it.StockCount
  3836. }
  3837. fmt.Println("历史出库数据", info.Count)
  3838. fmt.Println("出库数量", total_count)
  3839. if info.ID > 0 {
  3840. cancelStockInfo := models.CancelStockInfo{
  3841. GoodId: item.ProjectId,
  3842. CancelStockId: cancel.ID,
  3843. GoodTypeId: good.GoodTypeId,
  3844. Count: prescribingNumber,
  3845. Price: info.Price,
  3846. Total: 0,
  3847. ProductDate: info.ProductDate,
  3848. ExpiryDate: info.ExpiryDate,
  3849. Ctime: time.Now().Unix(),
  3850. Status: 1,
  3851. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3852. OrderNumber: cancel.OrderNumber,
  3853. Type: 0,
  3854. Dealer: deaerler.DealerName,
  3855. Manufacturer: manufacturer.ManufacturerName,
  3856. Number: info.Number,
  3857. RegisterAccount: "",
  3858. Remark: "",
  3859. WarehouseInfoId: info.WarehouseInfotId,
  3860. PatientId: info.PatientId,
  3861. RecordDate: info.SysRecordTime,
  3862. StorehouseId: houseConfig.StorehouseOutInfo,
  3863. IsCheck: 1,
  3864. }
  3865. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3866. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3867. //查询出库数量
  3868. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3869. //出库数据 大于 退库数量
  3870. if len(list) > 0 {
  3871. for _, it := range list {
  3872. //回退库存
  3873. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3874. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3875. var flush_count_one int64
  3876. for _, it := range goodList {
  3877. flush_count_one += it.StockCount
  3878. }
  3879. //查询该批次是否有退库数据
  3880. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3881. creater := c.GetAdminUserInfo().AdminUser.Id
  3882. flow := models.VmStockFlow{
  3883. WarehousingId: it.WarehouseInfotId,
  3884. GoodId: it.GoodId,
  3885. Number: it.Number,
  3886. LicenseNumber: it.LicenseNumber,
  3887. Count: it.Count,
  3888. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3889. PatientId: it.PatientId,
  3890. SystemTime: it.SysRecordTime,
  3891. ConsumableType: 7,
  3892. IsSys: 0,
  3893. WarehousingOrder: "",
  3894. WarehouseOutId: it.WarehouseOutId,
  3895. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3896. IsEdit: 0,
  3897. CancelStockId: cancel.ID,
  3898. CancelOrderNumber: cancel.OrderNumber,
  3899. Manufacturer: manufacturer.ID,
  3900. Dealer: 0,
  3901. Creator: creater,
  3902. UpdateCreator: 0,
  3903. Status: 1,
  3904. Ctime: time.Now().Unix(),
  3905. Mtime: 0,
  3906. Price: it.Price,
  3907. WarehousingDetailId: it.WarehouseInfotId,
  3908. WarehouseOutDetailId: it.ID,
  3909. CancelOutDetailId: cancelInfo.ID,
  3910. ProductDate: it.ProductDate,
  3911. ExpireDate: it.ExpiryDate,
  3912. StorehouseId: houseConfig.StorehouseOutInfo,
  3913. OverCount: flush_count_one,
  3914. }
  3915. service.CreateStockFlowOne(flow)
  3916. //if flow.ID > 0 {
  3917. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3918. //}
  3919. }
  3920. }
  3921. //flow := models.VmStockFlow{
  3922. // WarehousingId: info.WarehouseInfotId,
  3923. // GoodId: item.ProjectId,
  3924. // Number: info.Number,
  3925. // LicenseNumber: info.LicenseNumber,
  3926. // Count: prescribingNumber,
  3927. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3928. // PatientId: item.PatientId,
  3929. // SystemTime: info.SysRecordTime,
  3930. // ConsumableType: 7,
  3931. // IsSys: 0,
  3932. // WarehousingOrder: "",
  3933. // WarehouseOutId: info.WarehouseOutId,
  3934. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3935. // IsEdit: 0,
  3936. // CancelStockId: cancel.ID,
  3937. // CancelOrderNumber: cancel.OrderNumber,
  3938. // Manufacturer: manufacturer.ID,
  3939. // Dealer: 0,
  3940. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3941. // UpdateCreator: 0,
  3942. // Status: 1,
  3943. // Ctime: time.Now().Unix(),
  3944. // Mtime: 0,
  3945. // Price: info.Price,
  3946. // WarehousingDetailId: info.WarehouseInfotId,
  3947. // WarehouseOutDetailId: info.ID,
  3948. // CancelOutDetailId: cancelInfo.ID,
  3949. // ProductDate: info.ProductDate,
  3950. // ExpireDate: info.ExpiryDate,
  3951. // StorehouseId: houseConfig.StorehouseOutInfo,
  3952. // OverCount: flush_count,
  3953. //}
  3954. //service.CreateStockFlowOne(flow)
  3955. //退库数量增加
  3956. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3957. //出库数量减少
  3958. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3959. //查询已出库数量
  3960. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3961. if prescribingNumber < dialysisInfo.Count {
  3962. //改变数量
  3963. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3964. }
  3965. if prescribingNumber >= dialysisInfo.Count {
  3966. //删除出库表
  3967. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3968. }
  3969. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3970. var flush_count_one int64
  3971. for _, it := range goodList {
  3972. flush_count_one += it.StockCount
  3973. }
  3974. //更新库存
  3975. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3976. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3977. //更新基础库库存
  3978. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3979. }
  3980. }
  3981. }
  3982. }
  3983. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3984. fmt.Println(err)
  3985. }
  3986. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3987. fmt.Println(err)
  3988. if len(advices) > 0 {
  3989. for _, item := range advices {
  3990. redis := service.RedisClient()
  3991. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3992. redis.Set(keyFive, "", time.Second)
  3993. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3994. redis.Set(keyOne, "", time.Second)
  3995. redis.Close()
  3996. }
  3997. }
  3998. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3999. if len(advices) > 0 {
  4000. for _, item := range advices {
  4001. creater := c.GetAdminUserInfo().AdminUser.Id
  4002. service.DrugAutoAddCancelInfo(item, creater)
  4003. }
  4004. }
  4005. } else {
  4006. if drugOutConfig.IsOpen == 1 {
  4007. if len(advices) > 0 {
  4008. for _, item := range advices {
  4009. creater := c.GetAdminUserInfo().AdminUser.Id
  4010. service.DrugAutoAddCancelInfo(item, creater)
  4011. }
  4012. }
  4013. } else {
  4014. if len(advices) > 0 {
  4015. for _, item := range advices {
  4016. creater := c.GetAdminUserInfo().AdminUser.Id
  4017. service.DrugAutoAddCancelInfo(item, creater)
  4018. }
  4019. }
  4020. }
  4021. }
  4022. c.ServeSuccessJSON(map[string]interface{}{
  4023. "msg": "删除成功",
  4024. })
  4025. return
  4026. }
  4027. func (c *HisApiController) DeleteDoctorAdvice() {
  4028. id, _ := c.GetInt64("id")
  4029. advice, _ := service.GetHisDoctorAdvicesById(id)
  4030. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4031. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4032. //已收费和已发药的限制逻辑
  4033. isCharge := false
  4034. isMedicine := false
  4035. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4036. //获取今天该患者所有处方,判断是否发药或者收费
  4037. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4038. for _, item := range new_prescriptions {
  4039. if item.IsMedicine == 1 {
  4040. isMedicine = true
  4041. }
  4042. }
  4043. for _, item := range new_prescriptions {
  4044. if item.OrderStatus == 4 {
  4045. isCharge = true
  4046. }
  4047. }
  4048. if isMedicine {
  4049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4050. return
  4051. }
  4052. if isCharge {
  4053. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4054. return
  4055. }
  4056. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4057. for _, item := range advices {
  4058. if item.IsMedicine == 1 {
  4059. isMedicine = true
  4060. }
  4061. }
  4062. if isMedicine {
  4063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4064. return
  4065. }
  4066. if new_prescription.ID > 0 {
  4067. if new_prescription.OrderStatus == 2 {
  4068. isCharge = true
  4069. }
  4070. }
  4071. if isCharge {
  4072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4073. return
  4074. }
  4075. //已收费和已发药的限制逻辑
  4076. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4077. redis := service.RedisClient()
  4078. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4079. redis.Set(keyFive, "", time.Second)
  4080. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4081. redis.Set(keyOne, "", time.Second)
  4082. defer redis.Close()
  4083. if err == nil {
  4084. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4085. //查询是否在处方中出库
  4086. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4087. if openConfig.IsOpen != 1 {
  4088. //判断该医嘱是否执行了
  4089. if advice.ExecutionState == 1 {
  4090. creater := c.GetAdminUserInfo().AdminUser.Id
  4091. service.DrugAutoAddCancelInfo(&advice, creater)
  4092. }
  4093. }
  4094. //开启保存处方扣减功能
  4095. if openConfig.IsOpen == 1 {
  4096. creater := c.GetAdminUserInfo().AdminUser.Id
  4097. service.DrugAutoAddCancelInfo(&advice, creater)
  4098. }
  4099. } else {
  4100. if drugOutConfig.IsOpen == 1 {
  4101. //查询是否在处方中出库
  4102. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4103. if openConfig.IsOpen != 1 {
  4104. //判断该医嘱是否执行了
  4105. if advice.ExecutionState == 1 {
  4106. creater := c.GetAdminUserInfo().AdminUser.Id
  4107. service.DrugAutoAddCancelInfo(&advice, creater)
  4108. }
  4109. }
  4110. //开启保存处方扣减功能
  4111. if openConfig.IsOpen == 1 {
  4112. creater := c.GetAdminUserInfo().AdminUser.Id
  4113. service.DrugAutoAddCancelInfo(&advice, creater)
  4114. }
  4115. } else {
  4116. //判断该医嘱是否执行了
  4117. if advice.ExecutionState == 1 {
  4118. creater := c.GetAdminUserInfo().AdminUser.Id
  4119. service.DrugAutoAddCancelInfo(&advice, creater)
  4120. }
  4121. }
  4122. }
  4123. c.ServeSuccessJSON(map[string]interface{}{
  4124. "msg": "删除成功",
  4125. })
  4126. return
  4127. } else {
  4128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4129. return
  4130. }
  4131. }
  4132. func (c *HisApiController) DeleteProject() {
  4133. id, _ := c.GetInt64("id")
  4134. adminInfo := c.GetAdminUserInfo()
  4135. project, _ := service.GetHisProjectByID(id)
  4136. // var consumable models.DialysisBeforePrepare
  4137. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4138. //耗材保存处方出库
  4139. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4140. isCharge := false
  4141. isMedicine := false
  4142. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4143. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4144. for _, item := range new_prescriptions {
  4145. if item.IsMedicine == 1 {
  4146. isMedicine = true
  4147. }
  4148. }
  4149. for _, item := range new_prescriptions {
  4150. if item.OrderStatus == 4 {
  4151. isCharge = true
  4152. }
  4153. }
  4154. if isMedicine {
  4155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4156. return
  4157. }
  4158. if isCharge {
  4159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4160. return
  4161. }
  4162. if new_prescription.ID > 0 {
  4163. if new_prescription.OrderStatus == 2 {
  4164. isCharge = true
  4165. }
  4166. }
  4167. if isCharge {
  4168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4169. return
  4170. }
  4171. service.DeletePrintInfo(id)
  4172. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4173. label.Status = 0
  4174. service.CreateHisLabelRecord(&label)
  4175. fmt.Println(goodOutConfig.IsOpen)
  4176. if goodOutConfig.IsOpen != 1 {
  4177. if stockConfig.IsOpen == 1 {
  4178. if project.Type == 2 {
  4179. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4180. fmt.Println(err)
  4181. }
  4182. if project.Type == 3 && project.IsOut == 1 {
  4183. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4184. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4185. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4186. operation_time := time.Now().Unix()
  4187. creater := adminInfo.AdminUser.Id
  4188. //创建退库单
  4189. timeStr := time.Now().Format("2006-01-02")
  4190. timeArr := strings.Split(timeStr, "-")
  4191. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4192. total = total + 1
  4193. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4194. cancelStock := models.CancelStock{
  4195. OrderNumber: orderNumber,
  4196. OperaTime: operation_time,
  4197. OrgId: adminInfo.CurrentOrgId,
  4198. Creater: creater,
  4199. Ctime: time.Now().Unix(),
  4200. Status: 1,
  4201. ReturnTime: project.RecordDate,
  4202. Type: 1,
  4203. StorehouseId: houseConfig.StorehouseOutInfo,
  4204. IsCheck: 1,
  4205. }
  4206. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4207. if msgerrkonde == gorm.ErrRecordNotFound {
  4208. service.AddSigleCancelStock(&cancelStock)
  4209. }
  4210. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4211. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4212. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4213. //查询是否有出库
  4214. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4215. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4216. deaerler, _ := service.GetDealerById(info.Dealer)
  4217. if info.ID > 0 {
  4218. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4219. if info.Count >= prescribingNumber {
  4220. cancelStockInfo := models.CancelStockInfo{
  4221. GoodId: project.ProjectId,
  4222. CancelStockId: cancel.ID,
  4223. GoodTypeId: good.GoodTypeId,
  4224. Count: prescribingNumber,
  4225. Price: info.Price,
  4226. Total: 0,
  4227. ProductDate: info.ProductDate,
  4228. ExpiryDate: info.ExpiryDate,
  4229. Ctime: time.Now().Unix(),
  4230. Status: 1,
  4231. OrgId: adminInfo.CurrentOrgId,
  4232. OrderNumber: cancel.OrderNumber,
  4233. Type: 0,
  4234. Dealer: deaerler.DealerName,
  4235. Manufacturer: manufacturer.ManufacturerName,
  4236. Number: info.Number,
  4237. RegisterAccount: "",
  4238. Remark: "",
  4239. WarehouseInfoId: info.WarehouseInfotId,
  4240. PatientId: info.PatientId,
  4241. RecordDate: info.SysRecordTime,
  4242. StorehouseId: houseConfig.StorehouseOutInfo,
  4243. IsCheck: 1,
  4244. }
  4245. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4246. //回退库存
  4247. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4248. //退库数量增加
  4249. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4250. //出库数量减少
  4251. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4252. }
  4253. if info.Count < prescribingNumber {
  4254. cancelStockInfo := models.CancelStockInfo{
  4255. GoodId: project.ProjectId,
  4256. CancelStockId: cancel.ID,
  4257. GoodTypeId: good.GoodTypeId,
  4258. Count: info.Count,
  4259. Price: info.Price,
  4260. Total: 0,
  4261. ProductDate: info.ProductDate,
  4262. ExpiryDate: info.ExpiryDate,
  4263. Ctime: time.Now().Unix(),
  4264. Status: 1,
  4265. OrgId: adminInfo.CurrentOrgId,
  4266. OrderNumber: cancel.OrderNumber,
  4267. Type: 0,
  4268. Dealer: deaerler.DealerName,
  4269. Manufacturer: manufacturer.ManufacturerName,
  4270. Number: info.Number,
  4271. RegisterAccount: "",
  4272. Remark: "",
  4273. WarehouseInfoId: info.WarehouseInfotId,
  4274. PatientId: info.PatientId,
  4275. RecordDate: info.SysRecordTime,
  4276. StorehouseId: houseConfig.StorehouseOutInfo,
  4277. IsCheck: 1,
  4278. }
  4279. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4280. //回退库存
  4281. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4282. //退库数量增加
  4283. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4284. //出库数量减少
  4285. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4286. }
  4287. //查询剩余库存
  4288. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4289. var over_count int64
  4290. for _, it := range goodList {
  4291. over_count += it.StockCount
  4292. }
  4293. //出库数据 大于 退库数量
  4294. if info.Count >= prescribingNumber {
  4295. flow := models.VmStockFlow{
  4296. WarehousingId: info.WarehouseInfotId,
  4297. GoodId: project.ProjectId,
  4298. Number: info.Number,
  4299. LicenseNumber: info.LicenseNumber,
  4300. Count: prescribingNumber,
  4301. UserOrgId: adminInfo.CurrentOrgId,
  4302. PatientId: project.PatientId,
  4303. SystemTime: info.SysRecordTime,
  4304. ConsumableType: 7,
  4305. IsSys: 0,
  4306. WarehousingOrder: "",
  4307. WarehouseOutId: info.WarehouseOutId,
  4308. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4309. IsEdit: 0,
  4310. CancelStockId: cancel.ID,
  4311. CancelOrderNumber: cancel.OrderNumber,
  4312. Manufacturer: manufacturer.ID,
  4313. Dealer: 0,
  4314. Creator: adminInfo.AdminUser.Id,
  4315. UpdateCreator: 0,
  4316. Status: 1,
  4317. Ctime: time.Now().Unix(),
  4318. Mtime: 0,
  4319. Price: info.Price,
  4320. WarehousingDetailId: info.WarehouseInfotId,
  4321. WarehouseOutDetailId: info.ID,
  4322. CancelOutDetailId: cancelInfo.ID,
  4323. ProductDate: info.ProductDate,
  4324. ExpireDate: info.ExpiryDate,
  4325. StorehouseId: houseConfig.StorehouseOutInfo,
  4326. OverCount: over_count,
  4327. }
  4328. service.CreateStockFlowOne(flow)
  4329. }
  4330. //出库数据小于退库数据
  4331. if info.Count < prescribingNumber {
  4332. flow := models.VmStockFlow{
  4333. WarehousingId: info.WarehouseInfotId,
  4334. GoodId: project.ProjectId,
  4335. Number: info.Number,
  4336. LicenseNumber: info.LicenseNumber,
  4337. Count: info.Count,
  4338. UserOrgId: adminInfo.CurrentOrgId,
  4339. PatientId: project.PatientId,
  4340. SystemTime: info.SysRecordTime,
  4341. ConsumableType: 7,
  4342. IsSys: 0,
  4343. WarehousingOrder: "",
  4344. WarehouseOutId: info.WarehouseOutId,
  4345. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4346. IsEdit: 0,
  4347. CancelStockId: cancel.ID,
  4348. CancelOrderNumber: cancel.OrderNumber,
  4349. Manufacturer: manufacturer.ID,
  4350. Dealer: 0,
  4351. Creator: adminInfo.AdminUser.Id,
  4352. UpdateCreator: 0,
  4353. Status: 1,
  4354. Ctime: time.Now().Unix(),
  4355. Mtime: 0,
  4356. Price: info.Price,
  4357. WarehousingDetailId: info.WarehouseInfotId,
  4358. WarehouseOutDetailId: info.ID,
  4359. CancelOutDetailId: cancelInfo.ID,
  4360. ProductDate: info.ProductDate,
  4361. ExpireDate: info.ExpiryDate,
  4362. StorehouseId: houseConfig.StorehouseOutInfo,
  4363. OverCount: over_count,
  4364. }
  4365. service.CreateStockFlowOne(flow)
  4366. }
  4367. //查询已出库数量
  4368. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4369. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4370. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4371. if prescribingNumber < dialysisInfo.Count {
  4372. //改变数量
  4373. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4374. }
  4375. if prescribingNumber >= dialysisInfo.Count {
  4376. //删除出库表
  4377. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4378. }
  4379. //更新剩余库存
  4380. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4381. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4382. var total_count_one int64
  4383. for _, it := range stockList {
  4384. total_count_one += it.StockCount
  4385. }
  4386. //基础库插入数据
  4387. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4388. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4389. var flush_count int64
  4390. for _, it := range goodListOne {
  4391. flush_count += it.StockCount
  4392. }
  4393. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4394. if errs != nil {
  4395. goodErrcode := models.XtGoodErrcode{
  4396. UserOrgId: project.UserOrgId,
  4397. Errcode: "手动出库更新剩余出库失败",
  4398. GoodId: project.ProjectId,
  4399. Status: 1,
  4400. Ctime: time.Now().Unix(),
  4401. Mtime: 0,
  4402. Count: 0,
  4403. StockCount: 0,
  4404. Creater: creater,
  4405. BatchNumberId: 0,
  4406. WarehouseOutId: 0,
  4407. }
  4408. service.CreateGoodErrcode(goodErrcode)
  4409. }
  4410. }
  4411. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4412. fmt.Println(err)
  4413. } else {
  4414. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4415. fmt.Println(err)
  4416. }
  4417. } else {
  4418. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4419. fmt.Println(err)
  4420. }
  4421. }
  4422. //保存处方出库
  4423. if goodOutConfig.IsOpen == 1 {
  4424. if project.Type == 3 {
  4425. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4426. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4427. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4428. operation_time := time.Now().Unix()
  4429. creater := adminInfo.AdminUser.Id
  4430. //创建退库单
  4431. timeStr := time.Now().Format("2006-01-02")
  4432. timeArr := strings.Split(timeStr, "-")
  4433. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4434. total = total + 1
  4435. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4436. cancelStock := models.CancelStock{
  4437. OrderNumber: orderNumber,
  4438. OperaTime: operation_time,
  4439. OrgId: adminInfo.CurrentOrgId,
  4440. Creater: creater,
  4441. Ctime: time.Now().Unix(),
  4442. Status: 1,
  4443. ReturnTime: project.RecordDate,
  4444. Type: 1,
  4445. StorehouseId: houseConfig.StorehouseOutInfo,
  4446. IsCheck: 1,
  4447. }
  4448. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4449. if msgerrkonde == gorm.ErrRecordNotFound {
  4450. service.AddSigleCancelStock(&cancelStock)
  4451. }
  4452. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4453. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4454. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4455. //获取出库数据
  4456. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4457. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4458. deaerler, _ := service.GetDealerById(info.Dealer)
  4459. if info.ID > 0 {
  4460. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4461. if info.Count >= prescribingNumber {
  4462. cancelStockInfo := models.CancelStockInfo{
  4463. GoodId: project.ProjectId,
  4464. CancelStockId: cancel.ID,
  4465. GoodTypeId: good.GoodTypeId,
  4466. Count: prescribingNumber,
  4467. Price: info.Price,
  4468. Total: 0,
  4469. ProductDate: info.ProductDate,
  4470. ExpiryDate: info.ExpiryDate,
  4471. Ctime: time.Now().Unix(),
  4472. Status: 1,
  4473. OrgId: adminInfo.CurrentOrgId,
  4474. OrderNumber: cancel.OrderNumber,
  4475. Type: 0,
  4476. Dealer: deaerler.DealerName,
  4477. Manufacturer: manufacturer.ManufacturerName,
  4478. Number: info.Number,
  4479. RegisterAccount: "",
  4480. Remark: "",
  4481. WarehouseInfoId: info.WarehouseInfotId,
  4482. PatientId: info.PatientId,
  4483. RecordDate: info.SysRecordTime,
  4484. StorehouseId: houseConfig.StorehouseOutInfo,
  4485. IsCheck: 1,
  4486. }
  4487. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4488. //退库数量增加
  4489. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4490. //出库数量减少
  4491. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4492. }
  4493. if info.Count < prescribingNumber {
  4494. cancelStockInfo := models.CancelStockInfo{
  4495. GoodId: project.ProjectId,
  4496. CancelStockId: cancel.ID,
  4497. GoodTypeId: good.GoodTypeId,
  4498. Count: prescribingNumber,
  4499. Price: info.Price,
  4500. Total: 0,
  4501. ProductDate: info.ProductDate,
  4502. ExpiryDate: info.ExpiryDate,
  4503. Ctime: time.Now().Unix(),
  4504. Status: 1,
  4505. OrgId: adminInfo.CurrentOrgId,
  4506. OrderNumber: cancel.OrderNumber,
  4507. Type: 0,
  4508. Dealer: deaerler.DealerName,
  4509. Manufacturer: manufacturer.ManufacturerName,
  4510. Number: info.Number,
  4511. RegisterAccount: "",
  4512. Remark: "",
  4513. WarehouseInfoId: info.WarehouseInfotId,
  4514. PatientId: info.PatientId,
  4515. RecordDate: info.SysRecordTime,
  4516. StorehouseId: houseConfig.StorehouseOutInfo,
  4517. IsCheck: 1,
  4518. }
  4519. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4520. //回退库存
  4521. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4522. }
  4523. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4524. var over_count int64
  4525. for _, it := range goodList {
  4526. over_count += it.StockCount
  4527. }
  4528. //查询出库数量
  4529. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4530. //出库数据 大于 退库数量
  4531. if len(list) > 0 {
  4532. for _, it := range list {
  4533. //回退库存
  4534. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4535. //退库数量增加
  4536. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4537. //出库数量减少
  4538. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4539. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4540. var over_count_one int64
  4541. for _, it := range goodList {
  4542. over_count_one += it.StockCount
  4543. }
  4544. //查询该批次是否有退库数据
  4545. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4546. flow := models.VmStockFlow{
  4547. WarehousingId: it.WarehouseInfotId,
  4548. GoodId: it.GoodId,
  4549. Number: it.Number,
  4550. LicenseNumber: it.LicenseNumber,
  4551. Count: it.Count,
  4552. UserOrgId: adminInfo.CurrentOrgId,
  4553. PatientId: it.PatientId,
  4554. SystemTime: it.SysRecordTime,
  4555. ConsumableType: 7,
  4556. IsSys: 0,
  4557. WarehousingOrder: "",
  4558. WarehouseOutId: it.WarehouseOutId,
  4559. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4560. IsEdit: 0,
  4561. CancelStockId: cancel.ID,
  4562. CancelOrderNumber: cancel.OrderNumber,
  4563. Manufacturer: manufacturer.ID,
  4564. Dealer: 0,
  4565. Creator: adminInfo.AdminUser.Id,
  4566. UpdateCreator: 0,
  4567. Status: 1,
  4568. Ctime: time.Now().Unix(),
  4569. Mtime: 0,
  4570. Price: it.Price,
  4571. WarehousingDetailId: it.WarehouseInfotId,
  4572. WarehouseOutDetailId: it.ID,
  4573. CancelOutDetailId: cancelInfo.ID,
  4574. ProductDate: it.ProductDate,
  4575. ExpireDate: it.ExpiryDate,
  4576. StorehouseId: houseConfig.StorehouseOutInfo,
  4577. OverCount: over_count_one,
  4578. }
  4579. service.CreateStockFlowOne(flow)
  4580. }
  4581. }
  4582. //查询已出库数量
  4583. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4584. if prescribingNumber < dialysisInfo.Count {
  4585. //改变数量
  4586. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4587. }
  4588. if prescribingNumber >= dialysisInfo.Count {
  4589. //删除出库表
  4590. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4591. }
  4592. //更新剩余库存
  4593. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4594. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4595. var total_count_one int64
  4596. for _, it := range stockList {
  4597. total_count_one += it.StockCount
  4598. }
  4599. //基础库插入数据
  4600. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4601. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4602. var flush_count int64
  4603. for _, it := range goodListOne {
  4604. flush_count += it.StockCount
  4605. }
  4606. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4607. if errs != nil {
  4608. goodErrcode := models.XtGoodErrcode{
  4609. UserOrgId: project.UserOrgId,
  4610. Errcode: "手动出库更新剩余出库失败",
  4611. GoodId: project.ProjectId,
  4612. Status: 1,
  4613. Ctime: time.Now().Unix(),
  4614. Mtime: 0,
  4615. Count: 0,
  4616. StockCount: 0,
  4617. Creater: creater,
  4618. BatchNumberId: 0,
  4619. WarehouseOutId: 0,
  4620. }
  4621. service.CreateGoodErrcode(goodErrcode)
  4622. }
  4623. }
  4624. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4625. fmt.Println(err)
  4626. } else {
  4627. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4628. fmt.Println(err)
  4629. }
  4630. }
  4631. c.ServeSuccessJSON(map[string]interface{}{
  4632. "msg": "删除成功",
  4633. })
  4634. return
  4635. }
  4636. func (c *HisApiController) CreateHisAdditionalCharge() {
  4637. his_patient_id, _ := c.GetInt64("his_patient_id")
  4638. patient_id, _ := c.GetInt64("patient_id")
  4639. record_date := c.GetString("record_date")
  4640. timeLayout := "2006-01-02"
  4641. loc, _ := time.LoadLocation("Local")
  4642. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4643. if err != nil {
  4644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4645. return
  4646. }
  4647. adminInfo := c.GetAdminUserInfo()
  4648. recordDateTime := theTime.Unix()
  4649. dataBody := make(map[string]interface{}, 0)
  4650. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4651. if err != nil {
  4652. utils.ErrorLog(err.Error())
  4653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4654. return
  4655. }
  4656. var additions []*models.HisAdditionalCharge
  4657. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4658. additions, _ := dataBody["addition"].([]interface{})
  4659. if len(additions) > 0 {
  4660. for _, item := range additions {
  4661. items := item.(map[string]interface{})
  4662. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4663. utils.ErrorLog("item_id")
  4664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4665. return
  4666. }
  4667. item_id := int64(items["item_id"].(float64))
  4668. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4669. utils.ErrorLog("item_name")
  4670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4671. return
  4672. }
  4673. item_name := items["item_name"].(string)
  4674. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4675. utils.ErrorLog("price")
  4676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4677. return
  4678. }
  4679. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4680. ctime := time.Now().Unix()
  4681. additional := &models.HisAdditionalCharge{
  4682. PatientId: patient_id,
  4683. HisPatientId: his_patient_id,
  4684. UserOrgId: adminInfo.CurrentOrgId,
  4685. RecordDate: recordDateTime,
  4686. CreatedTime: ctime,
  4687. UpdatedTime: ctime,
  4688. Modifier: adminInfo.AdminUser.Id,
  4689. Creator: adminInfo.AdminUser.Id,
  4690. Price: price,
  4691. ItemName: item_name,
  4692. ItemId: item_id,
  4693. Status: 1,
  4694. }
  4695. additions = append(additions, additional)
  4696. }
  4697. }
  4698. }
  4699. for _, item := range additions {
  4700. service.CreateAddtionalCharge(item)
  4701. }
  4702. c.ServeSuccessJSON(map[string]interface{}{
  4703. "msg": "创建成功",
  4704. })
  4705. }
  4706. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4707. blood_fat := c.GetString("blood_fat")
  4708. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4709. blood_sugar := c.GetString("blood_sugar")
  4710. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4711. chief_conplaint := c.GetString("chief_conplaint")
  4712. dbp := c.GetString("dbp")
  4713. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4714. delivery_way, _ := c.GetInt64("delivery_way")
  4715. diagnostic := c.GetString("diagnostic")
  4716. family_history := c.GetString("family_history")
  4717. height := c.GetString("height")
  4718. history_of_present_illness := c.GetString("history_of_present_illness")
  4719. is_infect, _ := c.GetInt64("is_infect")
  4720. past_history := c.GetString("past_history")
  4721. patient_id, _ := c.GetInt64("patient_id")
  4722. his_patient_id, _ := c.GetInt64("his_patient_id")
  4723. personal_history := c.GetString("personal_history")
  4724. pulse := c.GetString("pulse")
  4725. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4726. sbp := c.GetString("sbp")
  4727. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4728. heightfloat, _ := strconv.ParseFloat(height, 64)
  4729. sicktype := c.GetString("sick_type")
  4730. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4731. symptom := c.GetString("symptom")
  4732. sick_date := c.GetString("sick_date")
  4733. temperatures := c.GetString("temperature")
  4734. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4735. record_date := c.GetString("record_date")
  4736. breathing := c.GetString("breathing")
  4737. doctor_advice := c.GetString("doctor_advice")
  4738. remark := c.GetString("remark")
  4739. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4740. sick, _ := c.GetInt64("sick")
  4741. diagnose, _ := c.GetInt64("diagnose")
  4742. //id, _ := c.GetInt64("id")
  4743. timeLayout := "2006-01-02"
  4744. loc, _ := time.LoadLocation("Local")
  4745. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4746. allergic_history := c.GetString("allergic_history")
  4747. if err != nil {
  4748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4749. return
  4750. }
  4751. recordDateTime := theTime.Unix()
  4752. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4753. if err != nil {
  4754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4755. return
  4756. }
  4757. sickTimes := sickTime.Unix()
  4758. ctime := time.Now().Unix()
  4759. primary_disease := c.GetString("primary_disease")
  4760. confirm_failure_date := c.GetString("confirm_failure_date")
  4761. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4762. drug_allergy_history := c.GetString("drug_allergy_history")
  4763. physical_examination := c.GetString("physical_examination")
  4764. special_inspection := c.GetString("special_inspection")
  4765. lab_apparatus := c.GetString("lab_apparatus")
  4766. caseHistory := models.HisPatientCaseHistory{
  4767. HisPatientId: his_patient_id,
  4768. PatientId: patient_id,
  4769. Temperature: temperature,
  4770. BloodSugar: bloodsugarfloat,
  4771. Pulse: pulsefloat,
  4772. Sbp: sbpfloat,
  4773. Dbp: dbpfloat,
  4774. Height: heightfloat,
  4775. BloodFat: bloodfatfloat,
  4776. SickType: sick_type,
  4777. Symptom: symptom,
  4778. SickDate: sickTimes,
  4779. IsInfect: is_infect,
  4780. HistoryOfPresentIllness: history_of_present_illness,
  4781. PastHistory: past_history,
  4782. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4783. ChiefConplaint: chief_conplaint,
  4784. PersonalHistory: personal_history,
  4785. FamilyHistory: family_history,
  4786. Diagnostic: diagnostic,
  4787. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4788. Status: 1,
  4789. Ctime: ctime,
  4790. Mtime: ctime,
  4791. RecordDate: recordDateTime,
  4792. DeliveryWay: delivery_way,
  4793. Breathing: breathingfloat,
  4794. DoctorAdvice: doctor_advice,
  4795. Remark: remark,
  4796. Sick: sick,
  4797. Diagnose: diagnose,
  4798. AllergicHistory: allergic_history,
  4799. PrimaryDisease: primary_disease,
  4800. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4801. DrugAllergyHistory: drug_allergy_history,
  4802. PhysicalExamination: physical_examination,
  4803. SpecialInspection: special_inspection,
  4804. LabApparatus: lab_apparatus,
  4805. }
  4806. //查询该患者是否有病历
  4807. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4808. if errcodes == gorm.ErrRecordNotFound {
  4809. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4810. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4811. if err != nil {
  4812. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4813. return
  4814. }
  4815. c.ServeSuccessJSON(map[string]interface{}{
  4816. "caseHistory": caseHistory,
  4817. "historyInfo": historyInfo,
  4818. })
  4819. return
  4820. } else if errcodes == nil {
  4821. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4822. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4823. if err != nil {
  4824. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4825. return
  4826. }
  4827. c.ServeSuccessJSON(map[string]interface{}{
  4828. "caseHistory": caseHistory,
  4829. "historyInfo": historyInfo,
  4830. })
  4831. }
  4832. //查询该患者是否有病历
  4833. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4834. //if errcode == gorm.ErrRecordNotFound {
  4835. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4836. // if err != nil {
  4837. // c.ServeSuccessJSON(map[string]interface{}{
  4838. // "msg": "保存成功",
  4839. // })
  4840. // }
  4841. //} else if errcode == nil {
  4842. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4843. // return
  4844. //}
  4845. }
  4846. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4847. patient_id, _ := c.GetInt64("patient_id", 0)
  4848. adminUser := c.GetAdminUserInfo()
  4849. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4850. c.ServeSuccessJSON(map[string]interface{}{
  4851. "list": caseHistorys,
  4852. })
  4853. }
  4854. func (c *HisApiController) GetHisPatientCaseHistory() {
  4855. record_date, _ := c.GetInt64("record_date", 0)
  4856. patient_id, _ := c.GetInt64("patient_id", 0)
  4857. admin := c.GetAdminUserInfo()
  4858. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4859. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4860. c.ServeSuccessJSON(map[string]interface{}{
  4861. "info": info,
  4862. "case_history": case_history,
  4863. })
  4864. }
  4865. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4866. template_name := c.GetString("template_name")
  4867. template_remark := c.GetString("template_remark")
  4868. doctor := c.GetAdminUserInfo().AdminUser.Id
  4869. diagnostic := c.GetString("diagnostic")
  4870. chief_conplaint := c.GetString("chief_conplain")
  4871. history_of_present_illness := c.GetString("history_of_present_illness")
  4872. past_history := c.GetString("past_history")
  4873. personal_history := c.GetString("personal_history")
  4874. family_history := c.GetString("family_history")
  4875. user_name := c.GetString("user_name")
  4876. doctor_advice := c.GetString("doctor_advice")
  4877. remark := c.GetString("remark")
  4878. //record_date := c.GetString("record_date")
  4879. //fmt.Println("record_date--------",record_date)
  4880. //timeLayout := "2006-01-02"
  4881. //loc, _ := time.LoadLocation("Local")
  4882. //
  4883. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4884. //if err != nil {
  4885. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4886. // return
  4887. //}
  4888. //recordDateTime := theTime.Unix()
  4889. ctime := time.Now().Unix()
  4890. template := models.HisCaseHistoryTemplate{
  4891. HistoryOfPresentIllness: history_of_present_illness,
  4892. PastHistory: past_history,
  4893. ChiefConplaint: chief_conplaint,
  4894. PersonalHistory: personal_history,
  4895. FamilyHistory: family_history,
  4896. Diagnostic: diagnostic,
  4897. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4898. Status: 1,
  4899. Ctime: ctime,
  4900. Mtime: ctime,
  4901. RecordDate: time.Now().Unix(),
  4902. TemplateName: template_name,
  4903. TemplateRemark: template_remark,
  4904. Creator: doctor,
  4905. Modifier: doctor,
  4906. UserName: user_name,
  4907. DoctorAdvice: doctor_advice,
  4908. Remark: remark,
  4909. }
  4910. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4911. if err == nil {
  4912. c.ServeSuccessJSON(map[string]interface{}{
  4913. "msg": "保存成功",
  4914. })
  4915. } else {
  4916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4917. return
  4918. }
  4919. }
  4920. func (c *HisApiController) GetCaseHistoryTemplate() {
  4921. timeLayout := "2006-01-02"
  4922. loc, _ := time.LoadLocation("Local")
  4923. keyword := c.GetString("keyword")
  4924. start_time := c.GetString("start_time")
  4925. end_time := c.GetString("end_time")
  4926. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4927. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4928. admin := c.GetAdminUserInfo()
  4929. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4930. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4931. c.ServeSuccessJSON(map[string]interface{}{
  4932. "template": template,
  4933. //"history": history,
  4934. })
  4935. }
  4936. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4937. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4938. utils.ErrorLog("drug_name")
  4939. return enums.ErrorCodeParamWrong
  4940. }
  4941. adviceName, _ := json["drug_name"].(string)
  4942. if len(adviceName) == 0 {
  4943. utils.ErrorLog("len(advice_name) == 0")
  4944. return enums.ErrorCodeParamWrong
  4945. }
  4946. advice.AdviceName = adviceName
  4947. adviceDesc, _ := json["advice_desc"].(string)
  4948. advice.AdviceDesc = adviceDesc
  4949. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4950. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4951. advice.DrugSpec = drugSpec
  4952. }
  4953. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4954. remark, _ := json["remark"].(string)
  4955. advice.Remark = remark
  4956. }
  4957. if json["id"] == nil {
  4958. advice.DrugId = 0
  4959. } else {
  4960. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4961. drug_id := int64(json["id"].(float64))
  4962. advice.DrugId = drug_id
  4963. }
  4964. }
  4965. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4966. advice_id := int64(json["advice_id"].(float64))
  4967. advice.ID = advice_id
  4968. if advice.ID > 0 {
  4969. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4970. if err == nil {
  4971. if hisAdvice.ID > 0 {
  4972. advice.ExecutionTime = hisAdvice.ExecutionTime
  4973. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4974. advice.ExecutionState = hisAdvice.ExecutionState
  4975. advice.CheckTime = hisAdvice.CheckTime
  4976. advice.Checker = hisAdvice.Checker
  4977. advice.CheckState = hisAdvice.CheckState
  4978. advice.StartTime = hisAdvice.StartTime
  4979. advice.FeedetlSn = hisAdvice.FeedetlSn
  4980. }
  4981. }
  4982. }
  4983. }
  4984. //
  4985. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4986. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4987. // advice.ExecutionTime = execution_time
  4988. //}
  4989. //
  4990. //
  4991. //
  4992. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4993. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4994. // advice.ExecutionStaff = execution_staff
  4995. //}
  4996. //
  4997. //
  4998. //
  4999. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5000. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5001. // advice.ExecutionState = execution_state
  5002. //}
  5003. //
  5004. //
  5005. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5006. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5007. // advice.CheckTime = check_time
  5008. //}
  5009. //
  5010. //
  5011. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5012. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5013. // advice.CheckState = check_state
  5014. //}
  5015. //
  5016. //
  5017. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5018. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5019. // advice.Checker = checker
  5020. //}
  5021. //
  5022. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5023. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5024. // advice.StartTime = start_time
  5025. //}
  5026. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5027. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5028. advice.IsSelfDrug = is_self_drug
  5029. }
  5030. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5031. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5032. drug_way_count, _ := json["drug_way_count"].(string)
  5033. advice.DrugWayCount = drug_way_count
  5034. }
  5035. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5036. drugSpecUnit, _ := json["min_unit"].(string)
  5037. advice.DrugSpecUnit = drugSpecUnit
  5038. }
  5039. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5040. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5041. advice.SingleDose = singleDose
  5042. }
  5043. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5044. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5045. advice.SingleDoseUnit = singleDoseUnit
  5046. }
  5047. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5048. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5049. advice.PrescribingNumber = prescribingNumber
  5050. }
  5051. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5052. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5053. advice.PrescribingNumberUnit = prescribingNumberUnit
  5054. }
  5055. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5056. deliveryWay, _ := json["delivery_way"].(string)
  5057. advice.DeliveryWay = deliveryWay
  5058. }
  5059. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5060. executionFrequency, _ := json["execution_frequency"].(string)
  5061. advice.ExecutionFrequency = executionFrequency
  5062. }
  5063. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5064. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5065. advice.Price = price
  5066. }
  5067. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5068. med_list_codg, _ := json["medical_insurance_number"].(string)
  5069. advice.MedListCodg = med_list_codg
  5070. }
  5071. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5072. day := int64(json["day"].(float64))
  5073. advice.Day = day
  5074. }
  5075. return 0
  5076. }
  5077. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5078. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5079. id := int64(json["id"].(float64))
  5080. project.ID = id
  5081. historyProject, _ := service.GetHisProjectByID(id)
  5082. project.FeedetlSn = historyProject.FeedetlSn
  5083. }
  5084. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5085. project_id := int64(json["project_id"].(float64))
  5086. project.ProjectId = project_id
  5087. }
  5088. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5089. // price := int64(json["price"].(float64))
  5090. // formatInt_price := strconv.FormatInt(price, 10)
  5091. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5092. // project.Price = float_price
  5093. // }
  5094. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5095. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5096. project.Price = price
  5097. }
  5098. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5099. total, _ := json["total"].(string)
  5100. project.Count = total
  5101. }
  5102. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5103. medical_code, _ := json["medical_code"].(string)
  5104. project.MedListCodg = medical_code
  5105. }
  5106. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5107. single_dose, _ := json["single_dose"].(string)
  5108. project.SingleDose = single_dose
  5109. }
  5110. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5111. delivery_way, _ := json["delivery_way"].(string)
  5112. project.DeliveryWay = delivery_way
  5113. }
  5114. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5115. execution_frequency, _ := json["execution_frequency"].(string)
  5116. project.ExecutionFrequency = execution_frequency
  5117. }
  5118. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5119. remark, _ := json["remark"].(string)
  5120. project.Remark = remark
  5121. }
  5122. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5123. day, _ := json["number_days"].(string)
  5124. project.Day = day
  5125. }
  5126. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5127. unit, _ := json["unit"].(string)
  5128. project.Unit = unit
  5129. }
  5130. return 0
  5131. }
  5132. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5133. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5134. id := int64(json["id"].(float64))
  5135. historyAddtions, _ := service.GetHisAdditionByID(id)
  5136. additionalCharge.ID = id
  5137. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5138. }
  5139. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5140. item_id := int64(json["item_id"].(float64))
  5141. additionalCharge.ItemId = item_id
  5142. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5143. if config.ID > 0 {
  5144. if len(config.Code) > 0 {
  5145. additionalCharge.MedListCodg = config.Code
  5146. }
  5147. }
  5148. }
  5149. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5150. // price := int64(json["price"].(float64))
  5151. // formatInt_price := strconv.FormatInt(price, 10)
  5152. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5153. // additionalCharge.Price = float_price
  5154. // }
  5155. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5156. // price := int64(json["price"].(float64))
  5157. // formatInt_price := strconv.FormatInt(price, 10)
  5158. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5159. // additionalCharge.Price = float_price
  5160. //}
  5161. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5162. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5163. additionalCharge.Price = price
  5164. }
  5165. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5166. count, _ := json["count"].(string)
  5167. counts, _ := strconv.ParseInt(count, 10, 64)
  5168. additionalCharge.Count = counts
  5169. }
  5170. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5171. item_name, _ := json["item_name"].(string)
  5172. additionalCharge.ItemName = item_name
  5173. }
  5174. return 0
  5175. }
  5176. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5177. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5178. utils.ErrorLog("drug_name")
  5179. return enums.ErrorCodeParamWrong
  5180. }
  5181. adviceName, _ := json["drug_name"].(string)
  5182. if len(adviceName) == 0 {
  5183. utils.ErrorLog("len(advice_name) == 0")
  5184. return enums.ErrorCodeParamWrong
  5185. }
  5186. advice.AdviceName = adviceName
  5187. adviceDesc, _ := json["advice_desc"].(string)
  5188. advice.AdviceDesc = adviceDesc
  5189. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5190. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5191. advice.DrugSpec = drugSpec
  5192. }
  5193. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5194. remark, _ := json["remark"].(string)
  5195. advice.Remark = remark
  5196. }
  5197. if json["id"] == nil {
  5198. advice.DrugId = 0
  5199. } else {
  5200. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5201. drug_id := int64(json["id"].(float64))
  5202. advice.DrugId = drug_id
  5203. }
  5204. }
  5205. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5206. groupno := int64(json["groupno"].(float64))
  5207. advice.Groupno = groupno
  5208. }
  5209. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5210. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5211. advice.IsSelfDrug = is_self_drug
  5212. }
  5213. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5214. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5215. drug_way_count, _ := json["drug_way_count"].(string)
  5216. advice.DrugWayCount = drug_way_count
  5217. }
  5218. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5219. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5220. advice.HospApprFlag = hosp_appr_flag
  5221. }
  5222. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5223. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5224. advice.PrescribingNumber = prescribingNumber
  5225. }
  5226. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5227. // frequency_type := int64(json["frequency_type"].(float64))
  5228. // advice.FrequencyType = frequency_type
  5229. //}
  5230. //
  5231. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5232. // day_count := int64(json["day_count"].(float64))
  5233. // advice.DayCount = day_count
  5234. //}
  5235. //
  5236. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5237. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5238. // week_day, _ := json["week_day"].(string)
  5239. // advice.WeekDay = week_day
  5240. //}
  5241. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5242. drugSpecUnit, _ := json["min_unit"].(string)
  5243. advice.DrugSpecUnit = drugSpecUnit
  5244. }
  5245. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5246. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5247. advice.SingleDose = singleDose
  5248. }
  5249. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5250. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5251. advice.SingleDoseUnit = singleDoseUnit
  5252. }
  5253. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5254. deliveryWay, _ := json["delivery_way"].(string)
  5255. advice.DeliveryWay = deliveryWay
  5256. }
  5257. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5258. executionFrequency, _ := json["execution_frequency"].(string)
  5259. advice.ExecutionFrequency = executionFrequency
  5260. }
  5261. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5262. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5263. advice.Price = price
  5264. }
  5265. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5266. med_list_codg, _ := json["medical_insurance_number"].(string)
  5267. advice.MedListCodg = med_list_codg
  5268. }
  5269. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5270. day := int64(json["day"].(float64))
  5271. advice.Day = day
  5272. }
  5273. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5274. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5275. advice.PrescribingNumberUnit = prescribingNumberUnit
  5276. }
  5277. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5278. advice_id := int64(json["advice_id"].(float64))
  5279. advice.ID = advice_id
  5280. if advice.ID > 0 {
  5281. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5282. if err == nil {
  5283. if hisAdvice.ID > 0 {
  5284. advice.ExecutionTime = hisAdvice.ExecutionTime
  5285. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5286. advice.ExecutionState = hisAdvice.ExecutionState
  5287. advice.CheckTime = hisAdvice.CheckTime
  5288. advice.Checker = hisAdvice.Checker
  5289. advice.CheckState = hisAdvice.CheckState
  5290. advice.StartTime = hisAdvice.StartTime
  5291. advice.HospApprFlag = hisAdvice.HospApprFlag
  5292. advice.IsMedicine = hisAdvice.IsMedicine
  5293. if hisAdvice.UserOrgId == 10028 {
  5294. 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 {
  5295. advice.ExecutionTime = 0
  5296. advice.ExecutionStaff = 0
  5297. advice.ExecutionState = 2
  5298. advice.CheckTime = 0
  5299. advice.Checker = 0
  5300. advice.CheckState = 2
  5301. }
  5302. } else {
  5303. 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 {
  5304. advice.ExecutionTime = 0
  5305. advice.ExecutionStaff = 0
  5306. advice.ExecutionState = 2
  5307. advice.CheckTime = 0
  5308. advice.Checker = 0
  5309. advice.CheckState = 2
  5310. }
  5311. }
  5312. //advice.Groupno = hisAdvice.Groupno
  5313. }
  5314. }
  5315. }
  5316. }
  5317. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5318. //
  5319. //if drugStockConfig.IsOpen == 1 {
  5320. //
  5321. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5322. // if advice.ID == 0 { //医嘱不存在
  5323. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5324. // drug.Total = drug.Total - advice.PrescribingNumber
  5325. // service.UpdateBaseDrugLib(&drug)
  5326. //
  5327. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5328. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5329. // drug.Total = drug.Total - num
  5330. // service.UpdateBaseDrugLib(&drug)
  5331. // }
  5332. //
  5333. // } else if advice.ID > 0 { //医嘱存在
  5334. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5335. // var num float64
  5336. //
  5337. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5338. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5339. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5340. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5341. // drug.Total = drug.Total + num
  5342. // service.UpdateBaseDrugLib(&drug)
  5343. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5344. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5345. // drug.Total = drug.Total - num
  5346. // service.UpdateBaseDrugLib(&drug)
  5347. // }
  5348. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5349. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5350. // if num2 > advice.PrescribingNumber {
  5351. // num = num2 - advice.PrescribingNumber
  5352. // drug.Total = drug.Total + num
  5353. // service.UpdateBaseDrugLib(&drug)
  5354. // } else if num2 < advice.PrescribingNumber {
  5355. // num = advice.PrescribingNumber - num2
  5356. // drug.Total = drug.Total - num
  5357. // service.UpdateBaseDrugLib(&drug)
  5358. // }
  5359. //
  5360. // }
  5361. //
  5362. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5363. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5364. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5365. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5366. // if num1 > num2 {
  5367. // num = num1 - num2
  5368. // drug.Total = drug.Total + num
  5369. // service.UpdateBaseDrugLib(&drug)
  5370. // } else if num1 < num2 {
  5371. // num = num2 - num1
  5372. // drug.Total = drug.Total - num
  5373. // service.UpdateBaseDrugLib(&drug)
  5374. // }
  5375. //
  5376. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5377. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5378. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5379. // if hisAdvice.PrescribingNumber > num2 {
  5380. // num = hisAdvice.PrescribingNumber - num2
  5381. // drug.Total = drug.Total + num
  5382. // service.UpdateBaseDrugLib(&drug)
  5383. // } else if num2 < advice.PrescribingNumber {
  5384. // num = num2 - hisAdvice.PrescribingNumber
  5385. // drug.Total = drug.Total - num
  5386. // service.UpdateBaseDrugLib(&drug)
  5387. // }
  5388. //
  5389. // }
  5390. // }
  5391. // }
  5392. //}
  5393. //
  5394. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5395. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5396. // advice.ExecutionTime = execution_time
  5397. //}
  5398. //
  5399. //
  5400. //
  5401. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5402. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5403. // advice.ExecutionStaff = execution_staff
  5404. //}
  5405. //
  5406. //
  5407. //
  5408. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5409. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5410. // advice.ExecutionState = execution_state
  5411. //}
  5412. //
  5413. //
  5414. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5415. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5416. // advice.CheckTime = check_time
  5417. //}
  5418. //
  5419. //
  5420. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5421. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5422. // advice.CheckState = check_state
  5423. //}
  5424. //
  5425. //
  5426. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5427. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5428. // advice.Checker = checker
  5429. //}
  5430. //
  5431. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5432. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5433. // advice.StartTime = start_time
  5434. //}
  5435. return 0
  5436. }
  5437. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5438. project.ExecutionStaff = 0
  5439. project.ExecutionState = 2
  5440. project.ExecutionTime = 0
  5441. project.Checker = 0
  5442. project.CheckState = 2
  5443. project.CheckTime = 0
  5444. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5445. id := int64(json["id"].(float64))
  5446. project.ID = id
  5447. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5448. project.ExecutionStaff = temp_project.ExecutionStaff
  5449. project.ExecutionState = temp_project.ExecutionState
  5450. project.ExecutionTime = temp_project.ExecutionTime
  5451. project.Checker = temp_project.Checker
  5452. project.CheckState = temp_project.CheckState
  5453. project.CheckTime = temp_project.CheckTime
  5454. project.TeamId = temp_project.TeamId
  5455. }
  5456. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5457. types := int64(json["type"].(float64))
  5458. project.Type = types
  5459. }
  5460. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5461. project_id := int64(json["project_id"].(float64))
  5462. project.ProjectId = project_id
  5463. }
  5464. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5465. team_id := int64(json["team_id"].(float64))
  5466. project.TeamId = team_id
  5467. }
  5468. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5469. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5470. project.Price = price
  5471. }
  5472. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5473. total, _ := json["total"].(string)
  5474. //totals, _ := strconv.ParseInt(total, 10, 64)
  5475. project.Count = total
  5476. }
  5477. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5478. medical_code, _ := json["medical_code"].(string)
  5479. project.MedListCodg = medical_code
  5480. }
  5481. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5482. single_dose, _ := json["single_dose"].(string)
  5483. project.SingleDose = single_dose
  5484. }
  5485. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5486. delivery_way, _ := json["delivery_way"].(string)
  5487. project.DeliveryWay = delivery_way
  5488. }
  5489. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5490. execution_frequency, _ := json["execution_frequency"].(string)
  5491. project.ExecutionFrequency = execution_frequency
  5492. }
  5493. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5494. remark, _ := json["remark"].(string)
  5495. project.Remark = remark
  5496. }
  5497. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5498. day, _ := json["number_days"].(string)
  5499. project.Day = day
  5500. }
  5501. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5502. unit, _ := json["unit"].(string)
  5503. project.Unit = unit
  5504. }
  5505. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5506. // frequency_type := int64(json["frequency_type"].(float64))
  5507. // project.FrequencyType = frequency_type
  5508. //}
  5509. //
  5510. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5511. // day_count := int64(json["day_count"].(float64))
  5512. // project.DayCount = day_count
  5513. //}
  5514. //
  5515. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5516. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5517. // week_day, _ := json["week_day"].(string)
  5518. // project.WeekDay = week_day
  5519. //}
  5520. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5521. //
  5522. //if project.ID == 0 {
  5523. // if stockConfig.IsOpen == 1 {
  5524. // if project.Type == 3 {
  5525. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5526. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5527. // good.Total = good.Total - f_count
  5528. // service.UpdateGoodInfo(&good)
  5529. // }
  5530. // }
  5531. //
  5532. //} else {
  5533. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5534. //
  5535. // if stockConfig.IsOpen == 1 {
  5536. // if project.Type == 3 {
  5537. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5538. // if project.Count < temp_project.Count {
  5539. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5540. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5541. //
  5542. // other_count := f_count_two - f_count_one
  5543. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5544. // good.Total = good.Total + other_count_two
  5545. // service.UpdateGoodInfo(&good)
  5546. // } else if project.Count > temp_project.Count {
  5547. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5548. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5549. //
  5550. // other_count := f_count_one - f_count_two
  5551. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5552. // good.Total = good.Total - other_count_two
  5553. // service.UpdateGoodInfo(&good)
  5554. // }
  5555. //
  5556. // }
  5557. // }
  5558. //
  5559. //}
  5560. return 0
  5561. }
  5562. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5563. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5564. id := int64(json["id"].(float64))
  5565. additionalCharge.ID = id
  5566. }
  5567. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5568. item_id := int64(json["item_id"].(float64))
  5569. additionalCharge.ItemId = item_id
  5570. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5571. if config.ID > 0 {
  5572. if len(config.Code) > 0 {
  5573. additionalCharge.MedListCodg = config.Code
  5574. }
  5575. }
  5576. }
  5577. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5578. // price := int64(json["price"].(float64))
  5579. // formatInt_price := strconv.FormatInt(price, 10)
  5580. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5581. // additionalCharge.Price = float_price
  5582. // }
  5583. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5584. // price := int64(json["price"].(float64))
  5585. // formatInt_price := strconv.FormatInt(price, 10)
  5586. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5587. // additionalCharge.Price = float_price
  5588. //}
  5589. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5590. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5591. additionalCharge.Price = price
  5592. }
  5593. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5594. count, _ := json["count"].(string)
  5595. counts, _ := strconv.ParseInt(count, 10, 64)
  5596. additionalCharge.Count = counts
  5597. }
  5598. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5599. item_name, _ := json["item_name"].(string)
  5600. additionalCharge.ItemName = item_name
  5601. }
  5602. return 0
  5603. }
  5604. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5605. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5606. utils.ErrorLog("drug_name")
  5607. return enums.ErrorCodeParamWrong
  5608. }
  5609. adviceName, _ := json["drug_name"].(string)
  5610. if len(adviceName) == 0 {
  5611. utils.ErrorLog("len(advice_name) == 0")
  5612. return enums.ErrorCodeParamWrong
  5613. }
  5614. advice.AdviceName = adviceName
  5615. adviceDesc, _ := json["advice_desc"].(string)
  5616. advice.AdviceDesc = adviceDesc
  5617. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5618. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5619. advice.DrugSpec = drugSpec
  5620. }
  5621. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5622. remark, _ := json["remark"].(string)
  5623. advice.Remark = remark
  5624. }
  5625. if json["id"] == nil {
  5626. advice.DrugId = 0
  5627. } else {
  5628. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5629. drug_id := int64(json["id"].(float64))
  5630. advice.DrugId = drug_id
  5631. }
  5632. }
  5633. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5634. groupno := int64(json["groupno"].(float64))
  5635. advice.Groupno = groupno
  5636. }
  5637. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5638. drugSpecUnit, _ := json["min_unit"].(string)
  5639. advice.DrugSpecUnit = drugSpecUnit
  5640. }
  5641. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5642. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5643. advice.SingleDose = singleDose
  5644. }
  5645. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5646. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5647. advice.SingleDoseUnit = singleDoseUnit
  5648. }
  5649. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5650. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5651. advice.PrescribingNumber = prescribingNumber
  5652. }
  5653. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5654. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5655. advice.PrescribingNumberUnit = prescribingNumberUnit
  5656. }
  5657. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5658. deliveryWay, _ := json["delivery_way"].(string)
  5659. advice.DeliveryWay = deliveryWay
  5660. }
  5661. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5662. executionFrequency, _ := json["execution_frequency"].(string)
  5663. advice.ExecutionFrequency = executionFrequency
  5664. }
  5665. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5666. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5667. advice.Price = price
  5668. }
  5669. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5670. med_list_codg, _ := json["medical_insurance_number"].(string)
  5671. advice.MedListCodg = med_list_codg
  5672. }
  5673. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5674. day := int64(json["day"].(float64))
  5675. advice.Day = day
  5676. }
  5677. advice.FrequencyType = 1
  5678. return 0
  5679. }
  5680. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5681. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5682. types := int64(json["type"].(float64))
  5683. project.Type = types
  5684. }
  5685. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5686. project_id := int64(json["project_id"].(float64))
  5687. project.ProjectId = project_id
  5688. }
  5689. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5690. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5691. project.Price = price
  5692. }
  5693. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5694. total, _ := json["total"].(string)
  5695. //totals, _ := strconv.ParseInt(total, 10, 64)
  5696. project.Count = total
  5697. }
  5698. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5699. medical_code, _ := json["medical_code"].(string)
  5700. project.MedListCodg = medical_code
  5701. }
  5702. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5703. single_dose, _ := json["single_dose"].(string)
  5704. project.SingleDose = single_dose
  5705. }
  5706. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5707. delivery_way, _ := json["delivery_way"].(string)
  5708. project.DeliveryWay = delivery_way
  5709. }
  5710. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5711. execution_frequency, _ := json["execution_frequency"].(string)
  5712. project.ExecutionFrequency = execution_frequency
  5713. }
  5714. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5715. remark, _ := json["remark"].(string)
  5716. project.Remark = remark
  5717. }
  5718. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5719. day, _ := json["number_days"].(string)
  5720. project.Day = day
  5721. }
  5722. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5723. unit, _ := json["unit"].(string)
  5724. project.Unit = unit
  5725. }
  5726. project.FrequencyType = 1
  5727. return 0
  5728. }
  5729. func (c *HisApiController) GetHisOrderList() {
  5730. page, _ := c.GetInt64("page", -1)
  5731. limit, _ := c.GetInt64("limit", -1)
  5732. start_time := c.GetString("start_time")
  5733. end_time := c.GetString("end_time")
  5734. types, _ := c.GetInt64("type", 0)
  5735. keywords := c.GetString("keywords")
  5736. p_type, _ := c.GetInt64("p_type", 0)
  5737. sort_type, _ := c.GetInt64("sort_type", 0)
  5738. charge_type, _ := c.GetInt64("charge_type", 0)
  5739. sch_type, _ := c.GetInt64("sch_type", 0)
  5740. zone_type, _ := c.GetInt64("zone_type", 0)
  5741. med_type, _ := c.GetInt64("med_type", 0)
  5742. timeLayout := "2006-01-02"
  5743. loc, _ := time.LoadLocation("Local")
  5744. var startTime int64
  5745. if len(start_time) > 0 {
  5746. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5747. if err != nil {
  5748. //fmt.Println(err)
  5749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5750. return
  5751. }
  5752. startTime = theTime.Unix()
  5753. }
  5754. var endTime int64
  5755. if len(end_time) > 0 {
  5756. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5757. if err != nil {
  5758. utils.ErrorLog(err.Error())
  5759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5760. return
  5761. }
  5762. endTime = theTime.Unix()
  5763. }
  5764. adminUser := c.GetAdminUserInfo()
  5765. org_id := adminUser.CurrentOrgId
  5766. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  5767. for _, item := range order {
  5768. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5769. item.DoctorName = info.Doctor
  5770. item.DepartmentName = info.XtHisDepartment.Name
  5771. }
  5772. if err == nil {
  5773. c.ServeSuccessJSON(map[string]interface{}{
  5774. "order": order,
  5775. "total": total,
  5776. })
  5777. } else {
  5778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5779. return
  5780. }
  5781. }
  5782. func (c *HisApiController) GetHisOrder() {
  5783. patient_id, _ := c.GetInt64("patient_id", 0)
  5784. number := c.GetString("number")
  5785. adminInfo := c.GetAdminUserInfo()
  5786. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5787. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5788. if err == nil {
  5789. c.ServeSuccessJSON(map[string]interface{}{
  5790. "order": order,
  5791. "prescription": prescriptions,
  5792. })
  5793. } else {
  5794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5795. return
  5796. }
  5797. }
  5798. func (c *HisApiController) GetHisPrescriptionList() {
  5799. record_date := c.GetString("record_date")
  5800. keywords := c.GetString("keywords")
  5801. page, _ := c.GetInt64("page")
  5802. limit, _ := c.GetInt64("limit")
  5803. sch_type, _ := c.GetInt64("sch_type")
  5804. timeLayout := "2006-01-02"
  5805. loc, _ := time.LoadLocation("Local")
  5806. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5807. if err != nil {
  5808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5809. return
  5810. }
  5811. recordDateTime := theTime.Unix()
  5812. adminInfo := c.GetAdminUserInfo()
  5813. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5814. //adminInfo := c.GetAdminUserInfo()
  5815. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5816. //fmt.Println(prescriptionOrder)
  5817. if err == nil {
  5818. c.ServeSuccessJSON(map[string]interface{}{
  5819. "order": prescriptionOrder,
  5820. "total": total,
  5821. })
  5822. } else {
  5823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5824. return
  5825. }
  5826. }
  5827. func (c *HisApiController) GetHisPrescriptionInfo() {
  5828. id, _ := c.GetInt64("id")
  5829. adminInfo := c.GetAdminUserInfo()
  5830. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5831. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5832. if err == nil {
  5833. c.ServeSuccessJSON(map[string]interface{}{
  5834. "order": prescriptionOrder,
  5835. "prescription": prescription,
  5836. })
  5837. } else {
  5838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5839. return
  5840. }
  5841. }
  5842. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5843. adminUser := c.GetAdminUserInfo()
  5844. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5845. c.ServeSuccessJSON(map[string]interface{}{
  5846. "config": config,
  5847. })
  5848. }
  5849. type ResultTwo struct {
  5850. ErrMsg interface{} `json:"err_msg"`
  5851. InfRefmsgid string `json:"inf_refmsgid"`
  5852. Infcode int64 `json:"infcode"`
  5853. Output struct {
  5854. Baseinfo struct {
  5855. Age float64 `json:"age"`
  5856. Brdy string `json:"brdy"`
  5857. Certno string `json:"certno"`
  5858. Gend string `json:"gend"`
  5859. Naty string `json:"naty"`
  5860. PsnCertType string `json:"psn_cert_type"`
  5861. PsnName string `json:"psn_name"`
  5862. PsnNo string `json:"psn_no"`
  5863. } `json:"baseinfo"`
  5864. Idetinfo []interface{} `json:"idetinfo"`
  5865. Iinfo []struct {
  5866. Balc float64 `json:"balc"`
  5867. CvlservFlag string `json:"cvlserv_flag"`
  5868. EmpName string `json:"emp_name"`
  5869. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5870. Insutype string `json:"insutype"`
  5871. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5872. PausInsuDate interface{} `json:"paus_insu_date"`
  5873. PsnInsuDate string `json:"psn_insu_date"`
  5874. PsnInsuStas string `json:"psn_insu_stas"`
  5875. PsnType string `json:"psn_type"`
  5876. } `json:"insuinfo"`
  5877. } `json:"output"`
  5878. RefmsgTime string `json:"refmsg_time"`
  5879. RespondTime string `json:"respond_time"`
  5880. Signtype interface{} `json:"signtype"`
  5881. WarnInfo interface{} `json:"warn_info"`
  5882. }
  5883. type ResultThree struct {
  5884. Cainfo interface{} `json:"cainfo"`
  5885. ErrMsg interface{} `json:"err_msg"`
  5886. InfRefmsgid string `json:"inf_refmsgid"`
  5887. Infcode int64 `json:"infcode"`
  5888. Output struct {
  5889. Data struct {
  5890. IptOtpNo string `json:"ipt_otp_no"`
  5891. MdtrtID string `json:"mdtrt_id"`
  5892. PsnNo string `json:"psn_no"`
  5893. } `json:"data"`
  5894. } `json:"output"`
  5895. RefmsgTime string `json:"refmsg_time"`
  5896. RespondTime string `json:"respond_time"`
  5897. Signtype interface{} `json:"signtype"`
  5898. WarnMsg interface{} `json:"warn_msg"`
  5899. }
  5900. type ResultFour struct {
  5901. Cainfo string `json:"cainfo"`
  5902. ErrMsg string `json:"err_msg"`
  5903. InfRefmsgid string `json:"inf_refmsgid"`
  5904. Infcode int64 `json:"infcode"`
  5905. Output struct {
  5906. Result []struct {
  5907. BasMednFlag string `json:"bas_medn_flag"`
  5908. ChldMedcFlag string `json:"chld_medc_flag"`
  5909. ChrgitmLv string `json:"chrgitm_lv"`
  5910. Cnt float64 `json:"cnt"`
  5911. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5912. DrtReimFlag string `json:"drt_reim_flag"`
  5913. FeedetlSn string `json:"feedetl_sn"`
  5914. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5915. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5916. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5917. ListSpItemFlag string `json:"list_sp_item_flag"`
  5918. LmtUsedFlag string `json:"lmt_used_flag"`
  5919. MedChrgitmType string `json:"med_chrgitm_type"`
  5920. Memo string `json:"memo"`
  5921. OverlmtAmt float64 `json:"overlmt_amt"`
  5922. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5923. Pric float64 `json:"pric"`
  5924. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5925. SelfpayProp float64 `json:"selfpay_prop"`
  5926. } `json:"result"`
  5927. } `json:"output"`
  5928. RefmsgTime string `json:"refmsg_time"`
  5929. RespondTime string `json:"respond_time"`
  5930. Signtype string `json:"signtype"`
  5931. WarnMsg string `json:"warn_msg"`
  5932. }
  5933. type ResultFive struct {
  5934. Insutype string `json:"insutype"`
  5935. }
  5936. type ResultSix struct {
  5937. Cainfo interface{} `json:"cainfo"`
  5938. ErrMsg interface{} `json:"err_msg"`
  5939. InfRefmsgid string `json:"inf_refmsgid"`
  5940. Infcode int64 `json:"infcode"`
  5941. Output struct {
  5942. } `json:"output"`
  5943. RefmsgTime string `json:"refmsg_time"`
  5944. RespondTime string `json:"respond_time"`
  5945. Signtype interface{} `json:"signtype"`
  5946. WarnMsg interface{} `json:"warn_msg"`
  5947. }
  5948. type ResultSeven struct {
  5949. Cainfo string `json:"cainfo"`
  5950. ErrMsg string `json:"err_msg"`
  5951. InfRefmsgid string `json:"inf_refmsgid"`
  5952. Infcode int64 `json:"infcode"`
  5953. Output struct {
  5954. Setldetail []interface{} `json:"setldetail"`
  5955. Setlinfo struct {
  5956. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5957. AcctPay float64 `json:"acct_pay"`
  5958. ActPayDedc float64 `json:"act_pay_dedc"`
  5959. Age float64 `json:"age"`
  5960. Balc float64 `json:"balc"`
  5961. Brdy string `json:"brdy"`
  5962. Certno string `json:"certno"`
  5963. ClrOptins string `json:"clr_optins"`
  5964. ClrType string `json:"clr_type"`
  5965. ClrWay string `json:"clr_way"`
  5966. CvlservFlag string `json:"cvlserv_flag"`
  5967. CvlservPay float64 `json:"cvlserv_pay"`
  5968. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5969. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5970. Gend string `json:"gend"`
  5971. HifesPay float64 `json:"hifes_pay"`
  5972. HifmiPay float64 `json:"hifmi_pay"`
  5973. HifobPay float64 `json:"hifob_pay"`
  5974. HifpPay float64 `json:"hifp_pay"`
  5975. HospPartAmt float64 `json:"hosp_part_amt"`
  5976. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5977. Insutype string `json:"insutype"`
  5978. MafPay float64 `json:"maf_pay"`
  5979. MdtrtCertType string `json:"mdtrt_cert_type"`
  5980. MdtrtID string `json:"mdtrt_id"`
  5981. MedType string `json:"med_type"`
  5982. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5983. MedinsSetlID string `json:"medins_setl_id"`
  5984. Naty string `json:"naty"`
  5985. OthPay float64 `json:"oth_pay"`
  5986. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5987. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5988. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5989. PsnCashPay float64 `json:"psn_cash_pay"`
  5990. PsnCertType string `json:"psn_cert_type"`
  5991. PsnName string `json:"psn_name"`
  5992. PsnNo string `json:"psn_no"`
  5993. PsnPartAmt float64 `json:"psn_part_amt"`
  5994. PsnType string `json:"psn_type"`
  5995. SetlID string `json:"setl_id"`
  5996. SetlTime string `json:"setl_time"`
  5997. } `json:"setlinfo"`
  5998. } `json:"output"`
  5999. RefmsgTime string `json:"refmsg_time"`
  6000. RespondTime string `json:"respond_time"`
  6001. Signtype interface{} `json:"signtype"`
  6002. WarnMsg interface{} `json:"warn_msg"`
  6003. }
  6004. type ResultEight struct {
  6005. Cainfo string `json:"cainfo"`
  6006. ErrMsg string `json:"err_msg"`
  6007. InfRefmsgid string `json:"inf_refmsgid"`
  6008. Infcode int64 `json:"infcode"`
  6009. Output struct {
  6010. Stmtinfo struct {
  6011. SetlOptins string `json:"setl_optins"`
  6012. StmtRslt string `json:"stmt_rslt"`
  6013. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6014. } `json:"stmtinfo"`
  6015. } `json:"output"`
  6016. RefmsgTime string `json:"refmsg_time"`
  6017. RespondTime string `json:"respond_time"`
  6018. Signtype interface{} `json:"signtype"`
  6019. WarnMsg interface{} `json:"warn_msg"`
  6020. }
  6021. type ResultNine struct {
  6022. Cainfo string `json:"cainfo"`
  6023. ErrMsg string `json:"err_msg"`
  6024. InfRefmsgid string `json:"inf_refmsgid"`
  6025. Infcode int64 `json:"infcode"`
  6026. Output struct {
  6027. FileQuryNo string `json:"file_qury_no"`
  6028. } `json:"output"`
  6029. RefmsgTime string `json:"refmsg_time"`
  6030. RespondTime string `json:"respond_time"`
  6031. Signtype interface{} `json:"signtype"`
  6032. WarnMsg interface{} `json:"warn_msg"`
  6033. }
  6034. type ResultTen struct {
  6035. Cainfo string `json:"cainfo"`
  6036. ErrMsg string `json:"err_msg"`
  6037. InfRefmsgid string `json:"inf_refmsgid"`
  6038. Infcode int64 `json:"infcode"`
  6039. Output struct {
  6040. DldEndtime string `json:"dld_endtime"`
  6041. FileQuryNo string `json:"file_qury_no"`
  6042. Filename string `json:"filename"`
  6043. } `json:"output"`
  6044. RefmsgTime string `json:"refmsg_time"`
  6045. RespondTime string `json:"respond_time"`
  6046. Signtype interface{} `json:"signtype"`
  6047. WarnMsg interface{} `json:"warn_msg"`
  6048. }
  6049. type ResultEleven struct {
  6050. Cainfo string `json:"cainfo"`
  6051. ErrMsg string `json:"err_msg"`
  6052. InfRefmsgid string `json:"inf_refmsgid"`
  6053. Infcode int64 `json:"infcode"`
  6054. Output struct {
  6055. Setlinfo struct {
  6056. FixmedinsName string `json:"fixmedins_name"`
  6057. FixmedinsCode string `json:"fixmedins_code"`
  6058. PsnNo string `json:"psn_no"`
  6059. PsnName string `json:"psn_name"`
  6060. HifobPay float64 `json:"hifob_pay"`
  6061. Gend string `json:"gend"`
  6062. Brdy string `json:"brdy"`
  6063. PsnCertType string `json:"psn_cert_type"`
  6064. PsnType string `json:"psn_type"`
  6065. EmpName string `json:"emp_name"`
  6066. Certno string `json:"certno"`
  6067. Insutype string `json:"insutype"`
  6068. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6069. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6070. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6071. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6072. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6073. ActPayDedc float64 `json:"act_pay_dedc"`
  6074. HifpPay float64 `json:"hifp_pay"`
  6075. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6076. CvlservPay float64 `json:"cvlserv_pay"`
  6077. HifesPay float64 `json:"hifes_pay"`
  6078. HifmiPay float64 `json:"hifmi_pay"`
  6079. MafPay float64 `json:"maf_pay"`
  6080. OthPay float64 `json:"oth_pay"`
  6081. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6082. PsnPay float64 `json:"psn_pay"`
  6083. AcctPay float64 `json:"acct_pay"`
  6084. CashPayamt float64 `json:"cash_payamt"`
  6085. Balc float64 `json:"balc"`
  6086. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6087. MedinsSetlId string `json:"medins_setl_id"`
  6088. RefdSetlFlag string `json:"refd_setl_flag"`
  6089. SetlTime string `json:"setl_time"`
  6090. MedType string `json:"med_type"`
  6091. } `json:"setlinfo"`
  6092. } `json:"output"`
  6093. RefmsgTime string `json:"refmsg_time"`
  6094. RespondTime string `json:"respond_time"`
  6095. Signtype interface{} `json:"signtype"`
  6096. WarnMsg interface{} `json:"warn_msg"`
  6097. }
  6098. type Custom struct {
  6099. DetItemFeeSumamt string
  6100. Cut string
  6101. FeedetlSn string
  6102. Price string
  6103. MedListCodg string
  6104. Type int64
  6105. AdviceId int64
  6106. ProjectId int64
  6107. ItemId int64
  6108. }
  6109. // 获取个人信息----挂号-----上传就诊信息
  6110. func (c *HisApiController) GetRegisterInfo() {
  6111. id, _ := c.GetInt64("id")
  6112. record_time := c.GetString("record_time")
  6113. settlementValue, _ := c.GetInt64("settlement_value")
  6114. medical_insurance_card := c.GetString("medical_insurance_card")
  6115. name := c.GetString("name")
  6116. id_card_type, _ := c.GetInt64("id_card_type")
  6117. certificates, _ := c.GetInt64("certificates")
  6118. medical_care, _ := c.GetInt64("medical_care")
  6119. birthday := c.GetString("birthday")
  6120. age, _ := c.GetInt64("age")
  6121. id_card := c.GetString("id_card")
  6122. register_type, _ := c.GetInt64("register")
  6123. doctor, _ := c.GetInt64("doctor")
  6124. department, _ := c.GetInt64("department")
  6125. gender, _ := c.GetInt64("sex")
  6126. phone := c.GetString("phone")
  6127. registration_fee, _ := c.GetFloat("registration_fee")
  6128. medical_expenses, _ := c.GetFloat("medical_expenses")
  6129. social_type, _ := c.GetInt64("social_type")
  6130. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6131. diagnosis_ids := c.GetString("diagnosis")
  6132. sick_type, _ := c.GetInt64("sick_type")
  6133. reg_type := c.GetString("p_type")
  6134. timeLayout := "2006-01-02"
  6135. loc, _ := time.LoadLocation("Local")
  6136. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6137. birthUnix := birthdays.Unix()
  6138. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6139. if err != nil {
  6140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6141. return
  6142. }
  6143. recordDateTime := theTime.Unix()
  6144. adminInfo := c.GetAdminUserInfo()
  6145. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6146. if tempPatient.ID == 0 {
  6147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6148. return
  6149. }
  6150. var patient service.Patients
  6151. if id == 0 {
  6152. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6153. } else {
  6154. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6155. }
  6156. if patient.ID == 0 {
  6157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6158. return
  6159. }
  6160. if len(patient.IdCardNo) == 0 {
  6161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6162. return
  6163. }
  6164. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6165. if len(his) >= 1 {
  6166. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6167. if len(his) >= 1 && order.ID == 0 {
  6168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6169. return
  6170. }
  6171. }
  6172. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6173. fmt.Println(timeStr)
  6174. timeArr := strings.Split(timeStr, " ")
  6175. fmt.Println(timeArr)
  6176. timeArrTwo := strings.Split(timeArr[0], "-")
  6177. timeArrThree := strings.Split(timeArr[1], ":")
  6178. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6179. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6180. if len(lists) == 0 {
  6181. var hisPatient models.XtHisPatient
  6182. hisPatient = models.XtHisPatient{
  6183. Name: name,
  6184. Age: age,
  6185. Gender: gender,
  6186. Birthday: birthUnix,
  6187. Phone: phone,
  6188. MedicalTreatmentType: medical_care,
  6189. IdType: certificates,
  6190. IdCardNo: id_card,
  6191. BalanceAccountsType: settlementValue,
  6192. SocialType: social_type,
  6193. MedicalInsuranceNumber: medical_insurance_card,
  6194. RegisterType: register_type,
  6195. RegisterCost: registration_fee,
  6196. TreatmentCost: medical_expenses,
  6197. AdminUserId: adminInfo.AdminUser.Id,
  6198. UserOrgId: adminInfo.CurrentOrgId,
  6199. Status: 1,
  6200. RecordDate: recordDateTime,
  6201. IsReturn: 1,
  6202. PatientId: patient.ID,
  6203. Ctime: time.Now().Unix(),
  6204. Mtime: time.Now().Unix(),
  6205. Number: str,
  6206. IdCardType: id_card_type,
  6207. Departments: department,
  6208. Doctor: doctor,
  6209. PType: reg_type,
  6210. Diagnosis: diagnosis_ids,
  6211. SickType: sick_type,
  6212. }
  6213. service.CreateHisPatient(&hisPatient)
  6214. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6215. c.ServeSuccessJSON(map[string]interface{}{
  6216. "his_info": hisPatient,
  6217. })
  6218. } else {
  6219. //chrgBchno := rand.Intn(1000000) + 10000
  6220. var hisPatient models.XtHisPatient
  6221. hisPatient = models.XtHisPatient{
  6222. Name: name,
  6223. Age: age,
  6224. Gender: gender,
  6225. Birthday: birthUnix,
  6226. Phone: phone,
  6227. MedicalTreatmentType: medical_care,
  6228. IdType: certificates,
  6229. IdCardNo: id_card,
  6230. BalanceAccountsType: settlementValue,
  6231. SocialType: social_type,
  6232. MedicalInsuranceNumber: medical_insurance_card,
  6233. RegisterType: register_type,
  6234. RegisterCost: registration_fee,
  6235. TreatmentCost: medical_expenses,
  6236. AdminUserId: adminInfo.AdminUser.Id,
  6237. UserOrgId: adminInfo.CurrentOrgId,
  6238. Status: 1,
  6239. RecordDate: recordDateTime,
  6240. IsReturn: 1,
  6241. PatientId: patient.ID,
  6242. Ctime: time.Now().Unix(),
  6243. Mtime: time.Now().Unix(),
  6244. Number: str,
  6245. IdCardType: id_card_type,
  6246. Departments: department,
  6247. Doctor: doctor,
  6248. PType: reg_type,
  6249. Diagnosis: diagnosis_ids,
  6250. SickType: sick_type,
  6251. }
  6252. service.CreateHisPatient(&hisPatient)
  6253. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6254. c.ServeSuccessJSON(map[string]interface{}{
  6255. "his_info": hisPatient,
  6256. })
  6257. }
  6258. }
  6259. // 上传明细----结算
  6260. func (c *HisApiController) GetUploadInfo() {
  6261. id, _ := c.GetInt64("id")
  6262. record_time := c.GetString("record_time")
  6263. his_patient_id, _ := c.GetInt64("his_patient_id")
  6264. oth_desc := c.GetString("oth_desc")
  6265. pay_way, _ := c.GetInt64("pay_way")
  6266. pay_ways := c.GetString("pay_ways")
  6267. pay_price, _ := c.GetFloat("pay_price")
  6268. pay_card_no := c.GetString("pay_card_no")
  6269. discount_price, _ := c.GetFloat("discount_price")
  6270. preferential_price, _ := c.GetFloat("preferential_price")
  6271. reality_price, _ := c.GetFloat("reality_price")
  6272. found_price, _ := c.GetFloat("found_price")
  6273. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6274. private_price, _ := c.GetFloat("private_price")
  6275. timeLayout := "2006-01-02"
  6276. loc, _ := time.LoadLocation("Local")
  6277. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6278. fapiao_code := c.GetString("fapiao_code")
  6279. fapiao_number := c.GetString("fapiao_number")
  6280. diagnosis_id := c.GetString("diagnosis")
  6281. sick_type, _ := c.GetInt64("sick_type")
  6282. reg_type, _ := c.GetInt64("p_type")
  6283. order_id, _ := c.GetInt64("order_id")
  6284. cash_pay := c.GetString("cash_pay")
  6285. wechat_pay := c.GetString("wechat_pay")
  6286. ali_pay := c.GetString("ali_pay")
  6287. jifen_pay := c.GetString("jifen_pay")
  6288. band_card_pay := c.GetString("band_card_pay")
  6289. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6290. tmp_decimal := c.GetString("tmp_decimal")
  6291. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6292. var decimal float64 //本次使用的押金
  6293. var errmsg error
  6294. tx := service.XTWriteDB().Begin() //开了事务
  6295. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6296. defer func() {
  6297. if errmsg != nil {
  6298. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6299. tx.Rollback()
  6300. } else {
  6301. tx.Commit()
  6302. }
  6303. }()
  6304. fmt.Println("dec_way", dec_way)
  6305. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6306. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6307. return
  6308. }
  6309. if len(tmp_decimal) > 0 {
  6310. if tmp_decimal[0] == 45 {
  6311. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6312. return
  6313. }
  6314. }
  6315. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6316. fmt.Println(errs)
  6317. decimal = tt
  6318. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6319. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6320. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6321. if err != nil {
  6322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6323. return
  6324. }
  6325. recordDateTime := theTime.Unix()
  6326. adminUser := c.GetAdminUserInfo()
  6327. var prescriptions []*models.HisPrescription
  6328. var prescriptionsOne []*models.HisPrescription
  6329. var start_time int64
  6330. var end_time int64
  6331. ids_str := c.GetString("ids")
  6332. ids_arr := strings.Split(ids_str, ",")
  6333. if tempOrder.ID == 0 {
  6334. if settle_accounts_type == 1 { //日结
  6335. fmt.Println(reg_type)
  6336. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6337. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6338. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6339. } else {
  6340. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6341. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6342. }
  6343. } else { //月结
  6344. start_time_str := c.GetString("start_time")
  6345. end_time_str := c.GetString("end_time")
  6346. timeLayout := "2006-01-02"
  6347. loc, _ := time.LoadLocation("Local")
  6348. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6349. if err != nil {
  6350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6351. return
  6352. }
  6353. recordStartTime := theStartTime.Unix()
  6354. start_time = recordStartTime
  6355. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6356. if err != nil {
  6357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6358. return
  6359. }
  6360. recordEndTime := theEndTime.Unix()
  6361. end_time = recordEndTime
  6362. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6363. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6364. }
  6365. var goods []*models.DialysisBeforePrepareGoods
  6366. var newGoods []*models.NewDialysisBeforePrepareGoods
  6367. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6368. var infos []*models.HisDoctorAdviceInfo
  6369. var infoList []*models.HisDoctorAdviceInfo
  6370. var hisAdvice []*models.HisDoctorAdviceInfo
  6371. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6372. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6373. //判断库存不足
  6374. //结算出库开关
  6375. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6376. if settConfig.IsOpen == 1 {
  6377. //判断库存的地方
  6378. for _, info := range prescriptions {
  6379. if info.Type == 1 {
  6380. infos = append(infos, info.HisDoctorAdviceInfo...)
  6381. }
  6382. if info.Type == 2 {
  6383. for _, sumItem := range info.HisPrescriptionProject {
  6384. if sumItem.Type == 3 {
  6385. var good models.DialysisBeforePrepareGoods
  6386. var newGood models.NewDialysisBeforePrepareGoods
  6387. good.GoodId = sumItem.GoodInfo.ID
  6388. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6389. count, _ := strconv.Atoi(sumItem.Count)
  6390. good.Count = int64(count)
  6391. good.StorehouseId = houseConfig.StorehouseOutInfo
  6392. good.ProjectId = sumItem.ID
  6393. goods = append(goods, &good)
  6394. newGood.GoodId = sumItem.GoodInfo.ID
  6395. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6396. count2, _ := strconv.Atoi(sumItem.Count)
  6397. newGood.Count = int64(count2)
  6398. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6399. newGood.ProjectId = sumItem.ID
  6400. newGoods = append(newGoods, &newGood)
  6401. }
  6402. }
  6403. }
  6404. }
  6405. for _, info := range prescriptionsOne {
  6406. if info.Type == 1 {
  6407. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6408. }
  6409. if info.Type == 2 {
  6410. for _, sumItem := range info.HisPrescriptionProject {
  6411. if sumItem.Type == 3 {
  6412. var newGood models.NewDialysisBeforePrepareGoods
  6413. newGood.GoodId = sumItem.GoodInfo.ID
  6414. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6415. count2, _ := strconv.Atoi(sumItem.Count)
  6416. newGood.Count = int64(count2)
  6417. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6418. newGood.ProjectId = sumItem.ID
  6419. newGoodOne = append(newGoodOne, &newGood)
  6420. }
  6421. }
  6422. }
  6423. }
  6424. //判断
  6425. for _, itemOne := range infos {
  6426. for _, itemTwo := range hisAdvice {
  6427. if itemOne.DrugId == itemTwo.DrugId {
  6428. itemTwo.Child = append(itemTwo.Child, itemOne)
  6429. }
  6430. }
  6431. }
  6432. for _, itemTwo := range hisAdvice {
  6433. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6434. var sum_out_count int64
  6435. for _, itemThree := range itemTwo.Child {
  6436. var prescribing_number int64
  6437. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6438. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6439. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6440. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6441. }
  6442. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6443. prescribing_number = parseIntPrescribingNumber
  6444. }
  6445. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6446. prescribing_number = parseIntPrescribingNumber
  6447. }
  6448. sum_out_count += prescribing_number
  6449. }
  6450. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6451. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6452. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6453. if sum_out_count > drugStockOut.FlushCount {
  6454. c.ServeSuccessJSON(map[string]interface{}{
  6455. "msg": "2",
  6456. "drug": medical,
  6457. })
  6458. return
  6459. }
  6460. }
  6461. fmt.Println("newGoods99999988882os", newGoods)
  6462. for _, itemOne := range newGoods {
  6463. for _, item := range newGoodOne {
  6464. if itemOne.GoodId == item.GoodId {
  6465. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6466. }
  6467. }
  6468. }
  6469. for _, item := range newGoodOne {
  6470. var sum_out_count_one int64
  6471. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6472. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6473. sum_out_count_one += itemOne.Count
  6474. }
  6475. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6476. fmt.Println("sum_out_count_one", sum_out_count_one)
  6477. fmt.Println("list.FlushCount", list.FlushCount)
  6478. if sum_out_count_one > list.FlushCount {
  6479. c.ServeSuccessJSON(map[string]interface{}{
  6480. "msg": "3",
  6481. "good": good,
  6482. })
  6483. return
  6484. }
  6485. }
  6486. }
  6487. timestamp := time.Now().Unix()
  6488. tempTime := time.Unix(timestamp, 0)
  6489. timeFormat := tempTime.Format("20060102150405")
  6490. chrgBchno := rand.Intn(100000) + 10000
  6491. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6492. strconv.FormatInt(his.PatientId, 10)
  6493. var ids []int64
  6494. for _, item := range prescriptions {
  6495. ids = append(ids, item.ID)
  6496. }
  6497. var total float64
  6498. for _, item := range prescriptions {
  6499. fmt.Println(item)
  6500. if item.Type == 1 { //药品
  6501. for _, subItem := range item.HisDoctorAdviceInfo {
  6502. total = total + (subItem.Price * subItem.PrescribingNumber)
  6503. }
  6504. }
  6505. if item.Type == 2 { //项目
  6506. for _, subItem := range item.HisPrescriptionProject {
  6507. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6508. total = total + (subItem.Price * cnt)
  6509. }
  6510. }
  6511. for _, subItem := range item.HisAdditionalCharge {
  6512. total = total + (subItem.Price * float64(subItem.Count))
  6513. }
  6514. }
  6515. if reg_type == 1111 || reg_type == 1112 {
  6516. reg_type = 11
  6517. }
  6518. tm := time.Unix(time.Now().Unix(), 0)
  6519. allTotal := fmt.Sprintf("%.4f", total)
  6520. totals, _ := strconv.ParseFloat(allTotal, 64)
  6521. order := &models.HisOrder{
  6522. UserOrgId: adminUser.CurrentOrgId,
  6523. HisPatientId: his.ID,
  6524. PatientId: id,
  6525. SettleAccountsDate: recordDateTime,
  6526. Ctime: time.Now().Unix(),
  6527. Mtime: time.Now().Unix(),
  6528. Status: 1,
  6529. OrderStatus: 2,
  6530. MdtrtId: his.Number,
  6531. Number: chrg_bchno,
  6532. MedfeeSumamt: totals,
  6533. PayWay: pay_way,
  6534. PayWays: pay_ways,
  6535. PayPrice: pay_price,
  6536. MedType: strconv.Itoa(int(reg_type)),
  6537. PayCardNo: pay_card_no,
  6538. DiscountPrice: discount_price,
  6539. PreferentialPrice: preferential_price,
  6540. RealityPrice: reality_price,
  6541. FoundPrice: found_price,
  6542. MedicalInsurancePrice: medical_insurance_price,
  6543. PrivatePrice: private_price,
  6544. SettleEndTime: end_time,
  6545. SettleStartTime: start_time,
  6546. PsnPartAmt: totals,
  6547. PsnCashPay: totals,
  6548. SettleType: settle_accounts_type,
  6549. FaPiaoCode: fapiao_code,
  6550. FaPiaoNumber: fapiao_number,
  6551. Diagnosis: diagnosis_id,
  6552. PType: 2,
  6553. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6554. Decimal: decimal,
  6555. OthDesc: oth_desc,
  6556. CashPay: cash_pay,
  6557. WechatPay: wechat_pay,
  6558. AliPay: ali_pay,
  6559. JifenPay: jifen_pay,
  6560. BandCardPay: band_card_pay,
  6561. }
  6562. err = service.CreateOrderTX(order, tx)
  6563. if err != nil {
  6564. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6565. return
  6566. }
  6567. var customs []*Custom
  6568. for _, item := range prescriptions {
  6569. if item.Type == 1 { //药品a
  6570. for _, subItem := range item.HisDoctorAdviceInfo {
  6571. cus := &Custom{
  6572. AdviceId: subItem.ID,
  6573. ProjectId: 0,
  6574. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6575. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6576. FeedetlSn: subItem.FeedetlSn,
  6577. Price: fmt.Sprintf("%.4f", subItem.Price),
  6578. MedListCodg: subItem.MedListCodg,
  6579. Type: 1,
  6580. }
  6581. customs = append(customs, cus)
  6582. }
  6583. }
  6584. if item.Type == 2 { //项目
  6585. for _, subItem := range item.HisPrescriptionProject {
  6586. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6587. cus := &Custom{
  6588. AdviceId: 0,
  6589. ProjectId: subItem.ID,
  6590. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6591. Cut: fmt.Sprintf("%.4f", cnt),
  6592. FeedetlSn: subItem.FeedetlSn,
  6593. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6594. MedListCodg: subItem.MedListCodg,
  6595. Type: 2,
  6596. }
  6597. customs = append(customs, cus)
  6598. }
  6599. }
  6600. for _, item := range item.HisAdditionalCharge {
  6601. cus := &Custom{
  6602. ItemId: item.ID,
  6603. AdviceId: 0,
  6604. ProjectId: 0,
  6605. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6606. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6607. FeedetlSn: item.FeedetlSn,
  6608. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6609. MedListCodg: item.XtHisAddtionConfig.Code,
  6610. Type: 3,
  6611. }
  6612. customs = append(customs, cus)
  6613. }
  6614. }
  6615. for _, item := range customs {
  6616. var advice_id int64 = 0
  6617. var project_id int64 = 0
  6618. var item_id int64 = 0
  6619. var types int64 = 0
  6620. if item.Type == 1 {
  6621. advice_id = item.AdviceId
  6622. project_id = 0
  6623. item_id = 0
  6624. } else if item.Type == 2 {
  6625. advice_id = 0
  6626. item_id = 0
  6627. project_id = item.ProjectId
  6628. } else if item.Type == 3 {
  6629. advice_id = 0
  6630. item_id = item.ItemId
  6631. project_id = 0
  6632. }
  6633. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6634. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6635. pric, _ := strconv.ParseFloat(item.Price, 32)
  6636. info := &models.HisOrderInfo{
  6637. OrderNumber: order.Number,
  6638. UploadDate: time.Now().Unix(),
  6639. AdviceId: advice_id,
  6640. DetItemFeeSumamt: detItemFeeSumamt,
  6641. Cnt: cut,
  6642. Pric: pric,
  6643. PatientId: id,
  6644. Status: 1,
  6645. Mtime: time.Now().Unix(),
  6646. Ctime: time.Now().Unix(),
  6647. UserOrgId: adminUser.CurrentOrgId,
  6648. HisPatientId: his.ID,
  6649. OrderId: order.ID,
  6650. ProjectId: project_id,
  6651. Type: types,
  6652. ItemId: item_id,
  6653. }
  6654. service.CreateOrderInfoTX(info, tx)
  6655. }
  6656. his.Diagnosis = diagnosis_id
  6657. his.SickType = sick_type
  6658. his.RegisterType = reg_type
  6659. his.MedicalTreatmentType = reg_type
  6660. service.UpdataHisPateintTX(&his, tx)
  6661. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6662. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6663. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6664. //判断是否使用了押金
  6665. if dec_way == "true" {
  6666. tmpstring := strconv.FormatInt(order.ID, 10)
  6667. //扣押金
  6668. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6669. order.Decimal = decimal
  6670. service.UpDateOrderTwo(order, tx)
  6671. if errmsg != nil {
  6672. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6673. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6674. return
  6675. }
  6676. }
  6677. if err == nil {
  6678. for _, info := range prescriptions {
  6679. if info.Type == 1 {
  6680. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6681. }
  6682. if info.Type == 2 {
  6683. for _, sumItem := range info.HisPrescriptionProject {
  6684. if sumItem.Type == 3 {
  6685. var good models.DialysisBeforePrepareGoods
  6686. var newGood models.NewDialysisBeforePrepareGoods
  6687. var oldGood models.OldDialysisBeforePrepareGoods
  6688. good.GoodId = sumItem.GoodInfo.ID
  6689. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6690. count, _ := strconv.Atoi(sumItem.Count)
  6691. good.Count = int64(count)
  6692. good.StorehouseId = houseConfig.StorehouseOutInfo
  6693. good.ProjectId = sumItem.ID
  6694. good.PatientId = sumItem.PatientId
  6695. goods = append(goods, &good)
  6696. newGood.GoodId = sumItem.GoodInfo.ID
  6697. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6698. count2, _ := strconv.Atoi(sumItem.Count)
  6699. newGood.Count = int64(count2)
  6700. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6701. newGood.ProjectId = sumItem.ID
  6702. newGood.PatientId = sumItem.HisPatientId
  6703. newGoods = append(newGoods, &newGood)
  6704. oldGood.GoodId = sumItem.GoodInfo.ID
  6705. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6706. count3, _ := strconv.Atoi(sumItem.Count)
  6707. oldGood.Count = int64(count3)
  6708. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6709. oldGood.ProjectId = sumItem.ID
  6710. oldGood.RecordDate = sumItem.RecordDate
  6711. oldGood.PatientId = sumItem.HisPatientId
  6712. oldGoods = append(oldGoods, &oldGood)
  6713. }
  6714. }
  6715. }
  6716. }
  6717. if settConfig.IsOpen == 1 {
  6718. for _, item := range infoList {
  6719. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6720. if medical.IsUse == 2 {
  6721. //药品出库
  6722. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6723. //查询默认仓库
  6724. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6725. //查询默认仓库剩余多少库存
  6726. var sum_count int64
  6727. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6728. for _, its := range stockInfo {
  6729. if its.MaxUnit == medical.MaxUnit {
  6730. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6731. }
  6732. sum_count += its.StockMaxNumber + its.StockMinNumber
  6733. }
  6734. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6735. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6736. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6737. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6738. }
  6739. }
  6740. orgId := c.GetAdminUserInfo().CurrentOrgId
  6741. if len(oldGoods) > 0 {
  6742. timeStr := time.Now().Format("2006-01-02")
  6743. timeArr := strings.Split(timeStr, "-")
  6744. total, _ := service.FindAllWarehouseOut(orgId)
  6745. total = total + 1
  6746. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6747. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6748. number = number + total
  6749. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6750. operation_time := time.Now().Unix()
  6751. creater := c.GetAdminUserInfo().AdminUser.Id
  6752. //查询默认出库仓库库存
  6753. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6754. recordDateStr := time.Now().Format("2006-01-02")
  6755. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6756. nowtime := recordDate.Unix()
  6757. warehouseOut := models.WarehouseOut{
  6758. WarehouseOutOrderNumber: warehousing_out_order,
  6759. OperationTime: operation_time,
  6760. OrgId: orgId,
  6761. Creater: creater,
  6762. Ctime: time.Now().Unix(),
  6763. Status: 1,
  6764. WarehouseOutTime: nowtime,
  6765. Type: 1,
  6766. StorehouseId: storeConfig.StorehouseOutInfo,
  6767. IsCheck: 1,
  6768. OrderId: order.ID,
  6769. IsSys: 5,
  6770. }
  6771. //查询是否生成出库单
  6772. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6773. if out.ID == 0 {
  6774. service.AddSigleWarehouseOut(&warehouseOut)
  6775. }
  6776. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6777. for _, item := range oldGoods {
  6778. dialyPrepareOne := models.DialysisBeforePrepare{
  6779. GoodTypeId: item.GoodTypeId,
  6780. GoodId: item.GoodId,
  6781. PatientId: his.PatientId,
  6782. RecordDate: item.RecordDate,
  6783. UserOrgId: adminUser.CurrentOrgId,
  6784. Count: item.Count,
  6785. Ctime: time.Now().Unix(),
  6786. Creater: adminUser.AdminUser.Id,
  6787. CommdityCode: item.CommdityCode,
  6788. Status: 1,
  6789. StorehouseId: houseConfig.StorehouseOutInfo,
  6790. }
  6791. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6792. //非零用
  6793. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6794. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6795. //查询剩余库存
  6796. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6797. var sum_count int64
  6798. for _, item := range goodList {
  6799. sum_count += item.StockCount
  6800. }
  6801. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6802. //耗材
  6803. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6804. }
  6805. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6806. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6807. //查询剩余库存
  6808. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6809. var sum_count int64
  6810. for _, item := range goodList {
  6811. sum_count += item.StockCount
  6812. }
  6813. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6814. //耗材
  6815. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6816. }
  6817. }
  6818. }
  6819. }
  6820. c.ServeSuccessJSON(map[string]interface{}{
  6821. "msg": "结算成功",
  6822. })
  6823. }
  6824. }
  6825. }
  6826. // 退款
  6827. func (c *HisApiController) Refund() {
  6828. order_id, _ := c.GetInt64("order_id")
  6829. order, _ := service.GetHisOrderByID(order_id)
  6830. adminUser := c.GetAdminUserInfo()
  6831. orgid := c.GetAdminUserInfo().CurrentOrgId
  6832. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6833. if err != nil {
  6834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6835. return
  6836. }
  6837. tmp := strconv.FormatInt(order.ID, 10)
  6838. //当押金不为零时产生退费记录
  6839. if order.Decimal != 0 {
  6840. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6841. if err != nil {
  6842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6843. return
  6844. }
  6845. }
  6846. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6847. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6848. var goods []*models.DialysisBeforePrepareGoods
  6849. var newGoods []*models.NewDialysisBeforePrepareGoods
  6850. var infos []*models.HisDoctorAdviceInfo
  6851. for _, info := range orders {
  6852. if info.AdviceId > 0 && info.ProjectId == 0 {
  6853. infos = append(infos, &info.HisDoctorAdviceInfo)
  6854. }
  6855. if info.ProjectId > 0 && info.AdviceId == 0 {
  6856. if info.HisPrescriptionProject.Type == 3 {
  6857. var good models.DialysisBeforePrepareGoods
  6858. var newGood models.NewDialysisBeforePrepareGoods
  6859. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6860. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6861. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6862. good.Count = int64(count)
  6863. good.StorehouseId = houseConfig.StorehouseOutInfo
  6864. good.ProjectId = info.HisPrescriptionProject.ID
  6865. good.PatientId = info.PatientId
  6866. good.OrderId = order_id
  6867. goods = append(goods, &good)
  6868. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6869. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6870. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6871. newGood.Count = int64(count2)
  6872. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6873. newGood.ProjectId = info.HisPrescriptionProject.ID
  6874. newGood.RecordDate = order.SettleAccountsDate
  6875. newGood.UserOrgId = order.UserOrgId
  6876. newGood.PatientId = info.PatientId
  6877. newGood.OrderId = order_id
  6878. newGoods = append(newGoods, &newGood)
  6879. }
  6880. }
  6881. }
  6882. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6883. if settConfig.IsOpen == 1 {
  6884. for _, item := range infos {
  6885. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6886. }
  6887. for _, item := range newGoods {
  6888. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6889. }
  6890. }
  6891. c.ServeSuccessJSON(map[string]interface{}{
  6892. "msg": "退费成功",
  6893. })
  6894. }
  6895. func (c *HisApiController) RefundNumber() {
  6896. his_patient_id, _ := c.GetInt64("id")
  6897. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6898. info.Status = 0
  6899. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6900. if count > 0 {
  6901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6902. return
  6903. }
  6904. err := service.SaveHisPatient(info)
  6905. if err == nil {
  6906. c.ServeSuccessJSON(map[string]interface{}{
  6907. "msg": "退号成功",
  6908. })
  6909. } else {
  6910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6911. return
  6912. }
  6913. }
  6914. func (this *HisApiController) AdditionalCharge() {
  6915. dataBody := make(map[string]interface{}, 0)
  6916. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6917. fmt.Println(err)
  6918. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6919. patient_id := int64(dataBody["patient_id"].(float64))
  6920. medicineData, _ := dataBody["medicineData"].([]interface{})
  6921. adminUserInfo := this.GetAdminUserInfo()
  6922. orgId := adminUserInfo.CurrentOrgId
  6923. admin_user_id := adminUserInfo.AdminUser.Id
  6924. timeStr := time.Now().Format("2006-01-02")
  6925. timeLayout := "2006-01-02 15:04:05"
  6926. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6927. timenow := timeStringToTime.Unix()
  6928. var additionalCharges []*models.HisAdditionalCharge
  6929. for _, item := range medicineData {
  6930. var randNum int
  6931. randNum = rand.Intn(10000) + 1000
  6932. timestamp := time.Now().Unix()
  6933. tempTime := time.Unix(timestamp, 0)
  6934. timeFormat := tempTime.Format("20060102150405")
  6935. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6936. items := item.(map[string]interface{})
  6937. money := items["price"].(string)
  6938. item_id_str := items["item_id"].(string)
  6939. name := items["name"].(string)
  6940. id_str := items["id"].(string)
  6941. moneys, _ := strconv.ParseInt(money, 10, 64)
  6942. monStr := strconv.FormatInt(moneys, 10)
  6943. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6944. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6945. id, _ := strconv.ParseInt(id_str, 10, 64)
  6946. additionalCharge := &models.HisAdditionalCharge{
  6947. ID: id,
  6948. HisPatientId: his_patient_id,
  6949. UserOrgId: orgId,
  6950. PatientId: patient_id,
  6951. RecordDate: timenow,
  6952. Price: monneyStr,
  6953. Status: 1,
  6954. ItemName: name,
  6955. ItemId: item_id,
  6956. AdminUserId: admin_user_id,
  6957. CreatedTime: time.Now().Unix(),
  6958. OrderStatus: 0,
  6959. PrescriptionNumber: "",
  6960. BatchNumber: "",
  6961. FeedetlSn: p_number,
  6962. }
  6963. service.CreateAdditionalCharge(additionalCharge)
  6964. additionalCharges = append(additionalCharges, additionalCharge)
  6965. }
  6966. this.ServeSuccessJSON(map[string]interface{}{
  6967. "msg": "添加成功",
  6968. "additional_charges": additionalCharges,
  6969. })
  6970. }
  6971. func (this *HisApiController) DeleteAddition() {
  6972. id, _ := this.GetInt64("id")
  6973. //TODO 需要判断是否已经结算
  6974. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6975. if err == nil {
  6976. this.ServeSuccessJSON(map[string]interface{}{
  6977. "msg": "删除成功",
  6978. })
  6979. return
  6980. } else {
  6981. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6982. return
  6983. }
  6984. }
  6985. func (this *HisApiController) GetAdminUsers() {
  6986. adminUser := this.GetAdminUserInfo()
  6987. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6988. this.ServeSuccessJSON(map[string]interface{}{
  6989. "doctors": doctors,
  6990. })
  6991. }
  6992. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6993. change_type, _ := this.GetInt64("type", 0)
  6994. record_date := this.GetString("record_time")
  6995. patient_id, _ := this.GetInt64("patient_id", 0)
  6996. p_type, _ := this.GetInt64("p_type", 0)
  6997. timeLayout := "2006-01-02"
  6998. loc, _ := time.LoadLocation("Local")
  6999. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7000. record_time := theAdviceRecordTime.Unix()
  7001. adminUserInfo := this.GetAdminUserInfo()
  7002. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7003. if err == nil {
  7004. if len(prescriptions) == 0 {
  7005. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7006. return
  7007. } else {
  7008. this.ServeSuccessJSON(map[string]interface{}{
  7009. "prescriptions": prescriptions,
  7010. })
  7011. return
  7012. }
  7013. } else {
  7014. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7015. return
  7016. }
  7017. }
  7018. func (this *HisApiController) GetCallHisPrescription() {
  7019. patient_id, _ := this.GetInt64("patient_id", 0)
  7020. timeLayout := "2006-01-02"
  7021. loc, _ := time.LoadLocation("Local")
  7022. start_time := this.GetString("start_time")
  7023. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7024. end_time := this.GetString("end_time")
  7025. p_type, _ := this.GetInt64("p_type")
  7026. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7027. adminUserInfo := this.GetAdminUserInfo()
  7028. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7029. if err == nil {
  7030. this.ServeSuccessJSON(map[string]interface{}{
  7031. "prescriptions": prescriptions,
  7032. })
  7033. return
  7034. } else {
  7035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7036. return
  7037. }
  7038. }
  7039. func (this *HisApiController) GetHisDayPrescription() {
  7040. timeLayout := "2006-01-02"
  7041. loc, _ := time.LoadLocation("Local")
  7042. start_time := this.GetString("start_time")
  7043. patient_id, _ := this.GetInt64("patient_id", 0)
  7044. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7045. end_time := this.GetString("end_time")
  7046. p_type, _ := this.GetInt64("p_type")
  7047. order_status, _ := this.GetInt64("type")
  7048. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7049. adminUserInfo := this.GetAdminUserInfo()
  7050. var dayHisPrescription []*models.HisPrescription
  7051. var err error
  7052. if order_status == 1 || order_status == 0 {
  7053. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7054. } else if order_status == 2 {
  7055. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7056. }
  7057. var settle_total float64
  7058. for _, item := range dayHisPrescription {
  7059. if len(item.HisPrescriptionProject) > 0 {
  7060. for _, subItem := range item.HisPrescriptionProject {
  7061. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7062. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7063. settle_total = settle_total + total
  7064. }
  7065. }
  7066. if len(item.HisDoctorAdviceInfo) > 0 {
  7067. for _, subItem := range item.HisDoctorAdviceInfo {
  7068. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7069. settle_total = settle_total + total
  7070. }
  7071. }
  7072. }
  7073. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7074. if err == nil {
  7075. this.ServeSuccessJSON(map[string]interface{}{
  7076. "day_prescription": dayHisPrescription,
  7077. "settle_total": settle_total,
  7078. })
  7079. return
  7080. } else {
  7081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7082. return
  7083. }
  7084. }
  7085. func (c *HisApiController) GetHisChargePatientList() {
  7086. record_date := c.GetString("record_date")
  7087. order_status, _ := c.GetInt64("type")
  7088. sch_type, _ := c.GetInt64("sch_type")
  7089. timeLayout := "2006-01-02"
  7090. loc, _ := time.LoadLocation("Local")
  7091. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7092. if err != nil {
  7093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7094. return
  7095. }
  7096. recordDateTime := theTime.Unix()
  7097. adminInfo := c.GetAdminUserInfo()
  7098. var tempPatients []*service.NewTempPatients
  7099. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7100. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7101. if order_status != 2 {
  7102. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7103. } else {
  7104. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7105. }
  7106. } else {
  7107. if order_status != 2 {
  7108. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7109. } else {
  7110. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7111. }
  7112. }
  7113. var patients []*service.NewTempPatients
  7114. var patients_two []*service.NewTempPatients
  7115. for _, item := range tempPatients {
  7116. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7117. //过滤掉没挂号的和没开处方的
  7118. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7119. patients = append(patients, item)
  7120. }
  7121. //过滤掉没挂号的
  7122. if len(item.HisPatient) > 0 {
  7123. patients_two = append(patients_two, item)
  7124. }
  7125. } else {
  7126. if len(item.HisPrescription) > 0 {
  7127. patients = append(patients, item)
  7128. }
  7129. }
  7130. }
  7131. c.ServeSuccessJSON(map[string]interface{}{
  7132. "list": patients,
  7133. "list_two": patients_two,
  7134. })
  7135. }
  7136. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7137. record_date := c.GetString("record_date")
  7138. timeLayout := "2006-01-02"
  7139. loc, _ := time.LoadLocation("Local")
  7140. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7141. if err != nil {
  7142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7143. return
  7144. }
  7145. recordDateTime := theTime.Unix()
  7146. adminUser := c.GetAdminUserInfo()
  7147. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7148. var patients []*service.Patients
  7149. for _, item := range tempPatients {
  7150. if item.HisPatient.ID == 0 {
  7151. patients = append(patients, item)
  7152. }
  7153. }
  7154. c.ServeSuccessJSON(map[string]interface{}{
  7155. "list": patients,
  7156. //"list_two": patients_two,
  7157. })
  7158. }
  7159. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7160. newArr = make([]*service.Patients, 0)
  7161. for i := 0; i < len(patient); i++ {
  7162. repeat := false
  7163. for j := i + 1; j < len(patient); j++ {
  7164. if patient[i].ID == patient[j].ID {
  7165. repeat = true
  7166. break
  7167. }
  7168. }
  7169. if !repeat {
  7170. newArr = append(newArr, patient[i])
  7171. }
  7172. }
  7173. return
  7174. }
  7175. func (c *HisApiController) GetHisChargePatientInfo() {
  7176. patient_id, _ := c.GetInt64("patient_id")
  7177. his_patient_id, _ := c.GetInt64("his_patient_id")
  7178. record_date := c.GetString("record_date")
  7179. //start_time := c.GetString("start_time")
  7180. //end_time := c.GetString("end_time")
  7181. order_status, _ := c.GetInt64("type", 0)
  7182. p_type, _ := c.GetInt64("p_type", 0)
  7183. order_id, _ := c.GetInt64("order_id", 0)
  7184. timeLayout := "2006-01-02"
  7185. loc, _ := time.LoadLocation("Local")
  7186. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7187. if err != nil {
  7188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7189. return
  7190. }
  7191. recordDateTime := theTime.Unix()
  7192. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7193. //if err != nil {
  7194. //
  7195. //}
  7196. //startRecordDateTime := startTime.Unix()
  7197. //
  7198. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7199. //if err != nil {
  7200. //
  7201. //}
  7202. //endRecordDateTime := endTime.Unix()
  7203. admin := c.GetAdminUserInfo()
  7204. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7205. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7206. var prescriptions []*models.HisPrescription
  7207. //var unChargeMonthPrescriptions []*models.HisPrescription
  7208. order, _ := service.GetHisOrderByID(order_id)
  7209. if order_status == 1 || order_status == 0 {
  7210. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7211. } else if order_status == 2 {
  7212. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7213. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7214. }
  7215. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7216. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7217. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7218. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7219. //获取所有科室信息
  7220. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7221. c.ServeSuccessJSON(map[string]interface{}{
  7222. "his_info": his_patient_info,
  7223. "xt_info": xt_patient_info,
  7224. "prescription": prescriptions,
  7225. "case_history": case_history,
  7226. "info": patientPrescriptionInfo,
  7227. "last_info": lastPatientPrescriptionInfo,
  7228. "order": order,
  7229. "doctors": doctors,
  7230. "department": department,
  7231. })
  7232. return
  7233. }
  7234. func (c *HisApiController) GetAllOrderDetail() {
  7235. order_id, _ := c.GetInt64("id", 0)
  7236. order, _ := service.GetHisOrderByID(order_id)
  7237. if order.ID == 0 {
  7238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7239. return
  7240. }
  7241. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7242. org_id := c.GetAdminUserInfo().CurrentOrgId
  7243. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7244. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7245. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7246. c.ServeSuccessJSON(map[string]interface{}{
  7247. "order": order,
  7248. "order_info": order_info,
  7249. "patient": patient,
  7250. "admin_info": adminInfo,
  7251. "hospital_record": record,
  7252. })
  7253. return
  7254. }
  7255. func (c *HisApiController) GetAllOrderDetailCollect() {
  7256. order_id, _ := c.GetInt64("id", 0)
  7257. order, _ := service.GetHisOrderByID(order_id)
  7258. if order.ID == 0 {
  7259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7260. return
  7261. }
  7262. org_id := c.GetAdminUserInfo().CurrentOrgId
  7263. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7264. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7265. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7266. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7267. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7268. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7269. var bedCostTotal float64 = 0 //床位总费
  7270. //var bedCostSelfTotal float64 = 0 //床位自费
  7271. var operationCostTotal float64 = 0 //手术费
  7272. //var operationCostSelfTotal float64 = 0 //手术费
  7273. var otherCostTotal float64 = 0 //其他费用
  7274. //var otherCostSelfTotal float64 = 0 //其他费用
  7275. var materialCostTotal float64 = 0 //材料费
  7276. //var materialCostSelfTotal float64 = 0 //材料费
  7277. var westernMedicineCostTotal float64 = 0 //西药费
  7278. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7279. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7280. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7281. var checkCostTotal float64 = 0 //检查费
  7282. //var checkCostSelfTotal float64 = 0 //检查费
  7283. var laboratoryCostTotal float64 = 0 //化验费
  7284. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7285. var treatCostTotal float64 = 0 //治疗费用
  7286. //var treatCostSelfTotal float64 = 0 //治疗费用
  7287. var zhenChaCostTotal float64 = 0 //其他费用
  7288. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7289. decimal.DivisionPrecision = 2
  7290. var BalanceAccountsType int64
  7291. if his.ID > 0 {
  7292. BalanceAccountsType = his.BalanceAccountsType
  7293. } else {
  7294. BalanceAccountsType = record.BalanceAccountsType
  7295. }
  7296. if BalanceAccountsType != 2 {
  7297. for _, item := range order_info {
  7298. if org_id == 10215 {
  7299. if item.MedChrgitmType == "01" { //床位费
  7300. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7301. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7302. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7303. }
  7304. if item.MedChrgitmType == "02" { //诊察费
  7305. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7306. //zhenChaCostSelfTotal = zhenChaCostTotal
  7307. }
  7308. if item.MedChrgitmType == "03" { //检查费
  7309. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7310. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7311. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7312. }
  7313. //if item.MedChrgitmType == "02" { //检查费
  7314. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7315. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7316. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7317. //}
  7318. if item.MedChrgitmType == "04" { //化验费
  7319. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7320. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7321. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7322. }
  7323. if item.MedChrgitmType == "05" { //治疗费
  7324. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7325. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7326. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7327. }
  7328. if item.MedChrgitmType == "06" { //手术费
  7329. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7330. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7331. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7332. }
  7333. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7334. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7335. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7336. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7337. }
  7338. if item.MedChrgitmType == "09" { //西药费
  7339. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7340. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7341. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7342. }
  7343. if item.MedChrgitmType == "11" { //中成费
  7344. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7345. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7346. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7347. }
  7348. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7349. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7350. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7351. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7352. }
  7353. } else if org_id == 10188 || org_id == 10217 {
  7354. if item.MedChrgitmType == "01" { //床位费
  7355. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7356. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7357. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7358. }
  7359. if item.MedChrgitmType == "02" { //诊察费
  7360. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7361. //zhenChaCostSelfTotal = zhenChaCostTotal
  7362. }
  7363. if item.MedChrgitmType == "03" { //检查费
  7364. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7365. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7366. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7367. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7368. }
  7369. //if item.MedChrgitmType == "02" { //检查费
  7370. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7371. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7372. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7373. //}
  7374. if item.MedChrgitmType == "04" { //化验费
  7375. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7376. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7377. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7378. }
  7379. if item.MedChrgitmType == "05" { //治疗费
  7380. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7381. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7382. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7383. }
  7384. if item.MedChrgitmType == "06" { //手术费
  7385. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7386. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7387. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7388. }
  7389. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7390. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7391. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7392. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7393. }
  7394. if item.MedChrgitmType == "09" { //西药费
  7395. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7396. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7397. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7398. }
  7399. if item.MedChrgitmType == "11" { //中成费
  7400. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7401. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7402. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7403. }
  7404. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7405. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7406. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7407. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7408. }
  7409. } else {
  7410. if item.MedChrgitmType == "01" { //床位费
  7411. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7412. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7413. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7414. }
  7415. //if item.MedChrgitmType == "02" { //诊察费
  7416. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7417. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7418. //}
  7419. if item.MedChrgitmType == "03" { //检查费
  7420. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7421. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7422. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7423. }
  7424. //if item.MedChrgitmType == "02" { //检查费
  7425. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7426. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7427. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7428. //}
  7429. if item.MedChrgitmType == "04" { //化验费
  7430. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7431. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7432. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7433. }
  7434. if item.MedChrgitmType == "05" { //治疗费
  7435. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7436. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7437. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7438. }
  7439. if item.MedChrgitmType == "06" { //手术费
  7440. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7441. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7442. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7443. }
  7444. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7445. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7446. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7447. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7448. }
  7449. if item.MedChrgitmType == "09" { //西药费
  7450. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7451. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7452. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7453. }
  7454. if item.MedChrgitmType == "11" { //中成费
  7455. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7456. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7457. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7458. }
  7459. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7460. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7461. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7462. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7463. }
  7464. }
  7465. }
  7466. c.ServeSuccessJSON(map[string]interface{}{
  7467. "order": order,
  7468. "order_info": order_info,
  7469. "patient": patient,
  7470. "admin_info": adminInfo,
  7471. "his_hospital": record,
  7472. "bedCostTotal": bedCostTotal,
  7473. "operationCostTotal": operationCostTotal,
  7474. "otherCostTotal": otherCostTotal,
  7475. "materialCostTotal": materialCostTotal,
  7476. "westernMedicineCostTotal": westernMedicineCostTotal,
  7477. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7478. "checkCostTotal": checkCostTotal,
  7479. "zhenChaCostTotal": zhenChaCostTotal,
  7480. "laboratoryCostTotal": laboratoryCostTotal,
  7481. "treatCostTotal": treatCostTotal,
  7482. })
  7483. } else {
  7484. for _, item := range order_info {
  7485. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7486. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7487. item.MedChrgitmType = "09"
  7488. }
  7489. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7490. if item.HisPrescriptionProject.Type == 2 {
  7491. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7492. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7493. case 0:
  7494. item.MedChrgitmType = "0"
  7495. break
  7496. case 1:
  7497. item.MedChrgitmType = "14"
  7498. break
  7499. case 2:
  7500. item.MedChrgitmType = "05"
  7501. break
  7502. case 3:
  7503. item.MedChrgitmType = "03"
  7504. break
  7505. case 4:
  7506. item.MedChrgitmType = "03"
  7507. break
  7508. case 5:
  7509. item.MedChrgitmType = "08"
  7510. break
  7511. case 6:
  7512. item.MedChrgitmType = "14"
  7513. break
  7514. case 7:
  7515. item.MedChrgitmType = "14"
  7516. break
  7517. case 8:
  7518. item.MedChrgitmType = "03"
  7519. break
  7520. case 9:
  7521. item.MedChrgitmType = "14"
  7522. break
  7523. case 10:
  7524. item.MedChrgitmType = "14"
  7525. break
  7526. case 11:
  7527. item.MedChrgitmType = "06"
  7528. break
  7529. case 12:
  7530. item.MedChrgitmType = "12"
  7531. break
  7532. case 13:
  7533. item.MedChrgitmType = "01"
  7534. break
  7535. case 14:
  7536. item.MedChrgitmType = "04"
  7537. break
  7538. case 15:
  7539. item.MedChrgitmType = "14"
  7540. break
  7541. }
  7542. } else {
  7543. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7544. case 1:
  7545. item.MedChrgitmType = "14"
  7546. break
  7547. case 2:
  7548. item.MedChrgitmType = "05"
  7549. break
  7550. case 3:
  7551. item.MedChrgitmType = "04"
  7552. break
  7553. case 4:
  7554. item.MedChrgitmType = "14"
  7555. break
  7556. case 5:
  7557. item.MedChrgitmType = "08"
  7558. break
  7559. case 6:
  7560. item.MedChrgitmType = "14"
  7561. break
  7562. case 7:
  7563. item.MedChrgitmType = "14"
  7564. break
  7565. case 8:
  7566. item.MedChrgitmType = "03"
  7567. break
  7568. case 9:
  7569. item.MedChrgitmType = "14"
  7570. break
  7571. }
  7572. }
  7573. } else if item.HisPrescriptionProject.Type == 3 {
  7574. item.MedChrgitmType = "08"
  7575. }
  7576. }
  7577. }
  7578. for _, item := range order_info {
  7579. if org_id == 10215 {
  7580. if item.MedChrgitmType == "01" { //床位费
  7581. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7582. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7583. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7584. }
  7585. if item.MedChrgitmType == "02" { //诊察费
  7586. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7587. //zhenChaCostSelfTotal = zhenChaCostTotal
  7588. }
  7589. if item.MedChrgitmType == "03" { //检查费
  7590. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7591. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7592. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7593. }
  7594. //if item.MedChrgitmType == "02" { //检查费
  7595. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7596. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7597. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7598. //}
  7599. if item.MedChrgitmType == "04" { //化验费
  7600. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7601. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7602. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7603. }
  7604. if item.MedChrgitmType == "05" { //治疗费
  7605. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7606. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7607. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7608. }
  7609. if item.MedChrgitmType == "06" { //手术费
  7610. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7611. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7612. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7613. }
  7614. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7615. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7616. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7617. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7618. }
  7619. if item.MedChrgitmType == "09" { //西药费
  7620. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7621. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7622. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7623. }
  7624. if item.MedChrgitmType == "11" { //中成费
  7625. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7626. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7627. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7628. }
  7629. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7630. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7631. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7632. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7633. }
  7634. } else {
  7635. if item.MedChrgitmType == "01" { //床位费
  7636. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7637. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7638. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7639. }
  7640. //if item.MedChrgitmType == "02" { //诊察费
  7641. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7642. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7643. //}
  7644. if item.MedChrgitmType == "03" { //检查费
  7645. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7646. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7647. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7648. }
  7649. //if item.MedChrgitmType == "02" { //检查费
  7650. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7651. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7652. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7653. //}
  7654. if item.MedChrgitmType == "04" { //化验费
  7655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7656. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7657. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7658. }
  7659. if item.MedChrgitmType == "05" { //治疗费
  7660. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7661. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7662. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7663. }
  7664. if item.MedChrgitmType == "06" { //手术费
  7665. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7666. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7667. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7668. }
  7669. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7670. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7671. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7672. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7673. }
  7674. if item.MedChrgitmType == "09" { //西药费
  7675. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7676. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7677. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7678. }
  7679. if item.MedChrgitmType == "11" { //中成费
  7680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7681. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7682. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7683. }
  7684. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7685. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7686. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7687. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7688. }
  7689. }
  7690. }
  7691. c.ServeSuccessJSON(map[string]interface{}{
  7692. "order": order,
  7693. "order_info": order_info,
  7694. "patient": patient,
  7695. "admin_info": adminInfo,
  7696. "his_hospital": record,
  7697. "bedCostTotal": bedCostTotal,
  7698. "operationCostTotal": operationCostTotal,
  7699. "otherCostTotal": otherCostTotal,
  7700. "materialCostTotal": materialCostTotal,
  7701. "westernMedicineCostTotal": westernMedicineCostTotal,
  7702. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7703. "checkCostTotal": checkCostTotal,
  7704. "zhenChaCostTotal": zhenChaCostTotal,
  7705. "laboratoryCostTotal": laboratoryCostTotal,
  7706. "treatCostTotal": treatCostTotal,
  7707. })
  7708. }
  7709. }
  7710. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7711. page, _ := c.GetInt64("page")
  7712. limit, _ := c.GetInt64("limit")
  7713. keywords := c.GetString("keywords")
  7714. start_time := c.GetString("start_time")
  7715. end_time := c.GetString("end_time")
  7716. //clr_type := c.GetString("clr_type")
  7717. insutype := c.GetString("insutype")
  7718. timeLayout := "2006-01-02"
  7719. loc, _ := time.LoadLocation("Local")
  7720. var theStartTIme int64
  7721. if len(start_time) > 0 {
  7722. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7723. theStartTIme = theTime.Unix()
  7724. }
  7725. var theEndtTIme int64
  7726. if len(end_time) > 0 {
  7727. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7728. theEndtTIme = theTime.Unix()
  7729. }
  7730. if page <= 0 {
  7731. page = 1
  7732. }
  7733. if limit <= 0 {
  7734. limit = 10
  7735. }
  7736. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7737. c.ServeSuccessJSON(map[string]interface{}{
  7738. "total": total,
  7739. "list": list,
  7740. })
  7741. return
  7742. }
  7743. func (c *HisApiController) GetPutOnRecordList() {
  7744. page, _ := c.GetInt64("page")
  7745. limit, _ := c.GetInt64("limit")
  7746. keywords := c.GetString("keywords")
  7747. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7748. if page <= 0 {
  7749. page = 1
  7750. }
  7751. if limit <= 0 {
  7752. limit = 10
  7753. }
  7754. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7755. c.ServeSuccessJSON(map[string]interface{}{
  7756. "total": total,
  7757. "list": list,
  7758. })
  7759. return
  7760. }
  7761. func (c *HisApiController) GetCompareData() {
  7762. start_time := c.GetString("start_time")
  7763. end_time := c.GetString("end_time")
  7764. insutype := c.GetString("insutype")
  7765. clr_type := c.GetString("clr_type")
  7766. timeLayout := "2006-01-02"
  7767. loc, _ := time.LoadLocation("Local")
  7768. var theStartTIme int64
  7769. if len(start_time) > 0 {
  7770. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7771. if err != nil {
  7772. theStartTIme = 0
  7773. }
  7774. theStartTIme = theTime.Unix()
  7775. }
  7776. var theEndtTIme int64
  7777. if len(end_time) > 0 {
  7778. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7779. if err != nil {
  7780. theEndtTIme = 0
  7781. }
  7782. theEndtTIme = theTime.Unix()
  7783. }
  7784. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7785. fmt.Println(err)
  7786. if err == nil {
  7787. c.ServeSuccessJSON(map[string]interface{}{
  7788. "list": formData,
  7789. })
  7790. } else {
  7791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7792. return
  7793. }
  7794. }
  7795. func (c *HisApiController) GetFaPiaoData() {
  7796. order_id, _ := c.GetInt64("order_id")
  7797. patient_id, _ := c.GetInt64("patient_id")
  7798. //number := c.GetString("number")
  7799. adminUser := c.GetAdminUserInfo()
  7800. order, _ := service.GetHisOrderByID(order_id)
  7801. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7802. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7803. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7804. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7805. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7806. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7807. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7808. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7809. var bedCostTotal float64 = 0 //床位总费
  7810. var bedCostSelfTotal float64 = 0 //床位自费
  7811. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7812. var operationCostTotal float64 = 0 //手术费
  7813. var operationCostSelfTotal float64 = 0 //手术费
  7814. var operationCostPartSelfTotal float64 = 0 //手术费
  7815. var otherCostTotal float64 = 0 //其他费用
  7816. var otherCostSelfTotal float64 = 0 //其他费用
  7817. var otherCostPartSelfTotal float64 = 0 //其他费用
  7818. var materialCostTotal float64 = 0 //材料费
  7819. var materialCostSelfTotal float64 = 0 //材料费
  7820. var materialCostPartSelfTotal float64 = 0 //材料费
  7821. var westernMedicineCostTotal float64 = 0 //西药费
  7822. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7823. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7824. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7825. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7826. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7827. var checkCostTotal float64 = 0 //检查费
  7828. var checkCostSelfTotal float64 = 0 //检查费
  7829. var checkCostPartSelfTotal float64 = 0 //检查费
  7830. var hiliCostTotal float64 = 0 //护理费
  7831. var hiliCostSelfTotal float64 = 0 //护理费
  7832. var hiliCostPartSelfTotal float64 = 0 //护理费
  7833. var laboratoryCostTotal float64 = 0 //化验费
  7834. var laboratoryCostSelfTotal float64 = 0 //化验费
  7835. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7836. var treatCostTotal float64 = 0 //治疗费用
  7837. var treatCostSelfTotal float64 = 0 //治疗费用
  7838. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7839. var zhenChaCostTotal float64 = 0 //其他费用
  7840. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7841. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7842. decimal.DivisionPrecision = 2
  7843. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7844. var balanceAccountsType int64
  7845. if his.ID > 0 {
  7846. balanceAccountsType = his.BalanceAccountsType
  7847. } else {
  7848. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7849. }
  7850. if balanceAccountsType == 2 {
  7851. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7852. for _, item := range orderInfos_two {
  7853. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7854. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7855. item.MedChrgitmType = "09"
  7856. }
  7857. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7858. if item.HisPrescriptionProject.Type == 2 {
  7859. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7860. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7861. case 0:
  7862. item.MedChrgitmType = "0"
  7863. break
  7864. case 1:
  7865. item.MedChrgitmType = "14"
  7866. break
  7867. case 2:
  7868. item.MedChrgitmType = "05"
  7869. break
  7870. case 3:
  7871. item.MedChrgitmType = "03"
  7872. break
  7873. case 4:
  7874. item.MedChrgitmType = "03"
  7875. break
  7876. case 5:
  7877. item.MedChrgitmType = "08"
  7878. break
  7879. case 6:
  7880. item.MedChrgitmType = "14"
  7881. break
  7882. case 7:
  7883. item.MedChrgitmType = "14"
  7884. break
  7885. case 8:
  7886. item.MedChrgitmType = "03"
  7887. break
  7888. case 9:
  7889. item.MedChrgitmType = "14"
  7890. break
  7891. case 10:
  7892. item.MedChrgitmType = "14"
  7893. break
  7894. case 11:
  7895. item.MedChrgitmType = "06"
  7896. break
  7897. case 12:
  7898. item.MedChrgitmType = "12"
  7899. break
  7900. case 13:
  7901. item.MedChrgitmType = "01"
  7902. break
  7903. case 14:
  7904. item.MedChrgitmType = "04"
  7905. break
  7906. case 15:
  7907. item.MedChrgitmType = "02"
  7908. break
  7909. }
  7910. } else {
  7911. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7912. case 1:
  7913. item.MedChrgitmType = "14"
  7914. break
  7915. case 2:
  7916. item.MedChrgitmType = "05"
  7917. break
  7918. case 3:
  7919. item.MedChrgitmType = "03"
  7920. break
  7921. case 4:
  7922. item.MedChrgitmType = "03"
  7923. break
  7924. case 5:
  7925. item.MedChrgitmType = "08"
  7926. break
  7927. case 6:
  7928. item.MedChrgitmType = "14"
  7929. break
  7930. case 7:
  7931. item.MedChrgitmType = "14"
  7932. break
  7933. case 8:
  7934. item.MedChrgitmType = "03"
  7935. break
  7936. case 9:
  7937. item.MedChrgitmType = "14"
  7938. break
  7939. }
  7940. }
  7941. } else if item.HisPrescriptionProject.Type == 3 {
  7942. item.MedChrgitmType = "08"
  7943. }
  7944. }
  7945. }
  7946. for _, item := range orderInfos_two {
  7947. fmt.Println(item.MedChrgitmType)
  7948. if item.MedChrgitmType == "07" { //床位费
  7949. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7950. hiliCostSelfTotal = hiliCostTotal
  7951. }
  7952. if item.MedChrgitmType == "01" { //床位费
  7953. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7954. bedCostSelfTotal = bedCostTotal
  7955. }
  7956. if item.MedChrgitmType == "02" { //诊察费
  7957. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7958. zhenChaCostSelfTotal = zhenChaCostTotal
  7959. }
  7960. if item.MedChrgitmType == "03" { //检查费
  7961. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7962. checkCostSelfTotal = checkCostTotal
  7963. }
  7964. if item.MedChrgitmType == "04" { //化验费
  7965. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7966. laboratoryCostSelfTotal = laboratoryCostTotal
  7967. }
  7968. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7969. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7970. treatCostSelfTotal = treatCostTotal
  7971. }
  7972. if item.MedChrgitmType == "06" { //手术费
  7973. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7974. operationCostSelfTotal = treatCostTotal
  7975. }
  7976. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7977. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7978. materialCostSelfTotal = materialCostTotal
  7979. }
  7980. if item.MedChrgitmType == "09" { //西药费
  7981. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7982. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7983. }
  7984. if item.MedChrgitmType == "11" { //中成费
  7985. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7986. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7987. }
  7988. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7989. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7990. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7991. otherCostSelfTotal = otherCostTotal
  7992. }
  7993. } else {
  7994. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7995. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7996. otherCostSelfTotal = otherCostTotal
  7997. }
  7998. }
  7999. }
  8000. } else {
  8001. for _, item := range orderInfos {
  8002. if item.MedChrgitmType == "01" { //床位费
  8003. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8004. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8005. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8006. }
  8007. if item.MedChrgitmType == "02" { //诊察费
  8008. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8009. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8010. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8011. }
  8012. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8013. if item.MedChrgitmType == "03" { //检查费
  8014. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8015. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8016. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8017. }
  8018. } else {
  8019. if item.MedChrgitmType == "03" { //检查费
  8020. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8021. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8022. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8023. }
  8024. }
  8025. if item.MedChrgitmType == "04" { //化验费
  8026. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8027. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8028. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8029. }
  8030. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8031. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8032. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8033. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8034. }
  8035. if item.MedChrgitmType == "06" { //手术费
  8036. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8037. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8038. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8039. }
  8040. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8041. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8042. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8043. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8044. }
  8045. if item.MedChrgitmType == "07" { //西药费
  8046. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8047. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8048. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8049. }
  8050. if item.MedChrgitmType == "09" { //西药费
  8051. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8052. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8053. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8054. }
  8055. if item.MedChrgitmType == "11" { //中成费
  8056. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8057. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8058. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8059. }
  8060. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8061. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8062. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8063. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8064. }
  8065. }
  8066. }
  8067. timeLayout := "2006-01-02"
  8068. loc, _ := time.LoadLocation("Local")
  8069. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8070. if err != nil {
  8071. }
  8072. startRecordDateTime := startTime.Unix()
  8073. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8074. if err != nil {
  8075. }
  8076. endRecordDateTime := endTime.Unix()
  8077. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8078. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8079. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8080. c.ServeSuccessJSON(map[string]interface{}{
  8081. "order_number": order.Number, //业务流水号
  8082. "id_card_no": his.IdCardNo, //社会保障号
  8083. "patient": patient,
  8084. "department_name": department.Name, //科室
  8085. "number": his.Number, //门诊号
  8086. "date": order.SettleAccountsDate, //结算日期
  8087. "name": order.PsnName, //姓名
  8088. "gender": patient.Gender, //性别
  8089. "psn_cash_money": order.PsnCashPay, //个人支付
  8090. "pay_way": "门诊", //结算方式
  8091. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8092. "admin_user_name": admin.UserName, //收款员
  8093. "order": order,
  8094. "order_info": orderInfos_two,
  8095. "his": his,
  8096. "bedCostTotal": bedCostTotal,
  8097. "bedCostSelfTotal": bedCostSelfTotal,
  8098. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8099. "operationCostTotal": operationCostTotal,
  8100. "operationCostSelfTotal": operationCostSelfTotal,
  8101. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8102. "otherCostTotal": otherCostTotal,
  8103. "otherCostSelfTotal": otherCostSelfTotal,
  8104. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8105. "materialCostTotal": materialCostTotal,
  8106. "materialCostSelfTotal": materialCostSelfTotal,
  8107. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8108. "westernMedicineCostTotal": westernMedicineCostTotal,
  8109. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8110. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8111. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8112. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8113. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8114. "checkCostTotal": checkCostTotal,
  8115. "checkCostSelfTotal": checkCostSelfTotal,
  8116. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8117. "laboratoryCostTotal": laboratoryCostTotal,
  8118. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8119. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8120. "treatCostTotal": treatCostTotal,
  8121. "treatCostSelfTotal": treatCostSelfTotal,
  8122. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8123. "zhenChaCostTotal": zhenChaCostTotal,
  8124. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8125. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8126. "his_hospital_record": his_hospital_record,
  8127. "pre_pay_money": pre_pay_money,
  8128. "refund_sum": sum,
  8129. "doctor_info": doctor_info,
  8130. "hiliCostTotal": hiliCostTotal,
  8131. "hiliCostSelfTotal": hiliCostSelfTotal,
  8132. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8133. })
  8134. }
  8135. //func (c *HisApiController) GetFaPiaoDatas() {
  8136. // order_ids := c.GetString("order_ids")
  8137. // patient_id, _ := c.GetInt64("patient_id")
  8138. // adminUser := c.GetAdminUserInfo()
  8139. //
  8140. // orders := strings.Split(order_ids, ",")
  8141. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8142. //
  8143. // for _, item := range orders {
  8144. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8145. // order, _ := service.GetHisOrderByID(order_id)
  8146. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8147. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8148. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8149. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8150. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8151. //
  8152. // }
  8153. //
  8154. // var bedCostTotal float64 = 0 //床位总费
  8155. // var bedCostSelfTotal float64 = 0 //床位自费
  8156. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8157. //
  8158. // var operationCostTotal float64 = 0 //手术费
  8159. // var operationCostSelfTotal float64 = 0 //手术费
  8160. // var operationCostPartSelfTotal float64 = 0 //手术费
  8161. //
  8162. // var otherCostTotal float64 = 0 //其他费用
  8163. // var otherCostSelfTotal float64 = 0 //其他费用
  8164. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8165. //
  8166. // var materialCostTotal float64 = 0 //材料费
  8167. // var materialCostSelfTotal float64 = 0 //材料费
  8168. // var materialCostPartSelfTotal float64 = 0 //材料费
  8169. //
  8170. // var westernMedicineCostTotal float64 = 0 //西药费
  8171. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8172. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8173. //
  8174. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8175. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8176. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8177. //
  8178. // var checkCostTotal float64 = 0 //检查费
  8179. // var checkCostSelfTotal float64 = 0 //检查费
  8180. // var checkCostPartSelfTotal float64 = 0 //检查费
  8181. //
  8182. // var laboratoryCostTotal float64 = 0 //化验费
  8183. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8184. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8185. //
  8186. // var treatCostTotal float64 = 0 //治疗费用
  8187. // var treatCostSelfTotal float64 = 0 //治疗费用
  8188. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8189. //
  8190. // var zhenChaCostTotal float64 = 0 //其他费用
  8191. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8192. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8193. //
  8194. // decimal.DivisionPrecision = 2
  8195. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8196. //
  8197. // var balanceAccountsType int64
  8198. // if his.ID > 0 {
  8199. // balanceAccountsType = his.BalanceAccountsType
  8200. // } else {
  8201. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8202. // }
  8203. // if balanceAccountsType == 2 {
  8204. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8205. // for _, item := range orderInfos_two {
  8206. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8207. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8208. // item.MedChrgitmType = "09"
  8209. // }
  8210. //
  8211. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8212. // if item.HisPrescriptionProject.Type == 2 {
  8213. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8214. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8215. // case 0:
  8216. // item.MedChrgitmType = "0"
  8217. // break
  8218. // case 1:
  8219. // item.MedChrgitmType = "14"
  8220. // break
  8221. // case 2:
  8222. // item.MedChrgitmType = "05"
  8223. //
  8224. // break
  8225. // case 3:
  8226. // item.MedChrgitmType = "03"
  8227. //
  8228. // break
  8229. // case 4:
  8230. // item.MedChrgitmType = "03"
  8231. //
  8232. // break
  8233. // case 5:
  8234. // item.MedChrgitmType = "08"
  8235. //
  8236. // break
  8237. // case 6:
  8238. // item.MedChrgitmType = "14"
  8239. //
  8240. // break
  8241. // case 7:
  8242. // item.MedChrgitmType = "14"
  8243. //
  8244. // break
  8245. // case 8:
  8246. // item.MedChrgitmType = "03"
  8247. // break
  8248. // case 9:
  8249. // item.MedChrgitmType = "14"
  8250. // break
  8251. // case 10:
  8252. // item.MedChrgitmType = "14"
  8253. // break
  8254. // case 11:
  8255. // item.MedChrgitmType = "06"
  8256. // break
  8257. // case 12:
  8258. // item.MedChrgitmType = "12"
  8259. // break
  8260. // case 13:
  8261. // item.MedChrgitmType = "01"
  8262. // break
  8263. // case 14:
  8264. // item.MedChrgitmType = "04"
  8265. // break
  8266. // case 15:
  8267. // item.MedChrgitmType = "02"
  8268. // break
  8269. //
  8270. // }
  8271. //
  8272. // } else {
  8273. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8274. //
  8275. // case 1:
  8276. // item.MedChrgitmType = "14"
  8277. // break
  8278. // case 2:
  8279. // item.MedChrgitmType = "05"
  8280. //
  8281. // break
  8282. // case 3:
  8283. // item.MedChrgitmType = "03"
  8284. //
  8285. // break
  8286. // case 4:
  8287. // item.MedChrgitmType = "03"
  8288. //
  8289. // break
  8290. // case 5:
  8291. // item.MedChrgitmType = "08"
  8292. //
  8293. // break
  8294. // case 6:
  8295. // item.MedChrgitmType = "14"
  8296. //
  8297. // break
  8298. // case 7:
  8299. // item.MedChrgitmType = "14"
  8300. //
  8301. // break
  8302. // case 8:
  8303. // item.MedChrgitmType = "03"
  8304. // break
  8305. // case 9:
  8306. // item.MedChrgitmType = "14"
  8307. // break
  8308. //
  8309. // }
  8310. //
  8311. // }
  8312. //
  8313. // } else if item.HisPrescriptionProject.Type == 3 {
  8314. // item.MedChrgitmType = "08"
  8315. // }
  8316. // }
  8317. // }
  8318. //
  8319. // for _, item := range orderInfos_two {
  8320. // fmt.Println(item.MedChrgitmType)
  8321. // if item.MedChrgitmType == "01" { //床位费
  8322. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8323. // bedCostSelfTotal = bedCostTotal
  8324. // }
  8325. //
  8326. // if item.MedChrgitmType == "02" { //诊察费
  8327. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8328. // zhenChaCostSelfTotal = zhenChaCostTotal
  8329. // }
  8330. //
  8331. // if item.MedChrgitmType == "03" { //检查费
  8332. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8333. // checkCostSelfTotal = checkCostTotal
  8334. // }
  8335. //
  8336. // if item.MedChrgitmType == "04" { //化验费
  8337. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8338. // laboratoryCostSelfTotal = laboratoryCostTotal
  8339. // }
  8340. //
  8341. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8342. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8343. // treatCostSelfTotal = treatCostTotal
  8344. // }
  8345. //
  8346. // if item.MedChrgitmType == "06" { //手术费
  8347. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8348. // operationCostSelfTotal = treatCostTotal
  8349. // }
  8350. //
  8351. // if item.MedChrgitmType == "08" { //材料费
  8352. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8353. // materialCostSelfTotal = materialCostTotal
  8354. // }
  8355. //
  8356. // if item.MedChrgitmType == "09" { //西药费
  8357. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8358. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8359. // }
  8360. //
  8361. // if item.MedChrgitmType == "11" { //中成费
  8362. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8363. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8364. // }
  8365. //
  8366. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8367. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8368. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8369. // otherCostSelfTotal = otherCostTotal
  8370. // }
  8371. // } else {
  8372. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8373. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8374. // otherCostSelfTotal = otherCostTotal
  8375. // }
  8376. //
  8377. // }
  8378. //
  8379. // }
  8380. //
  8381. // } else {
  8382. // for _, item := range orderInfos {
  8383. // if item.MedChrgitmType == "01" { //床位费
  8384. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8385. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8386. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8387. // }
  8388. //
  8389. // if item.MedChrgitmType == "02" { //诊察费
  8390. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8391. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8392. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8393. // }
  8394. //
  8395. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8396. // if item.MedChrgitmType == "03" { //检查费
  8397. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8398. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8399. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8400. //
  8401. // }
  8402. // } else {
  8403. // if item.MedChrgitmType == "03" { //检查费
  8404. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8405. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8406. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8407. // }
  8408. //
  8409. // }
  8410. //
  8411. // if item.MedChrgitmType == "04" { //化验费
  8412. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8413. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8414. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8415. //
  8416. // }
  8417. //
  8418. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8419. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8420. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8421. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8422. //
  8423. // }
  8424. //
  8425. // if item.MedChrgitmType == "06" { //手术费
  8426. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8427. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8428. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8429. // }
  8430. //
  8431. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8432. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8433. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8434. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8435. // }
  8436. //
  8437. // if item.MedChrgitmType == "09" { //西药费
  8438. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8439. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8440. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8441. // }
  8442. //
  8443. // if item.MedChrgitmType == "11" { //中成费
  8444. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8445. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8446. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8447. // }
  8448. //
  8449. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8450. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8451. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8452. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8453. // }
  8454. //
  8455. // }
  8456. // }
  8457. // timeLayout := "2006-01-02"
  8458. // loc, _ := time.LoadLocation("Local")
  8459. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8460. // if err != nil {
  8461. // }
  8462. // startRecordDateTime := startTime.Unix()
  8463. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8464. // if err != nil {
  8465. // }
  8466. // endRecordDateTime := endTime.Unix()
  8467. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8468. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8469. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8470. //
  8471. // c.ServeSuccessJSON(map[string]interface{}{
  8472. // "order_number": order.Number, //业务流水号
  8473. // "id_card_no": his.IdCardNo, //社会保障号
  8474. // "department_name": department.Name, //科室
  8475. // "number": his.Number, //门诊号
  8476. // "date": order.SettleAccountsDate, //结算日期
  8477. // "name": order.PsnName, //姓名
  8478. // "gender": patient.Gender, //性别
  8479. // "psn_cash_money": order.PsnCashPay, //个人支付
  8480. // "pay_way": "门诊", //结算方式
  8481. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8482. // "admin_user_name": admin.UserName, //收款员
  8483. // "order": order,
  8484. // "order_info": orderInfos_two,
  8485. // "his": his,
  8486. // "bedCostTotal": bedCostTotal,
  8487. // "bedCostSelfTotal": bedCostSelfTotal,
  8488. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8489. // "operationCostTotal": operationCostTotal,
  8490. // "operationCostSelfTotal": operationCostSelfTotal,
  8491. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8492. // "otherCostTotal": otherCostTotal,
  8493. // "otherCostSelfTotal": otherCostSelfTotal,
  8494. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8495. // "materialCostTotal": materialCostTotal,
  8496. // "materialCostSelfTotal": materialCostSelfTotal,
  8497. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8498. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8499. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8500. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8501. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8502. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8503. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8504. // "checkCostTotal": checkCostTotal,
  8505. // "checkCostSelfTotal": checkCostSelfTotal,
  8506. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8507. // "laboratoryCostTotal": laboratoryCostTotal,
  8508. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8509. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8510. // "treatCostTotal": treatCostTotal,
  8511. // "treatCostSelfTotal": treatCostSelfTotal,
  8512. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8513. // "zhenChaCostTotal": zhenChaCostTotal,
  8514. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8515. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8516. // "his_hospital_record": his_hospital_record,
  8517. // "pre_pay_money": pre_pay_money,
  8518. // "refund_sum": sum,
  8519. // })
  8520. //
  8521. //}
  8522. func (this *HisApiController) GetIncomeStatisticsData() {
  8523. start_time := this.GetString("start_time")
  8524. end_time := this.GetString("end_time")
  8525. key_words := this.GetString("key_words")
  8526. limit, _ := this.GetInt64("limit")
  8527. page, _ := this.GetInt64("page")
  8528. if page <= 0 {
  8529. page = 1
  8530. }
  8531. if limit <= 0 {
  8532. limit = 10
  8533. }
  8534. statistics_type, _ := this.GetInt64("statistics_type")
  8535. admin := this.GetAdminUserInfo()
  8536. timeLayout := "2006-01-02"
  8537. loc, _ := time.LoadLocation("Local")
  8538. var theStartTIme int64
  8539. if len(start_time) > 0 {
  8540. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8541. if err != nil {
  8542. theStartTIme = 0
  8543. }
  8544. theStartTIme = theTime.Unix()
  8545. }
  8546. var theEndtTIme int64
  8547. if len(end_time) > 0 {
  8548. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8549. if err != nil {
  8550. theEndtTIme = 0
  8551. }
  8552. theEndtTIme = theTime.Unix()
  8553. }
  8554. if statistics_type == 1 {
  8555. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8556. this.ServeSuccessJSON(map[string]interface{}{
  8557. "list": list,
  8558. "total": total,
  8559. })
  8560. } else {
  8561. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8562. this.ServeSuccessJSON(map[string]interface{}{
  8563. "list": list,
  8564. "total": total,
  8565. })
  8566. }
  8567. }
  8568. func (c *HisApiController) PostProjectInformation() {
  8569. adminUser := c.GetAdminUserInfo()
  8570. orgId := adminUser.CurrentOrgId
  8571. dataBody := make(map[string]interface{}, 0)
  8572. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8573. if err != nil {
  8574. utils.ErrorLog(err.Error())
  8575. return
  8576. }
  8577. utils.ErrorLog("%v", dataBody)
  8578. var projectList []*models.HisProject
  8579. var total_goods []interface{}
  8580. tempProjects := dataBody["projects"].([]interface{})
  8581. total_goods = tempProjects
  8582. for index, projectMap := range tempProjects {
  8583. projectM := projectMap.(map[string]interface{})
  8584. var project models.HisProject
  8585. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8586. utils.ErrorLog("project_name")
  8587. return
  8588. }
  8589. project_name, _ := projectM["project_name"].(string)
  8590. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8591. err_log := models.ExportErrLog{
  8592. LogType: 6,
  8593. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8594. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8595. Status: 1,
  8596. CreateTime: time.Now().Unix(),
  8597. UpdateTime: time.Now().Unix(),
  8598. ExportTime: time.Now().Unix(),
  8599. }
  8600. service.CreateExportErrLog(&err_log)
  8601. continue
  8602. }
  8603. project.ProjectName = project_name
  8604. prices := projectM["price"].(string)
  8605. price, _ := strconv.ParseFloat(prices, 64)
  8606. if price <= 0 { //名字为空则生成一条导入错误日志
  8607. err_log := models.ExportErrLog{
  8608. LogType: 6,
  8609. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8610. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8611. Status: 1,
  8612. CreateTime: time.Now().Unix(),
  8613. UpdateTime: time.Now().Unix(),
  8614. ExportTime: time.Now().Unix(),
  8615. }
  8616. service.CreateExportErrLog(&err_log)
  8617. continue
  8618. }
  8619. project.Price = price
  8620. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8621. utils.ErrorLog("unit_id")
  8622. return
  8623. }
  8624. unit := projectM["unit"].(string)
  8625. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8626. err_log := models.ExportErrLog{
  8627. LogType: 6,
  8628. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8629. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8630. Status: 1,
  8631. CreateTime: time.Now().Unix(),
  8632. UpdateTime: time.Now().Unix(),
  8633. ExportTime: time.Now().Unix(),
  8634. }
  8635. service.CreateExportErrLog(&err_log)
  8636. continue
  8637. }
  8638. project.Unit = unit
  8639. cost_classify := projectM["cost_classify"].(string)
  8640. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8641. err_log := models.ExportErrLog{
  8642. LogType: 6,
  8643. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8644. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8645. Status: 1,
  8646. CreateTime: time.Now().Unix(),
  8647. UpdateTime: time.Now().Unix(),
  8648. ExportTime: time.Now().Unix(),
  8649. }
  8650. service.CreateExportErrLog(&err_log)
  8651. continue
  8652. }
  8653. var costClassify = "费用类别"
  8654. var cost_classify_id int64
  8655. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8656. if len(cost_classify) != 0 {
  8657. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8658. if errcode == gorm.ErrRecordNotFound {
  8659. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8660. dataconfig := models.DictDataconfig{
  8661. ParentId: costClassifyConfig.ID,
  8662. Module: "system",
  8663. OrgId: orgId,
  8664. Name: cost_classify,
  8665. FieldName: "",
  8666. Value: costConfig.Value + 1,
  8667. CreatedTime: "",
  8668. UpdatedTime: "",
  8669. CreateUserId: adminUser.AdminUser.Id,
  8670. Status: 1,
  8671. Remark: "",
  8672. DeleteIdSystem: 0,
  8673. Title: "",
  8674. Content: "",
  8675. Order: 0,
  8676. Code: "",
  8677. }
  8678. service.CreatedDicConfig(&dataconfig)
  8679. }
  8680. }
  8681. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8682. for _, it := range costClassList {
  8683. if cost_classify == it.Name {
  8684. cost_classify_id = int64(it.Value)
  8685. }
  8686. }
  8687. project.CostClassify = cost_classify_id
  8688. executive_section := projectM["executive_section"].(string)
  8689. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8690. err_log := models.ExportErrLog{
  8691. LogType: 6,
  8692. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8693. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8694. Status: 1,
  8695. CreateTime: time.Now().Unix(),
  8696. UpdateTime: time.Now().Unix(),
  8697. ExportTime: time.Now().Unix(),
  8698. }
  8699. service.CreateExportErrLog(&err_log)
  8700. continue
  8701. }
  8702. if len(executive_section) != 0 {
  8703. //查找科室是否有内容
  8704. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8705. if errcodedepart == gorm.ErrRecordNotFound {
  8706. department := models.XtHisDepartment{
  8707. Name: executive_section,
  8708. Status: 1,
  8709. UserOrgId: adminUser.CurrentOrgId,
  8710. CreatedTime: time.Now().Unix(),
  8711. }
  8712. service.CreateDePartment(&department)
  8713. }
  8714. }
  8715. var executive_section_id int64
  8716. departMentList, _ := service.GetAllDepartMent(orgId)
  8717. for _, it := range departMentList {
  8718. if executive_section == it.Name {
  8719. executive_section_id = it.ID
  8720. }
  8721. }
  8722. project.ExecutiveSection = executive_section_id
  8723. medical_coverage := projectM["medical_coverage"].(string)
  8724. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8725. err_log := models.ExportErrLog{
  8726. LogType: 6,
  8727. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8728. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8729. Status: 1,
  8730. CreateTime: time.Now().Unix(),
  8731. UpdateTime: time.Now().Unix(),
  8732. ExportTime: time.Now().Unix(),
  8733. }
  8734. service.CreateExportErrLog(&err_log)
  8735. continue
  8736. }
  8737. var medicalCoverage = "医保等级"
  8738. var medical_coverage_id int64
  8739. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8740. if len(medical_coverage) != 0 {
  8741. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8742. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8743. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8744. dataconfig := models.DictDataconfig{
  8745. ParentId: medicalCoverageConfig.ID,
  8746. Module: "system",
  8747. OrgId: orgId,
  8748. Name: medical_coverage,
  8749. FieldName: "",
  8750. Value: medicalCoverageConfig.Value + 1,
  8751. CreatedTime: "",
  8752. UpdatedTime: "",
  8753. CreateUserId: adminUser.AdminUser.Id,
  8754. Status: 1,
  8755. Remark: "",
  8756. DeleteIdSystem: 0,
  8757. Title: "",
  8758. Content: "",
  8759. Order: 0,
  8760. Code: "",
  8761. }
  8762. service.CreatedDicConfig(&dataconfig)
  8763. }
  8764. }
  8765. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8766. for _, it := range medicalCoverageList {
  8767. if medical_coverage == it.Name {
  8768. medical_coverage_id = int64(it.Value)
  8769. }
  8770. }
  8771. project.MedicalCoverage = medical_coverage_id
  8772. pinyin := projectM["pinyin"].(string)
  8773. project.Pinyin = pinyin
  8774. wubi := projectM["wubi"].(string)
  8775. project.Wubi = wubi
  8776. statistical_classification := projectM["statistical_classification"].(string)
  8777. var statisticalClassification = "统计分类"
  8778. var statistical_classification_id int64
  8779. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8780. if len(statistical_classification) != 0 {
  8781. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8782. if classificationerrcodes == gorm.ErrRecordNotFound {
  8783. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8784. dataconfig := models.DictDataconfig{
  8785. ParentId: classiFication.ID,
  8786. Module: "system",
  8787. OrgId: orgId,
  8788. Name: statistical_classification,
  8789. FieldName: "",
  8790. Value: classiFicationConfig.Value + 1,
  8791. CreatedTime: "",
  8792. UpdatedTime: "",
  8793. CreateUserId: adminUser.AdminUser.Id,
  8794. Status: 1,
  8795. Remark: "",
  8796. DeleteIdSystem: 0,
  8797. Title: "",
  8798. Content: "",
  8799. Order: 0,
  8800. Code: "",
  8801. }
  8802. service.CreatedDicConfig(&dataconfig)
  8803. }
  8804. }
  8805. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8806. for _, it := range classiFicationList {
  8807. if statistical_classification == it.Name {
  8808. statistical_classification_id = int64(it.Value)
  8809. }
  8810. }
  8811. project.StatisticalClassification = statistical_classification_id
  8812. disease_directory := int64(projectM["disease_directory"].(float64))
  8813. project.DiseaseDirectory = disease_directory
  8814. is_record := int64(projectM["is_record"].(float64))
  8815. project.IsRecord = is_record
  8816. medical_code := projectM["medical_code"].(string)
  8817. project.MedicalCode = medical_code
  8818. tube_color := projectM["tube_color"].(string)
  8819. var tubeColor = "试管颜色"
  8820. var tube_color_id int64
  8821. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8822. if len(tube_color) != 0 {
  8823. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8824. if errcodetube == gorm.ErrRecordNotFound {
  8825. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8826. dataconfig := models.DictDataconfig{
  8827. ParentId: tubeColorConfig.ID,
  8828. Module: "system",
  8829. OrgId: orgId,
  8830. Name: tube_color,
  8831. FieldName: "",
  8832. Value: tubeConfig.Value + 1,
  8833. CreatedTime: "",
  8834. UpdatedTime: "",
  8835. CreateUserId: adminUser.AdminUser.Id,
  8836. Status: 1,
  8837. Remark: "",
  8838. DeleteIdSystem: 0,
  8839. Title: "",
  8840. Content: "",
  8841. Order: 0,
  8842. Code: "",
  8843. }
  8844. service.CreatedDicConfig(&dataconfig)
  8845. }
  8846. }
  8847. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8848. for _, it := range tubeColorList {
  8849. if tube_color == it.Name {
  8850. tube_color_id = int64(it.Value)
  8851. }
  8852. }
  8853. project.TubeColor = tube_color_id
  8854. single_dose := projectM["single_dose"].(string)
  8855. project.SingleDose = single_dose
  8856. execution_frequency := projectM["execution_frequency"].(string)
  8857. project.ExecutionFrequency = execution_frequency
  8858. delivery_way := projectM["delivery_way"].(string)
  8859. project.DeliveryWay = delivery_way
  8860. number_days := projectM["number_days"].(string)
  8861. project.NumberDays = number_days
  8862. total := projectM["total"].(string)
  8863. project.Total = total
  8864. medical_status := int64(projectM["medical_status"].(float64))
  8865. project.MedicalStatus = medical_status
  8866. category := int64(projectM["category"].(float64))
  8867. project.Category = category
  8868. specail_project := int64(projectM["specail_project"].(float64))
  8869. project.SpecailProject = specail_project
  8870. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8871. project.SocialSecurityDirectoryCode = social_security_directory_code
  8872. remark := projectM["remark"].(string)
  8873. project.Remark = remark
  8874. record_date := projectM["record_date"].(string)
  8875. timeLayout := "2006-01-02"
  8876. loc, _ := time.LoadLocation("Local")
  8877. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8878. project.RecordDate = theTime.Unix()
  8879. projectList = append(projectList, &project)
  8880. }
  8881. export_time := time.Now().Unix()
  8882. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8883. if len(projectList) > 0 {
  8884. for _, item := range projectList {
  8885. project := models.HisProject{
  8886. ProjectName: item.ProjectName,
  8887. Price: item.Price,
  8888. Unit: item.Unit,
  8889. CostClassify: item.CostClassify,
  8890. ExecutiveSection: item.ExecutiveSection,
  8891. MedicalCoverage: item.MedicalCoverage,
  8892. UserOrgId: orgId,
  8893. Status: 1,
  8894. CreatedTime: time.Now().Unix(),
  8895. Pinyin: item.Pinyin,
  8896. Wubi: item.Wubi,
  8897. StatisticalClassification: item.StatisticalClassification,
  8898. DiseaseDirectory: item.DiseaseDirectory,
  8899. IsRecord: item.IsRecord,
  8900. MedicalCode: item.MedicalCode,
  8901. TubeColor: item.TubeColor,
  8902. SingleDose: item.SingleDose,
  8903. DeliveryWay: item.DeliveryWay,
  8904. NumberDays: item.NumberDays,
  8905. Total: item.Total,
  8906. Category: item.Category,
  8907. MedicalStatus: item.MedicalStatus,
  8908. SpecailProject: item.SpecailProject,
  8909. RecordDate: item.RecordDate,
  8910. Remark: item.Remark,
  8911. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8912. ExecutionFrequency: item.ExecutionFrequency,
  8913. }
  8914. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8915. if errcodeproject == gorm.ErrRecordNotFound {
  8916. service.CreateProjectInfomation(&project)
  8917. } else if errcodeproject == nil {
  8918. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8919. }
  8920. log := models.ExportLog{
  8921. LogType: 6,
  8922. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8923. TotalNum: int64(len(total_goods)),
  8924. FailNum: int64(len(errLogs)),
  8925. SuccessNum: int64(len(projectList)),
  8926. CreateTime: time.Now().Unix(),
  8927. UpdateTime: time.Now().Unix(),
  8928. ExportTime: export_time,
  8929. Status: 1,
  8930. }
  8931. service.CreateExportLog(&log)
  8932. c.ServeSuccessJSON(map[string]interface{}{
  8933. "msg": "导入成功",
  8934. "total_num": len(total_goods),
  8935. "success_num": len(projectList),
  8936. "fail_num": int64(len(errLogs)),
  8937. })
  8938. }
  8939. } else {
  8940. log := models.ExportLog{
  8941. LogType: 6,
  8942. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8943. TotalNum: int64(len(total_goods)),
  8944. FailNum: int64(len(errLogs)),
  8945. SuccessNum: int64(len(projectList)),
  8946. CreateTime: time.Now().Unix(),
  8947. UpdateTime: time.Now().Unix(),
  8948. ExportTime: export_time,
  8949. Status: 1,
  8950. }
  8951. service.CreateExportLog(&log)
  8952. c.ServeSuccessJSON(map[string]interface{}{
  8953. "msg": "导入成功",
  8954. "total_num": len(total_goods),
  8955. "success_num": len(projectList),
  8956. "fail_num": int64(len(errLogs)),
  8957. })
  8958. }
  8959. }
  8960. //func (this *HisApiController) EditProjectInformation(){
  8961. //
  8962. // id, _ := this.GetInt64("id")
  8963. // project_team := this.GetString("project_team")
  8964. // price := this.GetString("price")
  8965. // price_float, _ := strconv.ParseFloat(price, 64)
  8966. // pinyin := this.GetString("pinyin")
  8967. // wubi := this.GetString("wubi")
  8968. // tube_color, _ := this.GetInt64("tube_color")
  8969. // team_type, _ := this.GetInt64("team_type")
  8970. // remark := this.GetString("remark")
  8971. // ids := this.GetString("ids")
  8972. // item_id := this.GetString("item_id")
  8973. // projectTeam := models.XtHisProjectTeam{
  8974. // ProjectTeam: project_team,
  8975. // Price: price_float,
  8976. // Pinyin: pinyin,
  8977. // Wubi: wubi,
  8978. // TubeColor: tube_color,
  8979. // TeamType: team_type,
  8980. // Remark: remark,
  8981. // ProjectId: ids,
  8982. // ItemId: item_id,
  8983. // }
  8984. //
  8985. //
  8986. // dataBody := make(map[string]interface{}, 0)
  8987. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8988. // if err != nil {
  8989. // utils.ErrorLog(err.Error())
  8990. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8991. // return
  8992. // }
  8993. //
  8994. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8995. //
  8996. //
  8997. // if err != nil {
  8998. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8999. // return
  9000. // }
  9001. //
  9002. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9003. // infos, _ := dataBody["info"].([]interface{})
  9004. // if len(infos) > 0 {
  9005. // var ids []string
  9006. //
  9007. // for _, item := range infos {
  9008. // items := item.(map[string]interface{})
  9009. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9010. // utils.ErrorLog("id")
  9011. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9012. // return
  9013. // }
  9014. // id := int64(items["id"].(float64))
  9015. //
  9016. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9017. // utils.ErrorLog("type")
  9018. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9019. // return
  9020. // }
  9021. // types := int64(items["type"].(float64))
  9022. //
  9023. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9024. // utils.ErrorLog("number")
  9025. // }
  9026. //
  9027. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9028. //
  9029. // projectList := models.XtHisProjectList{
  9030. // Number: number,
  9031. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9032. // ProjectId: id,
  9033. // Status: 1,
  9034. // CreatedTime: time.Now().Unix(),
  9035. // UpdatedTime: time.Now().Unix(),
  9036. // TeamId: projectTeam.ID,
  9037. // Type: types,
  9038. // }
  9039. // list := projectList
  9040. //
  9041. // service.CreateProjectList(&list)
  9042. //
  9043. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9044. //
  9045. // }
  9046. // ids_str := strings.Join(ids, ",")
  9047. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9048. // service.SaveProjectTeam(&projectTeam)
  9049. // this.ServeSuccessJSON(map[string]interface{}{
  9050. // "projectTeam": projectTeam,
  9051. // })
  9052. // }
  9053. // }
  9054. //}
  9055. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9056. name := c.GetString("name")
  9057. mode_id, _ := c.GetInt64("mode", 0)
  9058. types, _ := c.GetInt64("type", 0)
  9059. patient_id, _ := c.GetInt64("patient_id", 0)
  9060. types = 1
  9061. adminInfo := c.GetAdminUserInfo()
  9062. template := &models.HisPrescriptionTemplate{
  9063. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9064. PatientId: patient_id,
  9065. Type: types,
  9066. Status: 1,
  9067. Ctime: time.Now().Unix(),
  9068. Mtime: time.Now().Unix(),
  9069. Name: name,
  9070. Mode: mode_id,
  9071. }
  9072. dataBody := make(map[string]interface{}, 0)
  9073. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9074. if err != nil {
  9075. utils.ErrorLog(err.Error())
  9076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9077. return
  9078. }
  9079. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9080. //如果已经存在记录则删除处方
  9081. if template_one.ID > 0 {
  9082. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9083. for _, item := range ps {
  9084. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  9085. }
  9086. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9087. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9088. if len(prescriptions) > 0 {
  9089. for _, item := range prescriptions {
  9090. items := item.(map[string]interface{})
  9091. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9092. utils.ErrorLog("type")
  9093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9094. return
  9095. }
  9096. types := int64(items["type"].(float64))
  9097. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9098. utils.ErrorLog("med_type")
  9099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9100. return
  9101. }
  9102. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9103. ctime := time.Now().Unix()
  9104. prescription := &models.HisPrescriptionInfoTemplate{
  9105. PatientId: patient_id,
  9106. UserOrgId: adminInfo.CurrentOrgId,
  9107. Ctime: ctime,
  9108. Mtime: ctime,
  9109. Type: types,
  9110. Modifier: adminInfo.AdminUser.Id,
  9111. Creator: adminInfo.AdminUser.Id,
  9112. Status: 1,
  9113. PTemplateId: template_one.ID,
  9114. MedType: med_type,
  9115. }
  9116. service.CreateHisPrescriptionInfoTemplate(prescription)
  9117. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9118. advices := items["advices"].([]interface{})
  9119. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9120. ctime := time.Now().Unix()
  9121. mtime := ctime
  9122. if len(advices) > 0 {
  9123. for _, advice := range advices {
  9124. var s models.HisPrescriptionAdviceTemplate
  9125. s.PrescriptionId = prescription.ID
  9126. s.AdviceType = 2
  9127. s.StopState = 2
  9128. s.ExecutionState = 2
  9129. s.Status = 1
  9130. s.UserOrgId = adminInfo.CurrentOrgId
  9131. s.CreatedTime = ctime
  9132. s.UpdatedTime = mtime
  9133. s.PatientId = patient_id
  9134. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9135. if errcode > 0 {
  9136. c.ServeFailJSONWithSGJErrorCode(errcode)
  9137. return
  9138. }
  9139. service.CreateHisPrescriptionAdviceTemplate(&s)
  9140. }
  9141. }
  9142. }
  9143. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9144. projects := items["project"].([]interface{})
  9145. if len(projects) > 0 {
  9146. for _, project := range projects {
  9147. var p models.HisPrescriptionProjectTemplate
  9148. p.PrescriptionId = prescription.ID
  9149. p.Ctime = time.Now().Unix()
  9150. p.Mtime = time.Now().Unix()
  9151. p.PatientId = patient_id
  9152. p.UserOrgId = adminInfo.CurrentOrgId
  9153. p.Status = 1
  9154. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9155. if errcode > 0 {
  9156. c.ServeFailJSONWithSGJErrorCode(errcode)
  9157. return
  9158. }
  9159. service.CreateHisPrescriptionProjectTemplate(&p)
  9160. }
  9161. }
  9162. }
  9163. }
  9164. c.ServeSuccessJSON(map[string]interface{}{
  9165. "msg": "创建成功",
  9166. })
  9167. }
  9168. }
  9169. } else {
  9170. err = service.CreateHisPrescriptionTemplate(template)
  9171. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9172. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9173. if len(prescriptions) > 0 {
  9174. for _, item := range prescriptions {
  9175. items := item.(map[string]interface{})
  9176. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9177. utils.ErrorLog("type")
  9178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9179. return
  9180. }
  9181. types := int64(items["type"].(float64))
  9182. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9183. utils.ErrorLog("med_type")
  9184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9185. return
  9186. }
  9187. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9188. ctime := time.Now().Unix()
  9189. prescription := &models.HisPrescriptionInfoTemplate{
  9190. PatientId: patient_id,
  9191. UserOrgId: adminInfo.CurrentOrgId,
  9192. Ctime: ctime,
  9193. Mtime: ctime,
  9194. Type: types,
  9195. Modifier: adminInfo.AdminUser.Id,
  9196. Creator: adminInfo.AdminUser.Id,
  9197. Status: 1,
  9198. PTemplateId: template.ID,
  9199. MedType: med_type,
  9200. }
  9201. service.CreateHisPrescriptionInfoTemplate(prescription)
  9202. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9203. advices := items["advices"].([]interface{})
  9204. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9205. ctime := time.Now().Unix()
  9206. mtime := ctime
  9207. if len(advices) > 0 {
  9208. for _, advice := range advices {
  9209. var s models.HisPrescriptionAdviceTemplate
  9210. s.PrescriptionId = prescription.ID
  9211. s.AdviceType = 2
  9212. s.StopState = 2
  9213. s.ExecutionState = 2
  9214. s.Status = 1
  9215. s.UserOrgId = adminInfo.CurrentOrgId
  9216. s.CreatedTime = ctime
  9217. s.UpdatedTime = mtime
  9218. s.PatientId = patient_id
  9219. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9220. if errcode > 0 {
  9221. c.ServeFailJSONWithSGJErrorCode(errcode)
  9222. return
  9223. }
  9224. service.CreateHisPrescriptionAdviceTemplate(&s)
  9225. }
  9226. }
  9227. }
  9228. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9229. projects := items["project"].([]interface{})
  9230. if len(projects) > 0 {
  9231. for _, project := range projects {
  9232. var p models.HisPrescriptionProjectTemplate
  9233. p.PrescriptionId = prescription.ID
  9234. p.Ctime = time.Now().Unix()
  9235. p.Mtime = time.Now().Unix()
  9236. p.PatientId = patient_id
  9237. p.UserOrgId = adminInfo.CurrentOrgId
  9238. p.Status = 1
  9239. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9240. if errcode > 0 {
  9241. c.ServeFailJSONWithSGJErrorCode(errcode)
  9242. return
  9243. }
  9244. service.CreateHisPrescriptionProjectTemplate(&p)
  9245. }
  9246. }
  9247. }
  9248. }
  9249. c.ServeSuccessJSON(map[string]interface{}{
  9250. "msg": "创建成功",
  9251. })
  9252. }
  9253. }
  9254. }
  9255. }
  9256. func (c *HisApiController) PreSettle() {
  9257. id, _ := c.GetInt64("id")
  9258. record_time := c.GetString("record_time")
  9259. his_patient_id, _ := c.GetInt64("his_patient_id")
  9260. timeLayout := "2006-01-02"
  9261. loc, _ := time.LoadLocation("Local")
  9262. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9263. diagnosis_id := c.GetString("diagnosis")
  9264. sick_type, _ := c.GetInt64("sick_type")
  9265. reg_type, _ := c.GetInt64("p_type")
  9266. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9267. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9268. if err != nil {
  9269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9270. return
  9271. }
  9272. recordDateTime := theTime.Unix()
  9273. adminUser := c.GetAdminUserInfo()
  9274. var prescriptions []*models.HisPrescription
  9275. var start_time int64
  9276. var end_time int64
  9277. ids_str := c.GetString("ids")
  9278. ids_arr := strings.Split(ids_str, ",")
  9279. fmt.Println(reg_type)
  9280. if settle_accounts_type == 1 { //日结
  9281. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9282. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9283. } else {
  9284. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9285. }
  9286. fmt.Println(prescriptions)
  9287. } else { //月结
  9288. start_time_str := c.GetString("start_time")
  9289. end_time_str := c.GetString("end_time")
  9290. timeLayout := "2006-01-02"
  9291. loc, _ := time.LoadLocation("Local")
  9292. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9293. if err != nil {
  9294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9295. return
  9296. }
  9297. recordStartTime := theStartTime.Unix()
  9298. start_time = recordStartTime
  9299. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9300. if err != nil {
  9301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9302. return
  9303. }
  9304. recordEndTime := theEndTime.Unix()
  9305. end_time = recordEndTime
  9306. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9307. }
  9308. if reg_type == 1111 || reg_type == 1112 {
  9309. reg_type = 11
  9310. }
  9311. timestamp := time.Now().Unix()
  9312. tempTime := time.Unix(timestamp, 0)
  9313. timeFormat := tempTime.Format("20060102150405")
  9314. chrgBchno := rand.Intn(100000) + 10000
  9315. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9316. strconv.FormatInt(his.PatientId, 10)
  9317. var ids []int64
  9318. for _, item := range prescriptions {
  9319. ids = append(ids, item.ID)
  9320. }
  9321. fmt.Println(ids)
  9322. var total float64
  9323. for _, item := range prescriptions {
  9324. fmt.Println(item)
  9325. if item.Type == 1 { //药品
  9326. for _, subItem := range item.HisDoctorAdviceInfo {
  9327. total = total + (subItem.Price * subItem.PrescribingNumber)
  9328. }
  9329. }
  9330. if item.Type == 2 { //项目
  9331. for _, subItem := range item.HisPrescriptionProject {
  9332. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9333. total = total + (subItem.Price * cnt)
  9334. }
  9335. }
  9336. for _, subItem := range item.HisAdditionalCharge {
  9337. total = total + (subItem.Price * float64(subItem.Count))
  9338. }
  9339. }
  9340. allTotal := fmt.Sprintf("%.2f", total)
  9341. totals, _ := strconv.ParseFloat(allTotal, 64)
  9342. order := &models.HisOrder{
  9343. UserOrgId: adminUser.CurrentOrgId,
  9344. HisPatientId: his.ID,
  9345. PatientId: id,
  9346. SettleAccountsDate: recordDateTime,
  9347. Ctime: time.Now().Unix(),
  9348. Mtime: time.Now().Unix(),
  9349. Status: 1,
  9350. OrderStatus: 1,
  9351. MdtrtId: his.Number,
  9352. Number: chrg_bchno,
  9353. MedfeeSumamt: totals,
  9354. SettleEndTime: end_time,
  9355. SettleStartTime: start_time,
  9356. SettleType: settle_accounts_type,
  9357. PsnPartAmt: totals,
  9358. PsnCashPay: totals,
  9359. PType: 2,
  9360. IsPre: 1,
  9361. MedType: strconv.Itoa(int(reg_type)),
  9362. Diagnosis: diagnosis_id,
  9363. }
  9364. err = service.CreateOrder(order)
  9365. if err != nil {
  9366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9367. return
  9368. }
  9369. var customs []*Custom
  9370. for _, item := range prescriptions {
  9371. fmt.Println(item.Type)
  9372. if item.Type == 1 { //药品
  9373. for _, subItem := range item.HisDoctorAdviceInfo {
  9374. cus := &Custom{
  9375. AdviceId: subItem.ID,
  9376. ProjectId: 0,
  9377. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9378. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9379. FeedetlSn: subItem.FeedetlSn,
  9380. Price: fmt.Sprintf("%.2f", subItem.Price),
  9381. MedListCodg: subItem.MedListCodg,
  9382. Type: 1,
  9383. }
  9384. customs = append(customs, cus)
  9385. }
  9386. }
  9387. if item.Type == 2 { //项目
  9388. for _, subItem := range item.HisPrescriptionProject {
  9389. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9390. cus := &Custom{
  9391. AdviceId: 0,
  9392. ProjectId: subItem.ID,
  9393. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9394. Cut: fmt.Sprintf("%.2f", cnt),
  9395. FeedetlSn: subItem.FeedetlSn,
  9396. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9397. MedListCodg: subItem.MedListCodg,
  9398. Type: 2,
  9399. }
  9400. customs = append(customs, cus)
  9401. }
  9402. }
  9403. for _, item := range item.HisAdditionalCharge {
  9404. cus := &Custom{
  9405. ItemId: item.ID,
  9406. AdviceId: 0,
  9407. ProjectId: 0,
  9408. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9409. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9410. FeedetlSn: item.FeedetlSn,
  9411. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9412. MedListCodg: item.XtHisAddtionConfig.Code,
  9413. Type: 3,
  9414. }
  9415. customs = append(customs, cus)
  9416. }
  9417. }
  9418. fmt.Println(customs)
  9419. for _, item := range customs {
  9420. var advice_id int64 = 0
  9421. var project_id int64 = 0
  9422. var item_id int64 = 0
  9423. var types int64 = 0
  9424. if item.Type == 1 {
  9425. advice_id = item.AdviceId
  9426. project_id = 0
  9427. item_id = 0
  9428. } else if item.Type == 2 {
  9429. advice_id = 0
  9430. item_id = 0
  9431. project_id = item.ProjectId
  9432. } else if item.Type == 3 {
  9433. advice_id = 0
  9434. item_id = item.ItemId
  9435. project_id = 0
  9436. }
  9437. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9438. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9439. pric, _ := strconv.ParseFloat(item.Price, 32)
  9440. info := &models.HisOrderInfo{
  9441. OrderNumber: order.Number,
  9442. UploadDate: time.Now().Unix(),
  9443. AdviceId: advice_id,
  9444. DetItemFeeSumamt: detItemFeeSumamt,
  9445. Cnt: cut,
  9446. Pric: pric,
  9447. PatientId: id,
  9448. Status: 1,
  9449. Mtime: time.Now().Unix(),
  9450. Ctime: time.Now().Unix(),
  9451. UserOrgId: adminUser.CurrentOrgId,
  9452. HisPatientId: his.ID,
  9453. OrderId: order.ID,
  9454. ProjectId: project_id,
  9455. Type: types,
  9456. ItemId: item_id,
  9457. }
  9458. service.CreateOrderInfo(info)
  9459. }
  9460. his.SickType = sick_type
  9461. service.UpdataHisPateint(&his)
  9462. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9463. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9464. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9465. if err == nil {
  9466. c.ServeSuccessJSON(map[string]interface{}{
  9467. "msg": "结算成功",
  9468. })
  9469. }
  9470. }
  9471. type CustomOrderInfo struct {
  9472. Name string
  9473. Spec string
  9474. Unit string
  9475. Count float64
  9476. Price float64
  9477. Total float64
  9478. }
  9479. func (c *HisApiController) GetPrivateExpensesInfo() {
  9480. order_id, _ := c.GetInt64("id", 0)
  9481. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9482. order, _ := service.GetHisOrderByID(order_id)
  9483. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9484. if order.ID == 0 {
  9485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9486. return
  9487. }
  9488. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9489. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9490. org_id := c.GetAdminUserInfo().CurrentOrgId
  9491. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9492. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9493. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9494. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9495. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9496. //var orderInfos_four []*models.HisOrderInfoTwo
  9497. //for _, item := range orderInfos_three {
  9498. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9499. // item.HisPrescriptionProject.IsCheckTeam = 1
  9500. // orderInfos_four = append(orderInfos_four, item)
  9501. //
  9502. // }
  9503. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9504. // item.HisPrescriptionProject.IsCheckTeam = 2
  9505. // orderInfos_two = append(orderInfos_two, item)
  9506. // }
  9507. //}
  9508. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9509. //var cus_slice []CustomOrderInfo
  9510. //for _, item := range new_order_info {
  9511. // var cus CustomOrderInfo
  9512. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9513. // cus.Unit = ""
  9514. // cus.Spec = ""
  9515. // var total float64
  9516. // for _, subItem := range orderInfos_four {
  9517. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9518. // total = total + subItem.DetItemFeeSumamt
  9519. // fmt.Println(subItem.DetItemFeeSumamt)
  9520. // }
  9521. // }
  9522. // cus.Count = 1
  9523. // cus.Total = total
  9524. // cus_slice = append(cus_slice, cus)
  9525. //}
  9526. orderInfos = append(orderInfos, orderInfos_two...)
  9527. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9528. //orderInfos = append(orderInfos, orderInfos_three...)
  9529. //}/**/
  9530. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9531. c.ServeSuccessJSON(map[string]interface{}{
  9532. "order": order,
  9533. "order_info": orderInfos,
  9534. "patient": patient,
  9535. "admin_info": adminInfo,
  9536. "his": his,
  9537. "current_admin": role,
  9538. "org_config": miConfig,
  9539. //"new_order_info": cus_slice,
  9540. })
  9541. }
  9542. func (this *HisApiController) ChangeMedType() {
  9543. med_type := this.GetString("med_type")
  9544. old_med_type := this.GetString("old_med_type")
  9545. ids := this.GetString("ids")
  9546. settle_type, _ := this.GetInt64("settle_type")
  9547. start_time := this.GetString("start_time")
  9548. end_time := this.GetString("end_time")
  9549. ids_arr := strings.Split(ids, ",")
  9550. if settle_type == 1 { //日结
  9551. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9552. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9553. prescription.MedType = med_type
  9554. err := service.SaveHisPrescription(&prescription)
  9555. if err == nil {
  9556. this.ServeSuccessJSON(map[string]interface{}{
  9557. "msg": "修改成功",
  9558. })
  9559. } else {
  9560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9561. return
  9562. }
  9563. } else if settle_type == 2 {
  9564. timeLayout := "2006-01-02"
  9565. loc, _ := time.LoadLocation("Local")
  9566. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9567. if err != nil {
  9568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9569. return
  9570. }
  9571. recordStartTime := theStartTime.Unix()
  9572. start_time_timestamp := recordStartTime
  9573. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9574. if err != nil {
  9575. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9576. return
  9577. }
  9578. recordEndTime := theEndTime.Unix()
  9579. end_time_timestamp := recordEndTime
  9580. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9581. if updateErr == nil {
  9582. this.ServeSuccessJSON(map[string]interface{}{
  9583. "msg": "修改成功",
  9584. })
  9585. } else {
  9586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9587. return
  9588. }
  9589. }
  9590. }
  9591. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9592. patient_id, _ := c.GetInt64("patient_id")
  9593. his_patient_id, _ := c.GetInt64("his_patient_id")
  9594. record_date := c.GetString("record_date")
  9595. start_time := c.GetString("start_time")
  9596. end_time := c.GetString("end_time")
  9597. order_status, _ := c.GetInt64("type", 0)
  9598. p_type, _ := c.GetInt64("p_type", 0)
  9599. order_id, _ := c.GetInt64("order_id", 0)
  9600. timeLayout := "2006-01-02"
  9601. loc, _ := time.LoadLocation("Local")
  9602. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9603. if err != nil {
  9604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9605. return
  9606. }
  9607. recordDateTime := theTime.Unix()
  9608. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9609. if err != nil {
  9610. }
  9611. startRecordDateTime := startTime.Unix()
  9612. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9613. if err != nil {
  9614. }
  9615. endRecordDateTime := endTime.Unix()
  9616. admin := c.GetAdminUserInfo()
  9617. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9618. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9619. order, _ := service.GetHisOrderByID(order_id)
  9620. var monthPrescriptions []*models.HisPrescription
  9621. if order_status == 1 || order_status == 0 {
  9622. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9623. } else if order_status == 2 {
  9624. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9625. }
  9626. var settle_total float64
  9627. for _, item := range monthPrescriptions {
  9628. if len(item.HisPrescriptionProject) > 0 {
  9629. for _, subItem := range item.HisPrescriptionProject {
  9630. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9631. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9632. settle_total = settle_total + total
  9633. }
  9634. }
  9635. if len(item.HisDoctorAdviceInfo) > 0 {
  9636. for _, subItem := range item.HisDoctorAdviceInfo {
  9637. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9638. settle_total = settle_total + total
  9639. }
  9640. }
  9641. }
  9642. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9643. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9644. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9645. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9646. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9647. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9648. //获取所有科室信息
  9649. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9650. var dia string
  9651. for _, item := range month_p_info {
  9652. if len(dia) == 0 {
  9653. dia = item.Diagnosis
  9654. } else {
  9655. dia = dia + "," + item.Diagnosis
  9656. }
  9657. }
  9658. dia_arr := removeDuplicates(strings.Split(dia, ","))
  9659. dia_arr = removeEmptyStrings(dia_arr)
  9660. c.ServeSuccessJSON(map[string]interface{}{
  9661. "his_info": his_patient_info,
  9662. "xt_info": xt_patient_info,
  9663. "case_history": case_history,
  9664. "info": patientPrescriptionInfo,
  9665. "last_info": lastPatientPrescriptionInfo,
  9666. "month_prescriptions": monthPrescriptions,
  9667. "order": order,
  9668. "doctors": doctors,
  9669. "department": department,
  9670. "settle_total": settle_total,
  9671. "dia_arr": dia_arr,
  9672. })
  9673. return
  9674. }
  9675. func removeEmptyStrings(input []string) []string {
  9676. var output []string
  9677. for _, s := range input {
  9678. if s != "" {
  9679. output = append(output, s)
  9680. }
  9681. }
  9682. return output
  9683. }
  9684. func removeDuplicates(input []string) []string {
  9685. seen := make(map[string]bool)
  9686. output := []string{}
  9687. for _, s := range input {
  9688. if _, exists := seen[s]; !exists {
  9689. seen[s] = true
  9690. output = append(output, s)
  9691. }
  9692. }
  9693. return output
  9694. }
  9695. func (c *HisApiController) GetHisMonthPatientInfo() {
  9696. patient_id, _ := c.GetInt64("patient_id")
  9697. his_patient_id, _ := c.GetInt64("his_patient_id")
  9698. record_date := c.GetString("record_date")
  9699. number := c.GetString("number")
  9700. start_time := c.GetString("start_time")
  9701. end_time := c.GetString("end_time")
  9702. p_type, _ := c.GetInt64("p_type")
  9703. timeLayout := "2006-01-02"
  9704. loc, _ := time.LoadLocation("Local")
  9705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9706. if err != nil {
  9707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9708. return
  9709. }
  9710. recordDateTime := theTime.Unix()
  9711. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9712. if err != nil {
  9713. }
  9714. startRecordDateTime := startTime.Unix()
  9715. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9716. if err != nil {
  9717. }
  9718. endRecordDateTime := endTime.Unix()
  9719. admin := c.GetAdminUserInfo()
  9720. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9721. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9722. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9723. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9724. var settle_total float64
  9725. for _, item := range monthPrescriptions {
  9726. if len(item.HisPrescriptionProject) > 0 {
  9727. for _, subItem := range item.HisPrescriptionProject {
  9728. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9729. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9730. settle_total = settle_total + total
  9731. }
  9732. }
  9733. if len(item.HisDoctorAdviceInfo) > 0 {
  9734. for _, subItem := range item.HisDoctorAdviceInfo {
  9735. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9736. settle_total = settle_total + total
  9737. }
  9738. }
  9739. }
  9740. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9741. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9742. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9743. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9744. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9745. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9746. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9747. //获取所有科室信息
  9748. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9749. c.ServeSuccessJSON(map[string]interface{}{
  9750. "his_info": his_patient_info,
  9751. "xt_info": xt_patient_info,
  9752. "case_history": case_history,
  9753. "info": patientPrescriptionInfo,
  9754. "month_prescriptions": monthPrescriptions,
  9755. "order": order,
  9756. "doctors": doctors,
  9757. "department": department,
  9758. "count": count,
  9759. "drugStockConfig": drugStockConfig,
  9760. "last_info": lastPatientPrescriptionInfo,
  9761. "settle_total": settle_total,
  9762. })
  9763. return
  9764. }
  9765. func (c *HisApiController) GetAllOrder() {
  9766. org_id := c.GetAdminUserInfo().CurrentOrgId
  9767. orders, _ := service.GetNewHisOrderList(org_id)
  9768. c.ServeSuccessJSON(map[string]interface{}{
  9769. "order": orders,
  9770. })
  9771. return
  9772. }
  9773. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9774. newArr = make([]*models.HisOrderInfoTwo, 0)
  9775. for i := 0; i < len(arr); i++ {
  9776. repeat := false
  9777. for j := i + 1; j < len(arr); j++ {
  9778. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9779. repeat = true
  9780. break
  9781. }
  9782. }
  9783. if !repeat {
  9784. newArr = append(newArr, arr[i])
  9785. }
  9786. }
  9787. return
  9788. }
  9789. // 修改处方退库操作 参数传修改之前的处方数据
  9790. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9791. if advice.ExecutionState == 1 {
  9792. //查询该病人该药品是否有库存记录
  9793. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9794. if errcode == gorm.ErrRecordNotFound {
  9795. } else {
  9796. //退库
  9797. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9798. if advice.PrescribingNumberUnit == drug.MinUnit {
  9799. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9800. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9801. //退库
  9802. warehouseInfo := models.DrugWarehouseInfo{
  9803. StockMinNumber: prescribingNumber,
  9804. }
  9805. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9806. operation_time := time.Now().Unix()
  9807. creater := advice.AdviceDoctor
  9808. ctime := time.Now().Unix()
  9809. timeStr := time.Now().Format("2006-01-02")
  9810. timeArr := strings.Split(timeStr, "-")
  9811. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9812. total = total + 1
  9813. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9814. cancelStock := models.DrugCancelStock{
  9815. OrderNumber: orderNumber,
  9816. OperaTime: operation_time,
  9817. OrgId: advice.UserOrgId,
  9818. Creater: creater,
  9819. Ctime: ctime,
  9820. Status: 1,
  9821. ReturnTime: advice.AdviceDate,
  9822. Dealer: info.Dealer,
  9823. Manufacturer: info.Manufacturer,
  9824. Type: 1,
  9825. }
  9826. service.AddSigleDrugCancelStock(&cancelStock)
  9827. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9828. dealer, _ := service.GetDealerById(info.Dealer)
  9829. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9830. cancelStockInfo := models.DrugCancelStockInfo{
  9831. OrderNumber: cancelInfo.OrderNumber,
  9832. CancelStockId: cancelInfo.ID,
  9833. DrugId: info.DrugId,
  9834. Count: info.Count,
  9835. Status: 1,
  9836. Ctime: ctime,
  9837. OrgId: advice.UserOrgId,
  9838. Type: 1,
  9839. Manufacturer: manufactureName.ManufacturerName,
  9840. Dealer: dealer.DealerName,
  9841. Total: 0,
  9842. RetailPrice: info.RetailPrice,
  9843. RetailTotalPrice: info.RetailTotalPrice,
  9844. Price: info.Price,
  9845. RegisterAccount: "",
  9846. Remark: info.Remark,
  9847. BatchNumber: info.BatchNumber,
  9848. MaxUnit: info.CountUnit,
  9849. ProductDate: info.ProductDate,
  9850. ExpiryDate: info.ExpiryDate,
  9851. BatchNumberId: info.WarehouseInfoId,
  9852. }
  9853. flow := models.DrugFlow{
  9854. WarehousingId: 0,
  9855. DrugId: info.DrugId,
  9856. Number: "",
  9857. BatchNumber: info.BatchNumber,
  9858. Count: info.Count,
  9859. UserOrgId: advice.UserOrgId,
  9860. PatientId: 0,
  9861. SystemTime: ctime,
  9862. ConsumableType: 4,
  9863. IsSys: 0,
  9864. WarehousingOrder: "",
  9865. WarehouseOutId: 0,
  9866. WarehouseOutOrderNumber: "",
  9867. IsEdit: 0,
  9868. CancelStockId: cancelStock.ID,
  9869. CancelOrderNumber: cancelStock.OrderNumber,
  9870. Manufacturer: info.Manufacturer,
  9871. Dealer: info.Dealer,
  9872. Creator: advice.UserOrgId,
  9873. UpdateCreator: 0,
  9874. Status: 1,
  9875. Ctime: time.Now().Unix(),
  9876. Mtime: 0,
  9877. Price: info.Price,
  9878. WarehousingDetailId: 0,
  9879. WarehouseOutDetailId: 0,
  9880. CancelOutDetailId: 0,
  9881. ExpireDate: info.ExpiryDate,
  9882. ProductDate: info.ProductDate,
  9883. MaxUnit: info.CountUnit,
  9884. MinUnit: "",
  9885. }
  9886. service.CreatedCancelStock(cancelStockInfo)
  9887. service.CreateDrugFlowOne(flow)
  9888. } else {
  9889. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9890. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9891. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9892. warehouseInfo := models.DrugWarehouseInfo{
  9893. StockMinNumber: prescribingNumber,
  9894. }
  9895. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9896. }
  9897. operation_time := time.Now().Unix()
  9898. creater := advice.AdviceDoctor
  9899. ctime := time.Now().Unix()
  9900. timeStr := time.Now().Format("2006-01-02")
  9901. timeArr := strings.Split(timeStr, "-")
  9902. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9903. total = total + 1
  9904. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9905. cancelStock := models.DrugCancelStock{
  9906. OrderNumber: orderNumber,
  9907. OperaTime: operation_time,
  9908. OrgId: advice.UserOrgId,
  9909. Creater: creater,
  9910. Ctime: ctime,
  9911. Status: 1,
  9912. ReturnTime: advice.AdviceDate,
  9913. Dealer: info.Dealer,
  9914. Manufacturer: info.Manufacturer,
  9915. Type: 1,
  9916. }
  9917. service.AddSigleDrugCancelStock(&cancelStock)
  9918. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9919. dealer, _ := service.GetDealerById(info.Dealer)
  9920. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9921. cancelStockInfo := models.DrugCancelStockInfo{
  9922. OrderNumber: cancelInfo.OrderNumber,
  9923. CancelStockId: cancelInfo.ID,
  9924. DrugId: info.DrugId,
  9925. Count: info.Count,
  9926. Status: 1,
  9927. Ctime: ctime,
  9928. OrgId: advice.UserOrgId,
  9929. Type: 1,
  9930. Manufacturer: manufactureName.ManufacturerName,
  9931. Dealer: dealer.DealerName,
  9932. Total: 0,
  9933. RetailPrice: info.RetailPrice,
  9934. RetailTotalPrice: info.RetailTotalPrice,
  9935. Price: info.Price,
  9936. RegisterAccount: "",
  9937. Remark: info.Remark,
  9938. BatchNumber: info.BatchNumber,
  9939. MaxUnit: info.CountUnit,
  9940. ProductDate: info.ProductDate,
  9941. ExpiryDate: info.ExpiryDate,
  9942. BatchNumberId: info.WarehouseInfoId,
  9943. }
  9944. flow := models.DrugFlow{
  9945. WarehousingId: 0,
  9946. DrugId: info.DrugId,
  9947. Number: "",
  9948. BatchNumber: info.BatchNumber,
  9949. Count: info.Count,
  9950. UserOrgId: advice.UserOrgId,
  9951. PatientId: 0,
  9952. SystemTime: ctime,
  9953. ConsumableType: 4,
  9954. IsSys: 0,
  9955. WarehousingOrder: "",
  9956. WarehouseOutId: 0,
  9957. WarehouseOutOrderNumber: "",
  9958. IsEdit: 0,
  9959. CancelStockId: cancelStock.ID,
  9960. CancelOrderNumber: cancelStock.OrderNumber,
  9961. Manufacturer: info.Manufacturer,
  9962. Dealer: info.Dealer,
  9963. Creator: advice.AdviceDoctor,
  9964. UpdateCreator: 0,
  9965. Status: 1,
  9966. Ctime: time.Now().Unix(),
  9967. Mtime: 0,
  9968. Price: info.Price,
  9969. WarehousingDetailId: 0,
  9970. WarehouseOutDetailId: 0,
  9971. CancelOutDetailId: 0,
  9972. ExpireDate: info.ExpiryDate,
  9973. ProductDate: info.ProductDate,
  9974. MaxUnit: info.CountUnit,
  9975. MinUnit: "",
  9976. }
  9977. service.CreatedCancelStock(cancelStockInfo)
  9978. service.CreateDrugFlowOne(flow)
  9979. }
  9980. }
  9981. }
  9982. return err
  9983. }
  9984. func (this *HisApiController) DeleteNCDS() {
  9985. id, _ := this.GetInt64("id", 0)
  9986. if id > 0 {
  9987. service.DeletePsnNCDSRecordById(id)
  9988. this.ServeSuccessJSON(map[string]interface{}{
  9989. "msg": "删除成功",
  9990. })
  9991. } else {
  9992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9993. return
  9994. }
  9995. }
  9996. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9997. id, _ := c.GetInt64("id")
  9998. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9999. c.ServeSuccessJSON(map[string]interface{}{
  10000. "advice": advice,
  10001. })
  10002. return
  10003. }
  10004. func (c *HisApiController) GetHisMonthChargePatientList() {
  10005. record_date := c.GetString("record_date")
  10006. start_time := c.GetString("start_time")
  10007. end_time := c.GetString("end_time")
  10008. timeLayout := "2006-01-02"
  10009. loc, _ := time.LoadLocation("Local")
  10010. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10011. if err != nil {
  10012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10013. return
  10014. }
  10015. if err != nil {
  10016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10017. return
  10018. }
  10019. recordDateTime := theTime.Unix()
  10020. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10021. if err != nil {
  10022. }
  10023. startRecordDateTime := startTime.Unix()
  10024. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10025. if err != nil {
  10026. }
  10027. endRecordDateTime := endTime.Unix()
  10028. adminInfo := c.GetAdminUserInfo()
  10029. var tempMonthChargePatients []*service.MonthChargePatients
  10030. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10031. for _, item := range tempPatients {
  10032. //过滤没有处方的
  10033. if len(item.HisPrescription) == 0 {
  10034. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10035. }
  10036. }
  10037. c.ServeSuccessJSON(map[string]interface{}{
  10038. "list": tempMonthChargePatients,
  10039. })
  10040. }