his_api_controller.go 540KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1214. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1215. //获取当前用户的信息
  1216. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1217. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1218. //获取所有科室信息
  1219. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1220. //var aa []service.PatientThree
  1221. noElementsSlice := make([]service.PatientThree, 0)
  1222. c.ServeSuccessJSON(map[string]interface{}{
  1223. "list": patients,
  1224. "list_two": patients_two,
  1225. "list_three": noElementsSlice,
  1226. "info": adminUserInfo,
  1227. "doctors": doctors,
  1228. "department": department,
  1229. })
  1230. }
  1231. type CustomTemplate struct {
  1232. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1233. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1234. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1235. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1236. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1237. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1238. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1239. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1240. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1241. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1242. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1243. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1244. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1245. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1246. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1247. }
  1248. func (c *HisApiController) GetHisPatientInfo() {
  1249. patient_id, _ := c.GetInt64("patient_id")
  1250. his_patient_id, _ := c.GetInt64("his_patient_id")
  1251. record_date := c.GetString("record_date")
  1252. number := c.GetString("number")
  1253. //start_time := c.GetString("start_time")
  1254. //end_time := c.GetString("end_time")
  1255. p_type, _ := c.GetInt64("p_type")
  1256. timeLayout := "2006-01-02"
  1257. loc, _ := time.LoadLocation("Local")
  1258. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1259. if err != nil {
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1261. return
  1262. }
  1263. recordDateTime := theTime.Unix()
  1264. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //startRecordDateTime := startTime.Unix()
  1269. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1270. //if err != nil {
  1271. //
  1272. //}
  1273. //endRecordDateTime := endTime.Unix()
  1274. admin := c.GetAdminUserInfo()
  1275. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1277. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1278. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1279. var prescriptions []*models.HisPrescription
  1280. var last_prescriptions []*models.HisPrescription
  1281. var sch_prescriptions []CustomTemplate
  1282. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1283. if p_type == 1 { //住院
  1284. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1285. for _, item := range prescriptions {
  1286. for _, subItem := range item.HisDoctorAdviceInfo {
  1287. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1288. if info.RetailPrice > 0 {
  1289. subItem.Drug.MinPrice = info.RetailPrice
  1290. }
  1291. }
  1292. }
  1293. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1294. } else { //门诊
  1295. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1296. for _, item := range prescriptions {
  1297. for _, subItem := range item.HisDoctorAdviceInfo {
  1298. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1299. if info.RetailPrice > 0 {
  1300. subItem.Drug.MinPrice = info.RetailPrice
  1301. }
  1302. }
  1303. }
  1304. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1305. }
  1306. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1307. if sch.ID > 0 {
  1308. var week string
  1309. t := time.Now()
  1310. switch t.Weekday().String() {
  1311. case "Monday":
  1312. week = "周一"
  1313. break
  1314. case "Tuesday":
  1315. week = "周二"
  1316. break
  1317. case "Wednesday":
  1318. week = "周三"
  1319. break
  1320. case "Thursday":
  1321. week = "周四"
  1322. break
  1323. case "Friday":
  1324. week = "周五"
  1325. break
  1326. case "Saturday":
  1327. week = "周六"
  1328. break
  1329. case "Sunday":
  1330. week = "周日"
  1331. break
  1332. }
  1333. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1334. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1335. //根据推送频率组装新的数组
  1336. for _, item := range temp_sch_prescriptions {
  1337. var cus CustomTemplate
  1338. cus.ID = item.ID
  1339. cus.UserOrgId = item.UserOrgId
  1340. cus.PatientId = item.PatientId
  1341. cus.MedType = item.MedType
  1342. cus.RecordDate = item.RecordDate
  1343. cus.Type = item.Type
  1344. cus.PType = item.PType
  1345. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1346. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1347. if subItem.FrequencyType == 1 { //每次必推
  1348. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1349. }
  1350. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1351. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1352. }
  1353. if subItem.FrequencyType == 2 { //按照天数频率
  1354. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1355. now := p.Unix()
  1356. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1357. dayStr2 := "-" + dayStr
  1358. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1359. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1360. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1361. if len(advices) == 0 {
  1362. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1363. }
  1364. }
  1365. }
  1366. }
  1367. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1368. if subItem.Type == 2 {
  1369. if subItem.XtHisProject.MedicalStatus != 1 {
  1370. if subItem.FrequencyType == 1 {
  1371. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1372. }
  1373. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1374. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1375. }
  1376. if subItem.FrequencyType == 2 {
  1377. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1378. now := p.Unix()
  1379. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1380. dayStr2 := "-" + dayStr
  1381. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1382. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1383. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1384. if len(projects) == 0 {
  1385. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1386. }
  1387. }
  1388. }
  1389. } else if subItem.Type == 3 {
  1390. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1391. if subItem.FrequencyType == 1 {
  1392. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1393. }
  1394. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1395. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1396. }
  1397. if subItem.FrequencyType == 2 {
  1398. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1399. now := p.Unix()
  1400. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1401. dayStr2 := "-" + dayStr
  1402. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1403. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1404. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1405. if len(projects) == 0 {
  1406. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1407. }
  1408. }
  1409. }
  1410. }
  1411. }
  1412. sch_prescriptions = append(sch_prescriptions, cus)
  1413. }
  1414. for _, item := range sch_prescriptions {
  1415. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1416. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1417. }
  1418. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1419. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1420. }
  1421. }
  1422. }
  1423. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1424. if config.ID > 0 && config.IsOpen == 1 {
  1425. for _, item := range sch_prescriptions {
  1426. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1427. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1428. if info.RetailPrice > 0 {
  1429. subItem.Drug.MinPrice = info.RetailPrice
  1430. if admin.CurrentOrgId != 10598 {
  1431. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1432. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. if config.ID > 0 && config.IsOpen == 1 {
  1439. for _, item := range sch_prescriptions {
  1440. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1441. if subItem.Type == 3 {
  1442. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1443. if info.Price > 0 {
  1444. subItem.GoodInfo.PackingPrice = info.Price
  1445. if admin.CurrentOrgId != 10598 {
  1446. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1447. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. }
  1454. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1455. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1456. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1457. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1458. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1459. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1460. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1461. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1462. //获取所有科室信息
  1463. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1464. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1465. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1466. c.ServeSuccessJSON(map[string]interface{}{
  1467. "his_info": his_patient_info,
  1468. "xt_info": xt_patient_info,
  1469. "prescription": prescriptions,
  1470. "case_history": case_history,
  1471. "info": patientPrescriptionInfo,
  1472. //"month_prescriptions": monthPrescriptions,
  1473. "order": order,
  1474. "doctors": doctors,
  1475. "department": department,
  1476. "sch_prescriptions": sch_prescriptions,
  1477. "last_prescriptions": last_prescriptions,
  1478. "schedule": sch,
  1479. "count": count,
  1480. "drugStockConfig": drugStockConfig,
  1481. "last_info": lastPatientPrescriptionInfo,
  1482. "befor": beforThrity,
  1483. "LastCaseHistory": LastCaseHistory,
  1484. })
  1485. return
  1486. }
  1487. func (c *HisApiController) GetHisPrescriptionConfig() {
  1488. adminInfo := c.GetAdminUserInfo()
  1489. //获取医嘱模版
  1490. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1491. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1492. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1493. //获取所有基础药
  1494. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1495. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1496. if config.ID > 0 && config.IsOpen == 1 {
  1497. for _, item := range drugs {
  1498. var index = 0
  1499. for _, subItem := range item.OtherDrugWarehouseInfo {
  1500. if index == 0 {
  1501. index = index + 1
  1502. if subItem.RetailPrice > 0 {
  1503. item.MinPrice = subItem.RetailPrice
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1510. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1511. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1512. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1513. //获取所有科室信息
  1514. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1515. //获取诊断信息
  1516. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1517. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1518. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1519. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1520. //获取是否开启保存耗材出库的开关
  1521. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1522. c.ServeSuccessJSON(map[string]interface{}{
  1523. "drugs": drugs,
  1524. "advices_template": advices,
  1525. "drugways": drugways,
  1526. "efs": efs,
  1527. "doctors": doctors,
  1528. "department": department,
  1529. "sick": sick,
  1530. "additions": additions,
  1531. "diagnose": diagnose,
  1532. "manufacturers": manufacturers,
  1533. "goodOutOpen": goodOutOpen,
  1534. "patientDiagnose": patientDiagnose,
  1535. })
  1536. }
  1537. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1538. //获取所有基础药
  1539. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1540. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1541. if config.ID > 0 && config.IsOpen == 1 {
  1542. for _, item := range drugs {
  1543. var index = 0
  1544. for _, subItem := range item.OtherDrugWarehouseInfo {
  1545. if index == 0 {
  1546. index = index + 1
  1547. if subItem.RetailPrice > 0 {
  1548. item.MinPrice = subItem.RetailPrice
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1555. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1556. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1557. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1558. //获取所有科室信息
  1559. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1560. //获取诊断信息
  1561. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1562. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1563. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1564. //获取是否开启保存耗材出库的开关
  1565. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1566. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1567. c.ServeSuccessJSON(map[string]interface{}{
  1568. "drugs": drugs,
  1569. "advices_template": advices,
  1570. "drugways": drugways,
  1571. "efs": efs,
  1572. "doctors": doctors,
  1573. "department": department,
  1574. "sick": sick,
  1575. "additions": additions,
  1576. "diagnose": diagnose,
  1577. "manufacturers": manufacturers,
  1578. "goodOutOpen": goodOutOpen,
  1579. "patientDiagnose": patientDiagnose,
  1580. })
  1581. }
  1582. }
  1583. func (c *HisApiController) CreateHisPrescription() {
  1584. record_date := c.GetString("record_date")
  1585. patient_id, _ := c.GetInt64("patient_id")
  1586. reg_type, _ := c.GetInt64("reg_type")
  1587. diagnose := c.GetString("diagnose")
  1588. sick_type, _ := c.GetInt64("sick_type")
  1589. sick_history := c.GetString("sick_history")
  1590. doctor_id, _ := c.GetInt64("doctor", 0)
  1591. department, _ := c.GetInt64("department", 0)
  1592. his_patient_id, _ := c.GetInt64("his_patient_id")
  1593. p_type, _ := c.GetInt64("p_type")
  1594. patient_diagnose := c.GetString("patient_diagnose")
  1595. dataBody := make(map[string]interface{}, 0)
  1596. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1597. if err != nil {
  1598. utils.ErrorLog(err.Error())
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1600. return
  1601. }
  1602. //edit, src := GetCompareData(dataBody)
  1603. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1604. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1605. //fmt.Println(drugResult)
  1606. //fmt.Println(goodResult)
  1607. timeLayout := "2006-01-02"
  1608. loc, _ := time.LoadLocation("Local")
  1609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1610. if err != nil {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1612. return
  1613. }
  1614. adminInfo := c.GetAdminUserInfo()
  1615. recordDateTime := theTime.Unix()
  1616. //查询默认出库仓库库存
  1617. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1618. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1619. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1620. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1621. if len(lists) == 1 {
  1622. his_patient_id = lists[0].ID
  1623. }
  1624. }
  1625. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1626. //自动出库的开关开启
  1627. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1628. //自动出库
  1629. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1630. //耗材保存处方出库
  1631. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1632. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1633. //已发药和已收费限制逻辑
  1634. isMidicine := false
  1635. isCharge := false
  1636. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1637. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1638. if len(prescriptions) > 0 {
  1639. for _, item := range prescriptions {
  1640. items := item.(map[string]interface{})
  1641. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1642. utils.ErrorLog("id")
  1643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1644. return
  1645. }
  1646. id := int64(items["id"].(float64))
  1647. if id > 0 {
  1648. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1649. if err != nil {
  1650. if new_prescription.OrderStatus == 4 {
  1651. isCharge = true
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. if isMidicine == true {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1660. return
  1661. }
  1662. if isCharge == true {
  1663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1664. return
  1665. }
  1666. // 开始主事务
  1667. db := service.XTWriteDB()
  1668. tx := db.Begin()
  1669. // 在函数结束时处理事务回滚
  1670. defer func() {
  1671. if r := recover(); r != nil {
  1672. tx.Rollback()
  1673. }
  1674. }()
  1675. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1676. //药品发药出库
  1677. if pharmacyConfig.IsOpen == 1 {
  1678. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1679. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1680. if len(prescriptions) > 0 {
  1681. for _, item := range prescriptions {
  1682. items := item.(map[string]interface{})
  1683. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1684. advices := items["advices"].([]interface{})
  1685. if len(advices) > 0 {
  1686. for _, advice := range advices {
  1687. var drug_id int64
  1688. var prescribing_number float64
  1689. var prescribingNumberUnit string
  1690. var adviceId int64
  1691. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1692. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1693. }
  1694. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1695. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1696. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1697. }
  1698. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1699. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1700. }
  1701. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1702. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1703. }
  1704. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1705. if drug.ID == 0 {
  1706. tx.Rollback()
  1707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1708. return
  1709. }
  1710. //查询药品的所有库存
  1711. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1712. var total_count int64
  1713. for _, it := range list {
  1714. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1715. }
  1716. totals := strconv.FormatInt(total_count, 10)
  1717. //查询该药品是否存在开药记录
  1718. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1719. //新增处方盘点库存是否充足
  1720. if advicelist.ID == 0 {
  1721. all_count, _ := strconv.ParseFloat(totals, 64)
  1722. if prescribingNumberUnit == drug.MinUnit {
  1723. if drug.IsUse != 1 {
  1724. if drug.IsProject == 0 || drug.IsProject == 2 {
  1725. if all_count == 0 {
  1726. tx.Rollback()
  1727. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1728. return
  1729. }
  1730. if prescribing_number > all_count {
  1731. tx.Rollback()
  1732. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1733. return
  1734. }
  1735. }
  1736. }
  1737. }
  1738. if prescribingNumberUnit == drug.MaxUnit {
  1739. num := prescribing_number * float64(drug.MinNumber)
  1740. if drug.IsUse != 1 {
  1741. if drug.IsProject == 0 || drug.IsProject == 2 {
  1742. if all_count == 0 {
  1743. tx.Rollback()
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1745. return
  1746. }
  1747. if num > all_count {
  1748. tx.Rollback()
  1749. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1750. return
  1751. }
  1752. }
  1753. }
  1754. }
  1755. }
  1756. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1757. //不使用保存处方出库
  1758. if drugOutConfig.IsOpen != 1 {
  1759. //修改处方
  1760. for _, advice := range advices {
  1761. var drug_id int64
  1762. var prescribing_number float64
  1763. var prescribingNumberUnit string
  1764. var prescribingNumber string
  1765. var adviceId int64
  1766. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1767. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1768. }
  1769. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1770. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1771. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1772. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1773. }
  1774. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1775. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1776. }
  1777. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1778. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1779. }
  1780. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1781. if drug.ID == 0 {
  1782. tx.Rollback()
  1783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1784. return
  1785. }
  1786. //查询药品的所有库存
  1787. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1788. var total_count int64
  1789. for _, it := range list {
  1790. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1791. }
  1792. totals := strconv.FormatInt(total_count, 10)
  1793. //查询该药品是否存在开药记录
  1794. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1795. //新增处方
  1796. if advicelist.ID == 0 {
  1797. all_count, _ := strconv.ParseFloat(totals, 64)
  1798. if prescribingNumberUnit == drug.MinUnit {
  1799. if drug.IsUse != 1 {
  1800. if drug.IsProject == 0 || drug.IsProject == 2 {
  1801. if all_count == 0 {
  1802. tx.Rollback()
  1803. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1804. return
  1805. }
  1806. if prescribing_number > all_count {
  1807. tx.Rollback()
  1808. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1809. return
  1810. }
  1811. }
  1812. }
  1813. } else {
  1814. if prescribingNumberUnit == drug.MaxUnit {
  1815. num := prescribing_number * float64(drug.MinNumber)
  1816. if drug.IsUse != 1 {
  1817. if drug.IsProject == 0 || drug.IsProject == 2 {
  1818. if all_count == 0 {
  1819. tx.Rollback()
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. if num > all_count {
  1824. tx.Rollback()
  1825. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1826. return
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. //修改处方
  1834. if advicelist.ID > 0 {
  1835. var device_number int64
  1836. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1837. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1838. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1839. device_number = prescribingNumberInt * drug.MinNumber
  1840. }
  1841. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1842. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1843. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1844. device_number = prescribingNumberInt
  1845. }
  1846. var number_count int64
  1847. if prescribingNumberUnit == drug.MaxUnit {
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1849. number_count = prescribingNumberInt * drug.MinNumber
  1850. }
  1851. if prescribingNumberUnit == drug.MinUnit {
  1852. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1853. number_count = prescribingNumberInt
  1854. }
  1855. //如果修改的数量大于之前修改的数量
  1856. if (number_count - device_number) > 0 {
  1857. //如果修改的差数量 大于库存数量
  1858. if drug.IsUse != 1 {
  1859. if (number_count - device_number) > total_count {
  1860. tx.Rollback()
  1861. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1862. return
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. }
  1876. //已发药和已收费限制逻辑
  1877. //执行出库的逻辑
  1878. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1879. //校验库存总量
  1880. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1881. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1882. if len(prescriptions) > 0 {
  1883. for _, item := range prescriptions {
  1884. items := item.(map[string]interface{})
  1885. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1886. advices := items["advices"].([]interface{})
  1887. if len(advices) > 0 {
  1888. for _, advice := range advices {
  1889. var drug_id int64
  1890. var prescribing_number float64
  1891. var prescribingNumberUnit string
  1892. var adviceId int64
  1893. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1894. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1895. }
  1896. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1897. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1898. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1899. }
  1900. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1901. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1902. }
  1903. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1904. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1905. }
  1906. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1907. if drug.ID == 0 {
  1908. tx.Rollback()
  1909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1910. return
  1911. }
  1912. //查询药品的所有库存
  1913. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1914. var total_count int64
  1915. for _, it := range list {
  1916. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1917. }
  1918. totals := strconv.FormatInt(total_count, 10)
  1919. //查询该药品是否存在开药记录
  1920. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1921. //查询最新批次库存
  1922. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1923. var batch_number_count int64
  1924. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1925. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1926. //新增处方
  1927. if advicelist.ID == 0 {
  1928. all_count, _ := strconv.ParseFloat(totals, 64)
  1929. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1930. if prescribingNumberUnit == drug.MinUnit {
  1931. if drug.IsUse != 1 {
  1932. if drug.IsProject == 0 || drug.IsProject == 2 {
  1933. if all_count == 0 {
  1934. tx.Rollback()
  1935. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1936. return
  1937. }
  1938. if prescribing_number > all_count {
  1939. tx.Rollback()
  1940. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1941. return
  1942. }
  1943. }
  1944. if adminInfo.CurrentOrgId == 10215 {
  1945. if prescribing_number > batch_number_all_count {
  1946. tx.Rollback()
  1947. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1948. return
  1949. }
  1950. }
  1951. }
  1952. }
  1953. if prescribingNumberUnit == drug.MaxUnit {
  1954. num := prescribing_number * float64(drug.MinNumber)
  1955. if drug.IsUse != 1 {
  1956. if drug.IsProject == 0 || drug.IsProject == 2 {
  1957. if all_count == 0 {
  1958. tx.Rollback()
  1959. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1960. return
  1961. }
  1962. if num > all_count {
  1963. tx.Rollback()
  1964. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1965. return
  1966. }
  1967. }
  1968. if adminInfo.CurrentOrgId == 10215 {
  1969. if num > batch_number_all_count {
  1970. tx.Rollback()
  1971. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1972. return
  1973. }
  1974. }
  1975. }
  1976. }
  1977. }
  1978. //不是保存处方出库
  1979. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1980. if drugOutConfig.IsOpen != 1 {
  1981. //修改处方
  1982. for _, advice := range advices {
  1983. var drug_id int64
  1984. var prescribing_number float64
  1985. var prescribingNumberUnit string
  1986. var prescribingNumber string
  1987. var adviceId int64
  1988. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1989. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1990. }
  1991. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1992. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1993. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1994. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1995. }
  1996. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1997. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1998. }
  1999. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2000. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2001. }
  2002. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2003. if drug.ID == 0 {
  2004. tx.Rollback()
  2005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2006. return
  2007. }
  2008. //查询药品的所有库存
  2009. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2010. var total_count int64
  2011. for _, it := range list {
  2012. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2013. }
  2014. totals := strconv.FormatInt(total_count, 10)
  2015. //查询该药品是否存在开药记录
  2016. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2017. //新增处方
  2018. if advicelist.ID == 0 {
  2019. //查询最新批次库存
  2020. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2021. var batch_number_count int64
  2022. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2023. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2024. all_count, _ := strconv.ParseFloat(totals, 64)
  2025. if all_count == 0 {
  2026. tx.Rollback()
  2027. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2028. return
  2029. }
  2030. if prescribingNumberUnit == drug.MinUnit {
  2031. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2032. if drug.IsUse != 1 {
  2033. if drug.IsProject == 0 || drug.IsProject == 2 {
  2034. if all_count == 0 {
  2035. tx.Rollback()
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2037. return
  2038. }
  2039. if prescribing_number > all_count {
  2040. tx.Rollback()
  2041. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2042. return
  2043. }
  2044. }
  2045. if adminInfo.CurrentOrgId == 10215 {
  2046. if prescribing_number > batch_number_all_count {
  2047. tx.Rollback()
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2049. return
  2050. }
  2051. }
  2052. }
  2053. } else {
  2054. if prescribingNumberUnit == drug.MaxUnit {
  2055. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2056. num := prescribing_number * float64(drug.MinNumber)
  2057. if drug.IsUse != 1 {
  2058. if drug.IsProject == 0 || drug.IsProject == 2 {
  2059. if all_count == 0 {
  2060. tx.Rollback()
  2061. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2062. return
  2063. }
  2064. if num > all_count {
  2065. tx.Rollback()
  2066. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2067. return
  2068. }
  2069. }
  2070. if adminInfo.CurrentOrgId == 10215 {
  2071. if prescribing_number > batch_number_all_count {
  2072. tx.Rollback()
  2073. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2074. return
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. }
  2081. //修改处方
  2082. if advicelist.ID > 0 {
  2083. //查询最新批次库存
  2084. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2085. var batch_number_count int64
  2086. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2087. var device_number int64
  2088. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2089. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2090. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2091. device_number = prescribingNumberInt * drug.MinNumber
  2092. }
  2093. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2094. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2095. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2096. device_number = prescribingNumberInt
  2097. //回退库存
  2098. }
  2099. var number_count int64
  2100. if prescribingNumberUnit == drug.MaxUnit {
  2101. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2102. number_count = prescribingNumberInt * drug.MinNumber
  2103. //回退库存
  2104. }
  2105. if prescribingNumberUnit == drug.MinUnit {
  2106. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2107. number_count = prescribingNumberInt
  2108. //回退库存
  2109. }
  2110. //如果修改的数量大于之前修改的数量
  2111. if (number_count - device_number) > 0 {
  2112. //如果修改的差数量 大于库存数量
  2113. if drug.IsUse != 1 {
  2114. if drug.IsProject == 0 || drug.IsProject == 2 {
  2115. if total_count == 0 {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. if (number_count - device_number) > total_count {
  2121. tx.Rollback()
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2123. return
  2124. }
  2125. if (number_count - device_number) > batch_number_count {
  2126. tx.Rollback()
  2127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2128. return
  2129. }
  2130. }
  2131. if adminInfo.CurrentOrgId == 10215 {
  2132. // 查询该药品最后一次出库记录
  2133. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2134. var out_count int64
  2135. var in_count int64
  2136. var stock_max_number int64
  2137. var stock_min_number int64
  2138. for _, it := range outInfo {
  2139. if it.CountUnit == drug.MaxUnit {
  2140. it.Count = it.Count * drug.MinNumber
  2141. }
  2142. out_count += it.Count
  2143. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2144. stock_max_number = warehouseInfoList.StockMaxNumber
  2145. stock_min_number = warehouseInfoList.StockMinNumber
  2146. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2147. }
  2148. if out_count > 0 {
  2149. if (number_count - device_number) > in_count {
  2150. tx.Rollback()
  2151. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2152. return
  2153. }
  2154. }
  2155. // 未出库
  2156. if out_count == 0 {
  2157. var sum_in_count int64
  2158. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2159. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2160. //如果修改的数量大于有库存的第一个批次
  2161. if number_count > sum_in_count {
  2162. tx.Rollback()
  2163. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2164. return
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. //药品发药
  2171. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2172. //不使用药品发药的功能
  2173. //if pharmacyConfig.IsOpen != 1 {
  2174. // if device_number != number_count {
  2175. //
  2176. // //查询该药品的出库记录
  2177. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2178. // if len(outListExport) > 0 {
  2179. // //
  2180. // for _, item := range outListExport {
  2181. // //回退库存
  2182. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2183. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2184. // }
  2185. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2186. // var stock_max_number int64
  2187. // var stock_min_number int64
  2188. //
  2189. // if number_count >= drug.MinNumber {
  2190. //
  2191. // stock_max_number = device_number / drug.MinNumber
  2192. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2193. //
  2194. // stock_min_number = device_number % drug.MinNumber
  2195. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2196. //
  2197. // } else {
  2198. //
  2199. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2200. //
  2201. // }
  2202. // }
  2203. //
  2204. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2205. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2206. // }
  2207. // }
  2208. // }
  2209. //
  2210. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2211. // var sum_count int64
  2212. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2213. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2214. // for _, its := range stockInfo {
  2215. // if its.MaxUnit == drug.MaxUnit {
  2216. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2217. // }
  2218. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2219. // }
  2220. // //更新字典里面的库存
  2221. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2222. //
  2223. // //剩余库存
  2224. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2225. //
  2226. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2227. // //减少出库数量
  2228. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2229. //
  2230. // }
  2231. //}
  2232. }
  2233. }
  2234. }
  2235. //保存处方开药
  2236. if drugOutConfig.IsOpen == 1 {
  2237. //修改处方
  2238. for _, advice := range advices {
  2239. var drug_id int64
  2240. var prescribing_number float64
  2241. var prescribingNumberUnit string
  2242. var prescribingNumber string
  2243. var adviceId int64
  2244. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2245. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2246. }
  2247. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2248. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2249. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2250. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2251. }
  2252. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2253. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2254. }
  2255. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2256. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2257. }
  2258. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2259. if drug.ID == 0 {
  2260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2261. return
  2262. }
  2263. //查询药品的所有库存
  2264. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2265. var total_count int64
  2266. for _, it := range list {
  2267. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2268. }
  2269. totals := strconv.FormatInt(total_count, 10)
  2270. //查询该药品是否存在开药记录
  2271. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2272. //新增处方
  2273. if advicelist.ID == 0 {
  2274. //查询最新批次库存
  2275. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2276. var batch_number_count int64
  2277. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2278. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2279. all_count, _ := strconv.ParseFloat(totals, 64)
  2280. if prescribingNumberUnit == drug.MinUnit {
  2281. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2282. if drug.IsUse != 1 {
  2283. if drug.IsProject == 0 || drug.IsProject == 2 {
  2284. if all_count == 0 {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. if prescribing_number > all_count {
  2290. tx.Rollback()
  2291. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2292. return
  2293. }
  2294. }
  2295. if adminInfo.CurrentOrgId == 10215 {
  2296. if prescribing_number > batch_number_all_count {
  2297. tx.Rollback()
  2298. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2299. return
  2300. }
  2301. }
  2302. }
  2303. } else {
  2304. if prescribingNumberUnit == drug.MaxUnit {
  2305. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2306. num := prescribing_number * float64(drug.MinNumber)
  2307. if drug.IsUse != 1 {
  2308. if drug.IsProject == 0 || drug.IsProject == 2 {
  2309. if all_count == 0 {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. if num > all_count {
  2315. tx.Rollback()
  2316. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2317. return
  2318. }
  2319. }
  2320. if adminInfo.CurrentOrgId == 10215 {
  2321. if prescribing_number > batch_number_all_count {
  2322. tx.Rollback()
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. //修改处方
  2332. if advicelist.ID > 0 {
  2333. //查询最新批次库存
  2334. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. var batch_number_count int64
  2336. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2337. var device_number int64
  2338. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt * drug.MinNumber
  2342. }
  2343. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2344. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2346. device_number = prescribingNumberInt
  2347. }
  2348. var number_count int64
  2349. if prescribingNumberUnit == drug.MaxUnit {
  2350. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2351. number_count = prescribingNumberInt * drug.MinNumber
  2352. }
  2353. if prescribingNumberUnit == drug.MinUnit {
  2354. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2355. number_count = prescribingNumberInt
  2356. }
  2357. //如果修改的数量大于之前修改的数量
  2358. if (number_count - device_number) > 0 {
  2359. //如果修改的差数量 大于库存数量
  2360. if drug.IsUse != 1 {
  2361. if drug.IsProject == 0 || drug.IsProject == 2 {
  2362. if total_count == 0 {
  2363. tx.Rollback()
  2364. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2365. return
  2366. }
  2367. if (number_count - device_number) > total_count {
  2368. tx.Rollback()
  2369. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2370. return
  2371. }
  2372. }
  2373. if adminInfo.CurrentOrgId == 10215 {
  2374. if (number_count - device_number) > batch_number_count {
  2375. tx.Rollback()
  2376. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2377. return
  2378. }
  2379. }
  2380. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2381. //查询历史出库数据总批次
  2382. // 查询该药品最后一次出库记录
  2383. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2384. var out_count int64
  2385. var in_count int64
  2386. var stock_max_number int64
  2387. var stock_min_number int64
  2388. for _, it := range outInfo {
  2389. if it.CountUnit == drug.MaxUnit {
  2390. it.Count = it.Count * drug.MinNumber
  2391. }
  2392. out_count += it.Count
  2393. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2394. stock_max_number = warehouseInfoList.StockMaxNumber
  2395. stock_min_number = warehouseInfoList.StockMinNumber
  2396. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2397. }
  2398. if out_count > 0 {
  2399. if (number_count - device_number) > in_count {
  2400. tx.Rollback()
  2401. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2402. return
  2403. }
  2404. }
  2405. // 未出库
  2406. if out_count == 0 {
  2407. var sum_in_count int64
  2408. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2409. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2410. if sum_in_count == 0 {
  2411. tx.Rollback()
  2412. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2413. return
  2414. }
  2415. //如果修改的数量大于有库存的第一个批次
  2416. if number_count > sum_in_count {
  2417. tx.Rollback()
  2418. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2419. return
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. }
  2435. //校验耗材库存
  2436. if goodOutConfig.IsOpen == 1 {
  2437. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2438. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2439. if len(prescriptions) > 0 {
  2440. for _, item := range prescriptions {
  2441. items := item.(map[string]interface{})
  2442. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2443. projects := items["project"].([]interface{})
  2444. if len(projects) > 0 {
  2445. for _, project := range projects {
  2446. var project_id int64
  2447. var project_type int64
  2448. var totals float64
  2449. var project_name string
  2450. var parsetotal int64
  2451. var id int64
  2452. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2453. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2454. }
  2455. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2456. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2457. }
  2458. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2459. total, _ := project.(map[string]interface{})["total"].(string)
  2460. totals, _ = strconv.ParseFloat(total, 64)
  2461. }
  2462. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2463. project_name = project.(map[string]interface{})["project_name"].(string)
  2464. }
  2465. if project_type == 3 {
  2466. //查找该耗材的出库记录
  2467. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2468. if len(goodWarehouseInfo) == 0 {
  2469. //查询耗材库存
  2470. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2471. var stock_count int64
  2472. for _, it := range list {
  2473. stock_count += it.StockCount
  2474. }
  2475. stock_counts := strconv.FormatInt(stock_count, 10)
  2476. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2477. if stock_total_count == 0 {
  2478. tx.Rollback()
  2479. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2480. return
  2481. }
  2482. if totals > stock_total_count {
  2483. tx.Rollback()
  2484. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2485. return
  2486. }
  2487. }
  2488. if len(goodWarehouseInfo) > 0 {
  2489. //查询该患者耗材的历史数据
  2490. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2491. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2492. //数量发生改变
  2493. if parsetotal != count {
  2494. //如果现在的数量大于历史数量,就要看库存是否足够
  2495. if parsetotal > count {
  2496. //查询耗材所有库存
  2497. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2498. var stock_count int64
  2499. for _, it := range list {
  2500. stock_count += it.StockCount
  2501. }
  2502. //库存不足
  2503. if stock_count == 0 {
  2504. tx.Rollback()
  2505. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2506. return
  2507. }
  2508. if (parsetotal - count) > stock_count {
  2509. tx.Rollback()
  2510. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2511. return
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. }
  2524. //不使用耗材保存处方出库
  2525. if goodOutConfig.IsOpen != 1 {
  2526. if stockConfig.IsOpen == 1 {
  2527. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2528. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2529. if len(prescriptions) > 0 {
  2530. for _, item := range prescriptions {
  2531. items := item.(map[string]interface{})
  2532. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2533. projects := items["project"].([]interface{})
  2534. if len(projects) > 0 {
  2535. for _, project := range projects {
  2536. var project_id int64
  2537. var project_type int64
  2538. var totals float64
  2539. var project_name string
  2540. var parsetotal int64
  2541. var id int64
  2542. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2543. id = int64(project.(map[string]interface{})["id"].(float64))
  2544. }
  2545. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2546. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2547. }
  2548. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2549. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2550. }
  2551. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2552. total, _ := project.(map[string]interface{})["total"].(string)
  2553. totals, _ = strconv.ParseFloat(total, 64)
  2554. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2555. }
  2556. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2557. project_name = project.(map[string]interface{})["project_name"].(string)
  2558. }
  2559. if project_type == 3 {
  2560. //查找该耗材的出库记录
  2561. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2562. //没有出库记录
  2563. if len(goodWarehouseInfo) == 0 {
  2564. //查询耗材库存
  2565. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2566. var stock_count int64
  2567. for _, it := range list {
  2568. stock_count += it.StockCount
  2569. }
  2570. stock_counts := strconv.FormatInt(stock_count, 10)
  2571. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2572. if stock_total_count == 0 {
  2573. tx.Rollback()
  2574. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2575. return
  2576. }
  2577. if totals > stock_total_count {
  2578. tx.Rollback()
  2579. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2580. return
  2581. }
  2582. //查找今日该患者已经出库的所有耗材
  2583. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2584. for _, item := range goodList {
  2585. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2586. var flush_count int64
  2587. for _, it := range goodListSix {
  2588. flush_count += it.StockCount
  2589. }
  2590. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2591. creater := adminInfo.AdminUser.Id
  2592. if errs != nil {
  2593. goodErrcode := models.XtGoodErrcode{
  2594. UserOrgId: item.OrgId,
  2595. Errcode: "手动出库更新剩余出库失败",
  2596. GoodId: item.GoodId,
  2597. Status: 1,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: 0,
  2600. Count: 0,
  2601. StockCount: 0,
  2602. Creater: creater,
  2603. BatchNumberId: 0,
  2604. WarehouseOutId: 0,
  2605. }
  2606. service.CreateGoodErrcode(goodErrcode)
  2607. }
  2608. }
  2609. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2610. }
  2611. //有出库记录
  2612. if len(goodWarehouseInfo) > 0 {
  2613. //查询该患者耗材的历史数据
  2614. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2615. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2616. //数量发生改变
  2617. if parsetotal != count {
  2618. //查找今日该患者已经出库的所有耗材
  2619. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2620. for _, item := range goodList {
  2621. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2622. var flush_count int64
  2623. for _, it := range goodListSix {
  2624. flush_count += it.StockCount
  2625. }
  2626. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2627. //减少出库数量
  2628. creater := adminInfo.AdminUser.Id
  2629. if errs != nil {
  2630. goodErrcode := models.XtGoodErrcode{
  2631. UserOrgId: item.OrgId,
  2632. Errcode: "手动出库更新剩余出库失败",
  2633. GoodId: item.GoodId,
  2634. Status: 1,
  2635. Ctime: time.Now().Unix(),
  2636. Mtime: 0,
  2637. Count: 0,
  2638. StockCount: 0,
  2639. Creater: creater,
  2640. BatchNumberId: 0,
  2641. WarehouseOutId: 0,
  2642. }
  2643. service.CreateGoodErrcode(goodErrcode)
  2644. }
  2645. //查询默认仓库
  2646. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2647. var total_count int64
  2648. for _, it := range stockList {
  2649. total_count += it.StockCount
  2650. }
  2651. //基础库插入数据
  2652. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2653. }
  2654. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. }
  2666. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2667. var hpInfo models.HisPrescriptionInfo
  2668. if info.ID == 0 {
  2669. var randNum int
  2670. randNum = rand.Intn(10000) + 1000
  2671. timestamp := time.Now().Unix()
  2672. tempTime := time.Unix(timestamp, 0)
  2673. timeFormat := tempTime.Format("20060102150405")
  2674. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2675. hpInfo = models.HisPrescriptionInfo{
  2676. HisPatientId: his_patient_id,
  2677. UserOrgId: adminInfo.CurrentOrgId,
  2678. RecordDate: theTime.Unix(),
  2679. PatientId: patient_id,
  2680. Status: 1,
  2681. Ctime: time.Now().Unix(),
  2682. Mtime: time.Now().Unix(),
  2683. Creator: adminInfo.AdminUser.Id,
  2684. Modifier: adminInfo.AdminUser.Id,
  2685. Diagnosis: diagnose,
  2686. SickHistory: sick_history,
  2687. Departments: department,
  2688. RegisterType: reg_type,
  2689. PrescriptionNumber: p_number,
  2690. PrescriptionStatus: 1,
  2691. Doctor: role.UserName,
  2692. DoctorId: doctor_id,
  2693. SickType: sick_type,
  2694. PType: p_type,
  2695. PatientDiagnosis: patient_diagnose,
  2696. }
  2697. service.SavePatientPrescriptionInfo(hpInfo)
  2698. //创建步骤表
  2699. finish := models.XtDialysisFinish{
  2700. IsFinish: 1,
  2701. UserOrgId: adminInfo.CurrentOrgId,
  2702. Status: 1,
  2703. Ctime: time.Now().Unix(),
  2704. Mtime: 0,
  2705. Module: 4,
  2706. RecordDate: theTime.Unix(),
  2707. Sourse: 1,
  2708. PatientId: patient_id,
  2709. }
  2710. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2711. if dialysisFinish.ID == 0 {
  2712. service.CreateDialysisFinish(finish)
  2713. }
  2714. redis := service.RedisClient()
  2715. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2716. redis.Set(key, "", time.Second)
  2717. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2718. redis.Set(keyOne, "", time.Second)
  2719. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2720. redis.Set(keySeven, "", time.Second)
  2721. defer redis.Close()
  2722. } else {
  2723. hpInfo = models.HisPrescriptionInfo{
  2724. ID: info.ID,
  2725. UserOrgId: adminInfo.CurrentOrgId,
  2726. RecordDate: info.RecordDate,
  2727. PatientId: info.PatientId,
  2728. Status: 1,
  2729. Ctime: info.Ctime,
  2730. Mtime: time.Now().Unix(),
  2731. Creator: info.Creator,
  2732. Modifier: adminInfo.AdminUser.Id,
  2733. Diagnosis: diagnose,
  2734. SickHistory: sick_history,
  2735. Departments: department,
  2736. RegisterType: reg_type,
  2737. PrescriptionNumber: info.PrescriptionNumber,
  2738. Doctor: role.UserName,
  2739. PrescriptionStatus: info.PrescriptionStatus,
  2740. DoctorId: doctor_id,
  2741. SickType: sick_type,
  2742. PType: info.PType,
  2743. HisPatientId: info.HisPatientId,
  2744. PatientDiagnosis: patient_diagnose,
  2745. }
  2746. service.SavePatientPrescriptionInfo(hpInfo)
  2747. //创建步骤表
  2748. finish := models.XtDialysisFinish{
  2749. IsFinish: 1,
  2750. UserOrgId: adminInfo.CurrentOrgId,
  2751. Status: 1,
  2752. Ctime: time.Now().Unix(),
  2753. Mtime: 0,
  2754. Module: 4,
  2755. RecordDate: info.RecordDate,
  2756. Sourse: 1,
  2757. PatientId: info.PatientId,
  2758. }
  2759. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2760. if dialysisFinish.ID == 0 {
  2761. service.CreateDialysisFinish(finish)
  2762. }
  2763. redis := service.RedisClient()
  2764. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2765. redis.Set(key, "", time.Second)
  2766. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2767. redis.Set(keyOne, "", time.Second)
  2768. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2769. redis.Set(keySeven, "", time.Second)
  2770. defer redis.Close()
  2771. }
  2772. //定义切片
  2773. var adviceList []models.HisDoctorAdviceInfo
  2774. var projectList []models.HisPrescriptionProject
  2775. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10537 || adminInfo.CurrentOrgId == 10265 || adminInfo.CurrentOrgId == 9675 {
  2776. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2777. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2778. var tempPrescription *models.HisPrescription
  2779. if len(prescriptions) > 0 {
  2780. for _, item := range prescriptions {
  2781. // 开始外部循环的事务
  2782. tx := db.Begin()
  2783. // 在函数结束时处理事务回滚
  2784. defer func() {
  2785. if r := recover(); r != nil {
  2786. tx.Rollback()
  2787. }
  2788. }()
  2789. items := item.(map[string]interface{})
  2790. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2791. utils.ErrorLog("id")
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2793. return
  2794. }
  2795. id := int64(items["id"].(float64))
  2796. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2797. tempPrescription = &new_prescription
  2798. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2799. utils.ErrorLog("type")
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. types := int64(items["type"].(float64))
  2804. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2805. utils.ErrorLog("med_type")
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2807. return
  2808. }
  2809. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2810. if med_type == "0" {
  2811. med_type = "14"
  2812. }
  2813. //if order_status == 0 {
  2814. // order_status = 1
  2815. //}
  2816. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2817. utils.ErrorLog("pre_time")
  2818. }
  2819. preTime, _ := items["pre_time"].(string)
  2820. fmt.Println("preTime", preTime)
  2821. timeLayout := "2006-01-02"
  2822. loc, _ := time.LoadLocation("Local")
  2823. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2824. result := strings.Split(preTime, " ")
  2825. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2826. if err != nil {
  2827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2828. return
  2829. }
  2830. pTime := theTime2.Unix()
  2831. ctime := time.Now().Unix()
  2832. if tempPrescription.ID == 0 {
  2833. prescription := &models.HisPrescription{
  2834. ID: 0,
  2835. PatientId: patient_id,
  2836. UserOrgId: adminInfo.CurrentOrgId,
  2837. RecordDate: recordDateTime,
  2838. Ctime: ctime,
  2839. Mtime: ctime,
  2840. Type: types,
  2841. Modifier: adminInfo.AdminUser.Id,
  2842. Creator: adminInfo.AdminUser.Id,
  2843. Status: 1,
  2844. Doctor: role.UserName,
  2845. HisPatientId: his_patient_id,
  2846. OrderStatus: 1,
  2847. BatchNumber: "",
  2848. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2849. PreTime: pTime,
  2850. PType: p_type,
  2851. MedType: med_type,
  2852. }
  2853. tempPrescription = prescription
  2854. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2855. redis := service.RedisClient()
  2856. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2857. redis.Set(key, "", time.Second)
  2858. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2859. redis.Set(keyOne, "", time.Second)
  2860. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2861. redis.Set(keySeven, "", time.Second)
  2862. defer redis.Close()
  2863. } else {
  2864. tempPrescription.ID = id
  2865. tempPrescription.Type = types
  2866. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2867. tempPrescription.Mtime = time.Now().Unix()
  2868. tempPrescription.Doctor = role.UserName
  2869. //tempPrescription.OrderStatus = order_status
  2870. tempPrescription.PreTime = pTime
  2871. tempPrescription.MedType = med_type
  2872. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2873. redis := service.RedisClient()
  2874. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2875. redis.Set(key, "", time.Second)
  2876. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2877. redis.Set(keyOne, "", time.Second)
  2878. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2879. redis.Set(keySeven, "", time.Second)
  2880. defer redis.Close()
  2881. }
  2882. //service.SaveHisPrescription(prescription)
  2883. //更改患者挂号状态
  2884. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2885. fmt.Println("更改失败", err2)
  2886. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2887. advices := items["advices"].([]interface{})
  2888. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2889. groupNo := int64(0)
  2890. if len(advices) > 0 {
  2891. for _, advice := range advices {
  2892. tx := db.Begin()
  2893. // 在函数结束时处理事务回滚
  2894. defer func() {
  2895. if r := recover(); r != nil {
  2896. tx.Rollback()
  2897. }
  2898. }()
  2899. var s models.HisDoctorAdviceInfo
  2900. s.PrescriptionId = tempPrescription.ID
  2901. s.AdviceType = 2
  2902. s.AdviceDoctor = doctor_id
  2903. s.StopState = 2
  2904. s.ExecutionState = 2
  2905. s.AdviceDate = theTime3.Unix()
  2906. s.Status = 1
  2907. s.UserOrgId = adminInfo.CurrentOrgId
  2908. s.RecordDate = theTime3.Unix()
  2909. s.StartTime = tempPrescription.PreTime
  2910. s.Groupno = groupNo
  2911. s.PatientId = patient_id
  2912. s.HisPatientId = his_patient_id
  2913. s.StartTime = pTime
  2914. s.IsSettle = 2
  2915. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2916. if errcode > 0 {
  2917. c.ServeFailJSONWithSGJErrorCode(errcode)
  2918. return
  2919. }
  2920. s.StartTime = pTime
  2921. var total_count int64 //处方总库存
  2922. //查询改药品信息
  2923. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2924. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2925. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2926. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2927. total_count += prescribingNumberSeven * medical.MinNumber
  2928. }
  2929. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2930. total_count += prescribingNumberSeven
  2931. }
  2932. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2933. total_count += prescribingNumberSeven
  2934. }
  2935. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  2936. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2937. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2938. if s.Price != lastWarehouse.RetailPrice {
  2939. s.Price = lastWarehouse.RetailPrice
  2940. }
  2941. if s.Price == 0 {
  2942. if lastWarehouse.ID == 0 {
  2943. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2944. s.Price = lastWarehouseTwo.RetailPrice
  2945. }
  2946. }
  2947. }
  2948. //查询保存处方出库开关是否打开
  2949. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2950. if s.PatientId != 30038 {
  2951. if drugOutConfig.IsOpen == 1 {
  2952. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2953. // 查询该药品最后一次出库记录
  2954. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2955. var is_user_total int64
  2956. var no_user_total int64
  2957. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2958. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2959. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2960. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2961. }
  2962. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2963. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2964. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2965. no_user_total += prescribingNumberSevenTy
  2966. }
  2967. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2968. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2969. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2970. no_user_total += prescribingNumberSevenTy
  2971. }
  2972. if len(druginfo) > 0 {
  2973. for _, it := range druginfo {
  2974. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2975. it.Count = it.Count * drug.MinNumber
  2976. is_user_total += it.Count
  2977. }
  2978. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2979. is_user_total += it.Count
  2980. }
  2981. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2982. is_user_total += it.Count
  2983. }
  2984. }
  2985. }
  2986. //fmt.Println("药品名称----------------------", drug.DrugName)
  2987. //fmt.Println("药品名称----------------------", drug.IsUse)
  2988. //fmt.Println("is_user_total-------------------------", is_user_total)
  2989. //fmt.Println("no_user_total-------------------------", no_user_total)
  2990. if is_user_total != no_user_total {
  2991. //出库
  2992. if drug.IsUse == 2 {
  2993. creater := adminInfo.AdminUser.Id
  2994. newadviceInfo := &models.HisDoctorAdviceInfo{
  2995. ID: s.ID,
  2996. UserOrgId: s.UserOrgId,
  2997. PatientId: s.PatientId,
  2998. HisPatientId: s.HisPatientId,
  2999. AdviceType: s.AdviceType,
  3000. AdviceDate: s.AdviceDate,
  3001. StartTime: s.StartTime,
  3002. AdviceName: s.AdviceName,
  3003. AdviceDesc: s.AdviceDesc,
  3004. ReminderDate: s.ReminderDate,
  3005. SingleDose: s.SingleDose,
  3006. SingleDoseUnit: s.SingleDoseUnit,
  3007. PrescribingNumber: s.PrescribingNumber,
  3008. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3009. DeliveryWay: s.DeliveryWay,
  3010. ExecutionFrequency: s.ExecutionFrequency,
  3011. AdviceDoctor: s.AdviceDoctor,
  3012. Status: s.Status,
  3013. CreatedTime: s.CreatedTime,
  3014. UpdatedTime: s.UpdatedTime,
  3015. AdviceAffirm: s.AdviceAffirm,
  3016. Remark: s.Remark,
  3017. StopTime: s.StopTime,
  3018. StopReason: s.StopReason,
  3019. StopDoctor: s.StopDoctor,
  3020. StopState: s.StopState,
  3021. ParentId: s.ParentId,
  3022. ExecutionTime: s.ExecutionTime,
  3023. ExecutionStaff: s.ExecutionStaff,
  3024. ExecutionState: s.ExecutionState,
  3025. Checker: s.Checker,
  3026. RecordDate: s.RecordDate,
  3027. DialysisOrderId: s.DialysisOrderId,
  3028. CheckTime: s.CheckTime,
  3029. CheckState: s.CheckState,
  3030. DrugSpec: s.DrugSpec,
  3031. DrugSpecUnit: s.DrugSpecUnit,
  3032. Groupno: s.Groupno,
  3033. RemindType: s.RemindType,
  3034. FrequencyType: s.FrequencyType,
  3035. DayCount: s.DayCount,
  3036. WeekDay: s.WeekDay,
  3037. TemplateId: s.TemplateId,
  3038. Modifier: s.Modifier,
  3039. DrugId: s.DrugId,
  3040. Price: s.Price,
  3041. PrescriptionId: s.PrescriptionId,
  3042. MedListCodg: s.MedListCodg,
  3043. FeedetlSn: s.FeedetlSn,
  3044. Day: s.DayCount,
  3045. ChildDoctorAdvice: nil,
  3046. Drug: models.Drug{},
  3047. Diagnosis: s.Diagnosis,
  3048. Way: s.Way,
  3049. HospApprFlag: s.HospApprFlag,
  3050. LmtUsedFlag: s.LmtUsedFlag,
  3051. HisOrderInfo: models.HisOrderInfo{},
  3052. IsMedicine: s.IsMedicine,
  3053. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3054. Child: nil,
  3055. IsSettle: s.IsSettle,
  3056. IsMobile: s.IsMobile,
  3057. IsSelfDrug: s.IsSelfDrug,
  3058. DrugWayCount: s.DrugWayCount,
  3059. }
  3060. var history_count int64
  3061. var local_count int64
  3062. //查找已经开过的医嘱信息
  3063. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3064. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3065. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3066. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3067. local_count += prescribingNumberSevenTy * drug.MinNumber
  3068. }
  3069. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3070. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3071. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3072. local_count += prescribingNumberSevenTy
  3073. }
  3074. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3075. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3076. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3077. local_count += prescribingNumberSevenTy
  3078. }
  3079. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3080. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3081. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3082. history_count += prescribingNumberSevenTy * drug.MinNumber
  3083. }
  3084. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3085. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3086. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3087. history_count += prescribingNumberSevenTy
  3088. }
  3089. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3090. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3091. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3092. history_count += prescribingNumberSevenTy
  3093. }
  3094. //如果当前出库数量大于历史出库数量则需要出库
  3095. if local_count > history_count {
  3096. //按最小单位出库
  3097. var cha_count = local_count - history_count
  3098. newadviceInfo.PrescribingNumber = float64(cha_count)
  3099. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3100. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3101. }
  3102. //如果当前出库数量小于历史出库数量则需要退库
  3103. if local_count < history_count {
  3104. var cha_count = history_count - local_count
  3105. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3107. }
  3108. if local_count == history_count {
  3109. if is_user_total == 0 {
  3110. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3111. }
  3112. }
  3113. }
  3114. //更新字典里面的库存
  3115. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3116. var sum_count int64
  3117. for _, its := range stockInfo {
  3118. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3119. if its.MaxUnit == baseDrug.MaxUnit {
  3120. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3121. }
  3122. sum_count += its.StockMaxNumber + its.StockMinNumber
  3123. }
  3124. //更新基础库存
  3125. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3126. //剩余库存
  3127. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3128. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3129. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3130. //创建医嘱
  3131. service.CreateHisDoctorAdviceOne(&s, tx)
  3132. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3134. if len(outInfoTwo) > 0 {
  3135. for _, item := range outInfoTwo {
  3136. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3137. }
  3138. }
  3139. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3140. if len(drugAutoDetail) > 0 {
  3141. for _, item := range drugAutoDetail {
  3142. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3143. }
  3144. }
  3145. }
  3146. }
  3147. }
  3148. //记录日志
  3149. byterequest, _ := json.Marshal(s)
  3150. adviceLog := models.XtDoctorAdviceLog{
  3151. UserOrgId: s.UserOrgId,
  3152. PatientId: s.PatientId,
  3153. AdminUserId: adminInfo.AdminUser.Id,
  3154. Module: 1,
  3155. ErrLog: string(byterequest),
  3156. Status: 1,
  3157. Ctime: time.Now().Unix(),
  3158. Mtime: 0,
  3159. Source: "电脑端新建his医嘱",
  3160. RecordDate: s.AdviceDate,
  3161. }
  3162. service.CreateDoctorAdviceLog(adviceLog)
  3163. //存储切片中
  3164. adviceList = append(adviceList, s)
  3165. redis := service.RedisClient()
  3166. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3167. redis.Set(key, "", time.Second)
  3168. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3169. redis.Set(keyOne, "", time.Second)
  3170. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3171. redis.Set(keySeven, "", time.Second)
  3172. var randNum int
  3173. randNum = rand.Intn(10000) + 1000
  3174. timestamp := time.Now().Unix()
  3175. tempTime := time.Unix(timestamp, 0)
  3176. timeFormat := tempTime.Format("20060102150405")
  3177. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3178. //查询改药品是否已经停用
  3179. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3180. if base.ID > 0 {
  3181. tx.Rollback()
  3182. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3183. return
  3184. }
  3185. service.CreateHisDoctorAdviceOne(&s, tx)
  3186. tx.Commit()
  3187. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3188. redis.Set(keySix, "", time.Second)
  3189. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3190. redis.Set(keyFive, "", time.Second)
  3191. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3192. redis.Set(keyEight, "", time.Second)
  3193. defer redis.Close()
  3194. }
  3195. }
  3196. }
  3197. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3198. projects := items["project"].([]interface{})
  3199. if len(projects) > 0 {
  3200. for _, project := range projects {
  3201. tx := db.Begin()
  3202. // 在函数结束时处理事务回滚
  3203. defer func() {
  3204. if r := recover(); r != nil {
  3205. tx.Rollback()
  3206. }
  3207. }()
  3208. var p models.HisPrescriptionProject
  3209. p.PrescriptionId = tempPrescription.ID
  3210. p.PatientId = patient_id
  3211. p.RecordDate = theTime3.Unix()
  3212. p.Doctor = doctor_id
  3213. p.UserOrgId = adminInfo.CurrentOrgId
  3214. p.HisPatientId = his_patient_id
  3215. p.Status = 1
  3216. p.StartTime = pTime
  3217. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3218. if errcode > 0 {
  3219. c.ServeFailJSONWithSGJErrorCode(errcode)
  3220. return
  3221. }
  3222. if p.ID == 0 {
  3223. p.IsOut = 2
  3224. }
  3225. if p.ID > 0 {
  3226. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3227. p.IsOut = projectDetail.IsOut
  3228. }
  3229. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3230. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3231. if p.Type == 3 {
  3232. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3233. if p.Price != lastWarehouse.PackingPrice {
  3234. p.Price = lastWarehouse.PackingPrice
  3235. }
  3236. if p.Price == 0 {
  3237. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3238. p.Price = lastWarehouseTwo.PackingPrice
  3239. }
  3240. if p.Unit == "" {
  3241. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3242. p.Unit = goodInfoOne.PackingUnit
  3243. }
  3244. }
  3245. }
  3246. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3247. //
  3248. // if p.Type == 3 {
  3249. // //查询该耗材是否停用
  3250. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3251. // //表示该耗材已经停用,不能保存
  3252. // if goodInfoSeven.ID == 0 {
  3253. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3254. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3255. // return
  3256. // }
  3257. // }
  3258. //
  3259. //}
  3260. //查询保存耗材出库开关是否打开
  3261. if p.PatientId != 30038 {
  3262. if goodOutConfig.IsOpen == 1 {
  3263. //耗材出库
  3264. if p.Type == 3 {
  3265. //对比当前数据和历史出库数据
  3266. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3267. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3268. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3269. //如果当前处方数量大于历史数据,则需要出库
  3270. if nowCount > historyCount {
  3271. var cha_count int64
  3272. cha_count = nowCount - historyCount
  3273. timeStr := time.Now().Format("2006-01-02")
  3274. timeArr := strings.Split(timeStr, "-")
  3275. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3276. total = total + 1
  3277. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3278. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3279. number = number + total
  3280. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3281. operation_time := time.Now().Unix()
  3282. creater := c.GetAdminUserInfo().AdminUser.Id
  3283. recordDateStr := time.Now().Format("2006-01-02")
  3284. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3285. nowtime := recordDate.Unix()
  3286. warehouseOut := models.WarehouseOut{
  3287. WarehouseOutOrderNumber: warehousing_out_order,
  3288. OperationTime: operation_time,
  3289. OrgId: adminInfo.CurrentOrgId,
  3290. Creater: creater,
  3291. Ctime: time.Now().Unix(),
  3292. Status: 1,
  3293. WarehouseOutTime: nowtime,
  3294. Type: 1,
  3295. StorehouseId: storeConfig.StorehouseOutInfo,
  3296. IsCheck: 1,
  3297. IsSys: 1,
  3298. }
  3299. //查询是否生成出库单
  3300. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3301. if out.ID == 0 {
  3302. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3303. }
  3304. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3305. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3306. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3307. dialyPrepareOne := models.DialysisBeforePrepare{
  3308. GoodTypeId: goodObj.GoodTypeId,
  3309. GoodId: p.ProjectId,
  3310. PatientId: p.PatientId,
  3311. RecordDate: p.RecordDate,
  3312. UserOrgId: adminInfo.CurrentOrgId,
  3313. Count: cha_count,
  3314. Ctime: time.Now().Unix(),
  3315. Creater: creater,
  3316. Status: 1,
  3317. StorehouseId: houseConfig.StorehouseOutInfo,
  3318. ProjectId: p.ID,
  3319. }
  3320. //出库
  3321. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3322. }
  3323. //如果当前处方数量小于历史数据,怎需要退库
  3324. if nowCount < historyCount {
  3325. var cha_count int64
  3326. cha_count = historyCount - nowCount
  3327. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3328. creater := c.GetAdminUserInfo().AdminUser.Id
  3329. newPrescriptionProject := &models.HisPrescriptionProject{
  3330. ID: p.ID,
  3331. ProjectId: p.ProjectId,
  3332. Price: p.Price,
  3333. UserOrgId: p.UserOrgId,
  3334. Status: 1,
  3335. Ctime: time.Now().Unix(),
  3336. Mtime: time.Now().Unix(),
  3337. PatientId: p.PatientId,
  3338. HisPatientId: p.HisPatientId,
  3339. RecordDate: p.RecordDate,
  3340. PrescriptionId: p.PrescriptionId,
  3341. Count: p.Count,
  3342. FeedetlSn: p.FeedetlSn,
  3343. MedListCodg: p.MedListCodg,
  3344. SingleDose: p.SingleDose,
  3345. DeliveryWay: p.DeliveryWay,
  3346. ExecutionFrequency: p.ExecutionFrequency,
  3347. Day: p.Day,
  3348. HisProject: models.HisProject{},
  3349. GoodInfo: models.GoodInfo{},
  3350. Remark: p.Remark,
  3351. Unit: p.Unit,
  3352. Type: p.Type,
  3353. Doctor: p.Doctor,
  3354. ExecutionTime: p.ExecutionTime,
  3355. ExecutionStaff: p.ExecutionStaff,
  3356. ExecutionState: p.ExecutionState,
  3357. CheckTime: p.CheckTime,
  3358. CheckState: p.CheckState,
  3359. Checker: p.Checker,
  3360. StartTime: p.StartTime,
  3361. TeamId: p.TeamId,
  3362. XtHisProjectTeam: models.XtHisProjectTeam{},
  3363. FrequencyType: p.FrequencyType,
  3364. DayCount: p.DayCount,
  3365. WeekDay: p.WeekDay,
  3366. IsCheckTeam: p.IsCheckTeam,
  3367. HisOrderInfo: models.HisOrderInfo{},
  3368. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3369. IsOut: p.IsOut,
  3370. YbSyncStatus: p.YbSyncStatus,
  3371. }
  3372. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3373. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3374. }
  3375. if nowCount == historyCount {
  3376. if historyCount == 0 {
  3377. recordDateStr := time.Now().Format("2006-01-02")
  3378. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3379. nowtime := recordDate.Unix()
  3380. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3381. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3382. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3383. creater := c.GetAdminUserInfo().AdminUser.Id
  3384. dialyPrepareOne := models.DialysisBeforePrepare{
  3385. GoodTypeId: goodObj.GoodTypeId,
  3386. GoodId: p.ProjectId,
  3387. PatientId: p.PatientId,
  3388. RecordDate: p.RecordDate,
  3389. UserOrgId: adminInfo.CurrentOrgId,
  3390. Count: nowCount,
  3391. Ctime: time.Now().Unix(),
  3392. Creater: creater,
  3393. Status: 1,
  3394. StorehouseId: houseConfig.StorehouseOutInfo,
  3395. ProjectId: p.ID,
  3396. }
  3397. //出库
  3398. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3399. }
  3400. }
  3401. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3402. ////查询历史出库数据
  3403. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3404. //
  3405. //var out_count_five int64
  3406. //for _, item := range flowGood {
  3407. // out_count_five += item.Count
  3408. //}
  3409. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3410. //
  3411. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3412. //if out_count_five != parseIntCount {
  3413. // //查询耗材最后一次出库记录
  3414. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3415. // //查询默认出库仓库库存
  3416. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3417. // if len(wareOut) > 0 {
  3418. //
  3419. // for _, it := range wareOut {
  3420. // //回退库存
  3421. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3422. //
  3423. // //删除出库记录
  3424. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3425. //
  3426. // }
  3427. // }
  3428. //
  3429. // timeStr := time.Now().Format("2006-01-02")
  3430. // timeArr := strings.Split(timeStr, "-")
  3431. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3432. //
  3433. // total = total + 1
  3434. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3435. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3436. // number = number + total
  3437. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3438. //
  3439. // operation_time := time.Now().Unix()
  3440. // creater := c.GetAdminUserInfo().AdminUser.Id
  3441. //
  3442. // recordDateStr := time.Now().Format("2006-01-02")
  3443. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3444. // nowtime := recordDate.Unix()
  3445. // warehouseOut := models.WarehouseOut{
  3446. // WarehouseOutOrderNumber: warehousing_out_order,
  3447. // OperationTime: operation_time,
  3448. // OrgId: adminInfo.CurrentOrgId,
  3449. // Creater: creater,
  3450. // Ctime: time.Now().Unix(),
  3451. // Status: 1,
  3452. // WarehouseOutTime: nowtime,
  3453. // Type: 1,
  3454. // StorehouseId: storeConfig.StorehouseOutInfo,
  3455. // IsCheck: 1,
  3456. // IsSys: 1,
  3457. // }
  3458. // //查询是否生成出库单
  3459. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3460. // if out.ID == 0 {
  3461. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3462. // }
  3463. //
  3464. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3465. //
  3466. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3467. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3468. //
  3469. // dialyPrepareOne := models.DialysisBeforePrepare{
  3470. // GoodTypeId: goodObj.GoodTypeId,
  3471. // GoodId: p.ProjectId,
  3472. // PatientId: p.PatientId,
  3473. // RecordDate: p.RecordDate,
  3474. // UserOrgId: adminInfo.CurrentOrgId,
  3475. // Count: parseIntCount,
  3476. // Ctime: time.Now().Unix(),
  3477. // Creater: creater,
  3478. // Status: 1,
  3479. // StorehouseId: houseConfig.StorehouseOutInfo,
  3480. // ProjectId: lastHisProject.ID,
  3481. // }
  3482. // //判断是否是零用耗材(非零用)
  3483. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3484. //
  3485. // //查询历史出库数据
  3486. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3487. // var out_count int64
  3488. // for _, item := range flowGood {
  3489. // out_count += item.Count
  3490. // }
  3491. // //如果历史数和当前数据不想等才进行退库出库
  3492. // if out_count != parseIntCount {
  3493. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3494. //
  3495. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3496. // detail := models.AutomaticReduceDetail{
  3497. // WarehouseOutId: 0,
  3498. // WarehouseOutOrderNumber: "",
  3499. // PatientId: p.PatientId,
  3500. // Ctime: time.Now().Unix(),
  3501. // Mtime: 0,
  3502. // Status: 1,
  3503. // RecordTime: p.RecordDate,
  3504. // OrgId: p.UserOrgId,
  3505. // GoodId: p.ProjectId,
  3506. // GoodTypeId: 0,
  3507. // Count: parseIntCount,
  3508. // Type: 0,
  3509. // ProjectId: lastHisProject.ID,
  3510. // StorehouseId: 0,
  3511. // }
  3512. //
  3513. // service.CreateNewAutoDetail(detail, tx)
  3514. //
  3515. // //查询剩余库存
  3516. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3517. // var sum_count int64
  3518. // for _, item := range goodList {
  3519. // sum_count += item.StockCount
  3520. // }
  3521. //
  3522. // //更新剩余库存
  3523. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3524. //
  3525. // //耗材
  3526. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3527. //
  3528. // }
  3529. // //判断是否是零用耗材(零用但是是出库耗材)
  3530. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3531. //
  3532. // //查询历史出库数据
  3533. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3534. // var out_count int64
  3535. // for _, item := range flowGood {
  3536. // out_count += item.Count
  3537. // }
  3538. // //如果历史数和当前数据不想等才进行退库出库
  3539. // if out_count != parseIntCount {
  3540. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3541. //
  3542. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3543. // detail := models.AutomaticReduceDetail{
  3544. // WarehouseOutId: 0,
  3545. // WarehouseOutOrderNumber: "",
  3546. // PatientId: p.PatientId,
  3547. // Ctime: time.Now().Unix(),
  3548. // Mtime: 0,
  3549. // Status: 1,
  3550. // RecordTime: p.RecordDate,
  3551. // OrgId: p.UserOrgId,
  3552. // GoodId: p.ProjectId,
  3553. // GoodTypeId: 0,
  3554. // Count: parseIntCount,
  3555. // Type: 0,
  3556. // ProjectId: p.ID,
  3557. // StorehouseId: 0,
  3558. // }
  3559. //
  3560. // service.CreateNewAutoDetail(detail, tx)
  3561. //
  3562. // //查询剩余库存
  3563. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3564. // var sum_count int64
  3565. // for _, item := range goodList {
  3566. // sum_count += item.StockCount
  3567. // }
  3568. //
  3569. // //更新剩余库存
  3570. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3571. //
  3572. // //耗材
  3573. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3574. // }
  3575. //
  3576. // }
  3577. //
  3578. // }
  3579. //
  3580. //}
  3581. //记录日志
  3582. byterequest, _ := json.Marshal(p)
  3583. adviceLog := models.XtDoctorAdviceLog{
  3584. UserOrgId: p.UserOrgId,
  3585. PatientId: p.PatientId,
  3586. AdminUserId: adminInfo.AdminUser.Id,
  3587. Module: 1,
  3588. ErrLog: string(byterequest),
  3589. Status: 1,
  3590. Ctime: time.Now().Unix(),
  3591. Mtime: 0,
  3592. Source: "电脑端新建his项目",
  3593. RecordDate: p.RecordDate,
  3594. }
  3595. service.CreateDoctorAdviceLog(adviceLog)
  3596. projectList = append(projectList, p)
  3597. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3598. //新增或者编辑项目,修改对应的标签数据
  3599. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3600. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3601. var label models.HisLabelPrintInfo
  3602. project, _ := service.GetProjectDetail(p.ProjectId)
  3603. if project.CostClassify == 3 { //类别为检验检查
  3604. if p.TeamId > 0 { //检验检查组套
  3605. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3606. if tempLabel.ID == 0 {
  3607. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3608. label.Number = tempPrescription.PrescriptionNumber
  3609. label.ProjectId = project.ID
  3610. label.Status = 1
  3611. label.IsPrint = 2
  3612. label.DoctorId = info.DoctorId
  3613. label.UserOrgId = p.UserOrgId
  3614. label.PatientId = patient_id
  3615. label.RecordDate = recordDateTime
  3616. label.Ctime = time.Now().Unix()
  3617. label.Mtime = time.Now().Unix()
  3618. label.ItemId = p.TeamId
  3619. label.FeedetlSn = p.FeedetlSn
  3620. label.PProjectId = p.ID
  3621. label.ProjectName = team.ProjectTeam
  3622. label.PatientName = patient.Name
  3623. service.CreateNewHisLabelRecord(&label, tx)
  3624. }
  3625. } else { //单条检验检查项目
  3626. label.Number = tempPrescription.PrescriptionNumber
  3627. label.ProjectId = project.ID
  3628. label.Status = 1
  3629. label.DoctorId = info.DoctorId
  3630. label.UserOrgId = p.UserOrgId
  3631. label.PatientId = patient_id
  3632. label.RecordDate = recordDateTime
  3633. label.IsPrint = 2
  3634. label.Ctime = time.Now().Unix()
  3635. label.Mtime = time.Now().Unix()
  3636. label.FeedetlSn = p.FeedetlSn
  3637. label.PProjectId = p.ID
  3638. label.ItemId = p.TeamId
  3639. label.ProjectName = project.ProjectName
  3640. label.PatientName = patient.Name
  3641. service.CreateNewHisLabelRecord(&label, tx)
  3642. }
  3643. }
  3644. }
  3645. }
  3646. }
  3647. }
  3648. }
  3649. service.CreateNewHisProjectTwo(&p, tx)
  3650. var randNum int
  3651. randNum = rand.Intn(10000) + 1000
  3652. timestamp := time.Now().Unix()
  3653. tempTime := time.Unix(timestamp, 0)
  3654. timeFormat := tempTime.Format("20060102150405")
  3655. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3656. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3657. if goodBase.ID > 0 {
  3658. tx.Rollback()
  3659. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3660. return
  3661. }
  3662. service.CreateNewHisProjectTwo(&p, tx)
  3663. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3664. //查询剩余库存
  3665. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3666. var sum_count int64
  3667. for _, item := range goodList {
  3668. sum_count += item.StockCount
  3669. }
  3670. //更新剩余库存
  3671. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3672. //耗材
  3673. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3674. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3675. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3676. if len(outInfoTwo) > 0 {
  3677. for _, item := range outInfoTwo {
  3678. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3679. }
  3680. }
  3681. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3682. if len(drugAutoDetail) > 0 {
  3683. for _, item := range drugAutoDetail {
  3684. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3685. }
  3686. }
  3687. tx.Commit()
  3688. }
  3689. }
  3690. }
  3691. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3692. // addition := items["addition"].([]interface{})
  3693. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3694. // ctime := time.Now().Unix()
  3695. // mtime := ctime
  3696. // if len(addition) > 0 {
  3697. // for _, item := range addition {
  3698. // var s models.HisAdditionalCharge
  3699. // s.PrescriptionId = tempPrescription.ID
  3700. // s.Status = 1
  3701. // s.UserOrgId = adminInfo.CurrentOrgId
  3702. // s.RecordDate = recordDateTime
  3703. // s.CreatedTime = ctime
  3704. // s.UpdatedTime = mtime
  3705. // s.PatientId = patient_id
  3706. // s.HisPatientId = his_patient_id
  3707. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3708. // if errcode > 0 {
  3709. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3710. // return
  3711. // }
  3712. // service.CreateAdditionalCharge(&s)
  3713. // var randNum int
  3714. // randNum = rand.Intn(10000) + 1000
  3715. // timestamp := time.Now().Unix()
  3716. // tempTime := time.Unix(timestamp, 0)
  3717. // timeFormat := tempTime.Format("20060102150405")
  3718. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3719. // service.CreateAdditionalCharge(&s)
  3720. //
  3721. // }
  3722. // }
  3723. //}
  3724. }
  3725. }
  3726. }
  3727. tx.Commit()
  3728. if err == nil {
  3729. c.ServeSuccessJSON(map[string]interface{}{
  3730. "msg": "保存成功",
  3731. })
  3732. return
  3733. } else {
  3734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3735. return
  3736. }
  3737. } else {
  3738. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3739. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3740. var tempPrescription *models.HisPrescription
  3741. if len(prescriptions) > 0 {
  3742. for _, item := range prescriptions {
  3743. items := item.(map[string]interface{})
  3744. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3745. utils.ErrorLog("id")
  3746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3747. return
  3748. }
  3749. id := int64(items["id"].(float64))
  3750. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3751. tempPrescription = &new_prescription
  3752. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3753. utils.ErrorLog("type")
  3754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3755. return
  3756. }
  3757. types := int64(items["type"].(float64))
  3758. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3759. utils.ErrorLog("med_type")
  3760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. return
  3762. }
  3763. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3764. if med_type == "0" {
  3765. med_type = "14"
  3766. }
  3767. //if order_status == 0 {
  3768. // order_status = 1
  3769. //}
  3770. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3771. utils.ErrorLog("pre_time")
  3772. }
  3773. preTime, _ := items["pre_time"].(string)
  3774. timeLayout := "2006-01-02"
  3775. loc, _ := time.LoadLocation("Local")
  3776. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3777. result := strings.Split(preTime, " ")
  3778. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3779. if err != nil {
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3781. return
  3782. }
  3783. pTime := theTime2.Unix()
  3784. ctime := time.Now().Unix()
  3785. if tempPrescription.ID == 0 {
  3786. prescription := &models.HisPrescription{
  3787. ID: 0,
  3788. PatientId: patient_id,
  3789. UserOrgId: adminInfo.CurrentOrgId,
  3790. RecordDate: recordDateTime,
  3791. Ctime: ctime,
  3792. Mtime: ctime,
  3793. Type: types,
  3794. Modifier: adminInfo.AdminUser.Id,
  3795. Creator: adminInfo.AdminUser.Id,
  3796. Status: 1,
  3797. Doctor: role.UserName,
  3798. HisPatientId: his_patient_id,
  3799. OrderStatus: 1,
  3800. BatchNumber: "",
  3801. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3802. PreTime: pTime,
  3803. PType: p_type,
  3804. MedType: med_type,
  3805. }
  3806. tempPrescription = prescription
  3807. service.SaveHisPrescription(tempPrescription)
  3808. redis := service.RedisClient()
  3809. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3810. redis.Set(key, "", time.Second)
  3811. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3812. redis.Set(keyOne, "", time.Second)
  3813. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3814. redis.Set(keySeven, "", time.Second)
  3815. defer redis.Close()
  3816. } else {
  3817. tempPrescription.ID = id
  3818. tempPrescription.Type = types
  3819. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3820. tempPrescription.Mtime = time.Now().Unix()
  3821. tempPrescription.Doctor = role.UserName
  3822. //tempPrescription.OrderStatus = order_status
  3823. tempPrescription.PreTime = pTime
  3824. tempPrescription.MedType = med_type
  3825. service.SaveHisPrescription(tempPrescription)
  3826. redis := service.RedisClient()
  3827. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3828. redis.Set(key, "", time.Second)
  3829. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3830. redis.Set(keyOne, "", time.Second)
  3831. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3832. redis.Set(keySeven, "", time.Second)
  3833. defer redis.Close()
  3834. }
  3835. //service.SaveHisPrescription(prescription)
  3836. //更改患者挂号状态
  3837. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3838. fmt.Println("更改失败", err2)
  3839. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3840. advices := items["advices"].([]interface{})
  3841. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3842. groupNo := int64(0)
  3843. if len(advices) > 0 {
  3844. for _, advice := range advices {
  3845. var s models.HisDoctorAdviceInfo
  3846. s.PrescriptionId = tempPrescription.ID
  3847. s.AdviceType = 2
  3848. s.AdviceDoctor = doctor_id
  3849. s.StopState = 2
  3850. s.ExecutionState = 2
  3851. s.AdviceDate = theTime3.Unix()
  3852. s.Status = 1
  3853. s.UserOrgId = adminInfo.CurrentOrgId
  3854. s.RecordDate = theTime3.Unix()
  3855. s.StartTime = tempPrescription.PreTime
  3856. s.Groupno = groupNo
  3857. s.PatientId = patient_id
  3858. s.HisPatientId = his_patient_id
  3859. s.StartTime = pTime
  3860. s.IsSettle = 2
  3861. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3862. if errcode > 0 {
  3863. c.ServeFailJSONWithSGJErrorCode(errcode)
  3864. return
  3865. }
  3866. s.StartTime = pTime
  3867. var total_count int64 //处方总库存
  3868. //查询改药品信息
  3869. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3870. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3871. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3872. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3873. total_count += prescribingNumberSeven * medical.MinNumber
  3874. }
  3875. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3876. total_count += prescribingNumberSeven
  3877. }
  3878. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3879. total_count += prescribingNumberSeven
  3880. }
  3881. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3882. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3883. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3884. if s.Price != lastWarehouse.RetailPrice {
  3885. s.Price = lastWarehouse.RetailPrice
  3886. }
  3887. if s.Price == 0 {
  3888. if lastWarehouse.ID == 0 {
  3889. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3890. s.Price = lastWarehouseTwo.RetailPrice
  3891. }
  3892. }
  3893. }
  3894. service.CreateHisDoctorAdvice(&s)
  3895. //记录日志
  3896. byterequest, _ := json.Marshal(s)
  3897. adviceLog := models.XtDoctorAdviceLog{
  3898. UserOrgId: s.UserOrgId,
  3899. PatientId: s.PatientId,
  3900. AdminUserId: adminInfo.AdminUser.Id,
  3901. Module: 1,
  3902. ErrLog: string(byterequest),
  3903. Status: 1,
  3904. Ctime: time.Now().Unix(),
  3905. Mtime: 0,
  3906. Source: "电脑端新建his医嘱",
  3907. RecordDate: s.AdviceDate,
  3908. }
  3909. service.CreateDoctorAdviceLog(adviceLog)
  3910. //存储切片中
  3911. adviceList = append(adviceList, s)
  3912. redis := service.RedisClient()
  3913. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3914. redis.Set(key, "", time.Second)
  3915. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3916. redis.Set(keyOne, "", time.Second)
  3917. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3918. redis.Set(keySeven, "", time.Second)
  3919. var randNum int
  3920. randNum = rand.Intn(10000) + 1000
  3921. timestamp := time.Now().Unix()
  3922. tempTime := time.Unix(timestamp, 0)
  3923. timeFormat := tempTime.Format("20060102150405")
  3924. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3925. service.CreateHisDoctorAdvice(&s)
  3926. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3927. redis.Set(keySix, "", time.Second)
  3928. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3929. redis.Set(keyFive, "", time.Second)
  3930. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3931. redis.Set(keyEight, "", time.Second)
  3932. defer redis.Close()
  3933. }
  3934. }
  3935. }
  3936. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3937. projects := items["project"].([]interface{})
  3938. if len(projects) > 0 {
  3939. for _, project := range projects {
  3940. var p models.HisPrescriptionProject
  3941. p.PrescriptionId = tempPrescription.ID
  3942. p.PatientId = patient_id
  3943. p.RecordDate = theTime3.Unix()
  3944. p.Doctor = doctor_id
  3945. p.UserOrgId = adminInfo.CurrentOrgId
  3946. p.HisPatientId = his_patient_id
  3947. p.Status = 1
  3948. p.StartTime = pTime
  3949. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3950. if errcode > 0 {
  3951. c.ServeFailJSONWithSGJErrorCode(errcode)
  3952. return
  3953. }
  3954. if p.ID == 0 {
  3955. p.IsOut = 2
  3956. }
  3957. if p.ID > 0 {
  3958. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3959. p.IsOut = projectDetail.IsOut
  3960. }
  3961. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3962. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3963. if p.Type == 3 {
  3964. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3965. if p.Price != lastWarehouse.PackingPrice {
  3966. p.Price = lastWarehouse.PackingPrice
  3967. }
  3968. if p.Price == 0 {
  3969. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3970. p.Price = lastWarehouseTwo.PackingPrice
  3971. }
  3972. if p.Unit == "" {
  3973. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3974. p.Unit = goodInfoOne.PackingUnit
  3975. }
  3976. }
  3977. }
  3978. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3979. //
  3980. // if p.Type == 3 {
  3981. // //查询该耗材是否停用
  3982. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3983. // //表示该耗材已经停用,不能保存
  3984. // if goodInfoSeven.ID == 0 {
  3985. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3986. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3987. // return
  3988. // }
  3989. // }
  3990. //
  3991. //}
  3992. service.CreateHisProjectTwo(&p)
  3993. //记录日志
  3994. byterequest, _ := json.Marshal(p)
  3995. adviceLog := models.XtDoctorAdviceLog{
  3996. UserOrgId: p.UserOrgId,
  3997. PatientId: p.PatientId,
  3998. AdminUserId: adminInfo.AdminUser.Id,
  3999. Module: 1,
  4000. ErrLog: string(byterequest),
  4001. Status: 1,
  4002. Ctime: time.Now().Unix(),
  4003. Mtime: 0,
  4004. Source: "电脑端新建his项目",
  4005. RecordDate: p.RecordDate,
  4006. }
  4007. service.CreateDoctorAdviceLog(adviceLog)
  4008. projectList = append(projectList, p)
  4009. var randNum int
  4010. randNum = rand.Intn(10000) + 1000
  4011. timestamp := time.Now().Unix()
  4012. tempTime := time.Unix(timestamp, 0)
  4013. timeFormat := tempTime.Format("20060102150405")
  4014. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4015. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4016. //新增或者编辑项目,修改对应的标签数据
  4017. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4018. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4019. var label models.HisLabelPrintInfo
  4020. project, _ := service.GetProjectDetail(p.ProjectId)
  4021. if project.CostClassify == 3 { //类别为检验检查
  4022. if p.TeamId > 0 { //检验检查组套
  4023. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4024. if tempLabel.ID == 0 {
  4025. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4026. label.Number = tempPrescription.PrescriptionNumber
  4027. label.ProjectId = project.ID
  4028. label.Status = 1
  4029. label.IsPrint = 2
  4030. label.DoctorId = info.DoctorId
  4031. label.UserOrgId = p.UserOrgId
  4032. label.PatientId = patient_id
  4033. label.RecordDate = recordDateTime
  4034. label.Ctime = time.Now().Unix()
  4035. label.Mtime = time.Now().Unix()
  4036. label.ItemId = p.TeamId
  4037. label.FeedetlSn = p.FeedetlSn
  4038. label.PProjectId = p.ID
  4039. label.ProjectName = team.ProjectTeam
  4040. label.PatientName = patient.Name
  4041. service.CreateHisLabelRecord(&label)
  4042. }
  4043. } else { //单条检验检查项目
  4044. label.Number = tempPrescription.PrescriptionNumber
  4045. label.ProjectId = project.ID
  4046. label.Status = 1
  4047. label.DoctorId = info.DoctorId
  4048. label.UserOrgId = p.UserOrgId
  4049. label.PatientId = patient_id
  4050. label.RecordDate = recordDateTime
  4051. label.IsPrint = 2
  4052. label.Ctime = time.Now().Unix()
  4053. label.Mtime = time.Now().Unix()
  4054. label.FeedetlSn = p.FeedetlSn
  4055. label.PProjectId = p.ID
  4056. label.ItemId = p.TeamId
  4057. label.ProjectName = project.ProjectName
  4058. label.PatientName = patient.Name
  4059. service.CreateHisLabelRecord(&label)
  4060. }
  4061. }
  4062. }
  4063. }
  4064. service.SaveHisProjectTwo(&p)
  4065. }
  4066. }
  4067. }
  4068. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4069. // addition := items["addition"].([]interface{})
  4070. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4071. // ctime := time.Now().Unix()
  4072. // mtime := ctime
  4073. // if len(addition) > 0 {
  4074. // for _, item := range addition {
  4075. // var s models.HisAdditionalCharge
  4076. // s.PrescriptionId = tempPrescription.ID
  4077. // s.Status = 1
  4078. // s.UserOrgId = adminInfo.CurrentOrgId
  4079. // s.RecordDate = recordDateTime
  4080. // s.CreatedTime = ctime
  4081. // s.UpdatedTime = mtime
  4082. // s.PatientId = patient_id
  4083. // s.HisPatientId = his_patient_id
  4084. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4085. // if errcode > 0 {
  4086. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4087. // return
  4088. // }
  4089. // service.CreateAdditionalCharge(&s)
  4090. // var randNum int
  4091. // randNum = rand.Intn(10000) + 1000
  4092. // timestamp := time.Now().Unix()
  4093. // tempTime := time.Unix(timestamp, 0)
  4094. // timeFormat := tempTime.Format("20060102150405")
  4095. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4096. // service.CreateAdditionalCharge(&s)
  4097. //
  4098. // }
  4099. // }
  4100. //}
  4101. }
  4102. }
  4103. //查询今日该患者开的药品处方
  4104. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4105. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4106. //药品出库
  4107. if drugOutConfig.IsOpen == 1 {
  4108. for _, item := range hisdoctorlist {
  4109. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4110. // 查询该药品最后一次出库记录
  4111. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4112. if len(druginfo) > 0 {
  4113. //回退库存
  4114. for _, it := range druginfo {
  4115. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4116. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4117. }
  4118. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4119. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4120. }
  4121. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4122. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4123. }
  4124. }
  4125. }
  4126. //删除记录
  4127. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4128. //查询最后一次数据
  4129. if drugOutConfig.IsOpen == 1 {
  4130. //出库
  4131. if drug.IsUse == 2 {
  4132. creater := adminInfo.AdminUser.Id
  4133. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4134. }
  4135. //更新字典里面的库存
  4136. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4137. var sum_count int64
  4138. for _, its := range stockInfo {
  4139. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4140. if its.MaxUnit == baseDrug.MaxUnit {
  4141. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4142. }
  4143. sum_count += its.StockMaxNumber + its.StockMinNumber
  4144. }
  4145. //更新基础库存
  4146. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4147. //剩余库存
  4148. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4149. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4150. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4151. }
  4152. }
  4153. }
  4154. //耗材保存处方出库
  4155. if goodOutConfig.IsOpen == 1 {
  4156. //查询今日耗材出库数量
  4157. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4158. for _, item := range hisgoodlist {
  4159. //查询历史出库数据
  4160. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4161. var out_count_five int64
  4162. for _, item := range flowGood {
  4163. out_count_five += item.Count
  4164. }
  4165. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4166. if out_count_five != parseIntCount {
  4167. //查询耗材最后一次出库记录
  4168. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4169. //查询默认出库仓库库存
  4170. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4171. if len(wareOut) > 0 {
  4172. for _, it := range wareOut {
  4173. //回退库存
  4174. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4175. //删除出库记录
  4176. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4177. }
  4178. }
  4179. timeStr := time.Now().Format("2006-01-02")
  4180. timeArr := strings.Split(timeStr, "-")
  4181. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4182. total = total + 1
  4183. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4184. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4185. number = number + total
  4186. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4187. operation_time := time.Now().Unix()
  4188. creater := c.GetAdminUserInfo().AdminUser.Id
  4189. recordDateStr := time.Now().Format("2006-01-02")
  4190. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4191. nowtime := recordDate.Unix()
  4192. warehouseOut := models.WarehouseOut{
  4193. WarehouseOutOrderNumber: warehousing_out_order,
  4194. OperationTime: operation_time,
  4195. OrgId: adminInfo.CurrentOrgId,
  4196. Creater: creater,
  4197. Ctime: time.Now().Unix(),
  4198. Status: 1,
  4199. WarehouseOutTime: nowtime,
  4200. Type: 1,
  4201. StorehouseId: storeConfig.StorehouseOutInfo,
  4202. IsCheck: 1,
  4203. IsSys: 1,
  4204. }
  4205. //查询是否生成出库单
  4206. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4207. if out.ID == 0 {
  4208. service.AddSigleWarehouseOut(&warehouseOut)
  4209. }
  4210. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4211. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4212. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4213. dialyPrepareOne := models.DialysisBeforePrepare{
  4214. GoodTypeId: goodObj.GoodTypeId,
  4215. GoodId: item.ProjectId,
  4216. PatientId: item.PatientId,
  4217. RecordDate: item.RecordDate,
  4218. UserOrgId: adminInfo.CurrentOrgId,
  4219. Count: parseIntCount,
  4220. Ctime: time.Now().Unix(),
  4221. Creater: creater,
  4222. Status: 1,
  4223. StorehouseId: houseConfig.StorehouseOutInfo,
  4224. ProjectId: item.ID,
  4225. }
  4226. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4227. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4228. //查询历史出库数据
  4229. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4230. var out_count int64
  4231. for _, item := range flowGood {
  4232. out_count += item.Count
  4233. }
  4234. //如果历史数和当前数据不想等才进行退库出库
  4235. if out_count != parseIntCount {
  4236. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4237. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4238. detail := models.AutomaticReduceDetail{
  4239. WarehouseOutId: 0,
  4240. WarehouseOutOrderNumber: "",
  4241. PatientId: item.PatientId,
  4242. Ctime: time.Now().Unix(),
  4243. Mtime: 0,
  4244. Status: 1,
  4245. RecordTime: item.RecordDate,
  4246. OrgId: item.UserOrgId,
  4247. GoodId: item.ProjectId,
  4248. GoodTypeId: 0,
  4249. Count: parseIntCount,
  4250. Type: 0,
  4251. ProjectId: item.ID,
  4252. StorehouseId: 0,
  4253. }
  4254. service.CreateAutoDetail(detail)
  4255. //查询剩余库存
  4256. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4257. var sum_count int64
  4258. for _, item := range goodList {
  4259. sum_count += item.StockCount
  4260. }
  4261. //更新剩余库存
  4262. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4263. //耗材
  4264. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4265. }
  4266. }
  4267. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4268. //查询历史出库数据
  4269. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4270. var out_count int64
  4271. for _, item := range flowGood {
  4272. out_count += item.Count
  4273. }
  4274. //如果历史数和当前数据不想等才进行退库出库
  4275. if out_count != parseIntCount {
  4276. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4277. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4278. detail := models.AutomaticReduceDetail{
  4279. WarehouseOutId: 0,
  4280. WarehouseOutOrderNumber: "",
  4281. PatientId: item.PatientId,
  4282. Ctime: time.Now().Unix(),
  4283. Mtime: 0,
  4284. Status: 1,
  4285. RecordTime: item.RecordDate,
  4286. OrgId: item.UserOrgId,
  4287. GoodId: item.ProjectId,
  4288. GoodTypeId: 0,
  4289. Count: parseIntCount,
  4290. Type: 0,
  4291. ProjectId: item.ID,
  4292. StorehouseId: 0,
  4293. }
  4294. service.CreateAutoDetail(detail)
  4295. //查询剩余库存
  4296. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4297. var sum_count int64
  4298. for _, item := range goodList {
  4299. sum_count += item.StockCount
  4300. }
  4301. //更新剩余库存
  4302. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4303. //耗材
  4304. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4305. }
  4306. }
  4307. }
  4308. }
  4309. }
  4310. ////同步到自备药
  4311. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4312. fmt.Println("selfPrescriptionOpen--------------------------------------------------", selfPrescriptionOpen.IsOpen)
  4313. if selfPrescriptionOpen.IsOpen == 1 {
  4314. timeStr := time.Now().Format("2006-01-02")
  4315. timeArr := strings.Split(timeStr, "-")
  4316. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4317. total = total + 1
  4318. operation_time := time.Now().Unix()
  4319. creater := adminInfo.AdminUser.Id
  4320. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4321. warehousing := models.XtSelfDrugWarehouse{
  4322. WarehousingOrder: warehousing_order,
  4323. OperationTime: operation_time,
  4324. OrgId: adminInfo.CurrentOrgId,
  4325. Creater: creater,
  4326. Ctime: time.Now().Unix(),
  4327. Status: 1,
  4328. WarehousingTime: recordDateTime,
  4329. Type: 0,
  4330. StorehouseId: 0,
  4331. IsCheck: 1,
  4332. PatientId: patient_id,
  4333. IsSys: 1,
  4334. }
  4335. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4336. if selfDrugWarehouse.ID == 0 {
  4337. service.AddSelfDrugWarehouse(&warehousing, tx)
  4338. }
  4339. if selfDrugWarehouse.ID > 0 {
  4340. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4341. }
  4342. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4343. fmt.Println(info)
  4344. for _, item := range hisdoctorlist {
  4345. //查询该病人的该药品是否已经入库
  4346. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4347. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
  4348. var in_count int64
  4349. if len(selfdruginfo) > 0 {
  4350. for _, item := range selfdruginfo {
  4351. var in_count_one int64
  4352. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4353. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4354. }
  4355. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4356. in_count_one = item.WarehousingCount
  4357. }
  4358. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4359. in_count_one = item.WarehousingCount
  4360. }
  4361. in_count += in_count_one
  4362. }
  4363. }
  4364. fmt.Println("selfBasedrug--------------------", selfBasedrug.IsSelfDrug)
  4365. if selfBasedrug.IsSelfDrug == 1 {
  4366. var total_count int64
  4367. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4368. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4369. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4370. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4371. }
  4372. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4373. total_count += prescribingNumberSeven
  4374. }
  4375. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4376. total_count += prescribingNumberSeven
  4377. }
  4378. fmt.Println("tota_count==================================", total_count)
  4379. fmt.Println("in_count==================================", in_count)
  4380. //入库
  4381. if total_count > in_count {
  4382. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4383. WarehousingOrder: warehousing_order,
  4384. WarehousingId: info.ID,
  4385. DrugId: item.DrugId,
  4386. Number: "",
  4387. ProductDate: 0,
  4388. ExpiryDate: 0,
  4389. WarehousingCount: total_count - in_count,
  4390. WarehouseingUnit: selfBasedrug.MinUnit,
  4391. Price: 0,
  4392. TotalPrice: 0,
  4393. Status: 1,
  4394. Ctime: time.Now().Unix(),
  4395. Remark: "",
  4396. OrgId: adminInfo.CurrentOrgId,
  4397. Type: 0,
  4398. Manufacturer: selfBasedrug.Manufacturer,
  4399. Dealer: selfBasedrug.Dealer,
  4400. StockMaxNumber: total_count - in_count,
  4401. RetailTotalPrice: 0,
  4402. BatchNumber: "",
  4403. MaxUnit: selfBasedrug.MinUnit,
  4404. MinUnit: selfBasedrug.MinUnit,
  4405. RetailPrice: 0,
  4406. StorehouseId: 0,
  4407. IsCheck: 1,
  4408. StockMinNumber: 0,
  4409. PatientId: patient_id,
  4410. IsSys: 1,
  4411. RecordDate: item.RecordDate,
  4412. AdviceId: item.ID,
  4413. }
  4414. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4415. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4416. Creator := adminInfo.AdminUser.Id
  4417. //查询默认仓库剩余多少库存
  4418. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4419. var sum_count int64
  4420. for _, it := range list {
  4421. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4422. if it.MaxUnit == baseDrug.MaxUnit {
  4423. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4424. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4425. }
  4426. sum_count += it.StockMaxNumber + it.StockMinNumber
  4427. }
  4428. flow := &models.XtSelfDrugFlow{
  4429. WarehousingId: info.ID,
  4430. DrugId: item.DrugId,
  4431. Number: "",
  4432. BatchNumber: "",
  4433. Count: total_count - in_count,
  4434. UserOrgId: adminInfo.CurrentOrgId,
  4435. PatientId: item.PatientId,
  4436. SystemTime: time.Now().Unix(),
  4437. ConsumableType: 1,
  4438. IsSys: 1,
  4439. WarehousingOrder: warehousing_order,
  4440. WarehouseOutId: 0,
  4441. WarehouseOutOrderNumber: "",
  4442. IsEdit: 0,
  4443. CancelStockId: 0,
  4444. CancelOrderNumber: "",
  4445. Manufacturer: selfBasedrug.Manufacturer,
  4446. Dealer: selfBasedrug.Dealer,
  4447. Creator: Creator,
  4448. UpdateCreator: Creator,
  4449. Status: 1,
  4450. Ctime: item.AdviceDate,
  4451. Mtime: 0,
  4452. Price: item.Price,
  4453. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4454. WarehouseOutDetailId: 0,
  4455. CancelOutDetailId: 0,
  4456. ExpireDate: 0,
  4457. ProductDate: 0,
  4458. MaxUnit: selfBasedrug.MinUnit,
  4459. MinUnit: selfBasedrug.MinUnit,
  4460. StorehouseId: 0,
  4461. OverCount: sum_count,
  4462. OperateTime: time.Now().Unix(),
  4463. AdviceId: item.ID,
  4464. }
  4465. service.CreateSelfDrugFlow(flow, tx)
  4466. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4467. var total_count int64 // 入库总数量
  4468. var over_count int64 //剩余库存
  4469. for _, it := range drugInfolist {
  4470. if it.MaxUnit == selfBasedrug.MaxUnit {
  4471. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4472. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4473. }
  4474. }
  4475. for _, it := range drugInfolist {
  4476. total_count += it.WarehousingCount
  4477. over_count += it.StockMaxNumber + it.StockMinNumber
  4478. }
  4479. //查询该仓库是否有默认数据
  4480. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4481. if selfDrugStock.ID == 0 {
  4482. drugStock := models.XtSelfDrugStockCount{
  4483. UserOrgId: item.UserOrgId,
  4484. PatientId: item.PatientId,
  4485. SumInCount: total_count,
  4486. SumOutCount: 0,
  4487. SumCancelCount: 0,
  4488. DrugId: item.DrugId,
  4489. Ctime: time.Now().Unix(),
  4490. Mtime: 0,
  4491. Status: 1,
  4492. FlushCount: over_count,
  4493. SumActOutCount: 0,
  4494. }
  4495. service.CreateSelfDrugStockSum(drugStock, tx)
  4496. }
  4497. if selfDrugStock.ID > 0 {
  4498. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4499. }
  4500. }
  4501. //查询这个单据的出库数量
  4502. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4503. var his_out_count int64
  4504. for _, item := range drugFlowList {
  4505. his_out_count += item.Count
  4506. }
  4507. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4508. if (total_count + his_out_count) <= in_count {
  4509. // 出库
  4510. if total_count < in_count {
  4511. var cha_count int64
  4512. cha_count = in_count - total_count
  4513. var stock_number int64 = 0
  4514. //查询库存是否充足
  4515. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4516. // 将该批次的剩余库存数量转换为拆零数量
  4517. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4518. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4519. }
  4520. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4521. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4522. }
  4523. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4524. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4525. }
  4526. if stock_number >= cha_count {
  4527. var maxNumber int64 = 0
  4528. var minNumber int64 = 0
  4529. maxNumber = cha_count / selfBasedrug.MinNumber
  4530. minNumber = cha_count % selfBasedrug.MinNumber
  4531. fmt.Println("maxNumber----------------------------", maxNumber)
  4532. fmt.Println("minNumber----------------------------", minNumber)
  4533. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4534. minNumber = maxNumber
  4535. }
  4536. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4537. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4539. return
  4540. }
  4541. }
  4542. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4543. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4544. }
  4545. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4546. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4547. }
  4548. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4549. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4550. }
  4551. if warehouse.StockMaxNumber < 0 {
  4552. warehouse.StockMaxNumber = 0
  4553. }
  4554. if warehouse.StockMinNumber < 0 {
  4555. warehouse.StockMinNumber = 0
  4556. }
  4557. warehouse.Mtime = time.Now().Unix()
  4558. if warehouse.StockMinNumber < minNumber {
  4559. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4560. if warehouse.MaxUnit != warehouse.MinUnit {
  4561. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4562. }
  4563. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4564. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4565. }
  4566. } else {
  4567. if minNumber > 0 {
  4568. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4569. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4570. }
  4571. }
  4572. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4573. if warehouse.StockMinNumber > 0 {
  4574. if warehouse.StockMinNumber-cha_count >= 0 {
  4575. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4576. }
  4577. }
  4578. }
  4579. }
  4580. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4581. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4582. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4583. }
  4584. }
  4585. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4586. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4588. return
  4589. }
  4590. }
  4591. if warehouse.StockMinNumber <= 0 {
  4592. warehouse.StockMinNumber = 0
  4593. }
  4594. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4595. //查询该药品剩余库存
  4596. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4597. var over_count int64
  4598. for _, its := range infolist {
  4599. if its.MaxUnit == selfBasedrug.MaxUnit {
  4600. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4601. }
  4602. over_count += its.StockMaxNumber + its.StockMinNumber
  4603. }
  4604. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4605. drugflow := models.XtSelfDrugFlow{
  4606. WarehouseOutId: 0,
  4607. WarehouseOutOrderNumber: warehousing_order,
  4608. WarehousingOrder: warehousing_order,
  4609. DrugId: item.DrugId,
  4610. Number: warehouse.Number,
  4611. ProductDate: warehouse.ProductDate,
  4612. ExpireDate: warehouse.ExpiryDate,
  4613. Count: cha_count,
  4614. Price: warehouse.RetailPrice,
  4615. Status: 1,
  4616. Ctime: item.AdviceDate,
  4617. Mtime: time.Now().Unix(),
  4618. UserOrgId: item.UserOrgId,
  4619. Manufacturer: warehouse.Manufacturer,
  4620. Dealer: warehouse.Dealer,
  4621. BatchNumber: warehouse.BatchNumber,
  4622. MaxUnit: selfBasedrug.MinUnit,
  4623. ConsumableType: 20,
  4624. IsEdit: 1,
  4625. Creator: 0,
  4626. IsSys: 3,
  4627. WarehouseOutDetailId: drugWareInfo.ID,
  4628. AdviceId: item.ID,
  4629. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4630. StorehouseId: 0,
  4631. AdminUserId: creater,
  4632. LastPrice: warehouse.Price,
  4633. StockCount: "",
  4634. WarehousingDetailId: 0,
  4635. OverCount: over_count,
  4636. RetailPrice: item.Price, //手动出库出库价格
  4637. WarehousingId: warehouse.ID,
  4638. SystemTime: item.AdviceDate,
  4639. PatientId: item.PatientId,
  4640. Remark: "保存处方入库数据差",
  4641. OperateTime: time.Now().Unix(),
  4642. }
  4643. if warehouse.RetailPrice == 0 {
  4644. drugflow.Price = item.Price
  4645. }
  4646. service.CreateSelfDrugFlowOne(drugflow, tx)
  4647. var out_count int64
  4648. out_count = in_count - total_count
  4649. fmt.Println("in_count------------------", in_count)
  4650. fmt.Println("total_count------------------", total_count)
  4651. //添加出库数量
  4652. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4653. //查询剩余库存
  4654. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4655. var sum_count int64
  4656. for _, its := range stockInfo {
  4657. if its.MaxUnit == selfBasedrug.MaxUnit {
  4658. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4659. }
  4660. sum_count += its.StockMaxNumber + its.StockMinNumber
  4661. }
  4662. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4663. } else {
  4664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4665. return
  4666. }
  4667. }
  4668. }
  4669. }
  4670. }
  4671. }
  4672. }
  4673. tx.Commit()
  4674. if err == nil {
  4675. c.ServeSuccessJSON(map[string]interface{}{
  4676. "msg": "保存成功",
  4677. })
  4678. return
  4679. } else {
  4680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4681. return
  4682. }
  4683. }
  4684. }
  4685. //func (c *HisApiController) EditHisPrescription() {
  4686. // record_date := c.GetString("record_date")
  4687. // patient_id, _ := c.GetInt64("patient_id")
  4688. // reg_type, _ := c.GetInt64("reg_type")
  4689. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4690. // diagnose := c.GetString("diagnose")
  4691. // sick_type, _ := c.GetInt64("sick_type")
  4692. // sick_history := c.GetString("sick_history")
  4693. // doctor_id, _ := c.GetInt64("doctor", 0)
  4694. // department, _ := c.GetInt64("department", 0)
  4695. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4696. // p_type, _ := c.GetInt64("p_type")
  4697. //
  4698. // dataBody := make(map[string]interface{}, 0)
  4699. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4700. // if err != nil {
  4701. // utils.ErrorLog(err.Error())
  4702. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4703. // return
  4704. // }
  4705. //
  4706. // timeLayout := "2006-01-02"
  4707. // loc, _ := time.LoadLocation("Local")
  4708. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4709. // if err != nil {
  4710. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4711. // return
  4712. // }
  4713. // adminInfo := c.GetAdminUserInfo()
  4714. // recordDateTime := theTime.Unix()
  4715. //
  4716. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4717. //
  4718. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4719. // var hpInfo models.HisPrescriptionInfo
  4720. // if info.ID == 0 {
  4721. // var randNum int
  4722. // randNum = rand.Intn(10000) + 1000
  4723. // timestamp := time.Now().Unix()
  4724. // tempTime := time.Unix(timestamp, 0)
  4725. // timeFormat := tempTime.Format("20060102150405")
  4726. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4727. //
  4728. // hpInfo = models.HisPrescriptionInfo{
  4729. // UserOrgId: adminInfo.CurrentOrgId,
  4730. // RecordDate: theTime.Unix(),
  4731. // PatientId: patient_id,
  4732. // Status: 1,
  4733. // Ctime: time.Now().Unix(),
  4734. // Mtime: time.Now().Unix(),
  4735. // Creator: adminInfo.AdminUser.Id,
  4736. // Modifier: adminInfo.AdminUser.Id,
  4737. // Diagnosis: diagnose,
  4738. // SickHistory: sick_history,
  4739. // Departments: department,
  4740. // RegisterType: reg_type,
  4741. // PrescriptionNumber: p_number,
  4742. // PrescriptionStatus: 1,
  4743. // Doctor: role.UserName,
  4744. // DoctorId: doctor_id,
  4745. // SickType: sick_type,
  4746. // PType: p_type,
  4747. // }
  4748. // service.SavePatientPrescriptionInfo(hpInfo)
  4749. //
  4750. // } else {
  4751. // hpInfo = models.HisPrescriptionInfo{
  4752. // ID: info.ID,
  4753. // UserOrgId: adminInfo.CurrentOrgId,
  4754. // RecordDate: info.RecordDate,
  4755. // PatientId: info.PatientId,
  4756. // Status: 1,
  4757. // Ctime: info.Ctime,
  4758. // Mtime: time.Now().Unix(),
  4759. // Creator: info.Creator,
  4760. // Modifier: adminInfo.AdminUser.Id,
  4761. // Diagnosis: diagnose,
  4762. // SickHistory: sick_history,
  4763. // Departments: department,
  4764. // RegisterType: reg_type,
  4765. // PrescriptionNumber: info.PrescriptionNumber,
  4766. // Doctor: role.UserName,
  4767. // PrescriptionStatus: info.PrescriptionStatus,
  4768. // DoctorId: doctor_id,
  4769. // SickType: sick_type,
  4770. // PType: info.PType,
  4771. // }
  4772. // service.SavePatientPrescriptionInfo(hpInfo)
  4773. // }
  4774. //
  4775. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4776. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4777. //
  4778. // if len(prescriptions) > 0 {
  4779. // for _, item := range prescriptions {
  4780. // items := item.(map[string]interface{})
  4781. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4782. // utils.ErrorLog("id")
  4783. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4784. // return
  4785. // }
  4786. // id := int64(items["id"].(float64))
  4787. //
  4788. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4789. // utils.ErrorLog("type")
  4790. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4791. // return
  4792. // }
  4793. // types := int64(items["type"].(float64))
  4794. //
  4795. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4796. // utils.ErrorLog("med_type")
  4797. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4798. // return
  4799. // }
  4800. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4801. //
  4802. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4803. //
  4804. // ctime := time.Now().Unix()
  4805. //
  4806. // prescription := &models.HisPrescription{
  4807. // ID: id,
  4808. // PatientId: patient_id,
  4809. // UserOrgId: adminInfo.CurrentOrgId,
  4810. // RecordDate: recordDateTime,
  4811. // Ctime: ctime,
  4812. // Mtime: ctime,
  4813. // Type: types,
  4814. // Modifier: adminInfo.AdminUser.Id,
  4815. // Creator: adminInfo.AdminUser.Id,
  4816. // Status: 1,
  4817. // Doctor: role.UserName,
  4818. // HisPatientId: his_patient_id,
  4819. // OrderStatus: 1,
  4820. // BatchNumber: "",
  4821. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4822. // PType: hpInfo.PType,
  4823. // MedType: med_type,
  4824. // }
  4825. //
  4826. // if historyPrescription.ID > 0 {
  4827. // prescription.PreTime = historyPrescription.PreTime
  4828. //
  4829. // }
  4830. //
  4831. // service.SaveHisPrescription(prescription)
  4832. //
  4833. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4834. // advices := items["advices"].([]interface{})
  4835. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4836. // groupNo := int64(0)
  4837. // ctime := time.Now().Unix()
  4838. // mtime := ctime
  4839. // if len(advices) > 0 {
  4840. // for _, advice := range advices {
  4841. // var s models.HisDoctorAdviceInfo
  4842. // s.PrescriptionId = prescription.ID
  4843. // s.AdviceType = 2
  4844. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4845. // s.StopState = 2
  4846. // s.ExecutionState = 2
  4847. // s.AdviceDate = recordDateTime
  4848. // s.Status = 1
  4849. // s.UserOrgId = adminInfo.CurrentOrgId
  4850. // s.RecordDate = recordDateTime
  4851. // s.StartTime = prescription.PreTime
  4852. // s.Groupno = groupNo
  4853. // s.CreatedTime = ctime
  4854. // s.UpdatedTime = mtime
  4855. // s.PatientId = patient_id
  4856. // s.HisPatientId = his_patient_id
  4857. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4858. // if errcode > 0 {
  4859. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4860. // return
  4861. // }
  4862. //
  4863. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4864. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4865. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4866. // if s.Price == 0 {
  4867. // s.Price = lastWarehouse.RetailPrice
  4868. // }
  4869. // }
  4870. //
  4871. // service.CreateHisDoctorAdvice(&s)
  4872. // //记录日志
  4873. // byterequest, _ := json.Marshal(s)
  4874. // adviceLog := models.XtDoctorAdviceLog{
  4875. // UserOrgId: s.UserOrgId,
  4876. // PatientId: s.PatientId,
  4877. // AdminUserId: adminInfo.AdminUser.Id,
  4878. // Module: 1,
  4879. // ErrLog: string(byterequest),
  4880. // Status: 1,
  4881. // Ctime: time.Now().Unix(),
  4882. // Mtime: 0,
  4883. // Source: "电脑端his医嘱修改",
  4884. // RecordDate: s.AdviceDate,
  4885. // }
  4886. // service.CreateDoctorAdviceLog(adviceLog)
  4887. // redis := service.RedisClient()
  4888. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4889. // redis.Set(key, "", time.Second)
  4890. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4891. // fmt.Println("keyOne", keyOne)
  4892. // redis.Set(keyOne, "", time.Second)
  4893. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4894. // redis.Set(keySeven, "", time.Second)
  4895. // redis.Close()
  4896. //
  4897. // }
  4898. // }
  4899. // }
  4900. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4901. // projects := items["project"].([]interface{})
  4902. // if len(projects) > 0 {
  4903. // for _, project := range projects {
  4904. // var p models.HisPrescriptionProject
  4905. // p.PrescriptionId = prescription.ID
  4906. // p.Ctime = time.Now().Unix()
  4907. // p.Mtime = time.Now().Unix()
  4908. // p.PatientId = patient_id
  4909. // p.RecordDate = recordDateTime
  4910. // p.UserOrgId = adminInfo.CurrentOrgId
  4911. // p.HisPatientId = his_patient_id
  4912. // p.Status = 1
  4913. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4914. // if errcode > 0 {
  4915. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4916. // return
  4917. // }
  4918. // service.CreateHisProjectTwo(&p)
  4919. //
  4920. // //记录日志
  4921. // byterequest, _ := json.Marshal(p)
  4922. // adviceLog := models.XtDoctorAdviceLog{
  4923. // UserOrgId: p.UserOrgId,
  4924. // PatientId: p.PatientId,
  4925. // AdminUserId: adminInfo.AdminUser.Id,
  4926. // Module: 1,
  4927. // ErrLog: string(byterequest),
  4928. // Status: 1,
  4929. // Ctime: time.Now().Unix(),
  4930. // Mtime: 0,
  4931. // Source: "电脑端his项目修改",
  4932. // RecordDate: p.RecordDate,
  4933. // }
  4934. // service.CreateDoctorAdviceLog(adviceLog)
  4935. // }
  4936. // }
  4937. // }
  4938. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4939. // addition := items["addition"].([]interface{})
  4940. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4941. // ctime := time.Now().Unix()
  4942. // mtime := ctime
  4943. // if len(addition) > 0 {
  4944. // for _, item := range addition {
  4945. // var s models.HisAdditionalCharge
  4946. // s.PrescriptionId = prescription.ID
  4947. // s.Status = 1
  4948. // s.UserOrgId = adminInfo.CurrentOrgId
  4949. // s.RecordDate = recordDateTime
  4950. // s.CreatedTime = ctime
  4951. // s.UpdatedTime = mtime
  4952. // s.PatientId = patient_id
  4953. // s.HisPatientId = his_patient_id
  4954. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4955. // if errcode > 0 {
  4956. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4957. // return
  4958. // }
  4959. // service.CreateAdditionalCharge(&s)
  4960. // }
  4961. // }
  4962. // }
  4963. //
  4964. // }
  4965. // }
  4966. // }
  4967. // if err == nil {
  4968. // c.ServeSuccessJSON(map[string]interface{}{
  4969. // "msg": "保存成功",
  4970. // })
  4971. // return
  4972. //
  4973. // } else {
  4974. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4975. // return
  4976. // }
  4977. //}
  4978. func (c *HisApiController) DeletePrescription() {
  4979. prescription_id, _ := c.GetInt64("id")
  4980. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4981. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4982. ////同步到自备药
  4983. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  4984. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  4985. if selfPrescriptionOpen.IsOpen == 1 {
  4986. // 开始主事务
  4987. db := service.XTWriteDB()
  4988. tx := db.Begin()
  4989. // 在函数结束时处理事务回滚
  4990. defer func() {
  4991. if r := recover(); r != nil {
  4992. tx.Rollback()
  4993. }
  4994. }()
  4995. for _, item := range advices {
  4996. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
  4997. var total_count int64
  4998. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4999. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5000. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5001. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5002. }
  5003. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5004. total_count += prescribingNumberSeven
  5005. }
  5006. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5007. total_count += prescribingNumberSeven
  5008. }
  5009. //出库
  5010. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5011. DrugId: item.DrugId,
  5012. Count: total_count,
  5013. Price: 0,
  5014. TotalPrice: 0,
  5015. Status: 1,
  5016. Ctime: item.AdviceDate,
  5017. Mtime: item.AdviceDate,
  5018. Remark: "",
  5019. OrgId: item.UserOrgId,
  5020. Type: 0,
  5021. Manufacturer: selfBasedrug.Manufacturer,
  5022. Dealer: selfBasedrug.Dealer,
  5023. RetailPrice: 0,
  5024. RetailTotalPrice: 0,
  5025. CountUnit: item.PrescribingNumberUnit,
  5026. ExpiryDate: 0,
  5027. ProductDate: 0,
  5028. Number: "",
  5029. BatchNumber: "",
  5030. IsSys: 0,
  5031. WarehouseInfoId: 0,
  5032. AdminUserId: 0,
  5033. StockCount: "",
  5034. IsCheck: 2,
  5035. SysRecordTime: item.AdviceDate,
  5036. PatientId: item.PatientId,
  5037. ClassType: "",
  5038. }
  5039. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5040. }
  5041. for _, it := range warehousingOutInfo {
  5042. timeStr := time.Now().Format("2006-01-02")
  5043. timeArr := strings.Split(timeStr, "-")
  5044. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5045. total = total + 1
  5046. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5047. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5048. number = number + total
  5049. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5050. operation_time := time.Now().Unix()
  5051. creater := c.GetAdminUserInfo().AdminUser.Id
  5052. //创建一个出库单
  5053. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5054. WarehouseOutOrderNumber: warehousing_out_order,
  5055. OperationTime: operation_time,
  5056. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5057. Creater: creater,
  5058. Ctime: time.Now().Unix(),
  5059. Status: 1,
  5060. WarehouseOutTime: it.SysRecordTime,
  5061. Type: 0,
  5062. PatientId: it.PatientId,
  5063. IsCheck: 2,
  5064. }
  5065. //查询今日是否有出库数据
  5066. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx)
  5067. if lastWarehouseOut.ID == 0 {
  5068. service.AddSelfSigleDrugWarehouseOut(&lastWarehouseOut, tx)
  5069. }
  5070. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5071. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5072. //出库逻辑
  5073. service.AutoSelfDrugDeliverInfoFourtyOne(c.GetAdminUserInfo().CurrentOrgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
  5074. //查询剩余库存
  5075. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5076. var sum_count int64
  5077. for _, its := range stockInfo {
  5078. if its.MaxUnit == medical.MaxUnit {
  5079. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5080. }
  5081. sum_count += its.StockMaxNumber + its.StockMinNumber
  5082. }
  5083. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5084. }
  5085. }
  5086. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5087. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5088. //耗材保存处方出库
  5089. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5090. //已收费和已发药限制逻辑
  5091. isCharge := false
  5092. isMedicine := false
  5093. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5094. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5095. if new_prescription.IsMedicine == 1 {
  5096. isMedicine = true
  5097. }
  5098. for _, item := range new_prescriptions {
  5099. if item.OrderStatus == 4 {
  5100. isCharge = true
  5101. }
  5102. }
  5103. if p_err != nil {
  5104. if new_prescription.ID > 0 {
  5105. if new_prescription.OrderStatus == 2 {
  5106. isCharge = true
  5107. }
  5108. }
  5109. }
  5110. for _, item := range advices {
  5111. if item.IsMedicine == 1 {
  5112. isMedicine = true
  5113. }
  5114. }
  5115. if isCharge {
  5116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5117. return
  5118. }
  5119. if isMedicine {
  5120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5121. return
  5122. }
  5123. //已收费和已发药限制逻辑
  5124. if len(projects) > 0 {
  5125. for _, item := range projects {
  5126. service.DeletePrintInfo(item.ID) //删除打印信息
  5127. if goodOutConfig.IsOpen != 1 {
  5128. if stockConfig.IsOpen == 1 {
  5129. if item.Type == 3 && item.IsOut == 1 {
  5130. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5131. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5132. good.Total = good.Total + f_count
  5133. service.UpdateGoodInfo(&good)
  5134. operation_time := time.Now().Unix()
  5135. creater := c.GetAdminUserInfo().AdminUser.Id
  5136. //创建退库单
  5137. timeStr := time.Now().Format("2006-01-02")
  5138. timeArr := strings.Split(timeStr, "-")
  5139. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5140. total = total + 1
  5141. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5142. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5143. cancelStock := models.CancelStock{
  5144. OrderNumber: orderNumber,
  5145. OperaTime: operation_time,
  5146. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5147. Creater: creater,
  5148. Ctime: time.Now().Unix(),
  5149. Status: 1,
  5150. ReturnTime: item.RecordDate,
  5151. Type: 1,
  5152. StorehouseId: houseConfig.StorehouseOutInfo,
  5153. IsCheck: 1,
  5154. }
  5155. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5156. if msgerrkonde == gorm.ErrRecordNotFound {
  5157. service.AddSigleCancelStock(&cancelStock)
  5158. }
  5159. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5160. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5161. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5162. //查询该耗材是否出库
  5163. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5164. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5165. deaerler, _ := service.GetDealerById(info.Dealer)
  5166. var total_count int64
  5167. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5168. total_count += count
  5169. if info.ID > 0 {
  5170. if info.Count >= total_count {
  5171. //回退库存
  5172. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5173. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5174. var flush_count int64
  5175. for _, it := range goodList {
  5176. flush_count += it.StockCount
  5177. }
  5178. cancelStockInfo := models.CancelStockInfo{
  5179. GoodId: item.ProjectId,
  5180. CancelStockId: cancel.ID,
  5181. GoodTypeId: good.GoodTypeId,
  5182. Count: prescribingNumber,
  5183. Price: info.Price,
  5184. Total: 0,
  5185. ProductDate: info.ProductDate,
  5186. ExpiryDate: info.ExpiryDate,
  5187. Ctime: time.Now().Unix(),
  5188. Status: 1,
  5189. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5190. OrderNumber: cancel.OrderNumber,
  5191. Type: 0,
  5192. Dealer: deaerler.DealerName,
  5193. Manufacturer: manufacturer.ManufacturerName,
  5194. Number: info.Number,
  5195. RegisterAccount: "",
  5196. Remark: "",
  5197. WarehouseInfoId: info.WarehouseInfotId,
  5198. PatientId: info.PatientId,
  5199. RecordDate: info.SysRecordTime,
  5200. StorehouseId: houseConfig.StorehouseOutInfo,
  5201. IsCheck: 1,
  5202. }
  5203. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5204. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5205. flow := models.VmStockFlow{
  5206. WarehousingId: info.WarehouseInfotId,
  5207. GoodId: item.ProjectId,
  5208. Number: info.Number,
  5209. LicenseNumber: info.LicenseNumber,
  5210. Count: prescribingNumber,
  5211. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5212. PatientId: item.PatientId,
  5213. SystemTime: info.SysRecordTime,
  5214. ConsumableType: 7,
  5215. IsSys: 0,
  5216. WarehousingOrder: "",
  5217. WarehouseOutId: info.WarehouseOutId,
  5218. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5219. IsEdit: 0,
  5220. CancelStockId: cancel.ID,
  5221. CancelOrderNumber: cancel.OrderNumber,
  5222. Manufacturer: manufacturer.ID,
  5223. Dealer: 0,
  5224. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5225. UpdateCreator: 0,
  5226. Status: 1,
  5227. Ctime: time.Now().Unix(),
  5228. Mtime: 0,
  5229. Price: info.Price,
  5230. WarehousingDetailId: info.WarehouseInfotId,
  5231. WarehouseOutDetailId: info.ID,
  5232. CancelOutDetailId: cancelInfo.ID,
  5233. ProductDate: info.ProductDate,
  5234. ExpireDate: info.ExpiryDate,
  5235. StorehouseId: houseConfig.StorehouseOutInfo,
  5236. OverCount: flush_count,
  5237. OperateTime: time.Now().Unix(),
  5238. }
  5239. service.CreateStockFlowOne(flow)
  5240. //退库数量增加
  5241. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5242. //出库数量减少
  5243. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5244. }
  5245. if info.Count < total_count {
  5246. //回退库存
  5247. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5248. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5249. var flush_count int64
  5250. for _, it := range goodList {
  5251. flush_count += it.StockCount
  5252. }
  5253. cancelStockInfo := models.CancelStockInfo{
  5254. GoodId: item.ProjectId,
  5255. CancelStockId: cancel.ID,
  5256. GoodTypeId: good.GoodTypeId,
  5257. Count: info.Count,
  5258. Price: info.Price,
  5259. Total: 0,
  5260. ProductDate: info.ProductDate,
  5261. ExpiryDate: info.ExpiryDate,
  5262. Ctime: time.Now().Unix(),
  5263. Status: 1,
  5264. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5265. OrderNumber: cancel.OrderNumber,
  5266. Type: 0,
  5267. Dealer: deaerler.DealerName,
  5268. Manufacturer: manufacturer.ManufacturerName,
  5269. Number: info.Number,
  5270. RegisterAccount: "",
  5271. Remark: "",
  5272. WarehouseInfoId: info.WarehouseInfotId,
  5273. PatientId: info.PatientId,
  5274. RecordDate: info.SysRecordTime,
  5275. StorehouseId: houseConfig.StorehouseOutInfo,
  5276. IsCheck: 1,
  5277. }
  5278. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5279. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5280. flow := models.VmStockFlow{
  5281. WarehousingId: info.WarehouseInfotId,
  5282. GoodId: item.ProjectId,
  5283. Number: info.Number,
  5284. LicenseNumber: info.LicenseNumber,
  5285. Count: info.Count,
  5286. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5287. PatientId: item.PatientId,
  5288. SystemTime: info.SysRecordTime,
  5289. ConsumableType: 7,
  5290. IsSys: 0,
  5291. WarehousingOrder: "",
  5292. WarehouseOutId: info.WarehouseOutId,
  5293. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5294. IsEdit: 0,
  5295. CancelStockId: cancel.ID,
  5296. CancelOrderNumber: cancel.OrderNumber,
  5297. Manufacturer: manufacturer.ID,
  5298. Dealer: 0,
  5299. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5300. UpdateCreator: 0,
  5301. Status: 1,
  5302. Ctime: time.Now().Unix(),
  5303. Mtime: 0,
  5304. Price: info.Price,
  5305. WarehousingDetailId: info.WarehouseInfotId,
  5306. WarehouseOutDetailId: info.ID,
  5307. CancelOutDetailId: cancelInfo.ID,
  5308. ProductDate: info.ProductDate,
  5309. ExpireDate: info.ExpiryDate,
  5310. StorehouseId: houseConfig.StorehouseOutInfo,
  5311. OverCount: flush_count,
  5312. OperateTime: time.Now().Unix(),
  5313. }
  5314. service.CreateStockFlowOne(flow)
  5315. //退库数量增加
  5316. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5317. //出库数量减少
  5318. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5319. }
  5320. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5321. var flush_count int64
  5322. for _, it := range goodList {
  5323. flush_count += it.StockCount
  5324. }
  5325. //查询已出库数量
  5326. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5327. if prescribingNumber < dialysisInfo.Count {
  5328. //改变数量
  5329. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5330. }
  5331. if prescribingNumber >= dialysisInfo.Count {
  5332. //删除出库表
  5333. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5334. }
  5335. //更新库存
  5336. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5337. //更新基础库库存
  5338. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5339. }
  5340. }
  5341. }
  5342. }
  5343. //保存耗材出库
  5344. if goodOutConfig.IsOpen == 1 {
  5345. if item.Type == 3 {
  5346. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5347. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5348. good.Total = good.Total + f_count
  5349. service.UpdateGoodInfo(&good)
  5350. operation_time := time.Now().Unix()
  5351. creater := c.GetAdminUserInfo().AdminUser.Id
  5352. //创建退库单
  5353. timeStr := time.Now().Format("2006-01-02")
  5354. timeArr := strings.Split(timeStr, "-")
  5355. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5356. total = total + 1
  5357. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5358. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5359. cancelStock := models.CancelStock{
  5360. OrderNumber: orderNumber,
  5361. OperaTime: operation_time,
  5362. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5363. Creater: creater,
  5364. Ctime: time.Now().Unix(),
  5365. Status: 1,
  5366. ReturnTime: item.RecordDate,
  5367. Type: 1,
  5368. StorehouseId: houseConfig.StorehouseOutInfo,
  5369. IsCheck: 1,
  5370. }
  5371. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5372. if msgerrkonde == gorm.ErrRecordNotFound {
  5373. service.AddSigleCancelStock(&cancelStock)
  5374. }
  5375. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5376. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5377. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5378. //查询该耗材是否出库
  5379. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5380. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5381. deaerler, _ := service.GetDealerById(info.Dealer)
  5382. var total_count int64
  5383. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5384. total_count += count
  5385. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5386. var flush_count int64
  5387. for _, it := range goodList {
  5388. flush_count += it.StockCount
  5389. }
  5390. fmt.Println("历史出库数据", info.Count)
  5391. fmt.Println("出库数量", total_count)
  5392. if info.ID > 0 {
  5393. cancelStockInfo := models.CancelStockInfo{
  5394. GoodId: item.ProjectId,
  5395. CancelStockId: cancel.ID,
  5396. GoodTypeId: good.GoodTypeId,
  5397. Count: prescribingNumber,
  5398. Price: info.Price,
  5399. Total: 0,
  5400. ProductDate: info.ProductDate,
  5401. ExpiryDate: info.ExpiryDate,
  5402. Ctime: time.Now().Unix(),
  5403. Status: 1,
  5404. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5405. OrderNumber: cancel.OrderNumber,
  5406. Type: 0,
  5407. Dealer: deaerler.DealerName,
  5408. Manufacturer: manufacturer.ManufacturerName,
  5409. Number: info.Number,
  5410. RegisterAccount: "",
  5411. Remark: "",
  5412. WarehouseInfoId: info.WarehouseInfotId,
  5413. PatientId: info.PatientId,
  5414. RecordDate: info.SysRecordTime,
  5415. StorehouseId: houseConfig.StorehouseOutInfo,
  5416. IsCheck: 1,
  5417. }
  5418. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5419. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5420. //查询出库数量
  5421. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5422. //出库数据 大于 退库数量
  5423. if len(list) > 0 {
  5424. for _, it := range list {
  5425. //回退库存
  5426. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5427. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5428. var flush_count_one int64
  5429. for _, it := range goodList {
  5430. flush_count_one += it.StockCount
  5431. }
  5432. //查询该批次是否有退库数据
  5433. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5434. creater := c.GetAdminUserInfo().AdminUser.Id
  5435. flow := models.VmStockFlow{
  5436. WarehousingId: it.WarehouseInfotId,
  5437. GoodId: it.GoodId,
  5438. Number: it.Number,
  5439. LicenseNumber: it.LicenseNumber,
  5440. Count: it.Count,
  5441. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5442. PatientId: it.PatientId,
  5443. SystemTime: it.SysRecordTime,
  5444. ConsumableType: 7,
  5445. IsSys: 0,
  5446. WarehousingOrder: "",
  5447. WarehouseOutId: it.WarehouseOutId,
  5448. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5449. IsEdit: 0,
  5450. CancelStockId: cancel.ID,
  5451. CancelOrderNumber: cancel.OrderNumber,
  5452. Manufacturer: manufacturer.ID,
  5453. Dealer: 0,
  5454. Creator: creater,
  5455. UpdateCreator: 0,
  5456. Status: 1,
  5457. Ctime: time.Now().Unix(),
  5458. Mtime: 0,
  5459. Price: it.Price,
  5460. WarehousingDetailId: it.WarehouseInfotId,
  5461. WarehouseOutDetailId: it.ID,
  5462. CancelOutDetailId: cancelInfo.ID,
  5463. ProductDate: it.ProductDate,
  5464. ExpireDate: it.ExpiryDate,
  5465. StorehouseId: houseConfig.StorehouseOutInfo,
  5466. OverCount: flush_count_one,
  5467. }
  5468. service.CreateStockFlowOne(flow)
  5469. //if flow.ID > 0 {
  5470. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5471. //}
  5472. }
  5473. }
  5474. //flow := models.VmStockFlow{
  5475. // WarehousingId: info.WarehouseInfotId,
  5476. // GoodId: item.ProjectId,
  5477. // Number: info.Number,
  5478. // LicenseNumber: info.LicenseNumber,
  5479. // Count: prescribingNumber,
  5480. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5481. // PatientId: item.PatientId,
  5482. // SystemTime: info.SysRecordTime,
  5483. // ConsumableType: 7,
  5484. // IsSys: 0,
  5485. // WarehousingOrder: "",
  5486. // WarehouseOutId: info.WarehouseOutId,
  5487. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5488. // IsEdit: 0,
  5489. // CancelStockId: cancel.ID,
  5490. // CancelOrderNumber: cancel.OrderNumber,
  5491. // Manufacturer: manufacturer.ID,
  5492. // Dealer: 0,
  5493. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5494. // UpdateCreator: 0,
  5495. // Status: 1,
  5496. // Ctime: time.Now().Unix(),
  5497. // Mtime: 0,
  5498. // Price: info.Price,
  5499. // WarehousingDetailId: info.WarehouseInfotId,
  5500. // WarehouseOutDetailId: info.ID,
  5501. // CancelOutDetailId: cancelInfo.ID,
  5502. // ProductDate: info.ProductDate,
  5503. // ExpireDate: info.ExpiryDate,
  5504. // StorehouseId: houseConfig.StorehouseOutInfo,
  5505. // OverCount: flush_count,
  5506. //}
  5507. //service.CreateStockFlowOne(flow)
  5508. //退库数量增加
  5509. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5510. //出库数量减少
  5511. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5512. //查询已出库数量
  5513. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5514. if prescribingNumber < dialysisInfo.Count {
  5515. //改变数量
  5516. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5517. }
  5518. if prescribingNumber >= dialysisInfo.Count {
  5519. //删除出库表
  5520. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5521. }
  5522. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5523. var flush_count_one int64
  5524. for _, it := range goodList {
  5525. flush_count_one += it.StockCount
  5526. }
  5527. //更新库存
  5528. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5529. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5530. //更新基础库库存
  5531. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5532. }
  5533. }
  5534. }
  5535. }
  5536. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5537. fmt.Println(err)
  5538. }
  5539. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5540. fmt.Println(err)
  5541. if len(advices) > 0 {
  5542. for _, item := range advices {
  5543. redis := service.RedisClient()
  5544. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5545. redis.Set(keyFive, "", time.Second)
  5546. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5547. redis.Set(keyOne, "", time.Second)
  5548. redis.Close()
  5549. }
  5550. }
  5551. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5552. if len(advices) > 0 {
  5553. for _, item := range advices {
  5554. creater := c.GetAdminUserInfo().AdminUser.Id
  5555. service.DrugAutoAddCancelInfo(item, creater)
  5556. }
  5557. }
  5558. } else {
  5559. if drugOutConfig.IsOpen == 1 {
  5560. if len(advices) > 0 {
  5561. for _, item := range advices {
  5562. creater := c.GetAdminUserInfo().AdminUser.Id
  5563. service.DrugAutoAddCancelInfo(item, creater)
  5564. }
  5565. }
  5566. } else {
  5567. if len(advices) > 0 {
  5568. for _, item := range advices {
  5569. creater := c.GetAdminUserInfo().AdminUser.Id
  5570. service.DrugAutoAddCancelInfo(item, creater)
  5571. }
  5572. }
  5573. }
  5574. }
  5575. c.ServeSuccessJSON(map[string]interface{}{
  5576. "msg": "删除成功",
  5577. })
  5578. return
  5579. }
  5580. func (c *HisApiController) DeleteDoctorAdvice() {
  5581. id, _ := c.GetInt64("id")
  5582. advice, _ := service.GetHisDoctorAdvicesById(id)
  5583. ////同步到自备药
  5584. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5585. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5586. if selfPrescriptionOpen.IsOpen == 1 {
  5587. // 开始主事务
  5588. db := service.XTWriteDB()
  5589. tx := db.Begin()
  5590. // 在函数结束时处理事务回滚
  5591. defer func() {
  5592. if r := recover(); r != nil {
  5593. tx.Rollback()
  5594. }
  5595. }()
  5596. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
  5597. var total_count int64
  5598. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5599. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5600. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5601. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5602. }
  5603. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5604. total_count += prescribingNumberSeven
  5605. }
  5606. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5607. total_count += prescribingNumberSeven
  5608. }
  5609. //出库
  5610. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5611. DrugId: advice.DrugId,
  5612. Count: total_count,
  5613. Price: 0,
  5614. TotalPrice: 0,
  5615. Status: 1,
  5616. Ctime: advice.AdviceDate,
  5617. Mtime: advice.AdviceDate,
  5618. Remark: "",
  5619. OrgId: advice.UserOrgId,
  5620. Type: 0,
  5621. Manufacturer: selfBasedrug.Manufacturer,
  5622. Dealer: selfBasedrug.Dealer,
  5623. RetailPrice: 0,
  5624. RetailTotalPrice: 0,
  5625. CountUnit: advice.PrescribingNumberUnit,
  5626. ExpiryDate: 0,
  5627. ProductDate: 0,
  5628. Number: "",
  5629. BatchNumber: "",
  5630. IsSys: 0,
  5631. WarehouseInfoId: 0,
  5632. AdminUserId: 0,
  5633. StockCount: "",
  5634. IsCheck: 2,
  5635. SysRecordTime: advice.AdviceDate,
  5636. PatientId: advice.PatientId,
  5637. ClassType: "",
  5638. }
  5639. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5640. for _, it := range warehousingOutInfo {
  5641. timeStr := time.Now().Format("2006-01-02")
  5642. timeArr := strings.Split(timeStr, "-")
  5643. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5644. total = total + 1
  5645. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5646. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5647. number = number + total
  5648. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5649. operation_time := time.Now().Unix()
  5650. creater := c.GetAdminUserInfo().AdminUser.Id
  5651. //创建一个出库单
  5652. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5653. WarehouseOutOrderNumber: warehousing_out_order,
  5654. OperationTime: operation_time,
  5655. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5656. Creater: creater,
  5657. Ctime: time.Now().Unix(),
  5658. Status: 1,
  5659. WarehouseOutTime: it.SysRecordTime,
  5660. Type: 0,
  5661. PatientId: it.PatientId,
  5662. IsCheck: 2,
  5663. }
  5664. //查询今日是否有出库数据
  5665. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx)
  5666. if lastWarehouseOut.ID == 0 {
  5667. service.AddSelfSigleDrugWarehouseOut(&lastWarehouseOut, tx)
  5668. }
  5669. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5670. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5671. //出库逻辑
  5672. service.AutoSelfDrugDeliverInfoFourtyOne(c.GetAdminUserInfo().CurrentOrgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
  5673. //查询剩余库存
  5674. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5675. var sum_count int64
  5676. for _, its := range stockInfo {
  5677. if its.MaxUnit == medical.MaxUnit {
  5678. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5679. }
  5680. sum_count += its.StockMaxNumber + its.StockMinNumber
  5681. }
  5682. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5683. }
  5684. }
  5685. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5686. //已收费和已发药的限制逻辑
  5687. isCharge := false
  5688. isMedicine := false
  5689. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5690. //获取今天该患者所有处方,判断是否发药或者收费
  5691. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5692. //for _, item := range new_prescriptions {
  5693. if new_prescription.IsMedicine == 1 {
  5694. isMedicine = true
  5695. }
  5696. //}
  5697. for _, item := range new_prescriptions {
  5698. if item.OrderStatus == 4 {
  5699. isCharge = true
  5700. }
  5701. }
  5702. if isMedicine {
  5703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5704. return
  5705. }
  5706. if isCharge {
  5707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5708. return
  5709. }
  5710. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5711. for _, item := range advices {
  5712. if item.IsMedicine == 1 {
  5713. isMedicine = true
  5714. }
  5715. }
  5716. if isMedicine {
  5717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5718. return
  5719. }
  5720. if new_prescription.ID > 0 {
  5721. if new_prescription.OrderStatus == 2 {
  5722. isCharge = true
  5723. }
  5724. }
  5725. if isCharge {
  5726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5727. return
  5728. }
  5729. //已收费和已发药的限制逻辑
  5730. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5731. redis := service.RedisClient()
  5732. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5733. redis.Set(keyFive, "", time.Second)
  5734. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5735. redis.Set(keyOne, "", time.Second)
  5736. defer redis.Close()
  5737. if err == nil {
  5738. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5739. //查询是否在处方中出库
  5740. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5741. if openConfig.IsOpen != 1 {
  5742. //判断该医嘱是否执行了
  5743. if advice.ExecutionState == 1 {
  5744. creater := c.GetAdminUserInfo().AdminUser.Id
  5745. service.DrugAutoAddCancelInfo(&advice, creater)
  5746. }
  5747. }
  5748. //开启保存处方扣减功能
  5749. if openConfig.IsOpen == 1 {
  5750. creater := c.GetAdminUserInfo().AdminUser.Id
  5751. service.DrugAutoAddCancelInfo(&advice, creater)
  5752. }
  5753. } else {
  5754. if drugOutConfig.IsOpen == 1 {
  5755. //查询是否在处方中出库
  5756. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5757. if openConfig.IsOpen != 1 {
  5758. //判断该医嘱是否执行了
  5759. if advice.ExecutionState == 1 {
  5760. creater := c.GetAdminUserInfo().AdminUser.Id
  5761. service.DrugAutoAddCancelInfo(&advice, creater)
  5762. }
  5763. }
  5764. //开启保存处方扣减功能
  5765. if openConfig.IsOpen == 1 {
  5766. creater := c.GetAdminUserInfo().AdminUser.Id
  5767. service.DrugAutoAddCancelInfo(&advice, creater)
  5768. }
  5769. } else {
  5770. //判断该医嘱是否执行了
  5771. if advice.ExecutionState == 1 {
  5772. creater := c.GetAdminUserInfo().AdminUser.Id
  5773. service.DrugAutoAddCancelInfo(&advice, creater)
  5774. }
  5775. }
  5776. }
  5777. c.ServeSuccessJSON(map[string]interface{}{
  5778. "msg": "删除成功",
  5779. })
  5780. return
  5781. } else {
  5782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5783. return
  5784. }
  5785. }
  5786. func (c *HisApiController) DeleteProject() {
  5787. id, _ := c.GetInt64("id")
  5788. adminInfo := c.GetAdminUserInfo()
  5789. project, _ := service.GetHisProjectByID(id)
  5790. // var consumable models.DialysisBeforePrepare
  5791. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5792. //耗材保存处方出库
  5793. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5794. isCharge := false
  5795. isMedicine := false
  5796. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5797. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5798. for _, item := range new_prescriptions {
  5799. if item.IsMedicine == 1 {
  5800. isMedicine = true
  5801. }
  5802. }
  5803. for _, item := range new_prescriptions {
  5804. if item.OrderStatus == 4 {
  5805. isCharge = true
  5806. }
  5807. }
  5808. if isMedicine {
  5809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5810. return
  5811. }
  5812. if isCharge {
  5813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5814. return
  5815. }
  5816. if new_prescription.ID > 0 {
  5817. if new_prescription.OrderStatus == 2 {
  5818. isCharge = true
  5819. }
  5820. }
  5821. if isCharge {
  5822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5823. return
  5824. }
  5825. service.DeletePrintInfo(id)
  5826. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5827. label.Status = 0
  5828. service.CreateHisLabelRecordTwo(&label)
  5829. fmt.Println(goodOutConfig.IsOpen)
  5830. if goodOutConfig.IsOpen != 1 {
  5831. if stockConfig.IsOpen == 1 {
  5832. if project.Type == 2 {
  5833. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5834. fmt.Println(err)
  5835. }
  5836. if project.Type == 3 && project.IsOut == 1 {
  5837. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5838. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5839. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5840. operation_time := time.Now().Unix()
  5841. creater := adminInfo.AdminUser.Id
  5842. //创建退库单
  5843. timeStr := time.Now().Format("2006-01-02")
  5844. timeArr := strings.Split(timeStr, "-")
  5845. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5846. total = total + 1
  5847. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5848. cancelStock := models.CancelStock{
  5849. OrderNumber: orderNumber,
  5850. OperaTime: operation_time,
  5851. OrgId: adminInfo.CurrentOrgId,
  5852. Creater: creater,
  5853. Ctime: time.Now().Unix(),
  5854. Status: 1,
  5855. ReturnTime: project.RecordDate,
  5856. Type: 1,
  5857. StorehouseId: houseConfig.StorehouseOutInfo,
  5858. IsCheck: 1,
  5859. }
  5860. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5861. if msgerrkonde == gorm.ErrRecordNotFound {
  5862. service.AddSigleCancelStock(&cancelStock)
  5863. }
  5864. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5865. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5866. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5867. //查询是否有出库
  5868. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5869. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5870. deaerler, _ := service.GetDealerById(info.Dealer)
  5871. if info.ID > 0 {
  5872. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5873. if info.Count >= prescribingNumber {
  5874. cancelStockInfo := models.CancelStockInfo{
  5875. GoodId: project.ProjectId,
  5876. CancelStockId: cancel.ID,
  5877. GoodTypeId: good.GoodTypeId,
  5878. Count: prescribingNumber,
  5879. Price: info.Price,
  5880. Total: 0,
  5881. ProductDate: info.ProductDate,
  5882. ExpiryDate: info.ExpiryDate,
  5883. Ctime: time.Now().Unix(),
  5884. Status: 1,
  5885. OrgId: adminInfo.CurrentOrgId,
  5886. OrderNumber: cancel.OrderNumber,
  5887. Type: 0,
  5888. Dealer: deaerler.DealerName,
  5889. Manufacturer: manufacturer.ManufacturerName,
  5890. Number: info.Number,
  5891. RegisterAccount: "",
  5892. Remark: "",
  5893. WarehouseInfoId: info.WarehouseInfotId,
  5894. PatientId: info.PatientId,
  5895. RecordDate: info.SysRecordTime,
  5896. StorehouseId: houseConfig.StorehouseOutInfo,
  5897. IsCheck: 1,
  5898. }
  5899. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5900. //回退库存
  5901. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5902. //退库数量增加
  5903. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5904. //出库数量减少
  5905. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5906. }
  5907. if info.Count < prescribingNumber {
  5908. cancelStockInfo := models.CancelStockInfo{
  5909. GoodId: project.ProjectId,
  5910. CancelStockId: cancel.ID,
  5911. GoodTypeId: good.GoodTypeId,
  5912. Count: info.Count,
  5913. Price: info.Price,
  5914. Total: 0,
  5915. ProductDate: info.ProductDate,
  5916. ExpiryDate: info.ExpiryDate,
  5917. Ctime: time.Now().Unix(),
  5918. Status: 1,
  5919. OrgId: adminInfo.CurrentOrgId,
  5920. OrderNumber: cancel.OrderNumber,
  5921. Type: 0,
  5922. Dealer: deaerler.DealerName,
  5923. Manufacturer: manufacturer.ManufacturerName,
  5924. Number: info.Number,
  5925. RegisterAccount: "",
  5926. Remark: "",
  5927. WarehouseInfoId: info.WarehouseInfotId,
  5928. PatientId: info.PatientId,
  5929. RecordDate: info.SysRecordTime,
  5930. StorehouseId: houseConfig.StorehouseOutInfo,
  5931. IsCheck: 1,
  5932. }
  5933. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5934. //回退库存
  5935. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5936. //退库数量增加
  5937. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5938. //出库数量减少
  5939. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5940. }
  5941. //查询剩余库存
  5942. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5943. var over_count int64
  5944. for _, it := range goodList {
  5945. over_count += it.StockCount
  5946. }
  5947. //出库数据 大于 退库数量
  5948. if info.Count >= prescribingNumber {
  5949. flow := models.VmStockFlow{
  5950. WarehousingId: info.WarehouseInfotId,
  5951. GoodId: project.ProjectId,
  5952. Number: info.Number,
  5953. LicenseNumber: info.LicenseNumber,
  5954. Count: prescribingNumber,
  5955. UserOrgId: adminInfo.CurrentOrgId,
  5956. PatientId: project.PatientId,
  5957. SystemTime: info.SysRecordTime,
  5958. ConsumableType: 7,
  5959. IsSys: 0,
  5960. WarehousingOrder: "",
  5961. WarehouseOutId: info.WarehouseOutId,
  5962. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5963. IsEdit: 0,
  5964. CancelStockId: cancel.ID,
  5965. CancelOrderNumber: cancel.OrderNumber,
  5966. Manufacturer: manufacturer.ID,
  5967. Dealer: 0,
  5968. Creator: adminInfo.AdminUser.Id,
  5969. UpdateCreator: 0,
  5970. Status: 1,
  5971. Ctime: time.Now().Unix(),
  5972. Mtime: 0,
  5973. Price: info.Price,
  5974. WarehousingDetailId: info.WarehouseInfotId,
  5975. WarehouseOutDetailId: info.ID,
  5976. CancelOutDetailId: cancelInfo.ID,
  5977. ProductDate: info.ProductDate,
  5978. ExpireDate: info.ExpiryDate,
  5979. StorehouseId: houseConfig.StorehouseOutInfo,
  5980. OverCount: over_count,
  5981. OperateTime: time.Now().Unix(),
  5982. }
  5983. service.CreateStockFlowOne(flow)
  5984. }
  5985. //出库数据小于退库数据
  5986. if info.Count < prescribingNumber {
  5987. flow := models.VmStockFlow{
  5988. WarehousingId: info.WarehouseInfotId,
  5989. GoodId: project.ProjectId,
  5990. Number: info.Number,
  5991. LicenseNumber: info.LicenseNumber,
  5992. Count: info.Count,
  5993. UserOrgId: adminInfo.CurrentOrgId,
  5994. PatientId: project.PatientId,
  5995. SystemTime: info.SysRecordTime,
  5996. ConsumableType: 7,
  5997. IsSys: 0,
  5998. WarehousingOrder: "",
  5999. WarehouseOutId: info.WarehouseOutId,
  6000. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6001. IsEdit: 0,
  6002. CancelStockId: cancel.ID,
  6003. CancelOrderNumber: cancel.OrderNumber,
  6004. Manufacturer: manufacturer.ID,
  6005. Dealer: 0,
  6006. Creator: adminInfo.AdminUser.Id,
  6007. UpdateCreator: 0,
  6008. Status: 1,
  6009. Ctime: time.Now().Unix(),
  6010. Mtime: 0,
  6011. Price: info.Price,
  6012. WarehousingDetailId: info.WarehouseInfotId,
  6013. WarehouseOutDetailId: info.ID,
  6014. CancelOutDetailId: cancelInfo.ID,
  6015. ProductDate: info.ProductDate,
  6016. ExpireDate: info.ExpiryDate,
  6017. StorehouseId: houseConfig.StorehouseOutInfo,
  6018. OverCount: over_count,
  6019. OperateTime: time.Now().Unix(),
  6020. }
  6021. service.CreateStockFlowOne(flow)
  6022. }
  6023. //查询已出库数量
  6024. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6025. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6026. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6027. if prescribingNumber < dialysisInfo.Count {
  6028. //改变数量
  6029. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6030. }
  6031. if prescribingNumber >= dialysisInfo.Count {
  6032. //删除出库表
  6033. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6034. }
  6035. //更新剩余库存
  6036. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6037. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6038. var total_count_one int64
  6039. for _, it := range stockList {
  6040. total_count_one += it.StockCount
  6041. }
  6042. //基础库插入数据
  6043. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6044. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6045. var flush_count int64
  6046. for _, it := range goodListOne {
  6047. flush_count += it.StockCount
  6048. }
  6049. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6050. if errs != nil {
  6051. goodErrcode := models.XtGoodErrcode{
  6052. UserOrgId: project.UserOrgId,
  6053. Errcode: "手动出库更新剩余出库失败",
  6054. GoodId: project.ProjectId,
  6055. Status: 1,
  6056. Ctime: time.Now().Unix(),
  6057. Mtime: 0,
  6058. Count: 0,
  6059. StockCount: 0,
  6060. Creater: creater,
  6061. BatchNumberId: 0,
  6062. WarehouseOutId: 0,
  6063. }
  6064. service.CreateGoodErrcode(goodErrcode)
  6065. }
  6066. }
  6067. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6068. fmt.Println(err)
  6069. } else {
  6070. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6071. fmt.Println(err)
  6072. }
  6073. } else {
  6074. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6075. fmt.Println(err)
  6076. }
  6077. }
  6078. //保存处方出库
  6079. if goodOutConfig.IsOpen == 1 {
  6080. if project.Type == 3 {
  6081. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6082. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6083. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6084. operation_time := time.Now().Unix()
  6085. creater := adminInfo.AdminUser.Id
  6086. //创建退库单
  6087. timeStr := time.Now().Format("2006-01-02")
  6088. timeArr := strings.Split(timeStr, "-")
  6089. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6090. total = total + 1
  6091. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6092. cancelStock := models.CancelStock{
  6093. OrderNumber: orderNumber,
  6094. OperaTime: operation_time,
  6095. OrgId: adminInfo.CurrentOrgId,
  6096. Creater: creater,
  6097. Ctime: time.Now().Unix(),
  6098. Status: 1,
  6099. ReturnTime: project.RecordDate,
  6100. Type: 1,
  6101. StorehouseId: houseConfig.StorehouseOutInfo,
  6102. IsCheck: 1,
  6103. }
  6104. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6105. if msgerrkonde == gorm.ErrRecordNotFound {
  6106. service.AddSigleCancelStock(&cancelStock)
  6107. }
  6108. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6109. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6110. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6111. //获取出库数据
  6112. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6113. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6114. deaerler, _ := service.GetDealerById(info.Dealer)
  6115. if info.ID > 0 {
  6116. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6117. if info.Count >= prescribingNumber {
  6118. cancelStockInfo := models.CancelStockInfo{
  6119. GoodId: project.ProjectId,
  6120. CancelStockId: cancel.ID,
  6121. GoodTypeId: good.GoodTypeId,
  6122. Count: prescribingNumber,
  6123. Price: info.Price,
  6124. Total: 0,
  6125. ProductDate: info.ProductDate,
  6126. ExpiryDate: info.ExpiryDate,
  6127. Ctime: time.Now().Unix(),
  6128. Status: 1,
  6129. OrgId: adminInfo.CurrentOrgId,
  6130. OrderNumber: cancel.OrderNumber,
  6131. Type: 0,
  6132. Dealer: deaerler.DealerName,
  6133. Manufacturer: manufacturer.ManufacturerName,
  6134. Number: info.Number,
  6135. RegisterAccount: "",
  6136. Remark: "",
  6137. WarehouseInfoId: info.WarehouseInfotId,
  6138. PatientId: info.PatientId,
  6139. RecordDate: info.SysRecordTime,
  6140. StorehouseId: houseConfig.StorehouseOutInfo,
  6141. IsCheck: 1,
  6142. }
  6143. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6144. //退库数量增加
  6145. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6146. //出库数量减少
  6147. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6148. }
  6149. if info.Count < prescribingNumber {
  6150. cancelStockInfo := models.CancelStockInfo{
  6151. GoodId: project.ProjectId,
  6152. CancelStockId: cancel.ID,
  6153. GoodTypeId: good.GoodTypeId,
  6154. Count: prescribingNumber,
  6155. Price: info.Price,
  6156. Total: 0,
  6157. ProductDate: info.ProductDate,
  6158. ExpiryDate: info.ExpiryDate,
  6159. Ctime: time.Now().Unix(),
  6160. Status: 1,
  6161. OrgId: adminInfo.CurrentOrgId,
  6162. OrderNumber: cancel.OrderNumber,
  6163. Type: 0,
  6164. Dealer: deaerler.DealerName,
  6165. Manufacturer: manufacturer.ManufacturerName,
  6166. Number: info.Number,
  6167. RegisterAccount: "",
  6168. Remark: "",
  6169. WarehouseInfoId: info.WarehouseInfotId,
  6170. PatientId: info.PatientId,
  6171. RecordDate: info.SysRecordTime,
  6172. StorehouseId: houseConfig.StorehouseOutInfo,
  6173. IsCheck: 1,
  6174. }
  6175. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6176. //回退库存
  6177. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6178. }
  6179. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6180. var over_count int64
  6181. for _, it := range goodList {
  6182. over_count += it.StockCount
  6183. }
  6184. //查询出库数量
  6185. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6186. //出库数据 大于 退库数量
  6187. if len(list) > 0 {
  6188. for _, it := range list {
  6189. //回退库存
  6190. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6191. //退库数量增加
  6192. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6193. //出库数量减少
  6194. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6195. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6196. var over_count_one int64
  6197. for _, it := range goodList {
  6198. over_count_one += it.StockCount
  6199. }
  6200. //查询该批次是否有退库数据
  6201. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6202. flow := models.VmStockFlow{
  6203. WarehousingId: it.WarehouseInfotId,
  6204. GoodId: it.GoodId,
  6205. Number: it.Number,
  6206. LicenseNumber: it.LicenseNumber,
  6207. Count: it.Count,
  6208. UserOrgId: adminInfo.CurrentOrgId,
  6209. PatientId: it.PatientId,
  6210. SystemTime: it.SysRecordTime,
  6211. ConsumableType: 7,
  6212. IsSys: 0,
  6213. WarehousingOrder: "",
  6214. WarehouseOutId: it.WarehouseOutId,
  6215. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6216. IsEdit: 0,
  6217. CancelStockId: cancel.ID,
  6218. CancelOrderNumber: cancel.OrderNumber,
  6219. Manufacturer: manufacturer.ID,
  6220. Dealer: 0,
  6221. Creator: adminInfo.AdminUser.Id,
  6222. UpdateCreator: 0,
  6223. Status: 1,
  6224. Ctime: time.Now().Unix(),
  6225. Mtime: 0,
  6226. Price: it.Price,
  6227. WarehousingDetailId: it.WarehouseInfotId,
  6228. WarehouseOutDetailId: it.ID,
  6229. CancelOutDetailId: cancelInfo.ID,
  6230. ProductDate: it.ProductDate,
  6231. ExpireDate: it.ExpiryDate,
  6232. StorehouseId: houseConfig.StorehouseOutInfo,
  6233. OverCount: over_count_one,
  6234. OperateTime: time.Now().Unix(),
  6235. }
  6236. service.CreateStockFlowOne(flow)
  6237. }
  6238. }
  6239. //查询已出库数量
  6240. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6241. if prescribingNumber < dialysisInfo.Count {
  6242. //改变数量
  6243. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6244. }
  6245. if prescribingNumber >= dialysisInfo.Count {
  6246. //删除出库表
  6247. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6248. }
  6249. //更新剩余库存
  6250. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6251. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6252. var total_count_one int64
  6253. for _, it := range stockList {
  6254. total_count_one += it.StockCount
  6255. }
  6256. //基础库插入数据
  6257. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6258. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6259. var flush_count int64
  6260. for _, it := range goodListOne {
  6261. flush_count += it.StockCount
  6262. }
  6263. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6264. if errs != nil {
  6265. goodErrcode := models.XtGoodErrcode{
  6266. UserOrgId: project.UserOrgId,
  6267. Errcode: "手动出库更新剩余出库失败",
  6268. GoodId: project.ProjectId,
  6269. Status: 1,
  6270. Ctime: time.Now().Unix(),
  6271. Mtime: 0,
  6272. Count: 0,
  6273. StockCount: 0,
  6274. Creater: creater,
  6275. BatchNumberId: 0,
  6276. WarehouseOutId: 0,
  6277. }
  6278. service.CreateGoodErrcode(goodErrcode)
  6279. }
  6280. }
  6281. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6282. fmt.Println(err)
  6283. } else {
  6284. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6285. fmt.Println(err)
  6286. }
  6287. }
  6288. c.ServeSuccessJSON(map[string]interface{}{
  6289. "msg": "删除成功",
  6290. })
  6291. return
  6292. }
  6293. func (c *HisApiController) CreateHisAdditionalCharge() {
  6294. his_patient_id, _ := c.GetInt64("his_patient_id")
  6295. patient_id, _ := c.GetInt64("patient_id")
  6296. record_date := c.GetString("record_date")
  6297. timeLayout := "2006-01-02"
  6298. loc, _ := time.LoadLocation("Local")
  6299. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6300. if err != nil {
  6301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6302. return
  6303. }
  6304. adminInfo := c.GetAdminUserInfo()
  6305. recordDateTime := theTime.Unix()
  6306. dataBody := make(map[string]interface{}, 0)
  6307. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6308. if err != nil {
  6309. utils.ErrorLog(err.Error())
  6310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6311. return
  6312. }
  6313. var additions []*models.HisAdditionalCharge
  6314. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6315. additions, _ := dataBody["addition"].([]interface{})
  6316. if len(additions) > 0 {
  6317. for _, item := range additions {
  6318. items := item.(map[string]interface{})
  6319. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6320. utils.ErrorLog("item_id")
  6321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6322. return
  6323. }
  6324. item_id := int64(items["item_id"].(float64))
  6325. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6326. utils.ErrorLog("item_name")
  6327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6328. return
  6329. }
  6330. item_name := items["item_name"].(string)
  6331. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6332. utils.ErrorLog("price")
  6333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6334. return
  6335. }
  6336. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6337. ctime := time.Now().Unix()
  6338. additional := &models.HisAdditionalCharge{
  6339. PatientId: patient_id,
  6340. HisPatientId: his_patient_id,
  6341. UserOrgId: adminInfo.CurrentOrgId,
  6342. RecordDate: recordDateTime,
  6343. CreatedTime: ctime,
  6344. UpdatedTime: ctime,
  6345. Modifier: adminInfo.AdminUser.Id,
  6346. Creator: adminInfo.AdminUser.Id,
  6347. Price: price,
  6348. ItemName: item_name,
  6349. ItemId: item_id,
  6350. Status: 1,
  6351. }
  6352. additions = append(additions, additional)
  6353. }
  6354. }
  6355. }
  6356. for _, item := range additions {
  6357. service.CreateAddtionalCharge(item)
  6358. }
  6359. c.ServeSuccessJSON(map[string]interface{}{
  6360. "msg": "创建成功",
  6361. })
  6362. }
  6363. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6364. blood_fat := c.GetString("blood_fat")
  6365. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6366. blood_sugar := c.GetString("blood_sugar")
  6367. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6368. chief_conplaint := c.GetString("chief_conplaint")
  6369. dbp := c.GetString("dbp")
  6370. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6371. delivery_way, _ := c.GetInt64("delivery_way")
  6372. diagnostic := c.GetString("diagnostic")
  6373. family_history := c.GetString("family_history")
  6374. height := c.GetString("height")
  6375. history_of_present_illness := c.GetString("history_of_present_illness")
  6376. is_infect, _ := c.GetInt64("is_infect")
  6377. past_history := c.GetString("past_history")
  6378. patient_id, _ := c.GetInt64("patient_id")
  6379. his_patient_id, _ := c.GetInt64("his_patient_id")
  6380. personal_history := c.GetString("personal_history")
  6381. pulse := c.GetString("pulse")
  6382. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6383. sbp := c.GetString("sbp")
  6384. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6385. heightfloat, _ := strconv.ParseFloat(height, 64)
  6386. sicktype := c.GetString("sick_type")
  6387. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6388. symptom := c.GetString("symptom")
  6389. sick_date := c.GetString("sick_date")
  6390. temperatures := c.GetString("temperature")
  6391. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6392. record_date := c.GetString("record_date")
  6393. breathing := c.GetString("breathing")
  6394. doctor_advice := c.GetString("doctor_advice")
  6395. remark := c.GetString("remark")
  6396. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6397. sick, _ := c.GetInt64("sick")
  6398. diagnose, _ := c.GetInt64("diagnose")
  6399. //id, _ := c.GetInt64("id")
  6400. timeLayout := "2006-01-02"
  6401. loc, _ := time.LoadLocation("Local")
  6402. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6403. allergic_history := c.GetString("allergic_history")
  6404. if err != nil {
  6405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6406. return
  6407. }
  6408. recordDateTime := theTime.Unix()
  6409. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6410. if err != nil {
  6411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6412. return
  6413. }
  6414. sickTimes := sickTime.Unix()
  6415. ctime := time.Now().Unix()
  6416. primary_disease := c.GetString("primary_disease")
  6417. confirm_failure_date := c.GetString("confirm_failure_date")
  6418. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6419. drug_allergy_history := c.GetString("drug_allergy_history")
  6420. physical_examination := c.GetString("physical_examination")
  6421. special_inspection := c.GetString("special_inspection")
  6422. lab_apparatus := c.GetString("lab_apparatus")
  6423. caseHistory := models.HisPatientCaseHistory{
  6424. HisPatientId: his_patient_id,
  6425. PatientId: patient_id,
  6426. Temperature: temperature,
  6427. BloodSugar: bloodsugarfloat,
  6428. Pulse: pulsefloat,
  6429. Sbp: sbpfloat,
  6430. Dbp: dbpfloat,
  6431. Height: heightfloat,
  6432. BloodFat: bloodfatfloat,
  6433. SickType: sick_type,
  6434. Symptom: symptom,
  6435. SickDate: sickTimes,
  6436. IsInfect: is_infect,
  6437. HistoryOfPresentIllness: history_of_present_illness,
  6438. PastHistory: past_history,
  6439. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6440. ChiefConplaint: chief_conplaint,
  6441. PersonalHistory: personal_history,
  6442. FamilyHistory: family_history,
  6443. Diagnostic: diagnostic,
  6444. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6445. Status: 1,
  6446. Ctime: ctime,
  6447. Mtime: ctime,
  6448. RecordDate: recordDateTime,
  6449. DeliveryWay: delivery_way,
  6450. Breathing: breathingfloat,
  6451. DoctorAdvice: doctor_advice,
  6452. Remark: remark,
  6453. Sick: sick,
  6454. Diagnose: diagnose,
  6455. AllergicHistory: allergic_history,
  6456. PrimaryDisease: primary_disease,
  6457. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6458. DrugAllergyHistory: drug_allergy_history,
  6459. PhysicalExamination: physical_examination,
  6460. SpecialInspection: special_inspection,
  6461. LabApparatus: lab_apparatus,
  6462. }
  6463. //查询该患者是否有病历
  6464. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6465. if errcodes == gorm.ErrRecordNotFound {
  6466. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6467. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6468. if err != nil {
  6469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6470. return
  6471. }
  6472. c.ServeSuccessJSON(map[string]interface{}{
  6473. "caseHistory": caseHistory,
  6474. "historyInfo": historyInfo,
  6475. })
  6476. return
  6477. } else if errcodes == nil {
  6478. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6479. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6480. if err != nil {
  6481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6482. return
  6483. }
  6484. c.ServeSuccessJSON(map[string]interface{}{
  6485. "caseHistory": caseHistory,
  6486. "historyInfo": historyInfo,
  6487. })
  6488. }
  6489. //查询该患者是否有病历
  6490. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6491. //if errcode == gorm.ErrRecordNotFound {
  6492. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6493. // if err != nil {
  6494. // c.ServeSuccessJSON(map[string]interface{}{
  6495. // "msg": "保存成功",
  6496. // })
  6497. // }
  6498. //} else if errcode == nil {
  6499. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6500. // return
  6501. //}
  6502. }
  6503. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6504. patient_id, _ := c.GetInt64("patient_id", 0)
  6505. adminUser := c.GetAdminUserInfo()
  6506. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6507. c.ServeSuccessJSON(map[string]interface{}{
  6508. "list": caseHistorys,
  6509. })
  6510. }
  6511. func (c *HisApiController) GetHisPatientCaseHistory() {
  6512. record_date, _ := c.GetInt64("record_date", 0)
  6513. patient_id, _ := c.GetInt64("patient_id", 0)
  6514. admin := c.GetAdminUserInfo()
  6515. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6516. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6517. c.ServeSuccessJSON(map[string]interface{}{
  6518. "info": info,
  6519. "case_history": case_history,
  6520. })
  6521. }
  6522. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6523. template_name := c.GetString("template_name")
  6524. template_remark := c.GetString("template_remark")
  6525. doctor := c.GetAdminUserInfo().AdminUser.Id
  6526. diagnostic := c.GetString("diagnostic")
  6527. chief_conplaint := c.GetString("chief_conplain")
  6528. history_of_present_illness := c.GetString("history_of_present_illness")
  6529. past_history := c.GetString("past_history")
  6530. personal_history := c.GetString("personal_history")
  6531. family_history := c.GetString("family_history")
  6532. user_name := c.GetString("user_name")
  6533. doctor_advice := c.GetString("doctor_advice")
  6534. remark := c.GetString("remark")
  6535. //record_date := c.GetString("record_date")
  6536. //fmt.Println("record_date--------",record_date)
  6537. //timeLayout := "2006-01-02"
  6538. //loc, _ := time.LoadLocation("Local")
  6539. //
  6540. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6541. //if err != nil {
  6542. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6543. // return
  6544. //}
  6545. //recordDateTime := theTime.Unix()
  6546. ctime := time.Now().Unix()
  6547. template := models.HisCaseHistoryTemplate{
  6548. HistoryOfPresentIllness: history_of_present_illness,
  6549. PastHistory: past_history,
  6550. ChiefConplaint: chief_conplaint,
  6551. PersonalHistory: personal_history,
  6552. FamilyHistory: family_history,
  6553. Diagnostic: diagnostic,
  6554. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6555. Status: 1,
  6556. Ctime: ctime,
  6557. Mtime: ctime,
  6558. RecordDate: time.Now().Unix(),
  6559. TemplateName: template_name,
  6560. TemplateRemark: template_remark,
  6561. Creator: doctor,
  6562. Modifier: doctor,
  6563. UserName: user_name,
  6564. DoctorAdvice: doctor_advice,
  6565. Remark: remark,
  6566. }
  6567. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6568. if err == nil {
  6569. c.ServeSuccessJSON(map[string]interface{}{
  6570. "msg": "保存成功",
  6571. })
  6572. } else {
  6573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6574. return
  6575. }
  6576. }
  6577. func (c *HisApiController) GetCaseHistoryTemplate() {
  6578. timeLayout := "2006-01-02"
  6579. loc, _ := time.LoadLocation("Local")
  6580. keyword := c.GetString("keyword")
  6581. start_time := c.GetString("start_time")
  6582. end_time := c.GetString("end_time")
  6583. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6584. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6585. admin := c.GetAdminUserInfo()
  6586. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6587. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6588. c.ServeSuccessJSON(map[string]interface{}{
  6589. "template": template,
  6590. //"history": history,
  6591. })
  6592. }
  6593. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6594. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6595. utils.ErrorLog("drug_name")
  6596. return enums.ErrorCodeParamWrong
  6597. }
  6598. adviceName, _ := json["drug_name"].(string)
  6599. if len(adviceName) == 0 {
  6600. utils.ErrorLog("len(advice_name) == 0")
  6601. return enums.ErrorCodeParamWrong
  6602. }
  6603. advice.AdviceName = adviceName
  6604. adviceDesc, _ := json["advice_desc"].(string)
  6605. advice.AdviceDesc = adviceDesc
  6606. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6607. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6608. advice.DrugSpec = drugSpec
  6609. }
  6610. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6611. remark, _ := json["remark"].(string)
  6612. advice.Remark = remark
  6613. }
  6614. if json["id"] == nil {
  6615. advice.DrugId = 0
  6616. } else {
  6617. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6618. drug_id := int64(json["id"].(float64))
  6619. advice.DrugId = drug_id
  6620. }
  6621. }
  6622. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6623. advice_id := int64(json["advice_id"].(float64))
  6624. advice.ID = advice_id
  6625. if advice.ID > 0 {
  6626. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6627. if err == nil {
  6628. if hisAdvice.ID > 0 {
  6629. advice.ExecutionTime = hisAdvice.ExecutionTime
  6630. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6631. advice.ExecutionState = hisAdvice.ExecutionState
  6632. advice.CheckTime = hisAdvice.CheckTime
  6633. advice.Checker = hisAdvice.Checker
  6634. advice.CheckState = hisAdvice.CheckState
  6635. advice.StartTime = hisAdvice.StartTime
  6636. advice.FeedetlSn = hisAdvice.FeedetlSn
  6637. }
  6638. }
  6639. }
  6640. }
  6641. //
  6642. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6643. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6644. // advice.ExecutionTime = execution_time
  6645. //}
  6646. //
  6647. //
  6648. //
  6649. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6650. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6651. // advice.ExecutionStaff = execution_staff
  6652. //}
  6653. //
  6654. //
  6655. //
  6656. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6657. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6658. // advice.ExecutionState = execution_state
  6659. //}
  6660. //
  6661. //
  6662. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6663. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6664. // advice.CheckTime = check_time
  6665. //}
  6666. //
  6667. //
  6668. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6669. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6670. // advice.CheckState = check_state
  6671. //}
  6672. //
  6673. //
  6674. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6675. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6676. // advice.Checker = checker
  6677. //}
  6678. //
  6679. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6680. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6681. // advice.StartTime = start_time
  6682. //}
  6683. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6684. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6685. advice.IsSelfDrug = is_self_drug
  6686. }
  6687. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6688. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6689. drug_way_count, _ := json["drug_way_count"].(string)
  6690. advice.DrugWayCount = drug_way_count
  6691. }
  6692. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6693. drugSpecUnit, _ := json["min_unit"].(string)
  6694. advice.DrugSpecUnit = drugSpecUnit
  6695. }
  6696. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6697. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6698. advice.SingleDose = singleDose
  6699. }
  6700. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6701. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6702. advice.SingleDoseUnit = singleDoseUnit
  6703. }
  6704. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6705. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6706. advice.PrescribingNumber = prescribingNumber
  6707. }
  6708. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6709. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6710. advice.PrescribingNumberUnit = prescribingNumberUnit
  6711. }
  6712. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6713. deliveryWay, _ := json["delivery_way"].(string)
  6714. advice.DeliveryWay = deliveryWay
  6715. }
  6716. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6717. executionFrequency, _ := json["execution_frequency"].(string)
  6718. advice.ExecutionFrequency = executionFrequency
  6719. }
  6720. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6721. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6722. advice.Price = price
  6723. }
  6724. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6725. med_list_codg, _ := json["medical_insurance_number"].(string)
  6726. advice.MedListCodg = med_list_codg
  6727. }
  6728. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6729. day := int64(json["day"].(float64))
  6730. advice.Day = day
  6731. }
  6732. return 0
  6733. }
  6734. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6735. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6736. id := int64(json["id"].(float64))
  6737. project.ID = id
  6738. historyProject, _ := service.GetHisProjectByID(id)
  6739. project.FeedetlSn = historyProject.FeedetlSn
  6740. }
  6741. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6742. project_id := int64(json["project_id"].(float64))
  6743. project.ProjectId = project_id
  6744. }
  6745. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6746. // price := int64(json["price"].(float64))
  6747. // formatInt_price := strconv.FormatInt(price, 10)
  6748. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6749. // project.Price = float_price
  6750. // }
  6751. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6752. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6753. project.Price = price
  6754. }
  6755. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6756. total, _ := json["total"].(string)
  6757. project.Count = total
  6758. }
  6759. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6760. medical_code, _ := json["medical_code"].(string)
  6761. project.MedListCodg = medical_code
  6762. }
  6763. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6764. single_dose, _ := json["single_dose"].(string)
  6765. project.SingleDose = single_dose
  6766. }
  6767. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6768. delivery_way, _ := json["delivery_way"].(string)
  6769. project.DeliveryWay = delivery_way
  6770. }
  6771. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6772. execution_frequency, _ := json["execution_frequency"].(string)
  6773. project.ExecutionFrequency = execution_frequency
  6774. }
  6775. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6776. remark, _ := json["remark"].(string)
  6777. project.Remark = remark
  6778. }
  6779. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6780. day, _ := json["number_days"].(string)
  6781. project.Day = day
  6782. }
  6783. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6784. unit, _ := json["unit"].(string)
  6785. project.Unit = unit
  6786. }
  6787. return 0
  6788. }
  6789. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6790. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6791. id := int64(json["id"].(float64))
  6792. historyAddtions, _ := service.GetHisAdditionByID(id)
  6793. additionalCharge.ID = id
  6794. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6795. }
  6796. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6797. item_id := int64(json["item_id"].(float64))
  6798. additionalCharge.ItemId = item_id
  6799. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6800. if config.ID > 0 {
  6801. if len(config.Code) > 0 {
  6802. additionalCharge.MedListCodg = config.Code
  6803. }
  6804. }
  6805. }
  6806. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6807. // price := int64(json["price"].(float64))
  6808. // formatInt_price := strconv.FormatInt(price, 10)
  6809. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6810. // additionalCharge.Price = float_price
  6811. // }
  6812. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6813. // price := int64(json["price"].(float64))
  6814. // formatInt_price := strconv.FormatInt(price, 10)
  6815. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6816. // additionalCharge.Price = float_price
  6817. //}
  6818. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6819. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6820. additionalCharge.Price = price
  6821. }
  6822. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6823. count, _ := json["count"].(string)
  6824. counts, _ := strconv.ParseInt(count, 10, 64)
  6825. additionalCharge.Count = counts
  6826. }
  6827. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6828. item_name, _ := json["item_name"].(string)
  6829. additionalCharge.ItemName = item_name
  6830. }
  6831. return 0
  6832. }
  6833. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6834. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6835. utils.ErrorLog("drug_name")
  6836. return enums.ErrorCodeParamWrong
  6837. }
  6838. adviceName, _ := json["drug_name"].(string)
  6839. if len(adviceName) == 0 {
  6840. utils.ErrorLog("len(advice_name) == 0")
  6841. return enums.ErrorCodeParamWrong
  6842. }
  6843. advice.AdviceName = adviceName
  6844. adviceDesc, _ := json["advice_desc"].(string)
  6845. advice.AdviceDesc = adviceDesc
  6846. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6847. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6848. advice.DrugSpec = drugSpec
  6849. }
  6850. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6851. remark, _ := json["remark"].(string)
  6852. advice.Remark = remark
  6853. }
  6854. if json["id"] == nil {
  6855. advice.DrugId = 0
  6856. } else {
  6857. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6858. drug_id := int64(json["id"].(float64))
  6859. advice.DrugId = drug_id
  6860. }
  6861. }
  6862. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6863. groupno := int64(json["groupno"].(float64))
  6864. advice.Groupno = groupno
  6865. }
  6866. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6867. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6868. advice.IsSelfDrug = is_self_drug
  6869. }
  6870. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6871. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6872. drug_way_count, _ := json["drug_way_count"].(string)
  6873. advice.DrugWayCount = drug_way_count
  6874. }
  6875. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6876. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6877. advice.HospApprFlag = hosp_appr_flag
  6878. }
  6879. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6880. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6881. advice.PrescribingNumber = prescribingNumber
  6882. }
  6883. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6884. // frequency_type := int64(json["frequency_type"].(float64))
  6885. // advice.FrequencyType = frequency_type
  6886. //}
  6887. //
  6888. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6889. // day_count := int64(json["day_count"].(float64))
  6890. // advice.DayCount = day_count
  6891. //}
  6892. //
  6893. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6894. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6895. // week_day, _ := json["week_day"].(string)
  6896. // advice.WeekDay = week_day
  6897. //}
  6898. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6899. drugSpecUnit, _ := json["min_unit"].(string)
  6900. advice.DrugSpecUnit = drugSpecUnit
  6901. }
  6902. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6903. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6904. advice.SingleDose = singleDose
  6905. }
  6906. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6907. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6908. advice.SingleDoseUnit = singleDoseUnit
  6909. }
  6910. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6911. deliveryWay, _ := json["delivery_way"].(string)
  6912. advice.DeliveryWay = deliveryWay
  6913. }
  6914. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6915. executionFrequency, _ := json["execution_frequency"].(string)
  6916. advice.ExecutionFrequency = executionFrequency
  6917. }
  6918. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6919. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6920. advice.Price = price
  6921. }
  6922. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6923. med_list_codg, _ := json["medical_insurance_number"].(string)
  6924. advice.MedListCodg = med_list_codg
  6925. }
  6926. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6927. day := int64(json["day"].(float64))
  6928. advice.Day = day
  6929. }
  6930. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6931. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6932. advice.PrescribingNumberUnit = prescribingNumberUnit
  6933. }
  6934. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6935. advice_id := int64(json["advice_id"].(float64))
  6936. advice.ID = advice_id
  6937. if advice.ID > 0 {
  6938. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6939. if err == nil {
  6940. if hisAdvice.ID > 0 {
  6941. advice.ExecutionTime = hisAdvice.ExecutionTime
  6942. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6943. advice.ExecutionState = hisAdvice.ExecutionState
  6944. advice.CheckTime = hisAdvice.CheckTime
  6945. advice.Checker = hisAdvice.Checker
  6946. advice.CheckState = hisAdvice.CheckState
  6947. advice.StartTime = hisAdvice.StartTime
  6948. advice.HospApprFlag = hisAdvice.HospApprFlag
  6949. advice.IsMedicine = hisAdvice.IsMedicine
  6950. if hisAdvice.UserOrgId == 10028 {
  6951. 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 {
  6952. advice.ExecutionTime = 0
  6953. advice.ExecutionStaff = 0
  6954. advice.ExecutionState = 2
  6955. advice.CheckTime = 0
  6956. advice.Checker = 0
  6957. advice.CheckState = 2
  6958. }
  6959. } else {
  6960. 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 {
  6961. advice.ExecutionTime = 0
  6962. advice.ExecutionStaff = 0
  6963. advice.ExecutionState = 2
  6964. advice.CheckTime = 0
  6965. advice.Checker = 0
  6966. advice.CheckState = 2
  6967. advice.UpdatedTime = time.Now().Unix()
  6968. }
  6969. }
  6970. //advice.Groupno = hisAdvice.Groupno
  6971. }
  6972. }
  6973. }
  6974. }
  6975. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6976. //
  6977. //if drugStockConfig.IsOpen == 1 {
  6978. //
  6979. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6980. // if advice.ID == 0 { //医嘱不存在
  6981. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6982. // drug.Total = drug.Total - advice.PrescribingNumber
  6983. // service.UpdateBaseDrugLib(&drug)
  6984. //
  6985. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6986. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6987. // drug.Total = drug.Total - num
  6988. // service.UpdateBaseDrugLib(&drug)
  6989. // }
  6990. //
  6991. // } else if advice.ID > 0 { //医嘱存在
  6992. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6993. // var num float64
  6994. //
  6995. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6996. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6997. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6998. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6999. // drug.Total = drug.Total + num
  7000. // service.UpdateBaseDrugLib(&drug)
  7001. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7002. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7003. // drug.Total = drug.Total - num
  7004. // service.UpdateBaseDrugLib(&drug)
  7005. // }
  7006. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7007. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7008. // if num2 > advice.PrescribingNumber {
  7009. // num = num2 - advice.PrescribingNumber
  7010. // drug.Total = drug.Total + num
  7011. // service.UpdateBaseDrugLib(&drug)
  7012. // } else if num2 < advice.PrescribingNumber {
  7013. // num = advice.PrescribingNumber - num2
  7014. // drug.Total = drug.Total - num
  7015. // service.UpdateBaseDrugLib(&drug)
  7016. // }
  7017. //
  7018. // }
  7019. //
  7020. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7021. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7022. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7023. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7024. // if num1 > num2 {
  7025. // num = num1 - num2
  7026. // drug.Total = drug.Total + num
  7027. // service.UpdateBaseDrugLib(&drug)
  7028. // } else if num1 < num2 {
  7029. // num = num2 - num1
  7030. // drug.Total = drug.Total - num
  7031. // service.UpdateBaseDrugLib(&drug)
  7032. // }
  7033. //
  7034. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7035. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7036. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7037. // if hisAdvice.PrescribingNumber > num2 {
  7038. // num = hisAdvice.PrescribingNumber - num2
  7039. // drug.Total = drug.Total + num
  7040. // service.UpdateBaseDrugLib(&drug)
  7041. // } else if num2 < advice.PrescribingNumber {
  7042. // num = num2 - hisAdvice.PrescribingNumber
  7043. // drug.Total = drug.Total - num
  7044. // service.UpdateBaseDrugLib(&drug)
  7045. // }
  7046. //
  7047. // }
  7048. // }
  7049. // }
  7050. //}
  7051. //
  7052. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7053. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7054. // advice.ExecutionTime = execution_time
  7055. //}
  7056. //
  7057. //
  7058. //
  7059. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7060. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7061. // advice.ExecutionStaff = execution_staff
  7062. //}
  7063. //
  7064. //
  7065. //
  7066. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7067. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7068. // advice.ExecutionState = execution_state
  7069. //}
  7070. //
  7071. //
  7072. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7073. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7074. // advice.CheckTime = check_time
  7075. //}
  7076. //
  7077. //
  7078. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7079. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7080. // advice.CheckState = check_state
  7081. //}
  7082. //
  7083. //
  7084. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7085. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7086. // advice.Checker = checker
  7087. //}
  7088. //
  7089. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7090. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7091. // advice.StartTime = start_time
  7092. //}
  7093. return 0
  7094. }
  7095. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7096. project.ExecutionStaff = 0
  7097. project.ExecutionState = 2
  7098. project.ExecutionTime = 0
  7099. project.Checker = 0
  7100. project.CheckState = 2
  7101. project.CheckTime = 0
  7102. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7103. id := int64(json["id"].(float64))
  7104. project.ID = id
  7105. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7106. project.ExecutionStaff = temp_project.ExecutionStaff
  7107. project.ExecutionState = temp_project.ExecutionState
  7108. project.ExecutionTime = temp_project.ExecutionTime
  7109. project.Checker = temp_project.Checker
  7110. project.CheckState = temp_project.CheckState
  7111. project.CheckTime = temp_project.CheckTime
  7112. project.TeamId = temp_project.TeamId
  7113. }
  7114. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7115. types := int64(json["type"].(float64))
  7116. project.Type = types
  7117. }
  7118. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7119. project_id := int64(json["project_id"].(float64))
  7120. project.ProjectId = project_id
  7121. }
  7122. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7123. team_id := int64(json["team_id"].(float64))
  7124. project.TeamId = team_id
  7125. }
  7126. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7127. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7128. project.Price = price
  7129. }
  7130. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7131. total, _ := json["total"].(string)
  7132. //totals, _ := strconv.ParseInt(total, 10, 64)
  7133. project.Count = total
  7134. }
  7135. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7136. medical_code, _ := json["medical_code"].(string)
  7137. project.MedListCodg = medical_code
  7138. }
  7139. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7140. single_dose, _ := json["single_dose"].(string)
  7141. project.SingleDose = single_dose
  7142. }
  7143. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7144. delivery_way, _ := json["delivery_way"].(string)
  7145. project.DeliveryWay = delivery_way
  7146. }
  7147. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7148. execution_frequency, _ := json["execution_frequency"].(string)
  7149. project.ExecutionFrequency = execution_frequency
  7150. }
  7151. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7152. remark, _ := json["remark"].(string)
  7153. project.Remark = remark
  7154. }
  7155. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7156. day, _ := json["number_days"].(string)
  7157. project.Day = day
  7158. }
  7159. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7160. unit, _ := json["unit"].(string)
  7161. project.Unit = unit
  7162. }
  7163. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7164. // frequency_type := int64(json["frequency_type"].(float64))
  7165. // project.FrequencyType = frequency_type
  7166. //}
  7167. //
  7168. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7169. // day_count := int64(json["day_count"].(float64))
  7170. // project.DayCount = day_count
  7171. //}
  7172. //
  7173. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7174. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7175. // week_day, _ := json["week_day"].(string)
  7176. // project.WeekDay = week_day
  7177. //}
  7178. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7179. //
  7180. //if project.ID == 0 {
  7181. // if stockConfig.IsOpen == 1 {
  7182. // if project.Type == 3 {
  7183. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7184. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7185. // good.Total = good.Total - f_count
  7186. // service.UpdateGoodInfo(&good)
  7187. // }
  7188. // }
  7189. //
  7190. //} else {
  7191. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7192. //
  7193. // if stockConfig.IsOpen == 1 {
  7194. // if project.Type == 3 {
  7195. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7196. // if project.Count < temp_project.Count {
  7197. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7198. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7199. //
  7200. // other_count := f_count_two - f_count_one
  7201. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7202. // good.Total = good.Total + other_count_two
  7203. // service.UpdateGoodInfo(&good)
  7204. // } else if project.Count > temp_project.Count {
  7205. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7206. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7207. //
  7208. // other_count := f_count_one - f_count_two
  7209. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7210. // good.Total = good.Total - other_count_two
  7211. // service.UpdateGoodInfo(&good)
  7212. // }
  7213. //
  7214. // }
  7215. // }
  7216. //
  7217. //}
  7218. return 0
  7219. }
  7220. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7221. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7222. utils.ErrorLog("drug_name")
  7223. return enums.ErrorCodeParamWrong
  7224. }
  7225. adviceName, _ := json["drug_name"].(string)
  7226. if len(adviceName) == 0 {
  7227. utils.ErrorLog("len(advice_name) == 0")
  7228. return enums.ErrorCodeParamWrong
  7229. }
  7230. advice.AdviceName = adviceName
  7231. adviceDesc, _ := json["advice_desc"].(string)
  7232. advice.AdviceDesc = adviceDesc
  7233. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7234. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7235. advice.DrugSpec = drugSpec
  7236. }
  7237. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7238. remark, _ := json["remark"].(string)
  7239. advice.Remark = remark
  7240. }
  7241. if json["id"] == nil {
  7242. advice.DrugId = 0
  7243. } else {
  7244. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7245. drug_id := int64(json["id"].(float64))
  7246. advice.DrugId = drug_id
  7247. }
  7248. }
  7249. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7250. groupno := int64(json["groupno"].(float64))
  7251. advice.Groupno = groupno
  7252. }
  7253. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7254. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7255. advice.IsSelfDrug = is_self_drug
  7256. }
  7257. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7258. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7259. drug_way_count, _ := json["drug_way_count"].(string)
  7260. advice.DrugWayCount = drug_way_count
  7261. }
  7262. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7263. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7264. advice.HospApprFlag = hosp_appr_flag
  7265. }
  7266. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7267. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7268. advice.PrescribingNumber = prescribingNumber
  7269. }
  7270. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7271. // frequency_type := int64(json["frequency_type"].(float64))
  7272. // advice.FrequencyType = frequency_type
  7273. //}
  7274. //
  7275. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7276. // day_count := int64(json["day_count"].(float64))
  7277. // advice.DayCount = day_count
  7278. //}
  7279. //
  7280. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7281. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7282. // week_day, _ := json["week_day"].(string)
  7283. // advice.WeekDay = week_day
  7284. //}
  7285. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7286. drugSpecUnit, _ := json["min_unit"].(string)
  7287. advice.DrugSpecUnit = drugSpecUnit
  7288. }
  7289. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7290. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7291. advice.SingleDose = singleDose
  7292. }
  7293. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7294. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7295. advice.SingleDoseUnit = singleDoseUnit
  7296. }
  7297. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7298. deliveryWay, _ := json["delivery_way"].(string)
  7299. advice.DeliveryWay = deliveryWay
  7300. }
  7301. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7302. executionFrequency, _ := json["execution_frequency"].(string)
  7303. advice.ExecutionFrequency = executionFrequency
  7304. }
  7305. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7306. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7307. advice.Price = price
  7308. }
  7309. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7310. med_list_codg, _ := json["medical_insurance_number"].(string)
  7311. advice.MedListCodg = med_list_codg
  7312. }
  7313. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7314. day := int64(json["day"].(float64))
  7315. advice.Day = day
  7316. }
  7317. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7318. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7319. advice.PrescribingNumberUnit = prescribingNumberUnit
  7320. }
  7321. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7322. advice_id := int64(json["advice_id"].(float64))
  7323. advice.ID = advice_id
  7324. if advice.ID > 0 {
  7325. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7326. if err == nil {
  7327. if hisAdvice.ID > 0 {
  7328. advice.ExecutionTime = hisAdvice.ExecutionTime
  7329. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7330. advice.ExecutionState = hisAdvice.ExecutionState
  7331. advice.CheckTime = hisAdvice.CheckTime
  7332. advice.Checker = hisAdvice.Checker
  7333. advice.CheckState = hisAdvice.CheckState
  7334. advice.StartTime = hisAdvice.StartTime
  7335. advice.HospApprFlag = hisAdvice.HospApprFlag
  7336. advice.IsMedicine = hisAdvice.IsMedicine
  7337. if hisAdvice.UserOrgId == 10028 {
  7338. 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 {
  7339. advice.ExecutionTime = 0
  7340. advice.ExecutionStaff = 0
  7341. advice.ExecutionState = 2
  7342. advice.CheckTime = 0
  7343. advice.Checker = 0
  7344. advice.CheckState = 2
  7345. }
  7346. } else {
  7347. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || 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 {
  7348. advice.ExecutionTime = 0
  7349. advice.ExecutionStaff = 0
  7350. advice.ExecutionState = 2
  7351. advice.CheckTime = 0
  7352. advice.Checker = 0
  7353. advice.CheckState = 2
  7354. //advice.UpdatedTime = time.Now().Unix()
  7355. advice.CreatedTime = hisAdvice.CreatedTime
  7356. advice.UpdatedTime = time.Now().Unix()
  7357. } else {
  7358. advice.CreatedTime = hisAdvice.CreatedTime
  7359. advice.UpdatedTime = hisAdvice.UpdatedTime
  7360. }
  7361. }
  7362. //advice.Groupno = hisAdvice.Groupno
  7363. } else {
  7364. advice.IsMedicine = 0
  7365. ctime := time.Now().Unix()
  7366. advice.CreatedTime = ctime
  7367. advice.UpdatedTime = ctime
  7368. }
  7369. }
  7370. } else {
  7371. advice.IsMedicine = 0
  7372. ctime := time.Now().Unix()
  7373. advice.CreatedTime = ctime
  7374. advice.UpdatedTime = ctime
  7375. }
  7376. }
  7377. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7378. //
  7379. //if drugStockConfig.IsOpen == 1 {
  7380. //
  7381. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7382. // if advice.ID == 0 { //医嘱不存在
  7383. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7384. // drug.Total = drug.Total - advice.PrescribingNumber
  7385. // service.UpdateBaseDrugLib(&drug)
  7386. //
  7387. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7388. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7389. // drug.Total = drug.Total - num
  7390. // service.UpdateBaseDrugLib(&drug)
  7391. // }
  7392. //
  7393. // } else if advice.ID > 0 { //医嘱存在
  7394. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7395. // var num float64
  7396. //
  7397. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7398. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7399. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7400. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7401. // drug.Total = drug.Total + num
  7402. // service.UpdateBaseDrugLib(&drug)
  7403. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7404. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7405. // drug.Total = drug.Total - num
  7406. // service.UpdateBaseDrugLib(&drug)
  7407. // }
  7408. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7409. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7410. // if num2 > advice.PrescribingNumber {
  7411. // num = num2 - advice.PrescribingNumber
  7412. // drug.Total = drug.Total + num
  7413. // service.UpdateBaseDrugLib(&drug)
  7414. // } else if num2 < advice.PrescribingNumber {
  7415. // num = advice.PrescribingNumber - num2
  7416. // drug.Total = drug.Total - num
  7417. // service.UpdateBaseDrugLib(&drug)
  7418. // }
  7419. //
  7420. // }
  7421. //
  7422. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7423. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7424. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7425. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7426. // if num1 > num2 {
  7427. // num = num1 - num2
  7428. // drug.Total = drug.Total + num
  7429. // service.UpdateBaseDrugLib(&drug)
  7430. // } else if num1 < num2 {
  7431. // num = num2 - num1
  7432. // drug.Total = drug.Total - num
  7433. // service.UpdateBaseDrugLib(&drug)
  7434. // }
  7435. //
  7436. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7437. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7438. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7439. // if hisAdvice.PrescribingNumber > num2 {
  7440. // num = hisAdvice.PrescribingNumber - num2
  7441. // drug.Total = drug.Total + num
  7442. // service.UpdateBaseDrugLib(&drug)
  7443. // } else if num2 < advice.PrescribingNumber {
  7444. // num = num2 - hisAdvice.PrescribingNumber
  7445. // drug.Total = drug.Total - num
  7446. // service.UpdateBaseDrugLib(&drug)
  7447. // }
  7448. //
  7449. // }
  7450. // }
  7451. // }
  7452. //}
  7453. //
  7454. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7455. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7456. // advice.ExecutionTime = execution_time
  7457. //}
  7458. //
  7459. //
  7460. //
  7461. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7462. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7463. // advice.ExecutionStaff = execution_staff
  7464. //}
  7465. //
  7466. //
  7467. //
  7468. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7469. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7470. // advice.ExecutionState = execution_state
  7471. //}
  7472. //
  7473. //
  7474. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7475. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7476. // advice.CheckTime = check_time
  7477. //}
  7478. //
  7479. //
  7480. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7481. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7482. // advice.CheckState = check_state
  7483. //}
  7484. //
  7485. //
  7486. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7487. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7488. // advice.Checker = checker
  7489. //}
  7490. //
  7491. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7492. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7493. // advice.StartTime = start_time
  7494. //}
  7495. return 0
  7496. }
  7497. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7498. project.ExecutionStaff = 0
  7499. project.ExecutionState = 2
  7500. project.ExecutionTime = 0
  7501. project.Checker = 0
  7502. project.CheckState = 2
  7503. project.CheckTime = 0
  7504. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7505. id := int64(json["id"].(float64))
  7506. project.ID = id
  7507. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7508. project.ExecutionStaff = temp_project.ExecutionStaff
  7509. project.ExecutionState = temp_project.ExecutionState
  7510. project.ExecutionTime = temp_project.ExecutionTime
  7511. project.Checker = temp_project.Checker
  7512. project.CheckState = temp_project.CheckState
  7513. project.CheckTime = temp_project.CheckTime
  7514. project.TeamId = temp_project.TeamId
  7515. }
  7516. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7517. types := int64(json["type"].(float64))
  7518. project.Type = types
  7519. }
  7520. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7521. project_id := int64(json["project_id"].(float64))
  7522. project.ProjectId = project_id
  7523. }
  7524. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7525. team_id := int64(json["team_id"].(float64))
  7526. project.TeamId = team_id
  7527. }
  7528. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7529. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7530. project.Price = price
  7531. }
  7532. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7533. total, _ := json["total"].(string)
  7534. //totals, _ := strconv.ParseInt(total, 10, 64)
  7535. project.Count = total
  7536. }
  7537. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7538. medical_code, _ := json["medical_code"].(string)
  7539. project.MedListCodg = medical_code
  7540. }
  7541. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7542. single_dose, _ := json["single_dose"].(string)
  7543. project.SingleDose = single_dose
  7544. }
  7545. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7546. delivery_way, _ := json["delivery_way"].(string)
  7547. project.DeliveryWay = delivery_way
  7548. }
  7549. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7550. execution_frequency, _ := json["execution_frequency"].(string)
  7551. project.ExecutionFrequency = execution_frequency
  7552. }
  7553. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7554. remark, _ := json["remark"].(string)
  7555. project.Remark = remark
  7556. }
  7557. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7558. day, _ := json["number_days"].(string)
  7559. project.Day = day
  7560. }
  7561. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7562. unit, _ := json["unit"].(string)
  7563. project.Unit = unit
  7564. }
  7565. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7566. // frequency_type := int64(json["frequency_type"].(float64))
  7567. // project.FrequencyType = frequency_type
  7568. //}
  7569. //
  7570. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7571. // day_count := int64(json["day_count"].(float64))
  7572. // project.DayCount = day_count
  7573. //}
  7574. //
  7575. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7576. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7577. // week_day, _ := json["week_day"].(string)
  7578. // project.WeekDay = week_day
  7579. //}
  7580. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7581. //
  7582. //if project.ID == 0 {
  7583. // if stockConfig.IsOpen == 1 {
  7584. // if project.Type == 3 {
  7585. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7586. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7587. // good.Total = good.Total - f_count
  7588. // service.UpdateGoodInfo(&good)
  7589. // }
  7590. // }
  7591. //
  7592. //} else {
  7593. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7594. //
  7595. // if stockConfig.IsOpen == 1 {
  7596. // if project.Type == 3 {
  7597. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7598. // if project.Count < temp_project.Count {
  7599. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7600. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7601. //
  7602. // other_count := f_count_two - f_count_one
  7603. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7604. // good.Total = good.Total + other_count_two
  7605. // service.UpdateGoodInfo(&good)
  7606. // } else if project.Count > temp_project.Count {
  7607. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7608. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7609. //
  7610. // other_count := f_count_one - f_count_two
  7611. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7612. // good.Total = good.Total - other_count_two
  7613. // service.UpdateGoodInfo(&good)
  7614. // }
  7615. //
  7616. // }
  7617. // }
  7618. //
  7619. //}
  7620. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7621. id := int64(json["id"].(float64))
  7622. if id > 0 {
  7623. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7624. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7625. fmt.Println("666666")
  7626. project.Mtime = time.Now().Unix()
  7627. project.Ctime = temp_project.Ctime
  7628. } else {
  7629. project.Mtime = temp_project.Mtime
  7630. project.Ctime = temp_project.Ctime
  7631. }
  7632. } else {
  7633. ctime := time.Now().Unix()
  7634. project.Mtime = ctime
  7635. project.Ctime = ctime
  7636. }
  7637. }
  7638. return 0
  7639. }
  7640. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7641. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7642. id := int64(json["id"].(float64))
  7643. additionalCharge.ID = id
  7644. }
  7645. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7646. item_id := int64(json["item_id"].(float64))
  7647. additionalCharge.ItemId = item_id
  7648. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7649. if config.ID > 0 {
  7650. if len(config.Code) > 0 {
  7651. additionalCharge.MedListCodg = config.Code
  7652. }
  7653. }
  7654. }
  7655. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7656. // price := int64(json["price"].(float64))
  7657. // formatInt_price := strconv.FormatInt(price, 10)
  7658. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7659. // additionalCharge.Price = float_price
  7660. // }
  7661. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7662. // price := int64(json["price"].(float64))
  7663. // formatInt_price := strconv.FormatInt(price, 10)
  7664. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7665. // additionalCharge.Price = float_price
  7666. //}
  7667. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7668. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7669. additionalCharge.Price = price
  7670. }
  7671. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7672. count, _ := json["count"].(string)
  7673. counts, _ := strconv.ParseInt(count, 10, 64)
  7674. additionalCharge.Count = counts
  7675. }
  7676. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7677. item_name, _ := json["item_name"].(string)
  7678. additionalCharge.ItemName = item_name
  7679. }
  7680. return 0
  7681. }
  7682. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7683. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7684. utils.ErrorLog("drug_name")
  7685. return enums.ErrorCodeParamWrong
  7686. }
  7687. adviceName, _ := json["drug_name"].(string)
  7688. if len(adviceName) == 0 {
  7689. utils.ErrorLog("len(advice_name) == 0")
  7690. return enums.ErrorCodeParamWrong
  7691. }
  7692. advice.AdviceName = adviceName
  7693. adviceDesc, _ := json["advice_desc"].(string)
  7694. advice.AdviceDesc = adviceDesc
  7695. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7696. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7697. advice.DrugSpec = drugSpec
  7698. }
  7699. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7700. remark, _ := json["remark"].(string)
  7701. advice.Remark = remark
  7702. }
  7703. if json["id"] == nil {
  7704. advice.DrugId = 0
  7705. } else {
  7706. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7707. drug_id := int64(json["id"].(float64))
  7708. advice.DrugId = drug_id
  7709. }
  7710. }
  7711. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7712. groupno := int64(json["groupno"].(float64))
  7713. advice.Groupno = groupno
  7714. }
  7715. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7716. drugSpecUnit, _ := json["min_unit"].(string)
  7717. advice.DrugSpecUnit = drugSpecUnit
  7718. }
  7719. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7720. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7721. advice.SingleDose = singleDose
  7722. }
  7723. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7724. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7725. advice.SingleDoseUnit = singleDoseUnit
  7726. }
  7727. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7728. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7729. advice.PrescribingNumber = prescribingNumber
  7730. }
  7731. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7732. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7733. advice.PrescribingNumberUnit = prescribingNumberUnit
  7734. }
  7735. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7736. deliveryWay, _ := json["delivery_way"].(string)
  7737. advice.DeliveryWay = deliveryWay
  7738. }
  7739. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7740. executionFrequency, _ := json["execution_frequency"].(string)
  7741. advice.ExecutionFrequency = executionFrequency
  7742. }
  7743. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7744. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7745. advice.Price = price
  7746. }
  7747. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7748. med_list_codg, _ := json["medical_insurance_number"].(string)
  7749. advice.MedListCodg = med_list_codg
  7750. }
  7751. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7752. day := int64(json["day"].(float64))
  7753. advice.Day = day
  7754. }
  7755. advice.FrequencyType = 1
  7756. return 0
  7757. }
  7758. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7759. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7760. types := int64(json["type"].(float64))
  7761. project.Type = types
  7762. }
  7763. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7764. project_id := int64(json["project_id"].(float64))
  7765. project.ProjectId = project_id
  7766. }
  7767. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7768. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7769. project.Price = price
  7770. }
  7771. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7772. total, _ := json["total"].(string)
  7773. //totals, _ := strconv.ParseInt(total, 10, 64)
  7774. project.Count = total
  7775. }
  7776. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7777. medical_code, _ := json["medical_code"].(string)
  7778. project.MedListCodg = medical_code
  7779. }
  7780. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7781. single_dose, _ := json["single_dose"].(string)
  7782. project.SingleDose = single_dose
  7783. }
  7784. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7785. delivery_way, _ := json["delivery_way"].(string)
  7786. project.DeliveryWay = delivery_way
  7787. }
  7788. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7789. execution_frequency, _ := json["execution_frequency"].(string)
  7790. project.ExecutionFrequency = execution_frequency
  7791. }
  7792. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7793. remark, _ := json["remark"].(string)
  7794. project.Remark = remark
  7795. }
  7796. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7797. day, _ := json["number_days"].(string)
  7798. project.Day = day
  7799. }
  7800. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7801. unit, _ := json["unit"].(string)
  7802. project.Unit = unit
  7803. }
  7804. project.FrequencyType = 1
  7805. return 0
  7806. }
  7807. func (c *HisApiController) GetHisOrderListTwo() {
  7808. start_time := c.GetString("start_time")
  7809. end_time := c.GetString("end_time")
  7810. timeLayout := "2006-01-02"
  7811. loc, _ := time.LoadLocation("Local")
  7812. var startTime int64
  7813. if len(start_time) > 0 {
  7814. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7815. if err != nil {
  7816. //fmt.Println(err)
  7817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7818. return
  7819. }
  7820. startTime = theTime.Unix()
  7821. }
  7822. var endTime int64
  7823. if len(end_time) > 0 {
  7824. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7825. if err != nil {
  7826. utils.ErrorLog(err.Error())
  7827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7828. return
  7829. }
  7830. endTime = theTime.Unix()
  7831. }
  7832. adminUser := c.GetAdminUserInfo()
  7833. org_id := adminUser.CurrentOrgId
  7834. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7835. if err == nil {
  7836. c.ServeSuccessJSON(map[string]interface{}{
  7837. "order2": order,
  7838. })
  7839. } else {
  7840. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7841. return
  7842. }
  7843. }
  7844. func (c *HisApiController) GetHisOrderList() {
  7845. page, _ := c.GetInt64("page", -1)
  7846. limit, _ := c.GetInt64("limit", -1)
  7847. start_time := c.GetString("start_time")
  7848. end_time := c.GetString("end_time")
  7849. types, _ := c.GetInt64("type", 0)
  7850. keywords := c.GetString("keywords")
  7851. p_type, _ := c.GetInt64("p_type", 0)
  7852. sort_type, _ := c.GetInt64("sort_type", 0)
  7853. charge_type, _ := c.GetInt64("charge_type", 0)
  7854. sch_type, _ := c.GetInt64("sch_type", 0)
  7855. zone_type, _ := c.GetInt64("zone_type", 0)
  7856. med_type, _ := c.GetInt64("med_type", 0)
  7857. timeLayout := "2006-01-02"
  7858. loc, _ := time.LoadLocation("Local")
  7859. var startTime int64
  7860. if len(start_time) > 0 {
  7861. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7862. if err != nil {
  7863. //fmt.Println(err)
  7864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7865. return
  7866. }
  7867. startTime = theTime.Unix()
  7868. }
  7869. var endTime int64
  7870. if len(end_time) > 0 {
  7871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7872. if err != nil {
  7873. utils.ErrorLog(err.Error())
  7874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7875. return
  7876. }
  7877. endTime = theTime.Unix()
  7878. }
  7879. adminUser := c.GetAdminUserInfo()
  7880. org_id := adminUser.CurrentOrgId
  7881. 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)
  7882. for _, item := range order {
  7883. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7884. item.DoctorName = info.Doctor
  7885. item.DepartmentName = info.XtHisDepartment.Name
  7886. }
  7887. if err == nil {
  7888. c.ServeSuccessJSON(map[string]interface{}{
  7889. "order": order,
  7890. "total": total,
  7891. })
  7892. } else {
  7893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7894. return
  7895. }
  7896. }
  7897. func (c *HisApiController) GetHisOrder() {
  7898. patient_id, _ := c.GetInt64("patient_id", 0)
  7899. number := c.GetString("number")
  7900. adminInfo := c.GetAdminUserInfo()
  7901. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7902. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7903. if err == nil {
  7904. c.ServeSuccessJSON(map[string]interface{}{
  7905. "order": order,
  7906. "prescription": prescriptions,
  7907. })
  7908. } else {
  7909. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7910. return
  7911. }
  7912. }
  7913. func (c *HisApiController) GetHisPrescriptionList() {
  7914. record_date := c.GetString("record_date")
  7915. keywords := c.GetString("keywords")
  7916. page, _ := c.GetInt64("page")
  7917. limit, _ := c.GetInt64("limit")
  7918. sch_type, _ := c.GetInt64("sch_type")
  7919. timeLayout := "2006-01-02"
  7920. loc, _ := time.LoadLocation("Local")
  7921. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7922. if err != nil {
  7923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7924. return
  7925. }
  7926. recordDateTime := theTime.Unix()
  7927. adminInfo := c.GetAdminUserInfo()
  7928. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7929. //adminInfo := c.GetAdminUserInfo()
  7930. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7931. //fmt.Println(prescriptionOrder)
  7932. if err == nil {
  7933. c.ServeSuccessJSON(map[string]interface{}{
  7934. "order": prescriptionOrder,
  7935. "total": total,
  7936. })
  7937. } else {
  7938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7939. return
  7940. }
  7941. }
  7942. func (c *HisApiController) GetHisPrescriptionInfo() {
  7943. id, _ := c.GetInt64("id")
  7944. adminInfo := c.GetAdminUserInfo()
  7945. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7946. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7947. if err == nil {
  7948. c.ServeSuccessJSON(map[string]interface{}{
  7949. "order": prescriptionOrder,
  7950. "prescription": prescription,
  7951. })
  7952. } else {
  7953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7954. return
  7955. }
  7956. }
  7957. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7958. adminUser := c.GetAdminUserInfo()
  7959. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7960. c.ServeSuccessJSON(map[string]interface{}{
  7961. "config": config,
  7962. })
  7963. }
  7964. type ResultTwo struct {
  7965. ErrMsg interface{} `json:"err_msg"`
  7966. InfRefmsgid string `json:"inf_refmsgid"`
  7967. Infcode int64 `json:"infcode"`
  7968. Output struct {
  7969. Baseinfo struct {
  7970. Age float64 `json:"age"`
  7971. Brdy string `json:"brdy"`
  7972. Certno string `json:"certno"`
  7973. Gend string `json:"gend"`
  7974. Naty string `json:"naty"`
  7975. PsnCertType string `json:"psn_cert_type"`
  7976. PsnName string `json:"psn_name"`
  7977. PsnNo string `json:"psn_no"`
  7978. } `json:"baseinfo"`
  7979. Idetinfo []interface{} `json:"idetinfo"`
  7980. Iinfo []struct {
  7981. Balc float64 `json:"balc"`
  7982. CvlservFlag string `json:"cvlserv_flag"`
  7983. EmpName string `json:"emp_name"`
  7984. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7985. Insutype string `json:"insutype"`
  7986. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7987. PausInsuDate interface{} `json:"paus_insu_date"`
  7988. PsnInsuDate string `json:"psn_insu_date"`
  7989. PsnInsuStas string `json:"psn_insu_stas"`
  7990. PsnType string `json:"psn_type"`
  7991. } `json:"insuinfo"`
  7992. } `json:"output"`
  7993. RefmsgTime string `json:"refmsg_time"`
  7994. RespondTime string `json:"respond_time"`
  7995. Signtype interface{} `json:"signtype"`
  7996. WarnInfo interface{} `json:"warn_info"`
  7997. }
  7998. type ResultThree struct {
  7999. Cainfo interface{} `json:"cainfo"`
  8000. ErrMsg interface{} `json:"err_msg"`
  8001. InfRefmsgid string `json:"inf_refmsgid"`
  8002. Infcode int64 `json:"infcode"`
  8003. Output struct {
  8004. Data struct {
  8005. IptOtpNo string `json:"ipt_otp_no"`
  8006. MdtrtID string `json:"mdtrt_id"`
  8007. PsnNo string `json:"psn_no"`
  8008. } `json:"data"`
  8009. } `json:"output"`
  8010. RefmsgTime string `json:"refmsg_time"`
  8011. RespondTime string `json:"respond_time"`
  8012. Signtype interface{} `json:"signtype"`
  8013. WarnMsg interface{} `json:"warn_msg"`
  8014. }
  8015. type ResultFour struct {
  8016. Cainfo string `json:"cainfo"`
  8017. ErrMsg string `json:"err_msg"`
  8018. InfRefmsgid string `json:"inf_refmsgid"`
  8019. Infcode int64 `json:"infcode"`
  8020. Output struct {
  8021. Result []struct {
  8022. BasMednFlag string `json:"bas_medn_flag"`
  8023. ChldMedcFlag string `json:"chld_medc_flag"`
  8024. ChrgitmLv string `json:"chrgitm_lv"`
  8025. Cnt float64 `json:"cnt"`
  8026. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8027. DrtReimFlag string `json:"drt_reim_flag"`
  8028. FeedetlSn string `json:"feedetl_sn"`
  8029. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8030. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8031. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8032. ListSpItemFlag string `json:"list_sp_item_flag"`
  8033. LmtUsedFlag string `json:"lmt_used_flag"`
  8034. MedChrgitmType string `json:"med_chrgitm_type"`
  8035. Memo string `json:"memo"`
  8036. OverlmtAmt float64 `json:"overlmt_amt"`
  8037. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8038. Pric float64 `json:"pric"`
  8039. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8040. SelfpayProp float64 `json:"selfpay_prop"`
  8041. } `json:"result"`
  8042. } `json:"output"`
  8043. RefmsgTime string `json:"refmsg_time"`
  8044. RespondTime string `json:"respond_time"`
  8045. Signtype string `json:"signtype"`
  8046. WarnMsg string `json:"warn_msg"`
  8047. }
  8048. type ResultFive struct {
  8049. Insutype string `json:"insutype"`
  8050. }
  8051. type ResultSix struct {
  8052. Cainfo interface{} `json:"cainfo"`
  8053. ErrMsg interface{} `json:"err_msg"`
  8054. InfRefmsgid string `json:"inf_refmsgid"`
  8055. Infcode int64 `json:"infcode"`
  8056. Output struct {
  8057. } `json:"output"`
  8058. RefmsgTime string `json:"refmsg_time"`
  8059. RespondTime string `json:"respond_time"`
  8060. Signtype interface{} `json:"signtype"`
  8061. WarnMsg interface{} `json:"warn_msg"`
  8062. }
  8063. type ResultSeven struct {
  8064. Cainfo string `json:"cainfo"`
  8065. ErrMsg string `json:"err_msg"`
  8066. InfRefmsgid string `json:"inf_refmsgid"`
  8067. Infcode int64 `json:"infcode"`
  8068. Output struct {
  8069. Setldetail []interface{} `json:"setldetail"`
  8070. Setlinfo struct {
  8071. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8072. AcctPay float64 `json:"acct_pay"`
  8073. ActPayDedc float64 `json:"act_pay_dedc"`
  8074. Age float64 `json:"age"`
  8075. Balc float64 `json:"balc"`
  8076. Brdy string `json:"brdy"`
  8077. Certno string `json:"certno"`
  8078. ClrOptins string `json:"clr_optins"`
  8079. ClrType string `json:"clr_type"`
  8080. ClrWay string `json:"clr_way"`
  8081. CvlservFlag string `json:"cvlserv_flag"`
  8082. CvlservPay float64 `json:"cvlserv_pay"`
  8083. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8084. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8085. Gend string `json:"gend"`
  8086. HifesPay float64 `json:"hifes_pay"`
  8087. HifmiPay float64 `json:"hifmi_pay"`
  8088. HifobPay float64 `json:"hifob_pay"`
  8089. HifpPay float64 `json:"hifp_pay"`
  8090. HospPartAmt float64 `json:"hosp_part_amt"`
  8091. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8092. Insutype string `json:"insutype"`
  8093. MafPay float64 `json:"maf_pay"`
  8094. MdtrtCertType string `json:"mdtrt_cert_type"`
  8095. MdtrtID string `json:"mdtrt_id"`
  8096. MedType string `json:"med_type"`
  8097. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8098. MedinsSetlID string `json:"medins_setl_id"`
  8099. Naty string `json:"naty"`
  8100. OthPay float64 `json:"oth_pay"`
  8101. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8102. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8103. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8104. PsnCashPay float64 `json:"psn_cash_pay"`
  8105. PsnCertType string `json:"psn_cert_type"`
  8106. PsnName string `json:"psn_name"`
  8107. PsnNo string `json:"psn_no"`
  8108. PsnPartAmt float64 `json:"psn_part_amt"`
  8109. PsnType string `json:"psn_type"`
  8110. SetlID string `json:"setl_id"`
  8111. SetlTime string `json:"setl_time"`
  8112. } `json:"setlinfo"`
  8113. } `json:"output"`
  8114. RefmsgTime string `json:"refmsg_time"`
  8115. RespondTime string `json:"respond_time"`
  8116. Signtype interface{} `json:"signtype"`
  8117. WarnMsg interface{} `json:"warn_msg"`
  8118. }
  8119. type ResultEight struct {
  8120. Cainfo string `json:"cainfo"`
  8121. ErrMsg string `json:"err_msg"`
  8122. InfRefmsgid string `json:"inf_refmsgid"`
  8123. Infcode int64 `json:"infcode"`
  8124. Output struct {
  8125. Stmtinfo struct {
  8126. SetlOptins string `json:"setl_optins"`
  8127. StmtRslt string `json:"stmt_rslt"`
  8128. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8129. } `json:"stmtinfo"`
  8130. } `json:"output"`
  8131. RefmsgTime string `json:"refmsg_time"`
  8132. RespondTime string `json:"respond_time"`
  8133. Signtype interface{} `json:"signtype"`
  8134. WarnMsg interface{} `json:"warn_msg"`
  8135. }
  8136. type ResultNine struct {
  8137. Cainfo string `json:"cainfo"`
  8138. ErrMsg string `json:"err_msg"`
  8139. InfRefmsgid string `json:"inf_refmsgid"`
  8140. Infcode int64 `json:"infcode"`
  8141. Output struct {
  8142. FileQuryNo string `json:"file_qury_no"`
  8143. } `json:"output"`
  8144. RefmsgTime string `json:"refmsg_time"`
  8145. RespondTime string `json:"respond_time"`
  8146. Signtype interface{} `json:"signtype"`
  8147. WarnMsg interface{} `json:"warn_msg"`
  8148. }
  8149. type ResultTen struct {
  8150. Cainfo string `json:"cainfo"`
  8151. ErrMsg string `json:"err_msg"`
  8152. InfRefmsgid string `json:"inf_refmsgid"`
  8153. Infcode int64 `json:"infcode"`
  8154. Output struct {
  8155. DldEndtime string `json:"dld_endtime"`
  8156. FileQuryNo string `json:"file_qury_no"`
  8157. Filename string `json:"filename"`
  8158. } `json:"output"`
  8159. RefmsgTime string `json:"refmsg_time"`
  8160. RespondTime string `json:"respond_time"`
  8161. Signtype interface{} `json:"signtype"`
  8162. WarnMsg interface{} `json:"warn_msg"`
  8163. }
  8164. type ResultEleven struct {
  8165. Cainfo string `json:"cainfo"`
  8166. ErrMsg string `json:"err_msg"`
  8167. InfRefmsgid string `json:"inf_refmsgid"`
  8168. Infcode int64 `json:"infcode"`
  8169. Output struct {
  8170. Setlinfo struct {
  8171. FixmedinsName string `json:"fixmedins_name"`
  8172. FixmedinsCode string `json:"fixmedins_code"`
  8173. PsnNo string `json:"psn_no"`
  8174. PsnName string `json:"psn_name"`
  8175. HifobPay float64 `json:"hifob_pay"`
  8176. Gend string `json:"gend"`
  8177. Brdy string `json:"brdy"`
  8178. PsnCertType string `json:"psn_cert_type"`
  8179. PsnType string `json:"psn_type"`
  8180. EmpName string `json:"emp_name"`
  8181. Certno string `json:"certno"`
  8182. Insutype string `json:"insutype"`
  8183. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8184. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8185. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8186. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8187. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8188. ActPayDedc float64 `json:"act_pay_dedc"`
  8189. HifpPay float64 `json:"hifp_pay"`
  8190. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8191. CvlservPay float64 `json:"cvlserv_pay"`
  8192. HifesPay float64 `json:"hifes_pay"`
  8193. HifmiPay float64 `json:"hifmi_pay"`
  8194. MafPay float64 `json:"maf_pay"`
  8195. OthPay float64 `json:"oth_pay"`
  8196. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8197. PsnPay float64 `json:"psn_pay"`
  8198. AcctPay float64 `json:"acct_pay"`
  8199. CashPayamt float64 `json:"cash_payamt"`
  8200. Balc float64 `json:"balc"`
  8201. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8202. MedinsSetlId string `json:"medins_setl_id"`
  8203. RefdSetlFlag string `json:"refd_setl_flag"`
  8204. SetlTime string `json:"setl_time"`
  8205. MedType string `json:"med_type"`
  8206. } `json:"setlinfo"`
  8207. } `json:"output"`
  8208. RefmsgTime string `json:"refmsg_time"`
  8209. RespondTime string `json:"respond_time"`
  8210. Signtype interface{} `json:"signtype"`
  8211. WarnMsg interface{} `json:"warn_msg"`
  8212. }
  8213. type Custom struct {
  8214. DetItemFeeSumamt string
  8215. Cut string
  8216. FeedetlSn string
  8217. Price string
  8218. MedListCodg string
  8219. Type int64
  8220. AdviceId int64
  8221. ProjectId int64
  8222. ItemId int64
  8223. }
  8224. // 获取个人信息----挂号-----上传就诊信息
  8225. func (c *HisApiController) GetRegisterInfo() {
  8226. id, _ := c.GetInt64("id")
  8227. record_time := c.GetString("record_time")
  8228. settlementValue, _ := c.GetInt64("settlement_value")
  8229. medical_insurance_card := c.GetString("medical_insurance_card")
  8230. name := c.GetString("name")
  8231. id_card_type, _ := c.GetInt64("id_card_type")
  8232. certificates, _ := c.GetInt64("certificates")
  8233. medical_care, _ := c.GetInt64("medical_care")
  8234. birthday := c.GetString("birthday")
  8235. age, _ := c.GetInt64("age")
  8236. id_card := c.GetString("id_card")
  8237. register_type, _ := c.GetInt64("register")
  8238. doctor, _ := c.GetInt64("doctor")
  8239. department, _ := c.GetInt64("department")
  8240. gender, _ := c.GetInt64("sex")
  8241. phone := c.GetString("phone")
  8242. registration_fee, _ := c.GetFloat("registration_fee")
  8243. medical_expenses, _ := c.GetFloat("medical_expenses")
  8244. social_type, _ := c.GetInt64("social_type")
  8245. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8246. diagnosis_ids := c.GetString("diagnosis")
  8247. sick_type, _ := c.GetInt64("sick_type")
  8248. reg_type := c.GetString("p_type")
  8249. timeLayout := "2006-01-02"
  8250. loc, _ := time.LoadLocation("Local")
  8251. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8252. birthUnix := birthdays.Unix()
  8253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8254. if err != nil {
  8255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8256. return
  8257. }
  8258. recordDateTime := theTime.Unix()
  8259. adminInfo := c.GetAdminUserInfo()
  8260. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8261. if tempPatient.ID == 0 {
  8262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8263. return
  8264. }
  8265. var patient service.Patients
  8266. if id == 0 {
  8267. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8268. } else {
  8269. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8270. }
  8271. if patient.ID == 0 {
  8272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8273. return
  8274. }
  8275. if len(patient.IdCardNo) == 0 {
  8276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8277. return
  8278. }
  8279. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8280. if len(his) >= 1 {
  8281. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8282. if len(his) >= 1 && order.ID == 0 {
  8283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8284. return
  8285. }
  8286. }
  8287. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8288. fmt.Println(timeStr)
  8289. timeArr := strings.Split(timeStr, " ")
  8290. fmt.Println(timeArr)
  8291. timeArrTwo := strings.Split(timeArr[0], "-")
  8292. timeArrThree := strings.Split(timeArr[1], ":")
  8293. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8294. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8295. if len(lists) == 0 {
  8296. var hisPatient models.XtHisPatient
  8297. hisPatient = models.XtHisPatient{
  8298. Name: name,
  8299. Age: age,
  8300. Gender: gender,
  8301. Birthday: birthUnix,
  8302. Phone: phone,
  8303. MedicalTreatmentType: medical_care,
  8304. IdType: certificates,
  8305. IdCardNo: id_card,
  8306. BalanceAccountsType: settlementValue,
  8307. SocialType: social_type,
  8308. MedicalInsuranceNumber: medical_insurance_card,
  8309. RegisterType: register_type,
  8310. RegisterCost: registration_fee,
  8311. TreatmentCost: medical_expenses,
  8312. AdminUserId: adminInfo.AdminUser.Id,
  8313. UserOrgId: adminInfo.CurrentOrgId,
  8314. Status: 1,
  8315. RecordDate: recordDateTime,
  8316. IsReturn: 1,
  8317. PatientId: patient.ID,
  8318. Ctime: time.Now().Unix(),
  8319. Mtime: time.Now().Unix(),
  8320. Number: str,
  8321. IdCardType: id_card_type,
  8322. Departments: department,
  8323. Doctor: doctor,
  8324. PType: reg_type,
  8325. Diagnosis: diagnosis_ids,
  8326. SickType: sick_type,
  8327. }
  8328. service.CreateHisPatient(&hisPatient)
  8329. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8330. c.ServeSuccessJSON(map[string]interface{}{
  8331. "his_info": hisPatient,
  8332. })
  8333. } else {
  8334. //chrgBchno := rand.Intn(1000000) + 10000
  8335. var hisPatient models.XtHisPatient
  8336. hisPatient = models.XtHisPatient{
  8337. Name: name,
  8338. Age: age,
  8339. Gender: gender,
  8340. Birthday: birthUnix,
  8341. Phone: phone,
  8342. MedicalTreatmentType: medical_care,
  8343. IdType: certificates,
  8344. IdCardNo: id_card,
  8345. BalanceAccountsType: settlementValue,
  8346. SocialType: social_type,
  8347. MedicalInsuranceNumber: medical_insurance_card,
  8348. RegisterType: register_type,
  8349. RegisterCost: registration_fee,
  8350. TreatmentCost: medical_expenses,
  8351. AdminUserId: adminInfo.AdminUser.Id,
  8352. UserOrgId: adminInfo.CurrentOrgId,
  8353. Status: 1,
  8354. RecordDate: recordDateTime,
  8355. IsReturn: 1,
  8356. PatientId: patient.ID,
  8357. Ctime: time.Now().Unix(),
  8358. Mtime: time.Now().Unix(),
  8359. Number: str,
  8360. IdCardType: id_card_type,
  8361. Departments: department,
  8362. Doctor: doctor,
  8363. PType: reg_type,
  8364. Diagnosis: diagnosis_ids,
  8365. SickType: sick_type,
  8366. }
  8367. service.CreateHisPatient(&hisPatient)
  8368. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8369. c.ServeSuccessJSON(map[string]interface{}{
  8370. "his_info": hisPatient,
  8371. })
  8372. }
  8373. }
  8374. // 上传明细----结算
  8375. func (c *HisApiController) GetUploadInfo() {
  8376. id, _ := c.GetInt64("id")
  8377. record_time := c.GetString("record_time")
  8378. his_patient_id, _ := c.GetInt64("his_patient_id")
  8379. oth_desc := c.GetString("oth_desc")
  8380. pay_way, _ := c.GetInt64("pay_way")
  8381. pay_ways := c.GetString("pay_ways")
  8382. pay_price, _ := c.GetFloat("pay_price")
  8383. pay_card_no := c.GetString("pay_card_no")
  8384. discount_price, _ := c.GetFloat("discount_price")
  8385. preferential_price, _ := c.GetFloat("preferential_price")
  8386. reality_price, _ := c.GetFloat("reality_price")
  8387. found_price, _ := c.GetFloat("found_price")
  8388. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8389. private_price, _ := c.GetFloat("private_price")
  8390. timeLayout := "2006-01-02"
  8391. loc, _ := time.LoadLocation("Local")
  8392. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8393. fapiao_code := c.GetString("fapiao_code")
  8394. fapiao_number := c.GetString("fapiao_number")
  8395. diagnosis_id := c.GetString("diagnosis")
  8396. sick_type, _ := c.GetInt64("sick_type")
  8397. reg_type, _ := c.GetInt64("p_type")
  8398. order_id, _ := c.GetInt64("order_id")
  8399. cash_pay := c.GetString("cash_pay")
  8400. wechat_pay := c.GetString("wechat_pay")
  8401. ali_pay := c.GetString("ali_pay")
  8402. jifen_pay := c.GetString("jifen_pay")
  8403. band_card_pay := c.GetString("band_card_pay")
  8404. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8405. tmp_decimal := c.GetString("tmp_decimal")
  8406. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8407. var decimal float64 //本次使用的押金
  8408. var errmsg error
  8409. tx := service.XTWriteDB().Begin() //开了事务
  8410. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8411. defer func() {
  8412. if errmsg != nil {
  8413. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8414. tx.Rollback()
  8415. } else {
  8416. tx.Commit()
  8417. }
  8418. }()
  8419. fmt.Println("dec_way", dec_way)
  8420. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8421. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8422. return
  8423. }
  8424. if len(tmp_decimal) > 0 {
  8425. if tmp_decimal[0] == 45 {
  8426. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8427. return
  8428. }
  8429. }
  8430. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8431. fmt.Println(errs)
  8432. decimal = tt
  8433. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8434. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8435. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8436. if err != nil {
  8437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8438. return
  8439. }
  8440. recordDateTime := theTime.Unix()
  8441. adminUser := c.GetAdminUserInfo()
  8442. var prescriptions []*models.HisPrescription
  8443. var prescriptionsOne []*models.HisPrescription
  8444. var start_time int64
  8445. var end_time int64
  8446. ids_str := c.GetString("ids")
  8447. ids_arr := strings.Split(ids_str, ",")
  8448. if tempOrder.ID == 0 {
  8449. if settle_accounts_type == 1 { //日结
  8450. fmt.Println(reg_type)
  8451. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8452. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8453. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8454. } else {
  8455. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8456. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8457. }
  8458. } else { //月结
  8459. start_time_str := c.GetString("start_time")
  8460. end_time_str := c.GetString("end_time")
  8461. timeLayout := "2006-01-02"
  8462. loc, _ := time.LoadLocation("Local")
  8463. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8464. if err != nil {
  8465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8466. return
  8467. }
  8468. recordStartTime := theStartTime.Unix()
  8469. start_time = recordStartTime
  8470. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8471. if err != nil {
  8472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8473. return
  8474. }
  8475. recordEndTime := theEndTime.Unix()
  8476. end_time = recordEndTime
  8477. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8478. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8479. }
  8480. var goods []*models.DialysisBeforePrepareGoods
  8481. var newGoods []*models.NewDialysisBeforePrepareGoods
  8482. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8483. var infos []*models.HisDoctorAdviceInfo
  8484. var infoList []*models.HisDoctorAdviceInfo
  8485. var hisAdvice []*models.HisDoctorAdviceInfo
  8486. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8487. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8488. //判断库存不足
  8489. //结算出库开关
  8490. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8491. if settConfig.IsOpen == 1 {
  8492. //判断库存的地方
  8493. for _, info := range prescriptions {
  8494. if info.Type == 1 {
  8495. infos = append(infos, info.HisDoctorAdviceInfo...)
  8496. }
  8497. if info.Type == 2 {
  8498. for _, sumItem := range info.HisPrescriptionProject {
  8499. if sumItem.Type == 3 {
  8500. var good models.DialysisBeforePrepareGoods
  8501. var newGood models.NewDialysisBeforePrepareGoods
  8502. good.GoodId = sumItem.GoodInfo.ID
  8503. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8504. count, _ := strconv.Atoi(sumItem.Count)
  8505. good.Count = int64(count)
  8506. good.StorehouseId = houseConfig.StorehouseOutInfo
  8507. good.ProjectId = sumItem.ID
  8508. goods = append(goods, &good)
  8509. newGood.GoodId = sumItem.GoodInfo.ID
  8510. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8511. count2, _ := strconv.Atoi(sumItem.Count)
  8512. newGood.Count = int64(count2)
  8513. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8514. newGood.ProjectId = sumItem.ID
  8515. newGoods = append(newGoods, &newGood)
  8516. }
  8517. }
  8518. }
  8519. }
  8520. for _, info := range prescriptionsOne {
  8521. if info.Type == 1 {
  8522. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8523. }
  8524. if info.Type == 2 {
  8525. for _, sumItem := range info.HisPrescriptionProject {
  8526. if sumItem.Type == 3 {
  8527. var newGood models.NewDialysisBeforePrepareGoods
  8528. newGood.GoodId = sumItem.GoodInfo.ID
  8529. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8530. count2, _ := strconv.Atoi(sumItem.Count)
  8531. newGood.Count = int64(count2)
  8532. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8533. newGood.ProjectId = sumItem.ID
  8534. newGoodOne = append(newGoodOne, &newGood)
  8535. }
  8536. }
  8537. }
  8538. }
  8539. //判断
  8540. for _, itemOne := range infos {
  8541. for _, itemTwo := range hisAdvice {
  8542. if itemOne.DrugId == itemTwo.DrugId {
  8543. itemTwo.Child = append(itemTwo.Child, itemOne)
  8544. }
  8545. }
  8546. }
  8547. for _, itemTwo := range hisAdvice {
  8548. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8549. var sum_out_count int64
  8550. for _, itemThree := range itemTwo.Child {
  8551. var prescribing_number int64
  8552. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8553. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8554. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8555. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8556. }
  8557. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8558. prescribing_number = parseIntPrescribingNumber
  8559. }
  8560. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8561. prescribing_number = parseIntPrescribingNumber
  8562. }
  8563. sum_out_count += prescribing_number
  8564. }
  8565. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8566. if sum_out_count > drugStockOut.FlushCount {
  8567. c.ServeSuccessJSON(map[string]interface{}{
  8568. "msg": "2",
  8569. "drug": medical,
  8570. })
  8571. return
  8572. }
  8573. }
  8574. for _, itemOne := range newGoods {
  8575. for _, item := range newGoodOne {
  8576. if itemOne.GoodId == item.GoodId {
  8577. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8578. }
  8579. }
  8580. }
  8581. for _, item := range newGoodOne {
  8582. var sum_out_count_one int64
  8583. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8584. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8585. sum_out_count_one += itemOne.Count
  8586. }
  8587. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8588. fmt.Println("sum_out_count_one", sum_out_count_one)
  8589. fmt.Println("list.FlushCount", list.FlushCount)
  8590. if sum_out_count_one > list.FlushCount {
  8591. c.ServeSuccessJSON(map[string]interface{}{
  8592. "msg": "3",
  8593. "good": good,
  8594. })
  8595. return
  8596. }
  8597. }
  8598. }
  8599. timestamp := time.Now().Unix()
  8600. tempTime := time.Unix(timestamp, 0)
  8601. timeFormat := tempTime.Format("20060102150405")
  8602. chrgBchno := rand.Intn(100000) + 10000
  8603. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8604. strconv.FormatInt(his.PatientId, 10)
  8605. var ids []int64
  8606. for _, item := range prescriptions {
  8607. ids = append(ids, item.ID)
  8608. }
  8609. var total float64
  8610. for _, item := range prescriptions {
  8611. fmt.Println(item)
  8612. if item.Type == 1 { //药品
  8613. for _, subItem := range item.HisDoctorAdviceInfo {
  8614. total = total + (subItem.Price * subItem.PrescribingNumber)
  8615. }
  8616. }
  8617. if item.Type == 2 { //项目
  8618. for _, subItem := range item.HisPrescriptionProject {
  8619. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8620. total = total + (subItem.Price * cnt)
  8621. }
  8622. }
  8623. for _, subItem := range item.HisAdditionalCharge {
  8624. total = total + (subItem.Price * float64(subItem.Count))
  8625. }
  8626. }
  8627. if reg_type == 1111 || reg_type == 1112 {
  8628. reg_type = 11
  8629. }
  8630. tm := time.Unix(time.Now().Unix(), 0)
  8631. allTotal := fmt.Sprintf("%.4f", total)
  8632. totals, _ := strconv.ParseFloat(allTotal, 64)
  8633. order := &models.HisOrder{
  8634. UserOrgId: adminUser.CurrentOrgId,
  8635. HisPatientId: his.ID,
  8636. PatientId: id,
  8637. SettleAccountsDate: recordDateTime,
  8638. Ctime: time.Now().Unix(),
  8639. Mtime: time.Now().Unix(),
  8640. Status: 1,
  8641. OrderStatus: 2,
  8642. MdtrtId: his.Number,
  8643. Number: chrg_bchno,
  8644. MedfeeSumamt: totals,
  8645. PayWay: pay_way,
  8646. PayWays: pay_ways,
  8647. PayPrice: pay_price,
  8648. MedType: strconv.Itoa(int(reg_type)),
  8649. PayCardNo: pay_card_no,
  8650. DiscountPrice: discount_price,
  8651. PreferentialPrice: preferential_price,
  8652. RealityPrice: reality_price,
  8653. FoundPrice: found_price,
  8654. MedicalInsurancePrice: medical_insurance_price,
  8655. PrivatePrice: private_price,
  8656. SettleEndTime: end_time,
  8657. SettleStartTime: start_time,
  8658. PsnPartAmt: totals,
  8659. PsnCashPay: totals,
  8660. SettleType: settle_accounts_type,
  8661. FaPiaoCode: fapiao_code,
  8662. FaPiaoNumber: fapiao_number,
  8663. Diagnosis: diagnosis_id,
  8664. PType: 2,
  8665. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8666. Decimal: decimal,
  8667. OthDesc: oth_desc,
  8668. CashPay: cash_pay,
  8669. WechatPay: wechat_pay,
  8670. AliPay: ali_pay,
  8671. JifenPay: jifen_pay,
  8672. BandCardPay: band_card_pay,
  8673. Creator: adminUser.AdminUser.Id,
  8674. }
  8675. err = service.CreateOrderTX(order, tx)
  8676. if err != nil {
  8677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8678. return
  8679. }
  8680. var customs []*Custom
  8681. for _, item := range prescriptions {
  8682. if item.Type == 1 { //药品a
  8683. for _, subItem := range item.HisDoctorAdviceInfo {
  8684. cus := &Custom{
  8685. AdviceId: subItem.ID,
  8686. ProjectId: 0,
  8687. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8688. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8689. FeedetlSn: subItem.FeedetlSn,
  8690. Price: fmt.Sprintf("%.4f", subItem.Price),
  8691. MedListCodg: subItem.MedListCodg,
  8692. Type: 1,
  8693. }
  8694. customs = append(customs, cus)
  8695. }
  8696. }
  8697. if item.Type == 2 { //项目
  8698. for _, subItem := range item.HisPrescriptionProject {
  8699. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8700. cus := &Custom{
  8701. AdviceId: 0,
  8702. ProjectId: subItem.ID,
  8703. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8704. Cut: fmt.Sprintf("%.4f", cnt),
  8705. FeedetlSn: subItem.FeedetlSn,
  8706. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8707. MedListCodg: subItem.MedListCodg,
  8708. Type: 2,
  8709. }
  8710. customs = append(customs, cus)
  8711. }
  8712. }
  8713. for _, item := range item.HisAdditionalCharge {
  8714. cus := &Custom{
  8715. ItemId: item.ID,
  8716. AdviceId: 0,
  8717. ProjectId: 0,
  8718. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8719. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8720. FeedetlSn: item.FeedetlSn,
  8721. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8722. MedListCodg: item.XtHisAddtionConfig.Code,
  8723. Type: 3,
  8724. }
  8725. customs = append(customs, cus)
  8726. }
  8727. }
  8728. for _, item := range customs {
  8729. var advice_id int64 = 0
  8730. var project_id int64 = 0
  8731. var item_id int64 = 0
  8732. var types int64 = 0
  8733. if item.Type == 1 {
  8734. advice_id = item.AdviceId
  8735. project_id = 0
  8736. item_id = 0
  8737. } else if item.Type == 2 {
  8738. advice_id = 0
  8739. item_id = 0
  8740. project_id = item.ProjectId
  8741. } else if item.Type == 3 {
  8742. advice_id = 0
  8743. item_id = item.ItemId
  8744. project_id = 0
  8745. }
  8746. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8747. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8748. pric, _ := strconv.ParseFloat(item.Price, 32)
  8749. info := &models.HisOrderInfo{
  8750. OrderNumber: order.Number,
  8751. UploadDate: time.Now().Unix(),
  8752. AdviceId: advice_id,
  8753. DetItemFeeSumamt: detItemFeeSumamt,
  8754. Cnt: cut,
  8755. Pric: pric,
  8756. PatientId: id,
  8757. Status: 1,
  8758. Mtime: time.Now().Unix(),
  8759. Ctime: time.Now().Unix(),
  8760. UserOrgId: adminUser.CurrentOrgId,
  8761. HisPatientId: his.ID,
  8762. OrderId: order.ID,
  8763. ProjectId: project_id,
  8764. Type: types,
  8765. ItemId: item_id,
  8766. }
  8767. service.CreateOrderInfoTX(info, tx)
  8768. }
  8769. his.Diagnosis = diagnosis_id
  8770. his.SickType = sick_type
  8771. his.RegisterType = reg_type
  8772. his.MedicalTreatmentType = reg_type
  8773. service.UpdataHisPateintTX(&his, tx)
  8774. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8775. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8776. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8777. //判断是否使用了押金
  8778. if dec_way == "true" {
  8779. tmpstring := strconv.FormatInt(order.ID, 10)
  8780. //扣押金
  8781. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8782. order.Decimal = decimal
  8783. service.UpDateOrderTwo(order, tx)
  8784. if errmsg != nil {
  8785. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8786. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8787. return
  8788. }
  8789. }
  8790. if err == nil {
  8791. for _, info := range prescriptions {
  8792. if info.Type == 1 {
  8793. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8794. }
  8795. if info.Type == 2 {
  8796. for _, sumItem := range info.HisPrescriptionProject {
  8797. if sumItem.Type == 3 {
  8798. var good models.DialysisBeforePrepareGoods
  8799. var newGood models.NewDialysisBeforePrepareGoods
  8800. var oldGood models.OldDialysisBeforePrepareGoods
  8801. good.GoodId = sumItem.GoodInfo.ID
  8802. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8803. count, _ := strconv.Atoi(sumItem.Count)
  8804. good.Count = int64(count)
  8805. good.StorehouseId = houseConfig.StorehouseOutInfo
  8806. good.ProjectId = sumItem.ID
  8807. good.PatientId = sumItem.PatientId
  8808. goods = append(goods, &good)
  8809. newGood.GoodId = sumItem.GoodInfo.ID
  8810. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8811. count2, _ := strconv.Atoi(sumItem.Count)
  8812. newGood.Count = int64(count2)
  8813. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8814. newGood.ProjectId = sumItem.ID
  8815. newGood.PatientId = sumItem.HisPatientId
  8816. newGoods = append(newGoods, &newGood)
  8817. oldGood.GoodId = sumItem.GoodInfo.ID
  8818. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8819. count3, _ := strconv.Atoi(sumItem.Count)
  8820. oldGood.Count = int64(count3)
  8821. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8822. oldGood.ProjectId = sumItem.ID
  8823. oldGood.RecordDate = sumItem.RecordDate
  8824. oldGood.PatientId = sumItem.HisPatientId
  8825. oldGoods = append(oldGoods, &oldGood)
  8826. }
  8827. }
  8828. }
  8829. }
  8830. if settConfig.IsOpen == 1 {
  8831. for _, item := range infoList {
  8832. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8833. if medical.IsUse == 2 {
  8834. //药品出库
  8835. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8836. //查询默认仓库
  8837. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8838. //查询默认仓库剩余多少库存
  8839. var sum_count int64
  8840. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8841. for _, its := range stockInfo {
  8842. if its.MaxUnit == medical.MaxUnit {
  8843. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8844. }
  8845. sum_count += its.StockMaxNumber + its.StockMinNumber
  8846. }
  8847. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8848. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8849. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8850. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8851. }
  8852. }
  8853. orgId := c.GetAdminUserInfo().CurrentOrgId
  8854. if len(oldGoods) > 0 {
  8855. timeStr := time.Now().Format("2006-01-02")
  8856. timeArr := strings.Split(timeStr, "-")
  8857. total, _ := service.FindAllWarehouseOut(orgId)
  8858. total = total + 1
  8859. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8860. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8861. number = number + total
  8862. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8863. operation_time := time.Now().Unix()
  8864. creater := c.GetAdminUserInfo().AdminUser.Id
  8865. //查询默认出库仓库库存
  8866. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8867. recordDateStr := time.Now().Format("2006-01-02")
  8868. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8869. nowtime := recordDate.Unix()
  8870. warehouseOut := models.WarehouseOut{
  8871. WarehouseOutOrderNumber: warehousing_out_order,
  8872. OperationTime: operation_time,
  8873. OrgId: orgId,
  8874. Creater: creater,
  8875. Ctime: time.Now().Unix(),
  8876. Status: 1,
  8877. WarehouseOutTime: nowtime,
  8878. Type: 1,
  8879. StorehouseId: storeConfig.StorehouseOutInfo,
  8880. IsCheck: 1,
  8881. OrderId: order.ID,
  8882. IsSys: 5,
  8883. }
  8884. //查询是否生成出库单
  8885. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8886. if out.ID == 0 {
  8887. service.AddSigleWarehouseOut(&warehouseOut)
  8888. }
  8889. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8890. for _, item := range oldGoods {
  8891. dialyPrepareOne := models.DialysisBeforePrepare{
  8892. GoodTypeId: item.GoodTypeId,
  8893. GoodId: item.GoodId,
  8894. PatientId: his.PatientId,
  8895. RecordDate: item.RecordDate,
  8896. UserOrgId: adminUser.CurrentOrgId,
  8897. Count: item.Count,
  8898. Ctime: time.Now().Unix(),
  8899. Creater: adminUser.AdminUser.Id,
  8900. CommdityCode: item.CommdityCode,
  8901. Status: 1,
  8902. StorehouseId: houseConfig.StorehouseOutInfo,
  8903. }
  8904. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8905. //非零用
  8906. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8907. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8908. //查询剩余库存
  8909. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8910. var sum_count int64
  8911. for _, item := range goodList {
  8912. sum_count += item.StockCount
  8913. }
  8914. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8915. //耗材
  8916. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8917. }
  8918. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8919. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8920. //查询剩余库存
  8921. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8922. var sum_count int64
  8923. for _, item := range goodList {
  8924. sum_count += item.StockCount
  8925. }
  8926. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8927. //耗材
  8928. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8929. }
  8930. }
  8931. }
  8932. }
  8933. c.ServeSuccessJSON(map[string]interface{}{
  8934. "msg": "结算成功",
  8935. })
  8936. }
  8937. }
  8938. }
  8939. // 退款
  8940. func (c *HisApiController) Refund() {
  8941. order_id, _ := c.GetInt64("order_id")
  8942. order, _ := service.GetHisOrderByID(order_id)
  8943. adminUser := c.GetAdminUserInfo()
  8944. orgid := c.GetAdminUserInfo().CurrentOrgId
  8945. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8946. if err != nil {
  8947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8948. return
  8949. }
  8950. tmp := strconv.FormatInt(order.ID, 10)
  8951. //当押金不为零时产生退费记录
  8952. if order.Decimal != 0 {
  8953. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8954. if err != nil {
  8955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8956. return
  8957. }
  8958. }
  8959. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8960. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8961. var goods []*models.DialysisBeforePrepareGoods
  8962. var newGoods []*models.NewDialysisBeforePrepareGoods
  8963. var infos []*models.HisDoctorAdviceInfo
  8964. for _, info := range orders {
  8965. if info.AdviceId > 0 && info.ProjectId == 0 {
  8966. infos = append(infos, &info.HisDoctorAdviceInfo)
  8967. }
  8968. if info.ProjectId > 0 && info.AdviceId == 0 {
  8969. if info.HisPrescriptionProject.Type == 3 {
  8970. var good models.DialysisBeforePrepareGoods
  8971. var newGood models.NewDialysisBeforePrepareGoods
  8972. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8973. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8974. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8975. good.Count = int64(count)
  8976. good.StorehouseId = houseConfig.StorehouseOutInfo
  8977. good.ProjectId = info.HisPrescriptionProject.ID
  8978. good.PatientId = info.PatientId
  8979. good.OrderId = order_id
  8980. goods = append(goods, &good)
  8981. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8982. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8983. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8984. newGood.Count = int64(count2)
  8985. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8986. newGood.ProjectId = info.HisPrescriptionProject.ID
  8987. newGood.RecordDate = order.SettleAccountsDate
  8988. newGood.UserOrgId = order.UserOrgId
  8989. newGood.PatientId = info.PatientId
  8990. newGood.OrderId = order_id
  8991. newGoods = append(newGoods, &newGood)
  8992. }
  8993. }
  8994. }
  8995. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8996. if settConfig.IsOpen == 1 {
  8997. for _, item := range infos {
  8998. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8999. }
  9000. for _, item := range newGoods {
  9001. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9002. }
  9003. }
  9004. c.ServeSuccessJSON(map[string]interface{}{
  9005. "msg": "退费成功",
  9006. })
  9007. }
  9008. func (c *HisApiController) RefundNumber() {
  9009. his_patient_id, _ := c.GetInt64("id")
  9010. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9011. info.Status = 0
  9012. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9013. if count > 0 {
  9014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9015. return
  9016. }
  9017. err := service.SaveHisPatient(info)
  9018. if err == nil {
  9019. c.ServeSuccessJSON(map[string]interface{}{
  9020. "msg": "退号成功",
  9021. })
  9022. } else {
  9023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9024. return
  9025. }
  9026. }
  9027. func (this *HisApiController) AdditionalCharge() {
  9028. dataBody := make(map[string]interface{}, 0)
  9029. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9030. fmt.Println(err)
  9031. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9032. patient_id := int64(dataBody["patient_id"].(float64))
  9033. medicineData, _ := dataBody["medicineData"].([]interface{})
  9034. adminUserInfo := this.GetAdminUserInfo()
  9035. orgId := adminUserInfo.CurrentOrgId
  9036. admin_user_id := adminUserInfo.AdminUser.Id
  9037. timeStr := time.Now().Format("2006-01-02")
  9038. timeLayout := "2006-01-02 15:04:05"
  9039. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9040. timenow := timeStringToTime.Unix()
  9041. var additionalCharges []*models.HisAdditionalCharge
  9042. for _, item := range medicineData {
  9043. var randNum int
  9044. randNum = rand.Intn(10000) + 1000
  9045. timestamp := time.Now().Unix()
  9046. tempTime := time.Unix(timestamp, 0)
  9047. timeFormat := tempTime.Format("20060102150405")
  9048. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9049. items := item.(map[string]interface{})
  9050. money := items["price"].(string)
  9051. item_id_str := items["item_id"].(string)
  9052. name := items["name"].(string)
  9053. id_str := items["id"].(string)
  9054. moneys, _ := strconv.ParseInt(money, 10, 64)
  9055. monStr := strconv.FormatInt(moneys, 10)
  9056. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9057. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9058. id, _ := strconv.ParseInt(id_str, 10, 64)
  9059. additionalCharge := &models.HisAdditionalCharge{
  9060. ID: id,
  9061. HisPatientId: his_patient_id,
  9062. UserOrgId: orgId,
  9063. PatientId: patient_id,
  9064. RecordDate: timenow,
  9065. Price: monneyStr,
  9066. Status: 1,
  9067. ItemName: name,
  9068. ItemId: item_id,
  9069. AdminUserId: admin_user_id,
  9070. CreatedTime: time.Now().Unix(),
  9071. OrderStatus: 0,
  9072. PrescriptionNumber: "",
  9073. BatchNumber: "",
  9074. FeedetlSn: p_number,
  9075. }
  9076. service.CreateAdditionalCharge(additionalCharge)
  9077. additionalCharges = append(additionalCharges, additionalCharge)
  9078. }
  9079. this.ServeSuccessJSON(map[string]interface{}{
  9080. "msg": "添加成功",
  9081. "additional_charges": additionalCharges,
  9082. })
  9083. }
  9084. func (this *HisApiController) DeleteAddition() {
  9085. id, _ := this.GetInt64("id")
  9086. //TODO 需要判断是否已经结算
  9087. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9088. if err == nil {
  9089. this.ServeSuccessJSON(map[string]interface{}{
  9090. "msg": "删除成功",
  9091. })
  9092. return
  9093. } else {
  9094. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9095. return
  9096. }
  9097. }
  9098. func (this *HisApiController) GetAdminUsers() {
  9099. adminUser := this.GetAdminUserInfo()
  9100. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9101. this.ServeSuccessJSON(map[string]interface{}{
  9102. "doctors": doctors,
  9103. })
  9104. }
  9105. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9106. change_type, _ := this.GetInt64("type", 0)
  9107. record_date := this.GetString("record_time")
  9108. patient_id, _ := this.GetInt64("patient_id", 0)
  9109. p_type, _ := this.GetInt64("p_type", 0)
  9110. timeLayout := "2006-01-02"
  9111. loc, _ := time.LoadLocation("Local")
  9112. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9113. record_time := theAdviceRecordTime.Unix()
  9114. adminUserInfo := this.GetAdminUserInfo()
  9115. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9116. if err == nil {
  9117. if len(prescriptions) == 0 {
  9118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9119. return
  9120. } else {
  9121. this.ServeSuccessJSON(map[string]interface{}{
  9122. "prescriptions": prescriptions,
  9123. })
  9124. return
  9125. }
  9126. } else {
  9127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9128. return
  9129. }
  9130. }
  9131. func (this *HisApiController) GetCallHisPrescription() {
  9132. patient_id, _ := this.GetInt64("patient_id", 0)
  9133. timeLayout := "2006-01-02"
  9134. loc, _ := time.LoadLocation("Local")
  9135. start_time := this.GetString("start_time")
  9136. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9137. end_time := this.GetString("end_time")
  9138. p_type, _ := this.GetInt64("p_type")
  9139. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9140. adminUserInfo := this.GetAdminUserInfo()
  9141. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9142. if err == nil {
  9143. this.ServeSuccessJSON(map[string]interface{}{
  9144. "prescriptions": prescriptions,
  9145. })
  9146. return
  9147. } else {
  9148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9149. return
  9150. }
  9151. }
  9152. func (this *HisApiController) GetHisDayPrescription() {
  9153. timeLayout := "2006-01-02"
  9154. loc, _ := time.LoadLocation("Local")
  9155. start_time := this.GetString("start_time")
  9156. patient_id, _ := this.GetInt64("patient_id", 0)
  9157. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9158. end_time := this.GetString("end_time")
  9159. p_type, _ := this.GetInt64("p_type")
  9160. order_status, _ := this.GetInt64("type")
  9161. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9162. adminUserInfo := this.GetAdminUserInfo()
  9163. var dayHisPrescription []*models.HisPrescription
  9164. var err error
  9165. if order_status == 1 || order_status == 0 {
  9166. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9167. } else if order_status == 2 {
  9168. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9169. }
  9170. var settle_total float64
  9171. for _, item := range dayHisPrescription {
  9172. if len(item.HisPrescriptionProject) > 0 {
  9173. for _, subItem := range item.HisPrescriptionProject {
  9174. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9175. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9176. settle_total = settle_total + total
  9177. }
  9178. }
  9179. if len(item.HisDoctorAdviceInfo) > 0 {
  9180. for _, subItem := range item.HisDoctorAdviceInfo {
  9181. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9182. settle_total = settle_total + total
  9183. }
  9184. }
  9185. }
  9186. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9187. if err == nil {
  9188. this.ServeSuccessJSON(map[string]interface{}{
  9189. "day_prescription": dayHisPrescription,
  9190. "settle_total": settle_total,
  9191. })
  9192. return
  9193. } else {
  9194. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9195. return
  9196. }
  9197. }
  9198. func (c *HisApiController) GetHisChargePatientList() {
  9199. record_date := c.GetString("record_date")
  9200. order_status, _ := c.GetInt64("type")
  9201. sch_type, _ := c.GetInt64("sch_type")
  9202. timeLayout := "2006-01-02"
  9203. loc, _ := time.LoadLocation("Local")
  9204. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9205. if err != nil {
  9206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9207. return
  9208. }
  9209. recordDateTime := theTime.Unix()
  9210. adminInfo := c.GetAdminUserInfo()
  9211. var tempPatients []*service.NewTempPatients
  9212. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9213. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9214. if order_status != 2 {
  9215. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9216. } else {
  9217. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9218. }
  9219. } else {
  9220. if order_status != 2 {
  9221. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9222. } else {
  9223. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9224. }
  9225. }
  9226. var patients []*service.NewTempPatients
  9227. var patients_two []*service.NewTempPatients
  9228. for _, item := range tempPatients {
  9229. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9230. //过滤掉没挂号的和没开处方的
  9231. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9232. patients = append(patients, item)
  9233. }
  9234. //过滤掉没挂号的
  9235. if len(item.HisPatient) > 0 {
  9236. patients_two = append(patients_two, item)
  9237. }
  9238. } else {
  9239. if len(item.HisPrescription) > 0 {
  9240. patients = append(patients, item)
  9241. }
  9242. }
  9243. }
  9244. c.ServeSuccessJSON(map[string]interface{}{
  9245. "list": patients,
  9246. "list_two": patients_two,
  9247. })
  9248. }
  9249. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9250. record_date := c.GetString("record_date")
  9251. timeLayout := "2006-01-02"
  9252. loc, _ := time.LoadLocation("Local")
  9253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9254. if err != nil {
  9255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9256. return
  9257. }
  9258. recordDateTime := theTime.Unix()
  9259. adminUser := c.GetAdminUserInfo()
  9260. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9261. var patients []*service.Patients
  9262. for _, item := range tempPatients {
  9263. if item.HisPatient.ID == 0 {
  9264. patients = append(patients, item)
  9265. }
  9266. }
  9267. c.ServeSuccessJSON(map[string]interface{}{
  9268. "list": patients,
  9269. //"list_two": patients_two,
  9270. })
  9271. }
  9272. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9273. newArr = make([]*service.Patients, 0)
  9274. for i := 0; i < len(patient); i++ {
  9275. repeat := false
  9276. for j := i + 1; j < len(patient); j++ {
  9277. if patient[i].ID == patient[j].ID {
  9278. repeat = true
  9279. break
  9280. }
  9281. }
  9282. if !repeat {
  9283. newArr = append(newArr, patient[i])
  9284. }
  9285. }
  9286. return
  9287. }
  9288. func (c *HisApiController) GetHisChargePatientInfo() {
  9289. patient_id, _ := c.GetInt64("patient_id")
  9290. his_patient_id, _ := c.GetInt64("his_patient_id")
  9291. record_date := c.GetString("record_date")
  9292. //start_time := c.GetString("start_time")
  9293. //end_time := c.GetString("end_time")
  9294. order_status, _ := c.GetInt64("type", 0)
  9295. p_type, _ := c.GetInt64("p_type", 0)
  9296. order_id, _ := c.GetInt64("order_id", 0)
  9297. timeLayout := "2006-01-02"
  9298. loc, _ := time.LoadLocation("Local")
  9299. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9300. if err != nil {
  9301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9302. return
  9303. }
  9304. recordDateTime := theTime.Unix()
  9305. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9306. //if err != nil {
  9307. //
  9308. //}
  9309. //startRecordDateTime := startTime.Unix()
  9310. //
  9311. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9312. //if err != nil {
  9313. //
  9314. //}
  9315. //endRecordDateTime := endTime.Unix()
  9316. admin := c.GetAdminUserInfo()
  9317. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9318. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9319. var prescriptions []*models.HisPrescription
  9320. //var unChargeMonthPrescriptions []*models.HisPrescription
  9321. order, _ := service.GetHisOrderByID(order_id)
  9322. if order_status == 1 || order_status == 0 {
  9323. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9324. } else if order_status == 2 {
  9325. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9326. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9327. }
  9328. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9329. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9330. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9331. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9332. //获取所有科室信息
  9333. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9334. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9335. c.ServeSuccessJSON(map[string]interface{}{
  9336. "his_info": his_patient_info,
  9337. "xt_info": xt_patient_info,
  9338. "prescription": prescriptions,
  9339. "case_history": case_history,
  9340. "info": patientPrescriptionInfo,
  9341. "last_info": lastPatientPrescriptionInfo,
  9342. "order": order,
  9343. "doctors": doctors,
  9344. "department": department,
  9345. "sch": sch,
  9346. })
  9347. return
  9348. }
  9349. func (c *HisApiController) GetAllOrderDetail() {
  9350. order_id, _ := c.GetInt64("id", 0)
  9351. order, _ := service.GetHisOrderByID(order_id)
  9352. if order.ID == 0 {
  9353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9354. return
  9355. }
  9356. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9357. org_id := c.GetAdminUserInfo().CurrentOrgId
  9358. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9359. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9360. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9361. c.ServeSuccessJSON(map[string]interface{}{
  9362. "order": order,
  9363. "order_info": order_info,
  9364. "patient": patient,
  9365. "admin_info": adminInfo,
  9366. "hospital_record": record,
  9367. })
  9368. return
  9369. }
  9370. func (c *HisApiController) GetAllOrderDetailCollect() {
  9371. order_id, _ := c.GetInt64("id", 0)
  9372. order, _ := service.GetHisOrderByID(order_id)
  9373. if order.ID == 0 {
  9374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9375. return
  9376. }
  9377. org_id := c.GetAdminUserInfo().CurrentOrgId
  9378. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9379. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9380. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9381. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9382. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9383. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9384. var bedCostTotal float64 = 0 //床位总费
  9385. //var bedCostSelfTotal float64 = 0 //床位自费
  9386. var operationCostTotal float64 = 0 //手术费
  9387. //var operationCostSelfTotal float64 = 0 //手术费
  9388. var otherCostTotal float64 = 0 //其他费用
  9389. //var otherCostSelfTotal float64 = 0 //其他费用
  9390. var materialCostTotal float64 = 0 //材料费
  9391. //var materialCostSelfTotal float64 = 0 //材料费
  9392. var westernMedicineCostTotal float64 = 0 //西药费
  9393. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9394. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9395. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9396. var checkCostTotal float64 = 0 //检查费
  9397. //var checkCostSelfTotal float64 = 0 //检查费
  9398. var laboratoryCostTotal float64 = 0 //化验费
  9399. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9400. var treatCostTotal float64 = 0 //治疗费用
  9401. //var treatCostSelfTotal float64 = 0 //治疗费用
  9402. var zhenChaCostTotal float64 = 0 //其他费用
  9403. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9404. decimal.DivisionPrecision = 2
  9405. var BalanceAccountsType int64
  9406. if his.ID > 0 {
  9407. BalanceAccountsType = his.BalanceAccountsType
  9408. } else {
  9409. BalanceAccountsType = record.BalanceAccountsType
  9410. }
  9411. if BalanceAccountsType != 2 {
  9412. for _, item := range order_info {
  9413. if org_id == 10215 {
  9414. if item.MedChrgitmType == "01" { //床位费
  9415. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9416. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9417. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9418. }
  9419. if item.MedChrgitmType == "02" { //诊察费
  9420. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9421. //zhenChaCostSelfTotal = zhenChaCostTotal
  9422. }
  9423. if item.MedChrgitmType == "03" { //检查费
  9424. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9425. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9426. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9427. }
  9428. //if item.MedChrgitmType == "02" { //检查费
  9429. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9430. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9431. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9432. //}
  9433. if item.MedChrgitmType == "04" { //化验费
  9434. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9435. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9436. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9437. }
  9438. if item.MedChrgitmType == "05" { //治疗费
  9439. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9440. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9441. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9442. }
  9443. if item.MedChrgitmType == "06" { //手术费
  9444. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9445. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9446. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9447. }
  9448. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9449. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9450. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9451. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9452. }
  9453. if item.MedChrgitmType == "09" { //西药费
  9454. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9455. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9456. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9457. }
  9458. if item.MedChrgitmType == "11" { //中成费
  9459. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9460. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9461. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9462. }
  9463. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9464. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9465. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9466. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9467. }
  9468. } else if org_id == 10188 || org_id == 10217 {
  9469. if item.MedChrgitmType == "01" { //床位费
  9470. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9471. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9472. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9473. }
  9474. if item.MedChrgitmType == "02" { //诊察费
  9475. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9476. //zhenChaCostSelfTotal = zhenChaCostTotal
  9477. }
  9478. if item.MedChrgitmType == "03" { //检查费
  9479. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9480. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9481. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9482. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9483. }
  9484. //if item.MedChrgitmType == "02" { //检查费
  9485. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9486. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9487. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9488. //}
  9489. if item.MedChrgitmType == "04" { //化验费
  9490. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9491. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9492. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9493. }
  9494. if item.MedChrgitmType == "05" { //治疗费
  9495. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9496. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9497. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9498. }
  9499. if item.MedChrgitmType == "06" { //手术费
  9500. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9501. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9502. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9503. }
  9504. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9505. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9506. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9507. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9508. }
  9509. if item.MedChrgitmType == "09" { //西药费
  9510. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9511. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9512. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9513. }
  9514. if item.MedChrgitmType == "11" { //中成费
  9515. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9516. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9517. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9518. }
  9519. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9520. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9521. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9522. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9523. }
  9524. } else {
  9525. if item.MedChrgitmType == "01" { //床位费
  9526. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9527. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9528. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9529. }
  9530. //if item.MedChrgitmType == "02" { //诊察费
  9531. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9532. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9533. //}
  9534. if item.MedChrgitmType == "03" { //检查费
  9535. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9536. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9537. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9538. }
  9539. //if item.MedChrgitmType == "02" { //检查费
  9540. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9541. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9542. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9543. //}
  9544. if item.MedChrgitmType == "04" { //化验费
  9545. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9546. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9547. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9548. }
  9549. if item.MedChrgitmType == "05" { //治疗费
  9550. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9551. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9552. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9553. }
  9554. if item.MedChrgitmType == "06" { //手术费
  9555. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9556. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9557. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9558. }
  9559. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9560. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9561. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9562. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9563. }
  9564. if item.MedChrgitmType == "09" { //西药费
  9565. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9566. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9567. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9568. }
  9569. if item.MedChrgitmType == "11" { //中成费
  9570. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9571. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9572. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9573. }
  9574. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9575. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9576. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9577. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9578. }
  9579. }
  9580. }
  9581. c.ServeSuccessJSON(map[string]interface{}{
  9582. "order": order,
  9583. "order_info": order_info,
  9584. "patient": patient,
  9585. "admin_info": adminInfo,
  9586. "his_hospital": record,
  9587. "bedCostTotal": bedCostTotal,
  9588. "operationCostTotal": operationCostTotal,
  9589. "otherCostTotal": otherCostTotal,
  9590. "materialCostTotal": materialCostTotal,
  9591. "westernMedicineCostTotal": westernMedicineCostTotal,
  9592. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9593. "checkCostTotal": checkCostTotal,
  9594. "zhenChaCostTotal": zhenChaCostTotal,
  9595. "laboratoryCostTotal": laboratoryCostTotal,
  9596. "treatCostTotal": treatCostTotal,
  9597. })
  9598. } else {
  9599. for _, item := range order_info {
  9600. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9601. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9602. item.MedChrgitmType = "09"
  9603. }
  9604. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9605. if item.HisPrescriptionProject.Type == 2 {
  9606. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9607. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9608. case 0:
  9609. item.MedChrgitmType = "0"
  9610. break
  9611. case 1:
  9612. item.MedChrgitmType = "14"
  9613. break
  9614. case 2:
  9615. item.MedChrgitmType = "05"
  9616. break
  9617. case 3:
  9618. item.MedChrgitmType = "03"
  9619. break
  9620. case 4:
  9621. item.MedChrgitmType = "03"
  9622. break
  9623. case 5:
  9624. item.MedChrgitmType = "08"
  9625. break
  9626. case 6:
  9627. item.MedChrgitmType = "14"
  9628. break
  9629. case 7:
  9630. item.MedChrgitmType = "14"
  9631. break
  9632. case 8:
  9633. item.MedChrgitmType = "03"
  9634. break
  9635. case 9:
  9636. item.MedChrgitmType = "14"
  9637. break
  9638. case 10:
  9639. item.MedChrgitmType = "14"
  9640. break
  9641. case 11:
  9642. item.MedChrgitmType = "06"
  9643. break
  9644. case 12:
  9645. item.MedChrgitmType = "12"
  9646. break
  9647. case 13:
  9648. item.MedChrgitmType = "01"
  9649. break
  9650. case 14:
  9651. item.MedChrgitmType = "04"
  9652. break
  9653. case 15:
  9654. item.MedChrgitmType = "14"
  9655. break
  9656. }
  9657. } else {
  9658. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9659. case 1:
  9660. item.MedChrgitmType = "14"
  9661. break
  9662. case 2:
  9663. item.MedChrgitmType = "05"
  9664. break
  9665. case 3:
  9666. item.MedChrgitmType = "04"
  9667. break
  9668. case 4:
  9669. item.MedChrgitmType = "14"
  9670. break
  9671. case 5:
  9672. item.MedChrgitmType = "08"
  9673. break
  9674. case 6:
  9675. item.MedChrgitmType = "14"
  9676. break
  9677. case 7:
  9678. item.MedChrgitmType = "14"
  9679. break
  9680. case 8:
  9681. item.MedChrgitmType = "03"
  9682. break
  9683. case 9:
  9684. item.MedChrgitmType = "14"
  9685. break
  9686. }
  9687. }
  9688. } else if item.HisPrescriptionProject.Type == 3 {
  9689. item.MedChrgitmType = "08"
  9690. }
  9691. }
  9692. }
  9693. for _, item := range order_info {
  9694. if org_id == 10215 {
  9695. if item.MedChrgitmType == "01" { //床位费
  9696. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9697. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9698. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9699. }
  9700. if item.MedChrgitmType == "02" { //诊察费
  9701. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9702. //zhenChaCostSelfTotal = zhenChaCostTotal
  9703. }
  9704. if item.MedChrgitmType == "03" { //检查费
  9705. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9706. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9707. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9708. }
  9709. //if item.MedChrgitmType == "02" { //检查费
  9710. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9711. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9712. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9713. //}
  9714. if item.MedChrgitmType == "04" { //化验费
  9715. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9716. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9717. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9718. }
  9719. if item.MedChrgitmType == "05" { //治疗费
  9720. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9721. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9722. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9723. }
  9724. if item.MedChrgitmType == "06" { //手术费
  9725. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9726. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9727. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9728. }
  9729. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9730. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9731. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9732. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9733. }
  9734. if item.MedChrgitmType == "09" { //西药费
  9735. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9736. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9737. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9738. }
  9739. if item.MedChrgitmType == "11" { //中成费
  9740. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9741. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9742. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9743. }
  9744. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9745. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9746. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9747. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9748. }
  9749. } else {
  9750. if item.MedChrgitmType == "01" { //床位费
  9751. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9752. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9753. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9754. }
  9755. //if item.MedChrgitmType == "02" { //诊察费
  9756. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9757. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9758. //}
  9759. if item.MedChrgitmType == "03" { //检查费
  9760. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9761. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9762. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9763. }
  9764. //if item.MedChrgitmType == "02" { //检查费
  9765. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9766. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9767. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9768. //}
  9769. if item.MedChrgitmType == "04" { //化验费
  9770. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9771. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9772. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9773. }
  9774. if item.MedChrgitmType == "05" { //治疗费
  9775. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9776. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9777. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9778. }
  9779. if item.MedChrgitmType == "06" { //手术费
  9780. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9781. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9782. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9783. }
  9784. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9785. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9786. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9787. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9788. }
  9789. if item.MedChrgitmType == "09" { //西药费
  9790. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9791. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9792. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9793. }
  9794. if item.MedChrgitmType == "11" { //中成费
  9795. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9796. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9797. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9798. }
  9799. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9800. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9801. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9802. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9803. }
  9804. }
  9805. }
  9806. c.ServeSuccessJSON(map[string]interface{}{
  9807. "order": order,
  9808. "order_info": order_info,
  9809. "patient": patient,
  9810. "admin_info": adminInfo,
  9811. "his_hospital": record,
  9812. "bedCostTotal": bedCostTotal,
  9813. "operationCostTotal": operationCostTotal,
  9814. "otherCostTotal": otherCostTotal,
  9815. "materialCostTotal": materialCostTotal,
  9816. "westernMedicineCostTotal": westernMedicineCostTotal,
  9817. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9818. "checkCostTotal": checkCostTotal,
  9819. "zhenChaCostTotal": zhenChaCostTotal,
  9820. "laboratoryCostTotal": laboratoryCostTotal,
  9821. "treatCostTotal": treatCostTotal,
  9822. })
  9823. }
  9824. }
  9825. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9826. page, _ := c.GetInt64("page")
  9827. limit, _ := c.GetInt64("limit")
  9828. keywords := c.GetString("keywords")
  9829. start_time := c.GetString("start_time")
  9830. end_time := c.GetString("end_time")
  9831. //clr_type := c.GetString("clr_type")
  9832. insutype := c.GetString("insutype")
  9833. timeLayout := "2006-01-02"
  9834. loc, _ := time.LoadLocation("Local")
  9835. var theStartTIme int64
  9836. if len(start_time) > 0 {
  9837. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9838. theStartTIme = theTime.Unix()
  9839. }
  9840. var theEndtTIme int64
  9841. if len(end_time) > 0 {
  9842. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9843. theEndtTIme = theTime.Unix()
  9844. }
  9845. if page <= 0 {
  9846. page = 1
  9847. }
  9848. if limit <= 0 {
  9849. limit = 10
  9850. }
  9851. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9852. c.ServeSuccessJSON(map[string]interface{}{
  9853. "total": total,
  9854. "list": list,
  9855. })
  9856. return
  9857. }
  9858. func (c *HisApiController) GetPutOnRecordList() {
  9859. page, _ := c.GetInt64("page")
  9860. limit, _ := c.GetInt64("limit")
  9861. keywords := c.GetString("keywords")
  9862. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9863. if page <= 0 {
  9864. page = 1
  9865. }
  9866. if limit <= 0 {
  9867. limit = 10
  9868. }
  9869. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9870. c.ServeSuccessJSON(map[string]interface{}{
  9871. "total": total,
  9872. "list": list,
  9873. })
  9874. return
  9875. }
  9876. func (c *HisApiController) GetCompareData() {
  9877. start_time := c.GetString("start_time")
  9878. end_time := c.GetString("end_time")
  9879. insutype := c.GetString("insutype")
  9880. clr_type := c.GetString("clr_type")
  9881. timeLayout := "2006-01-02"
  9882. loc, _ := time.LoadLocation("Local")
  9883. var theStartTIme int64
  9884. if len(start_time) > 0 {
  9885. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9886. if err != nil {
  9887. theStartTIme = 0
  9888. }
  9889. theStartTIme = theTime.Unix()
  9890. }
  9891. var theEndtTIme int64
  9892. if len(end_time) > 0 {
  9893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9894. if err != nil {
  9895. theEndtTIme = 0
  9896. }
  9897. theEndtTIme = theTime.Unix()
  9898. }
  9899. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9900. fmt.Println(err)
  9901. if err == nil {
  9902. c.ServeSuccessJSON(map[string]interface{}{
  9903. "list": formData,
  9904. })
  9905. } else {
  9906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9907. return
  9908. }
  9909. }
  9910. func (c *HisApiController) GetFaPiaoData() {
  9911. order_id, _ := c.GetInt64("order_id")
  9912. patient_id, _ := c.GetInt64("patient_id")
  9913. //number := c.GetString("number")
  9914. adminUser := c.GetAdminUserInfo()
  9915. order, _ := service.GetHisOrderByID(order_id)
  9916. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9917. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9918. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9919. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9920. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9921. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9922. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9923. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9924. var bedCostTotal float64 = 0 //床位总费
  9925. var bedCostSelfTotal float64 = 0 //床位自费
  9926. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9927. var operationCostTotal float64 = 0 //手术费
  9928. var operationCostSelfTotal float64 = 0 //手术费
  9929. var operationCostPartSelfTotal float64 = 0 //手术费
  9930. var otherCostTotal float64 = 0 //其他费用
  9931. var otherCostSelfTotal float64 = 0 //其他费用
  9932. var otherCostPartSelfTotal float64 = 0 //其他费用
  9933. var materialCostTotal float64 = 0 //材料费
  9934. var materialCostSelfTotal float64 = 0 //材料费
  9935. var materialCostPartSelfTotal float64 = 0 //材料费
  9936. var westernMedicineCostTotal float64 = 0 //西药费
  9937. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9938. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9939. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9940. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9941. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9942. var checkCostTotal float64 = 0 //检查费
  9943. var checkCostSelfTotal float64 = 0 //检查费
  9944. var checkCostPartSelfTotal float64 = 0 //检查费
  9945. var hiliCostTotal float64 = 0 //护理费
  9946. var hiliCostSelfTotal float64 = 0 //护理费
  9947. var hiliCostPartSelfTotal float64 = 0 //护理费
  9948. var laboratoryCostTotal float64 = 0 //化验费
  9949. var laboratoryCostSelfTotal float64 = 0 //化验费
  9950. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9951. var treatCostTotal float64 = 0 //治疗费用
  9952. var treatCostSelfTotal float64 = 0 //治疗费用
  9953. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9954. var zhenChaCostTotal float64 = 0 //其他费用
  9955. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9956. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9957. decimal.DivisionPrecision = 2
  9958. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9959. var balanceAccountsType int64
  9960. if his.ID > 0 {
  9961. balanceAccountsType = his.BalanceAccountsType
  9962. } else {
  9963. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9964. }
  9965. if balanceAccountsType == 2 {
  9966. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9967. for _, item := range orderInfos_two {
  9968. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9969. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9970. item.MedChrgitmType = "09"
  9971. }
  9972. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9973. if item.HisPrescriptionProject.Type == 2 {
  9974. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9975. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9976. case 0:
  9977. item.MedChrgitmType = "0"
  9978. break
  9979. case 1:
  9980. item.MedChrgitmType = "14"
  9981. break
  9982. case 2:
  9983. item.MedChrgitmType = "05"
  9984. break
  9985. case 3:
  9986. item.MedChrgitmType = "03"
  9987. break
  9988. case 4:
  9989. item.MedChrgitmType = "03"
  9990. break
  9991. case 5:
  9992. item.MedChrgitmType = "08"
  9993. break
  9994. case 6:
  9995. item.MedChrgitmType = "14"
  9996. break
  9997. case 7:
  9998. item.MedChrgitmType = "14"
  9999. break
  10000. case 8:
  10001. item.MedChrgitmType = "03"
  10002. break
  10003. case 9:
  10004. item.MedChrgitmType = "14"
  10005. break
  10006. case 10:
  10007. item.MedChrgitmType = "14"
  10008. break
  10009. case 11:
  10010. item.MedChrgitmType = "06"
  10011. break
  10012. case 12:
  10013. item.MedChrgitmType = "12"
  10014. break
  10015. case 13:
  10016. item.MedChrgitmType = "01"
  10017. break
  10018. case 14:
  10019. item.MedChrgitmType = "04"
  10020. break
  10021. case 15:
  10022. item.MedChrgitmType = "02"
  10023. break
  10024. }
  10025. } else {
  10026. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10027. case 1:
  10028. item.MedChrgitmType = "14"
  10029. break
  10030. case 2:
  10031. item.MedChrgitmType = "05"
  10032. break
  10033. case 3:
  10034. item.MedChrgitmType = "04"
  10035. break
  10036. case 4:
  10037. item.MedChrgitmType = "03"
  10038. break
  10039. case 5:
  10040. item.MedChrgitmType = "08"
  10041. break
  10042. case 6:
  10043. item.MedChrgitmType = "14"
  10044. break
  10045. case 7:
  10046. item.MedChrgitmType = "14"
  10047. break
  10048. case 8:
  10049. item.MedChrgitmType = "03"
  10050. break
  10051. case 9:
  10052. item.MedChrgitmType = "14"
  10053. break
  10054. }
  10055. }
  10056. } else if item.HisPrescriptionProject.Type == 3 {
  10057. item.MedChrgitmType = "08"
  10058. }
  10059. }
  10060. }
  10061. for _, item := range orderInfos_two {
  10062. fmt.Println(item.MedChrgitmType)
  10063. if item.MedChrgitmType == "07" { //床位费
  10064. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10065. hiliCostSelfTotal = hiliCostTotal
  10066. }
  10067. if item.MedChrgitmType == "01" { //床位费
  10068. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10069. bedCostSelfTotal = bedCostTotal
  10070. }
  10071. if item.MedChrgitmType == "02" { //诊察费
  10072. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10073. zhenChaCostSelfTotal = zhenChaCostTotal
  10074. }
  10075. if item.MedChrgitmType == "03" { //检查费
  10076. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10077. checkCostSelfTotal = checkCostTotal
  10078. }
  10079. if item.MedChrgitmType == "04" { //化验费
  10080. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10081. laboratoryCostSelfTotal = laboratoryCostTotal
  10082. }
  10083. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10084. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10085. treatCostSelfTotal = treatCostTotal
  10086. }
  10087. if item.MedChrgitmType == "06" { //手术费
  10088. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10089. operationCostSelfTotal = treatCostTotal
  10090. }
  10091. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10092. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10093. materialCostSelfTotal = materialCostTotal
  10094. }
  10095. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10096. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10097. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10098. }
  10099. if item.MedChrgitmType == "11" { //中成费
  10100. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10101. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10102. }
  10103. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10104. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10105. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10106. otherCostSelfTotal = otherCostTotal
  10107. }
  10108. } else {
  10109. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10110. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10111. otherCostSelfTotal = otherCostTotal
  10112. }
  10113. }
  10114. }
  10115. } else {
  10116. for _, item := range orderInfos {
  10117. if item.MedChrgitmType == "01" { //床位费
  10118. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10119. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10120. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10121. }
  10122. if item.MedChrgitmType == "02" { //诊察费
  10123. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10124. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10125. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10126. }
  10127. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10128. if item.MedChrgitmType == "03" { //检查费
  10129. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10130. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10131. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10132. }
  10133. } else {
  10134. if item.MedChrgitmType == "03" { //检查费
  10135. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10136. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10137. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10138. }
  10139. }
  10140. if item.MedChrgitmType == "04" { //化验费
  10141. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10142. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10143. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10144. }
  10145. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10146. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10147. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10148. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10149. }
  10150. if item.MedChrgitmType == "06" { //手术费
  10151. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10152. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10153. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10154. }
  10155. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10156. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10157. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10158. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10159. }
  10160. if item.MedChrgitmType == "07" { //护理
  10161. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10162. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10163. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10164. }
  10165. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10166. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10167. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10168. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10169. }
  10170. if item.MedChrgitmType == "11" { //中成费
  10171. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10172. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10173. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10174. }
  10175. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10176. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10177. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10178. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10179. }
  10180. }
  10181. }
  10182. timeLayout := "2006-01-02"
  10183. loc, _ := time.LoadLocation("Local")
  10184. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10185. if err != nil {
  10186. }
  10187. startRecordDateTime := startTime.Unix()
  10188. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10189. if err != nil {
  10190. }
  10191. endRecordDateTime := endTime.Unix()
  10192. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10193. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10194. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10195. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10196. c.ServeSuccessJSON(map[string]interface{}{
  10197. "charge_admin_name": charge_admin.UserName,
  10198. "order_number": order.Number, //业务流水号
  10199. "id_card_no": his.IdCardNo, //社会保障号
  10200. "patient": patient,
  10201. "department_name": department.Name, //科室
  10202. "number": his.Number, //门诊号
  10203. "date": order.SettleAccountsDate, //结算日期
  10204. "name": order.PsnName, //姓名
  10205. "gender": patient.Gender, //性别
  10206. "psn_cash_money": order.PsnCashPay, //个人支付
  10207. "pay_way": "门诊", //结算方式
  10208. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10209. "admin_user_name": admin.UserName, //收款员
  10210. "order": order,
  10211. "order_info": orderInfos_two,
  10212. "his": his,
  10213. "bedCostTotal": bedCostTotal,
  10214. "bedCostSelfTotal": bedCostSelfTotal,
  10215. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10216. "operationCostTotal": operationCostTotal,
  10217. "operationCostSelfTotal": operationCostSelfTotal,
  10218. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10219. "otherCostTotal": otherCostTotal,
  10220. "otherCostSelfTotal": otherCostSelfTotal,
  10221. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10222. "materialCostTotal": materialCostTotal,
  10223. "materialCostSelfTotal": materialCostSelfTotal,
  10224. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10225. "westernMedicineCostTotal": westernMedicineCostTotal,
  10226. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10227. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10228. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10229. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10230. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10231. "checkCostTotal": checkCostTotal,
  10232. "checkCostSelfTotal": checkCostSelfTotal,
  10233. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10234. "laboratoryCostTotal": laboratoryCostTotal,
  10235. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10236. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10237. "treatCostTotal": treatCostTotal,
  10238. "treatCostSelfTotal": treatCostSelfTotal,
  10239. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10240. "zhenChaCostTotal": zhenChaCostTotal,
  10241. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10242. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10243. "his_hospital_record": his_hospital_record,
  10244. "pre_pay_money": pre_pay_money,
  10245. "refund_sum": sum,
  10246. "doctor_info": doctor_info,
  10247. "hiliCostTotal": hiliCostTotal,
  10248. "hiliCostSelfTotal": hiliCostSelfTotal,
  10249. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10250. })
  10251. }
  10252. //func (c *HisApiController) GetFaPiaoDatas() {
  10253. // order_ids := c.GetString("order_ids")
  10254. // patient_id, _ := c.GetInt64("patient_id")
  10255. // adminUser := c.GetAdminUserInfo()
  10256. //
  10257. // orders := strings.Split(order_ids, ",")
  10258. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10259. //
  10260. // for _, item := range orders {
  10261. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10262. // order, _ := service.GetHisOrderByID(order_id)
  10263. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10264. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10265. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10266. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10267. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10268. //
  10269. // }
  10270. //
  10271. // var bedCostTotal float64 = 0 //床位总费
  10272. // var bedCostSelfTotal float64 = 0 //床位自费
  10273. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10274. //
  10275. // var operationCostTotal float64 = 0 //手术费
  10276. // var operationCostSelfTotal float64 = 0 //手术费
  10277. // var operationCostPartSelfTotal float64 = 0 //手术费
  10278. //
  10279. // var otherCostTotal float64 = 0 //其他费用
  10280. // var otherCostSelfTotal float64 = 0 //其他费用
  10281. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10282. //
  10283. // var materialCostTotal float64 = 0 //材料费
  10284. // var materialCostSelfTotal float64 = 0 //材料费
  10285. // var materialCostPartSelfTotal float64 = 0 //材料费
  10286. //
  10287. // var westernMedicineCostTotal float64 = 0 //西药费
  10288. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10289. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10290. //
  10291. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10292. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10293. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10294. //
  10295. // var checkCostTotal float64 = 0 //检查费
  10296. // var checkCostSelfTotal float64 = 0 //检查费
  10297. // var checkCostPartSelfTotal float64 = 0 //检查费
  10298. //
  10299. // var laboratoryCostTotal float64 = 0 //化验费
  10300. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10301. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10302. //
  10303. // var treatCostTotal float64 = 0 //治疗费用
  10304. // var treatCostSelfTotal float64 = 0 //治疗费用
  10305. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10306. //
  10307. // var zhenChaCostTotal float64 = 0 //其他费用
  10308. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10309. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10310. //
  10311. // decimal.DivisionPrecision = 2
  10312. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10313. //
  10314. // var balanceAccountsType int64
  10315. // if his.ID > 0 {
  10316. // balanceAccountsType = his.BalanceAccountsType
  10317. // } else {
  10318. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10319. // }
  10320. // if balanceAccountsType == 2 {
  10321. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10322. // for _, item := range orderInfos_two {
  10323. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10324. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10325. // item.MedChrgitmType = "09"
  10326. // }
  10327. //
  10328. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10329. // if item.HisPrescriptionProject.Type == 2 {
  10330. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10331. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10332. // case 0:
  10333. // item.MedChrgitmType = "0"
  10334. // break
  10335. // case 1:
  10336. // item.MedChrgitmType = "14"
  10337. // break
  10338. // case 2:
  10339. // item.MedChrgitmType = "05"
  10340. //
  10341. // break
  10342. // case 3:
  10343. // item.MedChrgitmType = "03"
  10344. //
  10345. // break
  10346. // case 4:
  10347. // item.MedChrgitmType = "03"
  10348. //
  10349. // break
  10350. // case 5:
  10351. // item.MedChrgitmType = "08"
  10352. //
  10353. // break
  10354. // case 6:
  10355. // item.MedChrgitmType = "14"
  10356. //
  10357. // break
  10358. // case 7:
  10359. // item.MedChrgitmType = "14"
  10360. //
  10361. // break
  10362. // case 8:
  10363. // item.MedChrgitmType = "03"
  10364. // break
  10365. // case 9:
  10366. // item.MedChrgitmType = "14"
  10367. // break
  10368. // case 10:
  10369. // item.MedChrgitmType = "14"
  10370. // break
  10371. // case 11:
  10372. // item.MedChrgitmType = "06"
  10373. // break
  10374. // case 12:
  10375. // item.MedChrgitmType = "12"
  10376. // break
  10377. // case 13:
  10378. // item.MedChrgitmType = "01"
  10379. // break
  10380. // case 14:
  10381. // item.MedChrgitmType = "04"
  10382. // break
  10383. // case 15:
  10384. // item.MedChrgitmType = "02"
  10385. // break
  10386. //
  10387. // }
  10388. //
  10389. // } else {
  10390. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10391. //
  10392. // case 1:
  10393. // item.MedChrgitmType = "14"
  10394. // break
  10395. // case 2:
  10396. // item.MedChrgitmType = "05"
  10397. //
  10398. // break
  10399. // case 3:
  10400. // item.MedChrgitmType = "03"
  10401. //
  10402. // break
  10403. // case 4:
  10404. // item.MedChrgitmType = "03"
  10405. //
  10406. // break
  10407. // case 5:
  10408. // item.MedChrgitmType = "08"
  10409. //
  10410. // break
  10411. // case 6:
  10412. // item.MedChrgitmType = "14"
  10413. //
  10414. // break
  10415. // case 7:
  10416. // item.MedChrgitmType = "14"
  10417. //
  10418. // break
  10419. // case 8:
  10420. // item.MedChrgitmType = "03"
  10421. // break
  10422. // case 9:
  10423. // item.MedChrgitmType = "14"
  10424. // break
  10425. //
  10426. // }
  10427. //
  10428. // }
  10429. //
  10430. // } else if item.HisPrescriptionProject.Type == 3 {
  10431. // item.MedChrgitmType = "08"
  10432. // }
  10433. // }
  10434. // }
  10435. //
  10436. // for _, item := range orderInfos_two {
  10437. // fmt.Println(item.MedChrgitmType)
  10438. // if item.MedChrgitmType == "01" { //床位费
  10439. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10440. // bedCostSelfTotal = bedCostTotal
  10441. // }
  10442. //
  10443. // if item.MedChrgitmType == "02" { //诊察费
  10444. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10445. // zhenChaCostSelfTotal = zhenChaCostTotal
  10446. // }
  10447. //
  10448. // if item.MedChrgitmType == "03" { //检查费
  10449. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10450. // checkCostSelfTotal = checkCostTotal
  10451. // }
  10452. //
  10453. // if item.MedChrgitmType == "04" { //化验费
  10454. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10455. // laboratoryCostSelfTotal = laboratoryCostTotal
  10456. // }
  10457. //
  10458. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10459. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10460. // treatCostSelfTotal = treatCostTotal
  10461. // }
  10462. //
  10463. // if item.MedChrgitmType == "06" { //手术费
  10464. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10465. // operationCostSelfTotal = treatCostTotal
  10466. // }
  10467. //
  10468. // if item.MedChrgitmType == "08" { //材料费
  10469. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10470. // materialCostSelfTotal = materialCostTotal
  10471. // }
  10472. //
  10473. // if item.MedChrgitmType == "09" { //西药费
  10474. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10475. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10476. // }
  10477. //
  10478. // if item.MedChrgitmType == "11" { //中成费
  10479. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10480. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10481. // }
  10482. //
  10483. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10484. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10485. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10486. // otherCostSelfTotal = otherCostTotal
  10487. // }
  10488. // } else {
  10489. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10490. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10491. // otherCostSelfTotal = otherCostTotal
  10492. // }
  10493. //
  10494. // }
  10495. //
  10496. // }
  10497. //
  10498. // } else {
  10499. // for _, item := range orderInfos {
  10500. // if item.MedChrgitmType == "01" { //床位费
  10501. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10502. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10503. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10504. // }
  10505. //
  10506. // if item.MedChrgitmType == "02" { //诊察费
  10507. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10508. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10509. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10510. // }
  10511. //
  10512. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10513. // if item.MedChrgitmType == "03" { //检查费
  10514. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10515. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10516. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10517. //
  10518. // }
  10519. // } else {
  10520. // if item.MedChrgitmType == "03" { //检查费
  10521. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10522. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10523. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10524. // }
  10525. //
  10526. // }
  10527. //
  10528. // if item.MedChrgitmType == "04" { //化验费
  10529. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10530. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10531. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10532. //
  10533. // }
  10534. //
  10535. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10536. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10537. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10538. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10539. //
  10540. // }
  10541. //
  10542. // if item.MedChrgitmType == "06" { //手术费
  10543. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10544. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10545. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10546. // }
  10547. //
  10548. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10549. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10550. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10551. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10552. // }
  10553. //
  10554. // if item.MedChrgitmType == "09" { //西药费
  10555. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10556. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10557. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10558. // }
  10559. //
  10560. // if item.MedChrgitmType == "11" { //中成费
  10561. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10562. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10563. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10564. // }
  10565. //
  10566. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10567. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10568. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10569. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10570. // }
  10571. //
  10572. // }
  10573. // }
  10574. // timeLayout := "2006-01-02"
  10575. // loc, _ := time.LoadLocation("Local")
  10576. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10577. // if err != nil {
  10578. // }
  10579. // startRecordDateTime := startTime.Unix()
  10580. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10581. // if err != nil {
  10582. // }
  10583. // endRecordDateTime := endTime.Unix()
  10584. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10585. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10586. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10587. //
  10588. // c.ServeSuccessJSON(map[string]interface{}{
  10589. // "order_number": order.Number, //业务流水号
  10590. // "id_card_no": his.IdCardNo, //社会保障号
  10591. // "department_name": department.Name, //科室
  10592. // "number": his.Number, //门诊号
  10593. // "date": order.SettleAccountsDate, //结算日期
  10594. // "name": order.PsnName, //姓名
  10595. // "gender": patient.Gender, //性别
  10596. // "psn_cash_money": order.PsnCashPay, //个人支付
  10597. // "pay_way": "门诊", //结算方式
  10598. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10599. // "admin_user_name": admin.UserName, //收款员
  10600. // "order": order,
  10601. // "order_info": orderInfos_two,
  10602. // "his": his,
  10603. // "bedCostTotal": bedCostTotal,
  10604. // "bedCostSelfTotal": bedCostSelfTotal,
  10605. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10606. // "operationCostTotal": operationCostTotal,
  10607. // "operationCostSelfTotal": operationCostSelfTotal,
  10608. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10609. // "otherCostTotal": otherCostTotal,
  10610. // "otherCostSelfTotal": otherCostSelfTotal,
  10611. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10612. // "materialCostTotal": materialCostTotal,
  10613. // "materialCostSelfTotal": materialCostSelfTotal,
  10614. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10615. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10616. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10617. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10618. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10619. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10620. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10621. // "checkCostTotal": checkCostTotal,
  10622. // "checkCostSelfTotal": checkCostSelfTotal,
  10623. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10624. // "laboratoryCostTotal": laboratoryCostTotal,
  10625. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10626. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10627. // "treatCostTotal": treatCostTotal,
  10628. // "treatCostSelfTotal": treatCostSelfTotal,
  10629. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10630. // "zhenChaCostTotal": zhenChaCostTotal,
  10631. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10632. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10633. // "his_hospital_record": his_hospital_record,
  10634. // "pre_pay_money": pre_pay_money,
  10635. // "refund_sum": sum,
  10636. // })
  10637. //
  10638. //}
  10639. func (this *HisApiController) GetIncomeStatisticsData() {
  10640. start_time := this.GetString("start_time")
  10641. end_time := this.GetString("end_time")
  10642. key_words := this.GetString("key_words")
  10643. limit, _ := this.GetInt64("limit")
  10644. page, _ := this.GetInt64("page")
  10645. if page <= 0 {
  10646. page = 1
  10647. }
  10648. if limit <= 0 {
  10649. limit = 10
  10650. }
  10651. statistics_type, _ := this.GetInt64("statistics_type")
  10652. admin := this.GetAdminUserInfo()
  10653. timeLayout := "2006-01-02"
  10654. loc, _ := time.LoadLocation("Local")
  10655. var theStartTIme int64
  10656. if len(start_time) > 0 {
  10657. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10658. if err != nil {
  10659. theStartTIme = 0
  10660. }
  10661. theStartTIme = theTime.Unix()
  10662. }
  10663. var theEndtTIme int64
  10664. if len(end_time) > 0 {
  10665. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10666. if err != nil {
  10667. theEndtTIme = 0
  10668. }
  10669. theEndtTIme = theTime.Unix()
  10670. }
  10671. if statistics_type == 1 {
  10672. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10673. this.ServeSuccessJSON(map[string]interface{}{
  10674. "list": list,
  10675. "total": total,
  10676. })
  10677. } else {
  10678. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10679. this.ServeSuccessJSON(map[string]interface{}{
  10680. "list": list,
  10681. "total": total,
  10682. })
  10683. }
  10684. }
  10685. func (c *HisApiController) PostProjectInformation() {
  10686. adminUser := c.GetAdminUserInfo()
  10687. orgId := adminUser.CurrentOrgId
  10688. dataBody := make(map[string]interface{}, 0)
  10689. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10690. if err != nil {
  10691. utils.ErrorLog(err.Error())
  10692. return
  10693. }
  10694. utils.ErrorLog("%v", dataBody)
  10695. var projectList []*models.HisProject
  10696. var total_goods []interface{}
  10697. tempProjects := dataBody["projects"].([]interface{})
  10698. total_goods = tempProjects
  10699. for index, projectMap := range tempProjects {
  10700. projectM := projectMap.(map[string]interface{})
  10701. var project models.HisProject
  10702. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10703. utils.ErrorLog("project_name")
  10704. return
  10705. }
  10706. project_name, _ := projectM["project_name"].(string)
  10707. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10708. err_log := models.ExportErrLog{
  10709. LogType: 6,
  10710. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10711. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10712. Status: 1,
  10713. CreateTime: time.Now().Unix(),
  10714. UpdateTime: time.Now().Unix(),
  10715. ExportTime: time.Now().Unix(),
  10716. }
  10717. service.CreateExportErrLog(&err_log)
  10718. continue
  10719. }
  10720. project.ProjectName = project_name
  10721. prices := projectM["price"].(string)
  10722. price, _ := strconv.ParseFloat(prices, 64)
  10723. if price <= 0 { //名字为空则生成一条导入错误日志
  10724. err_log := models.ExportErrLog{
  10725. LogType: 6,
  10726. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10727. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10728. Status: 1,
  10729. CreateTime: time.Now().Unix(),
  10730. UpdateTime: time.Now().Unix(),
  10731. ExportTime: time.Now().Unix(),
  10732. }
  10733. service.CreateExportErrLog(&err_log)
  10734. continue
  10735. }
  10736. project.Price = price
  10737. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10738. utils.ErrorLog("unit_id")
  10739. return
  10740. }
  10741. unit := projectM["unit"].(string)
  10742. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10743. err_log := models.ExportErrLog{
  10744. LogType: 6,
  10745. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10746. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10747. Status: 1,
  10748. CreateTime: time.Now().Unix(),
  10749. UpdateTime: time.Now().Unix(),
  10750. ExportTime: time.Now().Unix(),
  10751. }
  10752. service.CreateExportErrLog(&err_log)
  10753. continue
  10754. }
  10755. project.Unit = unit
  10756. cost_classify := projectM["cost_classify"].(string)
  10757. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10758. err_log := models.ExportErrLog{
  10759. LogType: 6,
  10760. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10761. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10762. Status: 1,
  10763. CreateTime: time.Now().Unix(),
  10764. UpdateTime: time.Now().Unix(),
  10765. ExportTime: time.Now().Unix(),
  10766. }
  10767. service.CreateExportErrLog(&err_log)
  10768. continue
  10769. }
  10770. var costClassify = "费用类别"
  10771. var cost_classify_id int64
  10772. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10773. if len(cost_classify) != 0 {
  10774. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10775. if errcode == gorm.ErrRecordNotFound {
  10776. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10777. dataconfig := models.DictDataconfig{
  10778. ParentId: costClassifyConfig.ID,
  10779. Module: "system",
  10780. OrgId: orgId,
  10781. Name: cost_classify,
  10782. FieldName: "",
  10783. Value: costConfig.Value + 1,
  10784. CreatedTime: "",
  10785. UpdatedTime: "",
  10786. CreateUserId: adminUser.AdminUser.Id,
  10787. Status: 1,
  10788. Remark: "",
  10789. DeleteIdSystem: 0,
  10790. Title: "",
  10791. Content: "",
  10792. Order: 0,
  10793. Code: "",
  10794. }
  10795. service.CreatedDicConfig(&dataconfig)
  10796. }
  10797. }
  10798. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10799. for _, it := range costClassList {
  10800. if cost_classify == it.Name {
  10801. cost_classify_id = int64(it.Value)
  10802. }
  10803. }
  10804. project.CostClassify = cost_classify_id
  10805. executive_section := projectM["executive_section"].(string)
  10806. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10807. err_log := models.ExportErrLog{
  10808. LogType: 6,
  10809. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10810. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10811. Status: 1,
  10812. CreateTime: time.Now().Unix(),
  10813. UpdateTime: time.Now().Unix(),
  10814. ExportTime: time.Now().Unix(),
  10815. }
  10816. service.CreateExportErrLog(&err_log)
  10817. continue
  10818. }
  10819. if len(executive_section) != 0 {
  10820. //查找科室是否有内容
  10821. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10822. if errcodedepart == gorm.ErrRecordNotFound {
  10823. department := models.XtHisDepartment{
  10824. Name: executive_section,
  10825. Status: 1,
  10826. UserOrgId: adminUser.CurrentOrgId,
  10827. CreatedTime: time.Now().Unix(),
  10828. }
  10829. service.CreateDePartment(&department)
  10830. }
  10831. }
  10832. var executive_section_id int64
  10833. departMentList, _ := service.GetAllDepartMent(orgId)
  10834. for _, it := range departMentList {
  10835. if executive_section == it.Name {
  10836. executive_section_id = it.ID
  10837. }
  10838. }
  10839. project.ExecutiveSection = executive_section_id
  10840. medical_coverage := projectM["medical_coverage"].(string)
  10841. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10842. err_log := models.ExportErrLog{
  10843. LogType: 6,
  10844. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10845. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10846. Status: 1,
  10847. CreateTime: time.Now().Unix(),
  10848. UpdateTime: time.Now().Unix(),
  10849. ExportTime: time.Now().Unix(),
  10850. }
  10851. service.CreateExportErrLog(&err_log)
  10852. continue
  10853. }
  10854. var medicalCoverage = "医保等级"
  10855. var medical_coverage_id int64
  10856. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10857. if len(medical_coverage) != 0 {
  10858. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10859. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10860. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10861. dataconfig := models.DictDataconfig{
  10862. ParentId: medicalCoverageConfig.ID,
  10863. Module: "system",
  10864. OrgId: orgId,
  10865. Name: medical_coverage,
  10866. FieldName: "",
  10867. Value: medicalCoverageConfig.Value + 1,
  10868. CreatedTime: "",
  10869. UpdatedTime: "",
  10870. CreateUserId: adminUser.AdminUser.Id,
  10871. Status: 1,
  10872. Remark: "",
  10873. DeleteIdSystem: 0,
  10874. Title: "",
  10875. Content: "",
  10876. Order: 0,
  10877. Code: "",
  10878. }
  10879. service.CreatedDicConfig(&dataconfig)
  10880. }
  10881. }
  10882. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10883. for _, it := range medicalCoverageList {
  10884. if medical_coverage == it.Name {
  10885. medical_coverage_id = int64(it.Value)
  10886. }
  10887. }
  10888. project.MedicalCoverage = medical_coverage_id
  10889. pinyin := projectM["pinyin"].(string)
  10890. project.Pinyin = pinyin
  10891. wubi := projectM["wubi"].(string)
  10892. project.Wubi = wubi
  10893. statistical_classification := projectM["statistical_classification"].(string)
  10894. var statisticalClassification = "统计分类"
  10895. var statistical_classification_id int64
  10896. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10897. if len(statistical_classification) != 0 {
  10898. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10899. if classificationerrcodes == gorm.ErrRecordNotFound {
  10900. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10901. dataconfig := models.DictDataconfig{
  10902. ParentId: classiFication.ID,
  10903. Module: "system",
  10904. OrgId: orgId,
  10905. Name: statistical_classification,
  10906. FieldName: "",
  10907. Value: classiFicationConfig.Value + 1,
  10908. CreatedTime: "",
  10909. UpdatedTime: "",
  10910. CreateUserId: adminUser.AdminUser.Id,
  10911. Status: 1,
  10912. Remark: "",
  10913. DeleteIdSystem: 0,
  10914. Title: "",
  10915. Content: "",
  10916. Order: 0,
  10917. Code: "",
  10918. }
  10919. service.CreatedDicConfig(&dataconfig)
  10920. }
  10921. }
  10922. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10923. for _, it := range classiFicationList {
  10924. if statistical_classification == it.Name {
  10925. statistical_classification_id = int64(it.Value)
  10926. }
  10927. }
  10928. project.StatisticalClassification = statistical_classification_id
  10929. disease_directory := int64(projectM["disease_directory"].(float64))
  10930. project.DiseaseDirectory = disease_directory
  10931. is_record := int64(projectM["is_record"].(float64))
  10932. project.IsRecord = is_record
  10933. medical_code := projectM["medical_code"].(string)
  10934. project.MedicalCode = medical_code
  10935. tube_color := projectM["tube_color"].(string)
  10936. var tubeColor = "试管颜色"
  10937. var tube_color_id int64
  10938. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10939. if len(tube_color) != 0 {
  10940. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10941. if errcodetube == gorm.ErrRecordNotFound {
  10942. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10943. dataconfig := models.DictDataconfig{
  10944. ParentId: tubeColorConfig.ID,
  10945. Module: "system",
  10946. OrgId: orgId,
  10947. Name: tube_color,
  10948. FieldName: "",
  10949. Value: tubeConfig.Value + 1,
  10950. CreatedTime: "",
  10951. UpdatedTime: "",
  10952. CreateUserId: adminUser.AdminUser.Id,
  10953. Status: 1,
  10954. Remark: "",
  10955. DeleteIdSystem: 0,
  10956. Title: "",
  10957. Content: "",
  10958. Order: 0,
  10959. Code: "",
  10960. }
  10961. service.CreatedDicConfig(&dataconfig)
  10962. }
  10963. }
  10964. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10965. for _, it := range tubeColorList {
  10966. if tube_color == it.Name {
  10967. tube_color_id = int64(it.Value)
  10968. }
  10969. }
  10970. project.TubeColor = tube_color_id
  10971. single_dose := projectM["single_dose"].(string)
  10972. project.SingleDose = single_dose
  10973. execution_frequency := projectM["execution_frequency"].(string)
  10974. project.ExecutionFrequency = execution_frequency
  10975. delivery_way := projectM["delivery_way"].(string)
  10976. project.DeliveryWay = delivery_way
  10977. number_days := projectM["number_days"].(string)
  10978. project.NumberDays = number_days
  10979. total := projectM["total"].(string)
  10980. project.Total = total
  10981. medical_status := int64(projectM["medical_status"].(float64))
  10982. project.MedicalStatus = medical_status
  10983. category := int64(projectM["category"].(float64))
  10984. project.Category = category
  10985. specail_project := int64(projectM["specail_project"].(float64))
  10986. project.SpecailProject = specail_project
  10987. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10988. project.SocialSecurityDirectoryCode = social_security_directory_code
  10989. remark := projectM["remark"].(string)
  10990. project.Remark = remark
  10991. record_date := projectM["record_date"].(string)
  10992. timeLayout := "2006-01-02"
  10993. loc, _ := time.LoadLocation("Local")
  10994. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10995. project.RecordDate = theTime.Unix()
  10996. projectList = append(projectList, &project)
  10997. }
  10998. export_time := time.Now().Unix()
  10999. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11000. if len(projectList) > 0 {
  11001. for _, item := range projectList {
  11002. hans := item.ProjectName // 要转换的汉字字符串
  11003. // 创建一个拼音转换器
  11004. p := pinyin.NewArgs()
  11005. // 将汉字转为拼音
  11006. pinyinSlice := pinyin.Pinyin(hans, p)
  11007. // 输出拼音
  11008. fmt.Println("Pinyin:", pinyinSlice)
  11009. // 获取首字母
  11010. firstLetter := ""
  11011. for _, py := range pinyinSlice {
  11012. if len(py) > 0 {
  11013. firstLetter += string(py[0][0])
  11014. }
  11015. }
  11016. item.FirstLetter = firstLetter
  11017. project := models.HisProject{
  11018. ProjectName: item.ProjectName,
  11019. Price: item.Price,
  11020. Unit: item.Unit,
  11021. CostClassify: item.CostClassify,
  11022. ExecutiveSection: item.ExecutiveSection,
  11023. MedicalCoverage: item.MedicalCoverage,
  11024. UserOrgId: orgId,
  11025. Status: 1,
  11026. CreatedTime: time.Now().Unix(),
  11027. Pinyin: item.Pinyin,
  11028. Wubi: item.Wubi,
  11029. StatisticalClassification: item.StatisticalClassification,
  11030. DiseaseDirectory: item.DiseaseDirectory,
  11031. IsRecord: item.IsRecord,
  11032. MedicalCode: item.MedicalCode,
  11033. TubeColor: item.TubeColor,
  11034. SingleDose: item.SingleDose,
  11035. DeliveryWay: item.DeliveryWay,
  11036. NumberDays: item.NumberDays,
  11037. Total: item.Total,
  11038. Category: item.Category,
  11039. MedicalStatus: item.MedicalStatus,
  11040. SpecailProject: item.SpecailProject,
  11041. RecordDate: item.RecordDate,
  11042. Remark: item.Remark,
  11043. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11044. ExecutionFrequency: item.ExecutionFrequency,
  11045. FirstLetter: item.FirstLetter,
  11046. }
  11047. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11048. if errcodeproject == gorm.ErrRecordNotFound {
  11049. service.CreateProjectInfomation(&project)
  11050. } else if errcodeproject == nil {
  11051. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11052. }
  11053. log := models.ExportLog{
  11054. LogType: 6,
  11055. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11056. TotalNum: int64(len(total_goods)),
  11057. FailNum: int64(len(errLogs)),
  11058. SuccessNum: int64(len(projectList)),
  11059. CreateTime: time.Now().Unix(),
  11060. UpdateTime: time.Now().Unix(),
  11061. ExportTime: export_time,
  11062. Status: 1,
  11063. }
  11064. service.CreateExportLog(&log)
  11065. c.ServeSuccessJSON(map[string]interface{}{
  11066. "msg": "导入成功",
  11067. "total_num": len(total_goods),
  11068. "success_num": len(projectList),
  11069. "fail_num": int64(len(errLogs)),
  11070. })
  11071. }
  11072. } else {
  11073. log := models.ExportLog{
  11074. LogType: 6,
  11075. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11076. TotalNum: int64(len(total_goods)),
  11077. FailNum: int64(len(errLogs)),
  11078. SuccessNum: int64(len(projectList)),
  11079. CreateTime: time.Now().Unix(),
  11080. UpdateTime: time.Now().Unix(),
  11081. ExportTime: export_time,
  11082. Status: 1,
  11083. }
  11084. service.CreateExportLog(&log)
  11085. c.ServeSuccessJSON(map[string]interface{}{
  11086. "msg": "导入成功",
  11087. "total_num": len(total_goods),
  11088. "success_num": len(projectList),
  11089. "fail_num": int64(len(errLogs)),
  11090. })
  11091. }
  11092. }
  11093. //func (this *HisApiController) EditProjectInformation(){
  11094. //
  11095. // id, _ := this.GetInt64("id")
  11096. // project_team := this.GetString("project_team")
  11097. // price := this.GetString("price")
  11098. // price_float, _ := strconv.ParseFloat(price, 64)
  11099. // pinyin := this.GetString("pinyin")
  11100. // wubi := this.GetString("wubi")
  11101. // tube_color, _ := this.GetInt64("tube_color")
  11102. // team_type, _ := this.GetInt64("team_type")
  11103. // remark := this.GetString("remark")
  11104. // ids := this.GetString("ids")
  11105. // item_id := this.GetString("item_id")
  11106. // projectTeam := models.XtHisProjectTeam{
  11107. // ProjectTeam: project_team,
  11108. // Price: price_float,
  11109. // Pinyin: pinyin,
  11110. // Wubi: wubi,
  11111. // TubeColor: tube_color,
  11112. // TeamType: team_type,
  11113. // Remark: remark,
  11114. // ProjectId: ids,
  11115. // ItemId: item_id,
  11116. // }
  11117. //
  11118. //
  11119. // dataBody := make(map[string]interface{}, 0)
  11120. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11121. // if err != nil {
  11122. // utils.ErrorLog(err.Error())
  11123. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11124. // return
  11125. // }
  11126. //
  11127. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11128. //
  11129. //
  11130. // if err != nil {
  11131. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11132. // return
  11133. // }
  11134. //
  11135. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11136. // infos, _ := dataBody["info"].([]interface{})
  11137. // if len(infos) > 0 {
  11138. // var ids []string
  11139. //
  11140. // for _, item := range infos {
  11141. // items := item.(map[string]interface{})
  11142. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11143. // utils.ErrorLog("id")
  11144. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11145. // return
  11146. // }
  11147. // id := int64(items["id"].(float64))
  11148. //
  11149. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11150. // utils.ErrorLog("type")
  11151. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11152. // return
  11153. // }
  11154. // types := int64(items["type"].(float64))
  11155. //
  11156. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11157. // utils.ErrorLog("number")
  11158. // }
  11159. //
  11160. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11161. //
  11162. // projectList := models.XtHisProjectList{
  11163. // Number: number,
  11164. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11165. // ProjectId: id,
  11166. // Status: 1,
  11167. // CreatedTime: time.Now().Unix(),
  11168. // UpdatedTime: time.Now().Unix(),
  11169. // TeamId: projectTeam.ID,
  11170. // Type: types,
  11171. // }
  11172. // list := projectList
  11173. //
  11174. // service.CreateProjectList(&list)
  11175. //
  11176. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11177. //
  11178. // }
  11179. // ids_str := strings.Join(ids, ",")
  11180. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11181. // service.SaveProjectTeam(&projectTeam)
  11182. // this.ServeSuccessJSON(map[string]interface{}{
  11183. // "projectTeam": projectTeam,
  11184. // })
  11185. // }
  11186. // }
  11187. //}
  11188. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11189. name := c.GetString("name")
  11190. mode_id, _ := c.GetInt64("mode", 0)
  11191. types, _ := c.GetInt64("type", 0)
  11192. patient_id, _ := c.GetInt64("patient_id", 0)
  11193. types = 1
  11194. adminInfo := c.GetAdminUserInfo()
  11195. template := &models.HisPrescriptionTemplate{
  11196. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11197. PatientId: patient_id,
  11198. Type: types,
  11199. Status: 1,
  11200. Ctime: time.Now().Unix(),
  11201. Mtime: time.Now().Unix(),
  11202. Name: name,
  11203. Mode: mode_id,
  11204. }
  11205. dataBody := make(map[string]interface{}, 0)
  11206. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11207. if err != nil {
  11208. utils.ErrorLog(err.Error())
  11209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11210. return
  11211. }
  11212. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11213. //如果已经存在记录则删除处方
  11214. if template_one.ID > 0 {
  11215. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11216. var ids []int64
  11217. var org_id int64
  11218. for _, item := range ps {
  11219. org_id = c.GetAdminUserInfo().CurrentOrgId
  11220. ids = append(ids, item.ID)
  11221. }
  11222. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11223. if err2 == nil {
  11224. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11225. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11226. if len(prescriptions) > 0 {
  11227. for _, item := range prescriptions {
  11228. items := item.(map[string]interface{})
  11229. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11230. utils.ErrorLog("type")
  11231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11232. return
  11233. }
  11234. types := int64(items["type"].(float64))
  11235. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11236. utils.ErrorLog("med_type")
  11237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11238. return
  11239. }
  11240. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11241. ctime := time.Now().Unix()
  11242. prescription := &models.HisPrescriptionInfoTemplate{
  11243. PatientId: patient_id,
  11244. UserOrgId: adminInfo.CurrentOrgId,
  11245. Ctime: ctime,
  11246. Mtime: ctime,
  11247. Type: types,
  11248. Modifier: adminInfo.AdminUser.Id,
  11249. Creator: adminInfo.AdminUser.Id,
  11250. Status: 1,
  11251. PTemplateId: template_one.ID,
  11252. MedType: med_type,
  11253. }
  11254. service.CreateHisPrescriptionInfoTemplate(prescription)
  11255. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11256. advices := items["advices"].([]interface{})
  11257. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11258. ctime := time.Now().Unix()
  11259. mtime := ctime
  11260. if len(advices) > 0 {
  11261. for _, advice := range advices {
  11262. var s models.HisPrescriptionAdviceTemplate
  11263. s.PrescriptionId = prescription.ID
  11264. s.AdviceType = 2
  11265. s.StopState = 2
  11266. s.ExecutionState = 2
  11267. s.Status = 1
  11268. s.UserOrgId = adminInfo.CurrentOrgId
  11269. s.CreatedTime = ctime
  11270. s.UpdatedTime = mtime
  11271. s.PatientId = patient_id
  11272. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11273. if errcode > 0 {
  11274. c.ServeFailJSONWithSGJErrorCode(errcode)
  11275. return
  11276. }
  11277. service.CreateHisPrescriptionAdviceTemplate(&s)
  11278. }
  11279. }
  11280. }
  11281. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11282. projects := items["project"].([]interface{})
  11283. if len(projects) > 0 {
  11284. for _, project := range projects {
  11285. var p models.HisPrescriptionProjectTemplate
  11286. p.PrescriptionId = prescription.ID
  11287. p.Ctime = time.Now().Unix()
  11288. p.Mtime = time.Now().Unix()
  11289. p.PatientId = patient_id
  11290. p.UserOrgId = adminInfo.CurrentOrgId
  11291. p.Status = 1
  11292. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11293. if errcode > 0 {
  11294. c.ServeFailJSONWithSGJErrorCode(errcode)
  11295. return
  11296. }
  11297. service.CreateHisPrescriptionProjectTemplate(&p)
  11298. }
  11299. }
  11300. }
  11301. }
  11302. c.ServeSuccessJSON(map[string]interface{}{
  11303. "msg": "创建成功",
  11304. })
  11305. }
  11306. }
  11307. } else {
  11308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11309. return
  11310. }
  11311. } else {
  11312. err3 := service.CreateHisPrescriptionTemplate(template)
  11313. if err3 == nil {
  11314. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11315. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11316. if len(prescriptions) > 0 {
  11317. for _, item := range prescriptions {
  11318. items := item.(map[string]interface{})
  11319. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11320. utils.ErrorLog("type")
  11321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11322. return
  11323. }
  11324. types := int64(items["type"].(float64))
  11325. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11326. utils.ErrorLog("med_type")
  11327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11328. return
  11329. }
  11330. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11331. ctime := time.Now().Unix()
  11332. prescription := &models.HisPrescriptionInfoTemplate{
  11333. PatientId: patient_id,
  11334. UserOrgId: adminInfo.CurrentOrgId,
  11335. Ctime: ctime,
  11336. Mtime: ctime,
  11337. Type: types,
  11338. Modifier: adminInfo.AdminUser.Id,
  11339. Creator: adminInfo.AdminUser.Id,
  11340. Status: 1,
  11341. PTemplateId: template.ID,
  11342. MedType: med_type,
  11343. }
  11344. service.CreateHisPrescriptionInfoTemplate(prescription)
  11345. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11346. advices := items["advices"].([]interface{})
  11347. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11348. ctime := time.Now().Unix()
  11349. mtime := ctime
  11350. if len(advices) > 0 {
  11351. for _, advice := range advices {
  11352. var s models.HisPrescriptionAdviceTemplate
  11353. s.PrescriptionId = prescription.ID
  11354. s.AdviceType = 2
  11355. s.StopState = 2
  11356. s.ExecutionState = 2
  11357. s.Status = 1
  11358. s.UserOrgId = adminInfo.CurrentOrgId
  11359. s.CreatedTime = ctime
  11360. s.UpdatedTime = mtime
  11361. s.PatientId = patient_id
  11362. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11363. if errcode > 0 {
  11364. c.ServeFailJSONWithSGJErrorCode(errcode)
  11365. return
  11366. }
  11367. service.CreateHisPrescriptionAdviceTemplate(&s)
  11368. }
  11369. }
  11370. }
  11371. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11372. projects := items["project"].([]interface{})
  11373. if len(projects) > 0 {
  11374. for _, project := range projects {
  11375. var p models.HisPrescriptionProjectTemplate
  11376. p.PrescriptionId = prescription.ID
  11377. p.Ctime = time.Now().Unix()
  11378. p.Mtime = time.Now().Unix()
  11379. p.PatientId = patient_id
  11380. p.UserOrgId = adminInfo.CurrentOrgId
  11381. p.Status = 1
  11382. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11383. if errcode > 0 {
  11384. c.ServeFailJSONWithSGJErrorCode(errcode)
  11385. return
  11386. }
  11387. service.CreateHisPrescriptionProjectTemplate(&p)
  11388. }
  11389. }
  11390. }
  11391. }
  11392. c.ServeSuccessJSON(map[string]interface{}{
  11393. "msg": "创建成功",
  11394. })
  11395. }
  11396. }
  11397. } else {
  11398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11399. return
  11400. }
  11401. }
  11402. }
  11403. func (c *HisApiController) PreSettle() {
  11404. id, _ := c.GetInt64("id")
  11405. record_time := c.GetString("record_time")
  11406. his_patient_id, _ := c.GetInt64("his_patient_id")
  11407. timeLayout := "2006-01-02"
  11408. loc, _ := time.LoadLocation("Local")
  11409. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11410. diagnosis_id := c.GetString("diagnosis")
  11411. sick_type, _ := c.GetInt64("sick_type")
  11412. reg_type, _ := c.GetInt64("p_type")
  11413. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11414. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11415. if err != nil {
  11416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11417. return
  11418. }
  11419. recordDateTime := theTime.Unix()
  11420. adminUser := c.GetAdminUserInfo()
  11421. var prescriptions []*models.HisPrescription
  11422. var start_time int64
  11423. var end_time int64
  11424. ids_str := c.GetString("ids")
  11425. ids_arr := strings.Split(ids_str, ",")
  11426. fmt.Println(reg_type)
  11427. if settle_accounts_type == 1 { //日结
  11428. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11429. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11430. } else {
  11431. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11432. }
  11433. fmt.Println(prescriptions)
  11434. } else { //月结
  11435. start_time_str := c.GetString("start_time")
  11436. end_time_str := c.GetString("end_time")
  11437. timeLayout := "2006-01-02"
  11438. loc, _ := time.LoadLocation("Local")
  11439. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11440. if err != nil {
  11441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11442. return
  11443. }
  11444. recordStartTime := theStartTime.Unix()
  11445. start_time = recordStartTime
  11446. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11447. if err != nil {
  11448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11449. return
  11450. }
  11451. recordEndTime := theEndTime.Unix()
  11452. end_time = recordEndTime
  11453. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11454. }
  11455. if reg_type == 1111 || reg_type == 1112 {
  11456. reg_type = 11
  11457. }
  11458. timestamp := time.Now().Unix()
  11459. tempTime := time.Unix(timestamp, 0)
  11460. timeFormat := tempTime.Format("20060102150405")
  11461. chrgBchno := rand.Intn(100000) + 10000
  11462. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11463. strconv.FormatInt(his.PatientId, 10)
  11464. var ids []int64
  11465. for _, item := range prescriptions {
  11466. ids = append(ids, item.ID)
  11467. }
  11468. fmt.Println(ids)
  11469. var total float64
  11470. for _, item := range prescriptions {
  11471. fmt.Println(item)
  11472. if item.Type == 1 { //药品
  11473. for _, subItem := range item.HisDoctorAdviceInfo {
  11474. total = total + (subItem.Price * subItem.PrescribingNumber)
  11475. }
  11476. }
  11477. if item.Type == 2 { //项目
  11478. for _, subItem := range item.HisPrescriptionProject {
  11479. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11480. total = total + (subItem.Price * cnt)
  11481. }
  11482. }
  11483. for _, subItem := range item.HisAdditionalCharge {
  11484. total = total + (subItem.Price * float64(subItem.Count))
  11485. }
  11486. }
  11487. allTotal := fmt.Sprintf("%.2f", total)
  11488. totals, _ := strconv.ParseFloat(allTotal, 64)
  11489. order := &models.HisOrder{
  11490. UserOrgId: adminUser.CurrentOrgId,
  11491. HisPatientId: his.ID,
  11492. PatientId: id,
  11493. SettleAccountsDate: recordDateTime,
  11494. Ctime: time.Now().Unix(),
  11495. Mtime: time.Now().Unix(),
  11496. Status: 1,
  11497. OrderStatus: 1,
  11498. MdtrtId: his.Number,
  11499. Number: chrg_bchno,
  11500. MedfeeSumamt: totals,
  11501. SettleEndTime: end_time,
  11502. SettleStartTime: start_time,
  11503. SettleType: settle_accounts_type,
  11504. PsnPartAmt: totals,
  11505. PsnCashPay: totals,
  11506. PType: 2,
  11507. IsPre: 1,
  11508. MedType: strconv.Itoa(int(reg_type)),
  11509. Diagnosis: diagnosis_id,
  11510. }
  11511. err = service.CreateOrder(order)
  11512. if err != nil {
  11513. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11514. return
  11515. }
  11516. var customs []*Custom
  11517. for _, item := range prescriptions {
  11518. fmt.Println(item.Type)
  11519. if item.Type == 1 { //药品
  11520. for _, subItem := range item.HisDoctorAdviceInfo {
  11521. cus := &Custom{
  11522. AdviceId: subItem.ID,
  11523. ProjectId: 0,
  11524. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11525. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11526. FeedetlSn: subItem.FeedetlSn,
  11527. Price: fmt.Sprintf("%.2f", subItem.Price),
  11528. MedListCodg: subItem.MedListCodg,
  11529. Type: 1,
  11530. }
  11531. customs = append(customs, cus)
  11532. }
  11533. }
  11534. if item.Type == 2 { //项目
  11535. for _, subItem := range item.HisPrescriptionProject {
  11536. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11537. cus := &Custom{
  11538. AdviceId: 0,
  11539. ProjectId: subItem.ID,
  11540. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11541. Cut: fmt.Sprintf("%.2f", cnt),
  11542. FeedetlSn: subItem.FeedetlSn,
  11543. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11544. MedListCodg: subItem.MedListCodg,
  11545. Type: 2,
  11546. }
  11547. customs = append(customs, cus)
  11548. }
  11549. }
  11550. for _, item := range item.HisAdditionalCharge {
  11551. cus := &Custom{
  11552. ItemId: item.ID,
  11553. AdviceId: 0,
  11554. ProjectId: 0,
  11555. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11556. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11557. FeedetlSn: item.FeedetlSn,
  11558. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11559. MedListCodg: item.XtHisAddtionConfig.Code,
  11560. Type: 3,
  11561. }
  11562. customs = append(customs, cus)
  11563. }
  11564. }
  11565. fmt.Println(customs)
  11566. for _, item := range customs {
  11567. var advice_id int64 = 0
  11568. var project_id int64 = 0
  11569. var item_id int64 = 0
  11570. var types int64 = 0
  11571. if item.Type == 1 {
  11572. advice_id = item.AdviceId
  11573. project_id = 0
  11574. item_id = 0
  11575. } else if item.Type == 2 {
  11576. advice_id = 0
  11577. item_id = 0
  11578. project_id = item.ProjectId
  11579. } else if item.Type == 3 {
  11580. advice_id = 0
  11581. item_id = item.ItemId
  11582. project_id = 0
  11583. }
  11584. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11585. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11586. pric, _ := strconv.ParseFloat(item.Price, 32)
  11587. info := &models.HisOrderInfo{
  11588. OrderNumber: order.Number,
  11589. UploadDate: time.Now().Unix(),
  11590. AdviceId: advice_id,
  11591. DetItemFeeSumamt: detItemFeeSumamt,
  11592. Cnt: cut,
  11593. Pric: pric,
  11594. PatientId: id,
  11595. Status: 1,
  11596. Mtime: time.Now().Unix(),
  11597. Ctime: time.Now().Unix(),
  11598. UserOrgId: adminUser.CurrentOrgId,
  11599. HisPatientId: his.ID,
  11600. OrderId: order.ID,
  11601. ProjectId: project_id,
  11602. Type: types,
  11603. ItemId: item_id,
  11604. }
  11605. service.CreateOrderInfo(info)
  11606. }
  11607. his.SickType = sick_type
  11608. service.UpdataHisPateint(&his)
  11609. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11610. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11611. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11612. if err == nil {
  11613. c.ServeSuccessJSON(map[string]interface{}{
  11614. "msg": "结算成功",
  11615. })
  11616. }
  11617. }
  11618. type CustomOrderInfo struct {
  11619. Name string
  11620. Spec string
  11621. Unit string
  11622. Count float64
  11623. Price float64
  11624. Total float64
  11625. }
  11626. func (c *HisApiController) GetPrivateExpensesInfo() {
  11627. order_id, _ := c.GetInt64("id", 0)
  11628. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11629. order, _ := service.GetHisOrderByID(order_id)
  11630. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11631. if order.ID == 0 {
  11632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11633. return
  11634. }
  11635. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11636. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11637. org_id := c.GetAdminUserInfo().CurrentOrgId
  11638. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11639. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11640. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11641. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11642. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11643. //var orderInfos_four []*models.HisOrderInfoTwo
  11644. //for _, item := range orderInfos_three {
  11645. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11646. // item.HisPrescriptionProject.IsCheckTeam = 1
  11647. // orderInfos_four = append(orderInfos_four, item)
  11648. //
  11649. // }
  11650. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11651. // item.HisPrescriptionProject.IsCheckTeam = 2
  11652. // orderInfos_two = append(orderInfos_two, item)
  11653. // }
  11654. //}
  11655. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11656. //var cus_slice []CustomOrderInfo
  11657. //for _, item := range new_order_info {
  11658. // var cus CustomOrderInfo
  11659. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11660. // cus.Unit = ""
  11661. // cus.Spec = ""
  11662. // var total float64
  11663. // for _, subItem := range orderInfos_four {
  11664. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11665. // total = total + subItem.DetItemFeeSumamt
  11666. // fmt.Println(subItem.DetItemFeeSumamt)
  11667. // }
  11668. // }
  11669. // cus.Count = 1
  11670. // cus.Total = total
  11671. // cus_slice = append(cus_slice, cus)
  11672. //}
  11673. orderInfos = append(orderInfos, orderInfos_two...)
  11674. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11675. //orderInfos = append(orderInfos, orderInfos_three...)
  11676. //}/**/
  11677. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11678. c.ServeSuccessJSON(map[string]interface{}{
  11679. "order": order,
  11680. "order_info": orderInfos,
  11681. "patient": patient,
  11682. "admin_info": adminInfo,
  11683. "his": his,
  11684. "current_admin": role,
  11685. "org_config": miConfig,
  11686. //"new_order_info": cus_slice,
  11687. })
  11688. }
  11689. func (this *HisApiController) ChangeMedType() {
  11690. med_type := this.GetString("med_type")
  11691. old_med_type := this.GetString("old_med_type")
  11692. ids := this.GetString("ids")
  11693. settle_type, _ := this.GetInt64("settle_type")
  11694. start_time := this.GetString("start_time")
  11695. end_time := this.GetString("end_time")
  11696. ids_arr := strings.Split(ids, ",")
  11697. if settle_type == 1 { //日结
  11698. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11699. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11700. prescription.MedType = med_type
  11701. err := service.SaveHisPrescriptionTwo(&prescription)
  11702. if err == nil {
  11703. this.ServeSuccessJSON(map[string]interface{}{
  11704. "msg": "修改成功",
  11705. })
  11706. } else {
  11707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11708. return
  11709. }
  11710. } else if settle_type == 2 {
  11711. timeLayout := "2006-01-02"
  11712. loc, _ := time.LoadLocation("Local")
  11713. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11714. if err != nil {
  11715. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11716. return
  11717. }
  11718. recordStartTime := theStartTime.Unix()
  11719. start_time_timestamp := recordStartTime
  11720. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11721. if err != nil {
  11722. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11723. return
  11724. }
  11725. recordEndTime := theEndTime.Unix()
  11726. end_time_timestamp := recordEndTime
  11727. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11728. if updateErr == nil {
  11729. this.ServeSuccessJSON(map[string]interface{}{
  11730. "msg": "修改成功",
  11731. })
  11732. } else {
  11733. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11734. return
  11735. }
  11736. }
  11737. }
  11738. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11739. patient_id, _ := c.GetInt64("patient_id")
  11740. his_patient_id, _ := c.GetInt64("his_patient_id")
  11741. record_date := c.GetString("record_date")
  11742. start_time := c.GetString("start_time")
  11743. end_time := c.GetString("end_time")
  11744. order_status, _ := c.GetInt64("type", 0)
  11745. p_type, _ := c.GetInt64("p_type", 0)
  11746. order_id, _ := c.GetInt64("order_id", 0)
  11747. timeLayout := "2006-01-02"
  11748. loc, _ := time.LoadLocation("Local")
  11749. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11750. if err != nil {
  11751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11752. return
  11753. }
  11754. recordDateTime := theTime.Unix()
  11755. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11756. if err != nil {
  11757. }
  11758. startRecordDateTime := startTime.Unix()
  11759. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11760. if err != nil {
  11761. }
  11762. endRecordDateTime := endTime.Unix()
  11763. admin := c.GetAdminUserInfo()
  11764. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11765. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11766. order, _ := service.GetHisOrderByID(order_id)
  11767. var monthPrescriptions []*models.HisPrescription
  11768. if order_status == 1 || order_status == 0 {
  11769. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11770. } else if order_status == 2 {
  11771. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11772. }
  11773. var settle_total float64
  11774. for _, item := range monthPrescriptions {
  11775. if len(item.HisPrescriptionProject) > 0 {
  11776. for _, subItem := range item.HisPrescriptionProject {
  11777. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11778. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11779. settle_total = settle_total + total
  11780. }
  11781. }
  11782. if len(item.HisDoctorAdviceInfo) > 0 {
  11783. for _, subItem := range item.HisDoctorAdviceInfo {
  11784. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11785. settle_total = settle_total + total
  11786. }
  11787. }
  11788. }
  11789. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11790. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11791. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11792. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11793. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11794. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11795. //获取所有科室信息
  11796. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11797. var dia string
  11798. for _, item := range month_p_info {
  11799. if len(dia) == 0 {
  11800. dia = item.Diagnosis
  11801. } else {
  11802. dia = dia + "," + item.Diagnosis
  11803. }
  11804. }
  11805. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11806. dia_arr = removeEmptyStrings(dia_arr)
  11807. c.ServeSuccessJSON(map[string]interface{}{
  11808. "his_info": his_patient_info,
  11809. "xt_info": xt_patient_info,
  11810. "case_history": case_history,
  11811. "info": patientPrescriptionInfo,
  11812. "last_info": lastPatientPrescriptionInfo,
  11813. "month_prescriptions": monthPrescriptions,
  11814. "order": order,
  11815. "doctors": doctors,
  11816. "department": department,
  11817. "settle_total": settle_total,
  11818. "dia_arr": dia_arr,
  11819. })
  11820. return
  11821. }
  11822. func removeEmptyStrings(input []string) []string {
  11823. var output []string
  11824. for _, s := range input {
  11825. if s != "" {
  11826. output = append(output, s)
  11827. }
  11828. }
  11829. return output
  11830. }
  11831. func removeDuplicates(input []string) []string {
  11832. seen := make(map[string]bool)
  11833. output := []string{}
  11834. for _, s := range input {
  11835. if _, exists := seen[s]; !exists {
  11836. seen[s] = true
  11837. output = append(output, s)
  11838. }
  11839. }
  11840. return output
  11841. }
  11842. func (c *HisApiController) GetHisMonthPatientInfo() {
  11843. patient_id, _ := c.GetInt64("patient_id")
  11844. his_patient_id, _ := c.GetInt64("his_patient_id")
  11845. record_date := c.GetString("record_date")
  11846. number := c.GetString("number")
  11847. start_time := c.GetString("start_time")
  11848. end_time := c.GetString("end_time")
  11849. p_type, _ := c.GetInt64("p_type")
  11850. timeLayout := "2006-01-02"
  11851. loc, _ := time.LoadLocation("Local")
  11852. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11853. if err != nil {
  11854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11855. return
  11856. }
  11857. recordDateTime := theTime.Unix()
  11858. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11859. if err != nil {
  11860. }
  11861. startRecordDateTime := startTime.Unix()
  11862. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11863. if err != nil {
  11864. }
  11865. endRecordDateTime := endTime.Unix()
  11866. admin := c.GetAdminUserInfo()
  11867. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11868. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11869. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11870. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11871. var settle_total float64
  11872. for _, item := range monthPrescriptions {
  11873. if len(item.HisPrescriptionProject) > 0 {
  11874. for _, subItem := range item.HisPrescriptionProject {
  11875. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11876. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11877. settle_total = settle_total + total
  11878. }
  11879. }
  11880. if len(item.HisDoctorAdviceInfo) > 0 {
  11881. for _, subItem := range item.HisDoctorAdviceInfo {
  11882. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11883. settle_total = settle_total + total
  11884. }
  11885. }
  11886. }
  11887. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11888. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11889. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11890. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11891. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11892. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11893. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11894. //获取所有科室信息
  11895. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11896. c.ServeSuccessJSON(map[string]interface{}{
  11897. "his_info": his_patient_info,
  11898. "xt_info": xt_patient_info,
  11899. "case_history": case_history,
  11900. "info": patientPrescriptionInfo,
  11901. "month_prescriptions": monthPrescriptions,
  11902. "order": order,
  11903. "doctors": doctors,
  11904. "department": department,
  11905. "count": count,
  11906. "drugStockConfig": drugStockConfig,
  11907. "last_info": lastPatientPrescriptionInfo,
  11908. "settle_total": settle_total,
  11909. })
  11910. return
  11911. }
  11912. func (c *HisApiController) GetAllOrder() {
  11913. org_id := c.GetAdminUserInfo().CurrentOrgId
  11914. orders, _ := service.GetNewHisOrderList(org_id)
  11915. c.ServeSuccessJSON(map[string]interface{}{
  11916. "order": orders,
  11917. })
  11918. return
  11919. }
  11920. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11921. newArr = make([]*models.HisOrderInfoTwo, 0)
  11922. for i := 0; i < len(arr); i++ {
  11923. repeat := false
  11924. for j := i + 1; j < len(arr); j++ {
  11925. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11926. repeat = true
  11927. break
  11928. }
  11929. }
  11930. if !repeat {
  11931. newArr = append(newArr, arr[i])
  11932. }
  11933. }
  11934. return
  11935. }
  11936. // 修改处方退库操作 参数传修改之前的处方数据
  11937. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11938. if advice.ExecutionState == 1 {
  11939. //查询该病人该药品是否有库存记录
  11940. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11941. if errcode == gorm.ErrRecordNotFound {
  11942. } else {
  11943. //退库
  11944. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11945. if advice.PrescribingNumberUnit == drug.MinUnit {
  11946. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11947. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11948. //退库
  11949. warehouseInfo := models.DrugWarehouseInfo{
  11950. StockMinNumber: prescribingNumber,
  11951. }
  11952. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11953. operation_time := time.Now().Unix()
  11954. creater := advice.AdviceDoctor
  11955. ctime := time.Now().Unix()
  11956. timeStr := time.Now().Format("2006-01-02")
  11957. timeArr := strings.Split(timeStr, "-")
  11958. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11959. total = total + 1
  11960. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11961. cancelStock := models.DrugCancelStock{
  11962. OrderNumber: orderNumber,
  11963. OperaTime: operation_time,
  11964. OrgId: advice.UserOrgId,
  11965. Creater: creater,
  11966. Ctime: ctime,
  11967. Status: 1,
  11968. ReturnTime: advice.AdviceDate,
  11969. Dealer: info.Dealer,
  11970. Manufacturer: info.Manufacturer,
  11971. Type: 1,
  11972. }
  11973. service.AddSigleDrugCancelStock(&cancelStock)
  11974. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11975. dealer, _ := service.GetDealerById(info.Dealer)
  11976. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11977. cancelStockInfo := models.DrugCancelStockInfo{
  11978. OrderNumber: cancelInfo.OrderNumber,
  11979. CancelStockId: cancelInfo.ID,
  11980. DrugId: info.DrugId,
  11981. Count: info.Count,
  11982. Status: 1,
  11983. Ctime: ctime,
  11984. OrgId: advice.UserOrgId,
  11985. Type: 1,
  11986. Manufacturer: manufactureName.ManufacturerName,
  11987. Dealer: dealer.DealerName,
  11988. Total: 0,
  11989. RetailPrice: info.RetailPrice,
  11990. RetailTotalPrice: info.RetailTotalPrice,
  11991. Price: info.Price,
  11992. RegisterAccount: "",
  11993. Remark: info.Remark,
  11994. BatchNumber: info.BatchNumber,
  11995. MaxUnit: info.CountUnit,
  11996. ProductDate: info.ProductDate,
  11997. ExpiryDate: info.ExpiryDate,
  11998. BatchNumberId: info.WarehouseInfoId,
  11999. }
  12000. flow := models.DrugFlow{
  12001. WarehousingId: 0,
  12002. DrugId: info.DrugId,
  12003. Number: "",
  12004. BatchNumber: info.BatchNumber,
  12005. Count: info.Count,
  12006. UserOrgId: advice.UserOrgId,
  12007. PatientId: 0,
  12008. SystemTime: ctime,
  12009. ConsumableType: 4,
  12010. IsSys: 0,
  12011. WarehousingOrder: "",
  12012. WarehouseOutId: 0,
  12013. WarehouseOutOrderNumber: "",
  12014. IsEdit: 0,
  12015. CancelStockId: cancelStock.ID,
  12016. CancelOrderNumber: cancelStock.OrderNumber,
  12017. Manufacturer: info.Manufacturer,
  12018. Dealer: info.Dealer,
  12019. Creator: advice.UserOrgId,
  12020. UpdateCreator: 0,
  12021. Status: 1,
  12022. Ctime: time.Now().Unix(),
  12023. Mtime: 0,
  12024. Price: info.Price,
  12025. WarehousingDetailId: 0,
  12026. WarehouseOutDetailId: 0,
  12027. CancelOutDetailId: 0,
  12028. ExpireDate: info.ExpiryDate,
  12029. ProductDate: info.ProductDate,
  12030. MaxUnit: info.CountUnit,
  12031. MinUnit: "",
  12032. }
  12033. service.CreatedCancelStock(cancelStockInfo)
  12034. service.CreateDrugFlowOne(flow)
  12035. } else {
  12036. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12037. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12038. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12039. warehouseInfo := models.DrugWarehouseInfo{
  12040. StockMinNumber: prescribingNumber,
  12041. }
  12042. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12043. }
  12044. operation_time := time.Now().Unix()
  12045. creater := advice.AdviceDoctor
  12046. ctime := time.Now().Unix()
  12047. timeStr := time.Now().Format("2006-01-02")
  12048. timeArr := strings.Split(timeStr, "-")
  12049. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12050. total = total + 1
  12051. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12052. cancelStock := models.DrugCancelStock{
  12053. OrderNumber: orderNumber,
  12054. OperaTime: operation_time,
  12055. OrgId: advice.UserOrgId,
  12056. Creater: creater,
  12057. Ctime: ctime,
  12058. Status: 1,
  12059. ReturnTime: advice.AdviceDate,
  12060. Dealer: info.Dealer,
  12061. Manufacturer: info.Manufacturer,
  12062. Type: 1,
  12063. }
  12064. service.AddSigleDrugCancelStock(&cancelStock)
  12065. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12066. dealer, _ := service.GetDealerById(info.Dealer)
  12067. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12068. cancelStockInfo := models.DrugCancelStockInfo{
  12069. OrderNumber: cancelInfo.OrderNumber,
  12070. CancelStockId: cancelInfo.ID,
  12071. DrugId: info.DrugId,
  12072. Count: info.Count,
  12073. Status: 1,
  12074. Ctime: ctime,
  12075. OrgId: advice.UserOrgId,
  12076. Type: 1,
  12077. Manufacturer: manufactureName.ManufacturerName,
  12078. Dealer: dealer.DealerName,
  12079. Total: 0,
  12080. RetailPrice: info.RetailPrice,
  12081. RetailTotalPrice: info.RetailTotalPrice,
  12082. Price: info.Price,
  12083. RegisterAccount: "",
  12084. Remark: info.Remark,
  12085. BatchNumber: info.BatchNumber,
  12086. MaxUnit: info.CountUnit,
  12087. ProductDate: info.ProductDate,
  12088. ExpiryDate: info.ExpiryDate,
  12089. BatchNumberId: info.WarehouseInfoId,
  12090. }
  12091. flow := models.DrugFlow{
  12092. WarehousingId: 0,
  12093. DrugId: info.DrugId,
  12094. Number: "",
  12095. BatchNumber: info.BatchNumber,
  12096. Count: info.Count,
  12097. UserOrgId: advice.UserOrgId,
  12098. PatientId: 0,
  12099. SystemTime: ctime,
  12100. ConsumableType: 4,
  12101. IsSys: 0,
  12102. WarehousingOrder: "",
  12103. WarehouseOutId: 0,
  12104. WarehouseOutOrderNumber: "",
  12105. IsEdit: 0,
  12106. CancelStockId: cancelStock.ID,
  12107. CancelOrderNumber: cancelStock.OrderNumber,
  12108. Manufacturer: info.Manufacturer,
  12109. Dealer: info.Dealer,
  12110. Creator: advice.AdviceDoctor,
  12111. UpdateCreator: 0,
  12112. Status: 1,
  12113. Ctime: time.Now().Unix(),
  12114. Mtime: 0,
  12115. Price: info.Price,
  12116. WarehousingDetailId: 0,
  12117. WarehouseOutDetailId: 0,
  12118. CancelOutDetailId: 0,
  12119. ExpireDate: info.ExpiryDate,
  12120. ProductDate: info.ProductDate,
  12121. MaxUnit: info.CountUnit,
  12122. MinUnit: "",
  12123. }
  12124. service.CreatedCancelStock(cancelStockInfo)
  12125. service.CreateDrugFlowOne(flow)
  12126. }
  12127. }
  12128. }
  12129. return err
  12130. }
  12131. func (this *HisApiController) DeleteNCDS() {
  12132. id, _ := this.GetInt64("id", 0)
  12133. if id > 0 {
  12134. service.DeletePsnNCDSRecordById(id)
  12135. this.ServeSuccessJSON(map[string]interface{}{
  12136. "msg": "删除成功",
  12137. })
  12138. } else {
  12139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12140. return
  12141. }
  12142. }
  12143. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12144. id, _ := c.GetInt64("id")
  12145. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12146. c.ServeSuccessJSON(map[string]interface{}{
  12147. "advice": advice,
  12148. })
  12149. return
  12150. }
  12151. func (c *HisApiController) GetHisMonthChargePatientList() {
  12152. record_date := c.GetString("record_date")
  12153. start_time := c.GetString("start_time")
  12154. end_time := c.GetString("end_time")
  12155. timeLayout := "2006-01-02"
  12156. loc, _ := time.LoadLocation("Local")
  12157. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12158. if err != nil {
  12159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12160. return
  12161. }
  12162. if err != nil {
  12163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12164. return
  12165. }
  12166. recordDateTime := theTime.Unix()
  12167. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12168. if err != nil {
  12169. }
  12170. startRecordDateTime := startTime.Unix()
  12171. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12172. if err != nil {
  12173. }
  12174. endRecordDateTime := endTime.Unix()
  12175. adminInfo := c.GetAdminUserInfo()
  12176. var tempMonthChargePatients []*service.MonthChargePatients
  12177. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12178. for _, item := range tempPatients {
  12179. //过滤没有处方的
  12180. if len(item.HisPrescription) == 0 {
  12181. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12182. }
  12183. }
  12184. c.ServeSuccessJSON(map[string]interface{}{
  12185. "list": tempMonthChargePatients,
  12186. })
  12187. }
  12188. // PrescriptionDifference 医嘱数量差值结构体
  12189. type PrescriptionDrugDifference struct {
  12190. DrugID int64 //基础库药品id
  12191. ID int64 //医嘱id
  12192. Difference float64 //差值
  12193. Unit string //单位
  12194. }
  12195. type PrescriptionGoodDifference struct {
  12196. GoodID int64 //基础库项目耗材id
  12197. ID int64 //医嘱id
  12198. Difference int64 //差值
  12199. Unit string //单位
  12200. Type int64 //类型
  12201. }
  12202. type EditCustomData struct {
  12203. adviceList []*models.HisDoctorAdviceInfo
  12204. projectList []*models.HisPrescriptionProject
  12205. }
  12206. type SrcCustomData struct {
  12207. adviceList []*models.HisDoctorAdviceInfo
  12208. projectList []*models.HisPrescriptionProject
  12209. }
  12210. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12211. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12212. differences := make([]*PrescriptionDrugDifference, 0)
  12213. // 创建一个 map 来存储第一个切片中的药品信息
  12214. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12215. for _, advice := range firstPrescription {
  12216. firstMap[advice.DrugId] = advice
  12217. }
  12218. // 遍历第二个切片中的药品信息,并比较数量差值
  12219. for _, advice := range secondPrescription {
  12220. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12221. diff := &PrescriptionDrugDifference{
  12222. DrugID: advice.DrugId,
  12223. ID: firstAdvice.ID,
  12224. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12225. Unit: firstAdvice.PrescribingNumberUnit,
  12226. }
  12227. differences = append(differences, diff)
  12228. }
  12229. }
  12230. return differences
  12231. }
  12232. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12233. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12234. differences := make([]*PrescriptionGoodDifference, 0)
  12235. // 创建一个 map 来存储第一个切片中的耗材信息
  12236. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12237. for _, good := range firstPrescription {
  12238. firstMap[good.ProjectId] = good
  12239. }
  12240. // 遍历第二个切片中的耗材信息,并比较数量差值
  12241. for _, good := range secondPrescription {
  12242. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12243. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12244. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12245. diff := &PrescriptionGoodDifference{
  12246. GoodID: good.ProjectId,
  12247. ID: firstGood.ID,
  12248. Difference: count - firstCount,
  12249. Unit: firstGood.Unit,
  12250. Type: firstGood.Type,
  12251. }
  12252. differences = append(differences, diff)
  12253. }
  12254. }
  12255. return differences
  12256. }
  12257. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12258. var adviceList []*models.HisDoctorAdviceInfo
  12259. var projectList []*models.HisPrescriptionProject
  12260. var advice_ids []int64
  12261. var project_ids []int64
  12262. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12263. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12264. //var tempPrescription *models.HisPrescriptionProjectscription
  12265. if len(prescriptions) > 0 {
  12266. for _, item := range prescriptions {
  12267. items := item.(map[string]interface{})
  12268. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12269. advices := items["advices"].([]interface{})
  12270. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12271. groupNo := int64(0)
  12272. ctime := time.Now().Unix()
  12273. mtime := ctime
  12274. if len(advices) > 0 {
  12275. for _, advice := range advices {
  12276. var s models.HisDoctorAdviceInfo
  12277. s.AdviceType = 2
  12278. s.StopState = 2
  12279. s.ExecutionState = 2
  12280. s.Status = 1
  12281. s.Groupno = groupNo
  12282. s.CreatedTime = ctime
  12283. s.UpdatedTime = mtime
  12284. s.IsSettle = 2
  12285. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12286. //存储切片中
  12287. if s.ID > 0 {
  12288. advice_ids = append(advice_ids, s.ID)
  12289. adviceList = append(adviceList, &s)
  12290. }
  12291. }
  12292. }
  12293. }
  12294. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12295. projects := items["project"].([]interface{})
  12296. if len(projects) > 0 {
  12297. for _, project := range projects {
  12298. var p models.HisPrescriptionProject
  12299. p.Ctime = time.Now().Unix()
  12300. p.Mtime = time.Now().Unix()
  12301. p.Status = 1
  12302. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12303. if p.ID > 0 {
  12304. project_ids = append(project_ids, p.ID)
  12305. projectList = append(projectList, &p)
  12306. }
  12307. }
  12308. }
  12309. }
  12310. }
  12311. }
  12312. }
  12313. editCustomData.projectList = projectList
  12314. editCustomData.adviceList = adviceList
  12315. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12316. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12317. srcCustomData.adviceList = list
  12318. srcCustomData.projectList = list2
  12319. return
  12320. }